📄 davraloc.c
字号:
### on the object, the old object is erased. If the object is of
### type Level2, no copies are made and the object's data is
### erased from object space.
###
### PARAMETERS:
### obj_info_ptr - IN: Info structure contains valid name,
### type, security key,and privilege level.
### OUT: All information on the new header state
### is returned.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
ERR_CODE FDI_ReAllocateFlash( FDI_ObjectInfoPtr obj_info_ptr )
{
FDI_Handle old_start_addr;
FDI_Handle new_start_addr;
ERR_CODE status;
HDR_CompareInfo compare_info;
UINT16 save_page_object_counter;
/* Multitasking API exclusivity. (This may not be necessary to the
full extent as it is done here, but for now it is the safest way.) */
/* Check range of ObjectType */
if(obj_info_ptr->ObjectType < MIN_DAV_TYPE )
{
return ERR_PARAM;
}
FDI_APILock();
#ifdef ENABLE_REALLOCATE_TESTS
#ifdef DISABLE_REALLOCATE_POWERLOSS
EVT_EventElement tmp_event_value;
//Get Current State of Random Powerloss
tmp_event_value = EVT_EventList[EVT_FLASH_RandomFail];
//Disable PowerLoss
EVT_ClrEnabled(EVT_FLASH_RandomFail);
#endif
#endif
/* set recovery level to FDI_PLR_Level0 always */
obj_info_ptr->RecoveryLevel = FDI_PLR_Level0;
/* set alignment to page */
obj_info_ptr->Alignment = FDI_ALIGN_Page;
/* A WIP object exists, do not allow allocation or
* reallocation until the object is complete.
*/
if (FDI_LockoutObjectAllocation)
{
FDI_APIUnlock();
return ERR_WIP;
}
/* Clear Global flag for System State */
ClrSystemState(FDI_SystemState, FDI_ST_ReclaimFlag);
/* Verify that the desired object exists and calculate */
/* its address range. */
HDR_InitSearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));
compare_info.CompareValue = obj_info_ptr->ObjectType;
compare_info.NamePtr = (HDR_NamePtr)obj_info_ptr->Name;
compare_info.NameSize = obj_info_ptr->NameSize;
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if ( status != ERR_NONE )
{
if (status == ERR_NO_MORE_ENTRIES)
{
status = ERR_NOTEXISTS;
}
FDI_APIUnlock();
return status;
}
/* Store information from search into obj_info_ptr, for creating a backup */
HDR_SearchInfo2ObjectInfo(obj_info_ptr, &FDI_SearchInfo);
/* Make sure the object does not have WriteInProgress for */
/* status. */
if (HDR_GetStatusAttr(FDI_SearchInfo.HeaderPtr->Attr16) ==
HDR_HA_WriteInProgress)
{
FDI_APIUnlock();
return ERR_PARAM;
}
else
{
/* Prevent from Reallocating the same object twice at once.
* Search for another object after the first.
*/
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
FDI_APIUnlock();
return(status);
}
if (status == ERR_NONE)
{
FDI_APIUnlock();
/* Found a second header already existing */
return ERR_EXISTS;
}
else
{
/* Didn't find a second header, reset FDI_SearchInfo to original */
/* This is done below to reduce code */
}
}
/* If PLRLevel == 0 or 1, then allocate a new object. */
if ((obj_info_ptr->RecoveryLevel == FDI_PLR_Level0) ||
(obj_info_ptr->RecoveryLevel == FDI_PLR_Level1))
{
FDI_ReAllocateOverrideFlag = TRUE;
/* Save the counter for number of page objects in flash */
save_page_object_counter = FDI_PageObjectCounter;
status = AllocateFlash(obj_info_ptr);
/* Restore the counter for number of page objects in flash */
FDI_PageObjectCounter = save_page_object_counter;
FDI_ReAllocateOverrideFlag = FALSE;
if (status)
{
FDI_APIUnlock();
return status;
}
/* Re-Search for the first one just in case reclaim */
/* occurred when this object was allocated. */
FDI_SearchInfo.CurrObj.HeaderAddress = 0;
FDI_SearchInfo.CurrObj.ConfigEntry.Status = 0;
FDI_SearchInfo.CurrObj.ConfigEntry.Offset = 0;
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if ( status != ERR_NONE )
{
if (status == ERR_NO_MORE_ENTRIES)
{
status = ERR_SYSTEM;
}
FDI_APIUnlock();
return status;
}
old_start_addr = FDI_SearchInfo.CurrObj.ObjectAddress;
/* Calculate the address of the new object */
/* (start search from the last object). */
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if (status)
{
if (status == ERR_NO_MORE_ENTRIES)
{
status = ERR_SYSTEM;
}
FDI_APIUnlock();
return status;
}
new_start_addr = FDI_SearchInfo.CurrObj.ObjectAddress;
/* Copy the old object to the new object */
status = FLASH_CopyFlash(old_start_addr, new_start_addr,
FDI_SearchInfo.CurrObj.ObjectSize);
if (status)
{
FDI_APIUnlock();
return(status);
}
/* Mark attributes to Backup Complete */
FDI_SearchInfo.HeaderPtr->Attr16 =
HDR_SetBackupCompleteAttr(FDI_SearchInfo.HeaderPtr->Attr16,
HDR_HA_BackupComplete);
/* Write new attr to header in flash */
status = FLASH_WriteBuffer(
FDI_SearchInfo.CurrObj.HeaderAddress + HDR_Attrib16Offset,
(MemBufferPtr)&(FDI_SearchInfo.HeaderPtr->Attr16),
HDR_Attrib16Size);
if (status)
{
FDI_APIUnlock();
return(status);
}
}
/* Must re-read the original object */
/* May of had reclaim for level 0 or 1. */
/* Also re-finds original for error check above */
FDI_SearchInfo.CurrObj.HeaderAddress = 0;
FDI_SearchInfo.CurrObj.ConfigEntry.Status = 0;
FDI_SearchInfo.CurrObj.ConfigEntry.Offset = 0;
status = GetNextHeader(&FDI_SearchInfo, HDR_ByNameType, &compare_info, FALSE);
if ( status != ERR_NONE )
{
if (status == ERR_NO_MORE_ENTRIES)
{
/* At this point the original header has already been found once*/
status = ERR_SYSTEM;
}
FDI_APIUnlock();
return status;
}
/* A WIP object exists, do not allow allocation or */
/* reallocation until the object is complete. */
if ((obj_info_ptr->RecoveryLevel == FDI_PLR_Level0) ||
(obj_info_ptr->RecoveryLevel == FDI_PLR_Level1))
{
FDI_LockoutObjectAllocation = TRUE;
}
/* Load obj_info with current location of orignal object */
HDR_SearchInfo2ObjectInfo(obj_info_ptr, &FDI_SearchInfo);
#ifdef ENABLE_REALLOCATE_TESTS
#ifdef DISABLE_REALLOCATE_POWERLOSS
//Restore original event state
EVT_EventList[EVT_FLASH_RandomFail] = tmp_event_value;
#endif
#endif
RECOVER_MarkDatabaseBusy();
/* Erase the space associated with the old object. */
status = RECINPLC_ReclaimObjectInPlace(&FDI_SearchInfo, FALSE);
if (status)
{
FDI_APIUnlock();
return status;
}
status = HDR_CalcMemoryStatistics(FALSE);
if (status)
{
FDI_APIUnlock();
return status;
}
/* must reclaim to cleanup the used reserved para space. */
if(ReclaimState.ReclaimInProgress != TRUE)
status = RECLAIM_Cleanup(ReclaimParagraphObjects, FALSE);
RECOVER_MarkDatabaseReady();
FDI_APIUnlock();
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -