📄 davrecl.c
字号:
return status;
}
}
}
/* Initialize search information structure */
HDR_InitSearchInfo((&OTT_SearchInfo), (&OTT_SearchHeader));
/* Calculate the source and the destination address of the current object. */
current_dest_addr = ReclaimState.OTTTableInfo.dest_addr;
current_src_addr = ReclaimState.OTTTableInfo.src_addr;
prev_hdr_addr = 0;
prev_hdr_NameSize = 0;
/* Find the header of the first object that needs to be reallocated. */
do
{
/* To do reallocate of the moved objects, we need the object information. */
/* To get this info, do a getnextobject, until the object address matches
the dest_addr. */
for(;;)
{
status = GetNextHeader(&OTT_SearchInfo,
HDR_ByNextPageObject, &compare_info, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
if(!status)
{
/* Make sure that the interface cannot see any system objects. */
if(OTT_SearchInfo.HeaderPtr->ObjectType > FDI_HT_EndReservedTypes)
{
break;
}
}
else
{
break;
}
}
if(!status)
{
/* Need to read full header for this type of search */
status = HDR_ReadFullHeader(OTT_SearchInfo.CurrObj.HeaderAddress,
OTT_SearchInfo.HeaderPtr, restart);
if(status)
{
return status;
}
}
else
{
break;
}
/* Found the object, now translate the object information to */
/* the interface function equivalent. */
HDR_SearchInfo2ObjectInfo(&obj_info, &OTT_SearchInfo);
prev_hdr_addr = OTT_SearchInfo.CurrObj.HeaderAddress;
prev_hdr_NameSize = OTT_SearchInfo.HeaderPtr->NameSize;
/* If the dest_addr matches the object address,
then the first object that needs to be reallocated
is found. Hence exit. */
}while(ReclaimState.OTTTableInfo.dest_addr !=
obj_info.ObjectAddress);
if (status == ERR_NO_MORE_ENTRIES)
{
status = ERR_NONE;
}
}
/* end of if((ReclaimState.OTTTableInfo.dest_addr != DWORDMAX) &&
(ReclaimState.OTTTableInfo.src_addr != DWORDMAX)) */
if(status)
{
return status;
}
/* Process all the valid OTT table entries one by one and
call the call back function API, provided by the user
application. */
status = OTTTBL_ReadTable(ReclaimState.OTTTblBaseAddr,
ReclaimState.CurrentObject2Modify,
&ReclaimState.OTTTblEntry, restart);
if(status)
{
return status;
}
/* Do the reallocation. */
do
{
if(OTTTBL_IsOTTEntryValid(ReclaimState.OTTTblEntry.status))
{
if(restart)
{
/* Check if there is a WIP & Backup Complete object */
HDR_InitSearchInfo((&BC_SearchInfo), (&SearchHeader));
status = GetNextHeader(&BC_SearchInfo,
HDR_ByNextWriteInProgressObject,
&compare_info, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
if(!status)
{
/* Found a WIP oject, now check if it is a Backup Complete object */
if(HDR_IsBackupComplete((BC_SearchInfo.HeaderPtr->Attr16)))
{
/* Found a WIP & Backup Complete object */
WIP_BC_obj_found = TRUE;
}
else
{
/* Found a WIP & Backup not Complete object */
WIP_obj_found = TRUE;
}
}
/* Check if there is a invalid backup object */
else
{
HDR_InitSearchInfo((&BC_SearchInfo), (&SearchHeader));
do
{
invalid_backup_found = FALSE;
status = GetNextHeader(&BC_SearchInfo,
HDR_ByNextInvalidPageObject,
&compare_info, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
if(!status)
{
/* Check if this is the backup object */
if(BC_SearchInfo.HeaderPtr->ObjectType ==
OTT_SearchInfo.HeaderPtr->ObjectType)
{
/* Need to read full header for this type of search */
status = HDR_ReadFullHeader(BC_SearchInfo.CurrObj.HeaderAddress,
BC_SearchInfo.HeaderPtr, restart);
if(status)
{
return status;
}
if ((BC_SearchInfo.HeaderPtr->NameSize ==
OTT_SearchInfo.HeaderPtr->NameSize))
{
invalid_backup_found = TRUE;
for (name_index = 0;
name_index < OTT_SearchInfo.HeaderPtr->NameSize;
name_index++)
{
if (BC_SearchInfo.HeaderPtr->Name[name_index] !=
OTT_SearchInfo.HeaderPtr->Name[name_index])
{
invalid_backup_found = FALSE;
break;
}
}
}
else
{
invalid_backup_found = FALSE;
}
}
}
} while ((status != ERR_NO_MORE_ENTRIES) &&
(invalid_backup_found == FALSE));
}
}
if (!(invalid_backup_found)) /* If the backup object is not invalid */
{
if(!OTTTBL_IsObjectModified(ReclaimState.OTTTblEntry.status))
{
/* If power is off during the object is WIP and completed backup, */
/* reclaim in place original object space and copy the backup object */
/* back to the original object space. */
if(WIP_BC_obj_found) /* If there is a WIP & Backup Complete object */
{
if(restart) /* For power loss recovery process only */
{
/* Read the full header infomation of the WIP & Backup Complete object */
status = HDR_ReadFullHeader(BC_SearchInfo.CurrObj.HeaderAddress,
BC_SearchInfo.HeaderPtr, restart);
if(status)
{
return status;
}
compare_info.NamePtr =
(HDR_NamePtr)(BC_SearchInfo.HeaderPtr->Name);
compare_info.NameSize = BC_SearchInfo.HeaderPtr->NameSize;
compare_info.CompareValue = BC_SearchInfo.HeaderPtr->ObjectType;
/* Check if there is a valid original object */
HDR_InitSearchInfo((&old_obj_SearchInfo), (&old_obj_SearchHeader));
status = GetNextHeader(&old_obj_SearchInfo, HDR_ByNameType,
&compare_info, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
if (old_obj_SearchInfo.CurrObj.HeaderAddress ==
BC_SearchInfo.CurrObj.HeaderAddress)
{
/* Original header is the same as the backup header; */
/* that is, a backup but no original object was found */
return(ERR_SYSTEM);
}
else
{
/* Found original object, reclaim in place original object space */
status = RECINPLC_ReclaimObjectInPlace(&old_obj_SearchInfo, FALSE);
if (status != ERR_NONE)
{
return(status);
}
/* Copy the backup object back to the original object space */
status = FLASH_CopyFlash(BC_SearchInfo.CurrObj.ObjectAddress,
old_obj_SearchInfo.CurrObj.ObjectAddress,
old_obj_SearchInfo.CurrObj.ObjectSize);
if (status != ERR_NONE)
{
return(status);
}
}
}
}
/* Call the call back function here. */
modify_object_status =
FDI_ModifyObject((BYTE_PTR)current_dest_addr,
ReclaimState.OTTTblEntry.objsize,
(BYTE_PTR)current_src_addr,
(VOID_PTR_PTR)(&buffer_ptr));
/* If the return value is TRUE, then do object reallocate.
If the return value is FALSE, go to next state. */
if(modify_object_status == TRUE)
{
/* If There is no WIP & Backup Complete object */
if(!WIP_BC_obj_found)
{
/* If There is no WIP backup object */
if(!WIP_obj_found)
{
/* Copy the obj_info into old_obj_info. */
MemoryMove((BYTE_PTR) &old_obj_info,
(BYTE_PTR) &obj_info,
sizeof(FDI_ObjectInfo));
FDI_ReAllocateOverrideFlag = TRUE;
/* E.5.1.790 */
status = AllocateFlash(&obj_info);
/* E.5.1.790 */
FDI_ReAllocateOverrideFlag = FALSE;
if(status)
{
return status;
}
}
compare_info.CompareValue = obj_info.ObjectType;
compare_info.NamePtr = (HDR_NamePtr)obj_info.Name;
compare_info.NameSize = obj_info.NameSize;
/* Re-Search for the first one just in case reclaim */
/* occurred when this object was allocated. */
OTT_SearchInfo.CurrObj.HeaderAddress = 0;
OTT_SearchInfo.CurrObj.ConfigEntry.Offset = 0;
OTT_SearchInfo.CurrObj.ConfigEntry.Status = 0;
status = GetNextHeader(&OTT_SearchInfo, HDR_ByNameType, &compare_info, restart);
if(status != ERR_NONE)
{
if(status == ERR_NO_MORE_ENTRIES)
{
status = ERR_SYSTEM;
}
FDI_APIUnlock();
return status;
}
old_obj_info.ObjectAddress = OTT_SearchInfo.CurrObj.ObjectAddress;
/* Calculate the address of the new object */
/* (start search from the last object). */
status = GetNextHeader(&OTT_SearchInfo, HDR_ByNameType, &compare_info, restart);
if(status)
{
if(status == ERR_NO_MORE_ENTRIES)
{
status = ERR_SYSTEM;
}
FDI_APIUnlock();
return status;
}
obj_info.ObjectAddress = OTT_SearchInfo.CurrObj.ObjectAddress;
/* Copy the old object to the new object, creating backup */
status = FLASH_CopyFlash(old_obj_info.ObjectAddress,
obj_info.ObjectAddress,
PAGE_TO_BYTES(obj_info.ObjectSize));
if(status)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -