davrcvr.c
来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 1,739 行 · 第 1/5 页
C
1,739 行
(status == ERR_NONE) &&
(FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_WRITE_IN_PROGRESS) &&
(FHDR_GetReallocationStatus(&currHeader) == HDR_REALLOC_BACKUP_NOT_COMPLETE)
)
{
/* mark it as invalid */
status = FHDR_InvalidateHeaderInFlash(currHeaderHandle, &currHeader);
}
}
currHeaderHandle = SEARCH_CalcNextHdrAddr(currHeaderHandle);
} while ((status == ERR_NONE) &&
(FHDR_GetHeaderStatus(&currHeader) != HDR_HEADER_UNUSED));
if (status == ERR_NO_MORE_ENTRIES)
{
status = ERR_NONE;
}
return status;
}
/*#################################################################
### RECOVER_PAGE_ResetPageReclaimCtEntry
###
### DESCRIPTION:
### This will reset the page reclaim from allocation of the
### ct entry step.
###
### PARAMETERS
### None.
###
### 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 RECOVER_PAGE_ResetPageReclaimCtEntry()
{
ERR_CODE status;
UINT8 entryType;
/* Invalidate the PAGE_RECLAIM ct entry */
entryType = CFGTBL_CtEntryType_PAGE_RECLAIM;
status = CFGTBL_InvalidateCtEntryByStatus(entryType,
CFGTBL_CtEntryStatus_EntryValid, TRUE);
switch(status)
{
case ERR_NONE: /* Entry exists and was invalidated */
break;
case ERR_NOTEXISTS: /* Entry did not exists */
/* Invalidate the PAGE_RECLAIM ct entry */
status = CFGTBL_InvalidateCtEntryByStatus(entryType,
CFGTBL_CtEntryStatus_EntryAllocating, TRUE);
switch(status)
{
case ERR_NONE: /* Entry exists and was invalidated */
status = status;
break;
case ERR_NOTEXISTS: /* Entry did not exists */
status = status;
break;
default:
return status;
break;
} /* switch */
break;
default:
return status;
break;
} /* switch */
return status;
}
/*#################################################################
### RECOVER_PAGE_ResetDefragComplete
###
### DESCRIPTION:
### This will reset the page reclaim from the defrag complete
### step.
###
### PARAMETERS
### aRefPtr - Parameter used throughout the recovery.
###
### 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 RECOVER_PAGE_ResetDefragComplete(PAGE_RECLAIM_Address* aRefPtr, BOOLEAN* aManualRecovery)
{
ERR_CODE status = ERR_NONE;
OTTTBL_Leader ottLeader;
OTTTBL_Entry ottEntry;
FDI_Handle ottEntryHandle;
#ifdef ENABLE_RECOVER_TESTS
/*TBD EVT_TestEvent(EVT_RECOVER_RestartDefragComplete_Start);*/
#endif
/* Is the OTT missing? */
status = OTTTBL_GetFirstOttEntry(&ottEntryHandle, &ottEntry, &ottLeader);
if(status != ERR_NONE)
{
aRefPtr->startOperation = enAbortPageReclaim;
/* Yes. The cleanup occured and the ott was deleted (normal behavior in this state). */
/* However, we cannot recover using normal reclaim procedure because it */
/* is require that the OTT exists */
/* Invalidate the OTT table */
status = CFGTBL_InvalidateCtEntryByStatus(CFGTBL_CtEntryType_OTT, CFGTBL_CtEntryStatus_EntryValid, TRUE);
switch(status)
{
case ERR_NONE:
status = status;
break;
case ERR_NOTEXISTS:
status = ERR_NONE;
break;
default:
return status;
break;
} /* switch */
/* Invalidate the CTEntry for the page reclaim */
status = RECOVER_PAGE_ResetPageReclaimCtEntry(); /* Reset Defrag Complete */
if(status != ERR_NONE)
{
return status;
}
/* Set the restart step */
/* Record as a recovery, however, not through normal procedure */
*aManualRecovery = TRUE;
return ERR_NONE; /* Normal Exit */
}
aRefPtr->startOperation = enPageReclaimOperationComplete;
#ifdef ENABLE_RECOVER_TESTS
/*TBD EVT_TestEvent(EVT_RECOVER_RestartDefragComplete_End);*/
#endif
return status;
}
/*#################################################################
### RECOVER_PAGE_ResetModifyUserObjects
###
### DESCRIPTION:
### This function will reset a reallocation of object(s).
###
### PARAMETERS
### aRefPtr - Parameter used throughout the recovery.
###
### 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 RECOVER_PAGE_ResetModifyUserObjects(PAGE_RECLAIM_Address* aRefPtr)
{
#ifdef ENABLE_RECOVER_TESTS
/*TBD EVT_TestEvent(EVT_RECOVER_RestartModifyObjects_Start);*/
#endif
ERR_CODE status = ERR_NONE;
FDI_Handle ratEntryHandle = 0;
RATTBL_Entry ratEntry;
RATTBL_Leader ratLeader;
UINT32 ratIndex;
UINT16 ratEntryCount;
FDI_Handle ottHandle;
OTTTBL_Leader ottLeader;
OTTTBL_Entry ottEntry;
UINT16 ottIndex;
UINT16 ottBtmIndex;
/*Fix Start:SCR964 */
UINT16 topBlock;
/*Fix End:SCR964 */
FDI_Handle topObjectHandle;
UINT32 topObjectSizeInPages;
UINT32 bkupSizeInPages;
UINT32 groupSizeInPages;
/*Fix Start:SCR964 */
UINT16 bottomBlock;
/*Fix End:SCR964 */
UINT32 bottomObjectOffset;
FDI_Handle bottomObjectHandle;
/* PLR - REALLOCATE */
if(aRefPtr->reclaimType == enPageReallocate)
{
aRefPtr->startOperation = enModifyUserObjects;
return status; /* Normal exit */
}
/* PLR - RECLAIM-IN-PLACE */
if(aRefPtr->reclaimType == enPageReclaimInPlace)
{
/* This means we cannot recover */
aRefPtr->startOperation = enAbortPageReclaim;
/* Get the current state */
status = RATTBL_GetFirstRatEntry(&ratEntryHandle, &ratEntry, &ratLeader);
if (status != ERR_NONE)
{
return status;
}
/* Recover the current state bits & restart */
switch(RATTBL_GetRecoveredRatEntryBtmProgressState(&ratEntry, ratEntryHandle))
{
/* When calling back into modify, the top state setting will insure it will */
/* go to the proper place */
case RATTBL_RatEntryBtmProgressState_ModifyInProgress:
aRefPtr->startOperation = enModifyUserObjects;
break;
/* Anything else is an error */
default:
return ERR_STATE;
break;
} /* switch */
return status; /* Normal exit */
}
/* Assume that we can recover */
aRefPtr->startOperation = enModifyUserObjects;
status = RATTBL_GetFirstRatEntry(&ratEntryHandle, &ratEntry, &ratLeader);
if (status != ERR_NONE)
{
return status;
}
/* Check to see if there is anything to do. */
ratEntryCount = RATTBL_GetNumRows(&ratLeader);
if (ratEntryCount == 0)
{
return ERR_NONE;
}
/* Iterate through RAT to determine progress of modify objects */
for (ratIndex = 0; ratIndex < ratEntryCount; ratIndex++)
{
/* if bottom status != modifyInProgress and top status != bkupGroupReclaimComplete */
if (RATTBL_GetRecoveredRatEntryBtmProgressState(&ratEntry, ratEntryHandle) == RATTBL_RatEntryBtmProgressState_ModifyInProgress &&
RATTBL_GetRecoveredRatEntryTopProgressState(&ratEntry, ratEntryHandle) == RATTBL_RatEntryTopProgressState_ModifyUserObjectsComplete)
{
if ((ratIndex+1) < ratEntryCount)
{
/* Get next Rat Entry */
status = RATTBL_GetNextRatEntry(&ratEntryHandle, &ratEntry, &ratEntryHandle);
if (status != ERR_NONE)
{
return status;
}
}
}
else
{
/* this entry is in progress */
break;
}
} /* for */
if (ratIndex < ratEntryCount)
{
/* Set the current entry progress to a recoverable state, depending on the operation in progress */
switch (RATTBL_GetRatEntryOperation(&ratEntry))
{
case RATTBL_RatEntryOperation_ModifyWithBackup:
switch(RATTBL_GetRecoveredRatEntryBtmProgressState(&ratEntry, ratEntryHandle))
{
case RATTBL_RatEntryBtmProgressState_NoOperationInProgress:
break;
case RATTBL_RatEntryBtmProgressState_BkupOfOrigGroupInProgress:
case RATTBL_RatEntryBtmProgressState_RestartBtmBlkBkupGroupInReclaim:
case RATTBL_RatEntryBtmProgressState_RestartBtmBlkBkupGroupReclaimComplete:
case RATTBL_RatEntryBtmProgressState_RestartTopBlkBkupGroupInReclaim:
/* backups were in progress; just absorb the headers and */
/* write the backups back to exactly the same spot */
/* mark all backup objects in the group as absorbing */
status = RECLAIM_PAGE_SetBackupGroupAbsorbStatus(HDR_ABSORBING,
aRefPtr->plrRestart);
if (status != ERR_NONE)
{
return status;
}
/* mark all backup objects in the group as absorbing */
status = RECLAIM_PAGE_SetBackupGroupAbsorbStatus(HDR_ABSORBED,
aRefPtr->plrRestart);
if (status != ERR_NONE)
{
return status;
}
/* set bottom status to RestartTopBlkBkupGroupReclaimComplete */
RATTBL_SetRatEntryBtmProgressState(&ratEntry, RATTBL_RatEntryBtmProgressState_RestartTopBlkBkupGroupReclaimComplete);
status = RATTBL_WriteRatEntryBtmProgressState(&ratEntryHandle, &ratEntry);
if (status != ERR_NONE)
{
return status;
}
break;
case RATTBL_RatEntryBtmProgressState_RestartTopBlkBkupGroupReclaimComplete:
case RATTBL_RatEntryBtmProgressState_BkupOfOrigGroupComplete:
case RATTBL_RatEntryBtmProgressState_BtmBlkOrigGroupInReclaim:
case RATTBL_RatEntryBtmProgressState_BtmBlkOrigGroupReclaimComplete:
case RATTBL_RatEntryBtmProgressState_TopBlkOrigGroupInReclaim:
case RATTBL_RatEntryBtmProgressState_TopBlkOrigGroupReclaimComplete:
break;
case RATTBL_RatEntryBtmProgressState_ModifyInProgress:
if (RATTBL_GetRecoveredRatEntryTopProgressState(&ratEntry, ratEntryHandle) == RATTBL_RatEntryTopProgressState_NoOperationInProgress)
{
break;
}
switch(RATTBL_GetRecoveredRatEntryTopProgressState(&ratEntry, ratEntryHandle))
{
case RATTBL_RatEntryTopProgressState_NoOperationInProgress:
case RATTBL_RatEntryTopProgressState_ModifyComplete:
case RATTBL_RatEntryTopProgressState_BtmBlkBkupGroupInReclaim:
case RATTBL_RatEntryTopProgressState_BtmBlkBkupGroupReclaimComplete:
case RATTBL_RatEntryTopProgressState_TopBlkBkupGroupInReclaim:
case RATTBL_RatEntryTopProgressState_TopBlkBkupGroupReclaimComplete:
case RATTBL_RatEntryTopProgressState_ModifyUserObjectsComplete:
break;
default:
status = ERR_STATE;
if (status != ERR_NONE)
{
return status;
}
break;
}
break;
default:
status = ERR_STATE;
if (status != ERR_NONE)
{
return status;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?