davparecl.c
来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 765 行 · 第 1/2 页
C
765 行
while(status != ERR_NO_MORE_ENTRIES)
{
/* Is this a system object? */
if (FHDR_GetType(&result.HeaderPtr->FHdr) != FDI_HT_ConfigHeader)
{
/* Set the new location of the table (may reside in a new location) */
FHDR_SetHeaderIndexOffset(&result.HeaderPtr->FHdr, FHDR_CalcObjectOffset(aRef->currentReclaimTableHandle));
/* Write the new header */
status = FLASH_WriteBuffer(aRef->currentReclaimHeaderHandle, (UINT8*)&result.HeaderPtr->FHdr, sizeof(HDR_FixedHeader));
if(status != ERR_NONE)
{
return status;
}
/* Copy the table as is */
status = FLASH_CopyFlash(result.CurrObj.ObjectAddress, aRef->currentReclaimTableHandle, FHDR_GetSize(&result.HeaderPtr->FHdr));
if(status != ERR_NONE)
{
return status;
}
/* Move to the next empty location */
aRef->currentReclaimHeaderHandle -= sizeof(HDR_FixedHeader);
aRef->currentReclaimTableHandle += FHDR_GetSize(&result.HeaderPtr->FHdr);
}
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextValidParaObject, &compare_info, aRef->plrRestart);
} /* while */
/* This is the result if we get here */
return ERR_NONE;
}
/*#################################################################
### RECLAIM_PARAGRAPH_CopyConfigurationTable
###
### DESCRIPTION:
### This function copies the configuration table. This copy
### is called last to insure that all of the other data copy
### completed.
###
### PARAMETERS
### aRef -- Parameter used throughout the paragraph reclaim.
###
### 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 RECLAIM_PARAGRAPH_CopyConfigurationTable(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status;
HDR_Header allHeaders;
SEARCH_SearchInfo result;
SEARCH_CompareInfo compare_info;
/* Get the table */
result.HeaderPtr = &allHeaders;
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
compare_info.CompareValue = FDI_HT_ConfigHeader;
status = SEARCH_GetNextHeader(&result, SEARCH_ByValidType/*SEARCH_ByTypeOnly*/, &compare_info, aRef->plrRestart);
if(status != ERR_NONE)
{
return status;
}
/* Copy the fixed header */
status = FLASH_CopyFlash(result.CurrObj.HeaderAddress,
(FDI_Handle)(FDI_ReclaimBlockAddressTop - sizeof(HDR_FixedHeader) + 1),
sizeof(HDR_FixedHeader));
if(status != ERR_NONE)
{
return status;
}
/* The configuration table is not a direct copy, therefore, let the CFGTBL handle the specifics. */
status = CFGTBL_CopyTableToReclaim(result.CurrObj.ObjectAddress, FDI_ReclaimBlockAddressBottom);
if(status != ERR_NONE)
{
return status;
}
return status;
}
/* =========================== Level 0, 1 =============================*/
/*#################################################################
### RECLAIM_PARAGRAPH_CopyReclaimBlock
###
### DESCRIPTION:
### This function copies the reclaim table back down to paragraph
### space. It insure that the memory stats are recomputed.
###
### PARAMETERS
### aRef -- Parameter used throughout the paragraph reclaim.
###
### 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 RECLAIM_PARAGRAPH_CopyReclaimBlock(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status;
/* Perform a block copy */
status = FLASH_CopyFlash(FDI_ReclaimBlockAddressBottom, FDI_ParaSpaceAddressBottom, DAV_BLOCK_SIZE);
if(status != ERR_NONE)
{
return status;
}
/* Update the memory tracking variables now that we have our headers back in the paragraph block */
status = MEM_CalcMemoryStatistics(aRef->plrRestart);
if(status != ERR_NONE)
{
return status;
}
return status;
}
/*#################################################################
### RECLAIM_PARAGRAPH_CopyReclaimBlock
###
### DESCRIPTION:
### This function copies the paragraph block to the reclaim
### block. The copies are very specific to insure that
### we can recover with powerloss.
###
### PARAMETERS
### aRef -- Parameter used throughout the paragraph reclaim.
###
### 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 RECLAIM_PARAGRAPH_CopyParagraphBlock(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status;
status = RECLAIM_PARAGRAPH_ParagraphHeaderRelocate(aRef);
if(status != ERR_NONE)
{
return status;
}
status = RECLAIM_PARAGRAPH_CopyNormalFixedHeaders(aRef);
if(status != ERR_NONE)
{
return status;
}
status = RECLAIM_PARAGRAPH_CopySystemFixedHeaders(aRef);
if(status != ERR_NONE)
{
return status;
}
status = RECLAIM_PARAGRAPH_CopyConfigurationTable(aRef);
if(status != ERR_NONE)
{
return status;
}
/* State Transistion */
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_CopyOutComplete);
if(status != ERR_NONE)
{
return status;
}
return status;
}
/* =========================== Public Functions =============================*/
/*#################################################################
### RECLAIM_PARAGRAPH_StartReclaim
###
### DESCRIPTION:
### This function start the real paragraph reclaim based on
### parameters sent with the call.
###
### PARAMETERS
### aRef -- Parameter used throughout the paragraph reclaim.
###
### 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 RECLAIM_PARAGRAPH_StartReclaim(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status;
/* If we do not start at the very beginning, then we are recovering from a powerloss */
if(aRef->startOperation != enStartOfParagraphReclaim)
{
aRef->plrRestart = TRUE;
}
else
{
aRef->plrRestart = FALSE;
}
/* Headers are started from the top and proceeds down */
aRef->currentReclaimHeaderHandle = FDI_ReclaimBlockAddressTop;
/* Tables are started from the bottom and proceeds up */
aRef->currentReclaimTableHandle = FDI_ReclaimBlockAddressBottom;
/* Jump into the appropriate start point */
switch(aRef->startOperation)
{
case enStartOfParagraphReclaim:
case enCopyParagraphSpaceToReclaimBlock:
/* First state change indicate the type of reclaim */
if(aRef->userRequest == enPerformHeaderRelocate)
{
/* Complex reclaim used only with the page reclaim */
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_RelocateInProgress);
if(status != ERR_NONE)
{
break;
}
}
else if(aRef->userRequest == enPerformCfgEntryReclaim)
{
/* Simple reclaim called from a page reclaim and the API */
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_ReclaimInProgress);
if(status != ERR_NONE)
{
break;
}
}
status = RECLAIM_PARAGRAPH_CopyParagraphBlock(aRef);
if(status != ERR_NONE)
{
return status;
}
case enEraseEntireParagraphSpace:
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_ErasePSInProgress);
if(status != ERR_NONE)
{
return status;
}
status = FLASH_EraseBlock(FDI_ParaSpaceAddressBottom, TRUE);
if(status != ERR_NONE)
{
return status;
}
case enCopyReclaimBlockToParagraphSpace:
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_CopyBackInProgress);
if(status != ERR_NONE)
{
return status;
}
status = RECLAIM_PARAGRAPH_CopyReclaimBlock(aRef);
if(status != ERR_NONE)
{
return status;
}
case enEraseEntireReclaimBlock:
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_EraseRBInProgress);
if(status != ERR_NONE)
{
return status;
}
status = FLASH_EraseBlock(FDI_ReclaimBlockAddressBottom, TRUE);
if(status != ERR_NONE)
{
return status;
}
case enParagraphReclaimCleanup:
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_ReclaimComplete);
if(status != ERR_NONE)
{
return status;
}
/* Nothing to cleanup at this time*/
case enParagraphReclaimComplete:
status = CFGTBL_ModifyPaProgressState(CFGTBL_PaProgressState_Normal);
if(status != ERR_NONE)
{
return status;
}
status = ERR_NONE;
break;
default:
status = ERR_STATE;
break;
} /* switch */
return status;
}
/*#################################################################
### RECLAIM_PARAGRAPH_PerformReclaim
###
### DESCRIPTION:
### This function start the paragraph reclaim from the user.
### The parameter structure is built based on call options.
###
### PARAMETERS
### aUserRequest -- The type of reclaim from the user.
### aRestartFromRecovery -- Is this a power loss restart
###
### 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 RECLAIM_PARAGRAPH_PerformReclaim(EnParagraphReclaimUserRequest aUserRequest, BOOLEAN aRestartFromRecovery)
{
ERR_CODE status;
PARAGRAPH_RECLAIM_Address reclaimRef;
CFGTBL_ObjectTable table;
/* Read the table in Pa Space */
status = CFGTBL_ReadTable(FDI_ParaSpaceAddressBottom, &table);
if(status == ERR_NONE)
{
/* Within this call, insure that no paragraph reclaim is running */
if(CFGTBL_GetPaProgressState(&table.PaReclaimStatus) != CFGTBL_PaProgressState_Normal)
{
/* This should never happen */
return ERR_STATE;
}
/* Determine which reclaim type is being requested when restarting from a recovery module */
if(aRestartFromRecovery == TRUE)
{
switch(aUserRequest)
{
case enPerformCfgEntryReclaim:
/* Set Global flag for System State */
SetSystemState(FDI_SystemState, FDI_ST_CfgHdrRecover);
break;
case enPerformHeaderRelocate:
/* Set Global flag for System State */
SetSystemState(FDI_SystemState, FDI_ST_ReclaimRecover);
break;
default:
return ERR_PARAM;
} /* switch */
}
/* Start the reclaim (Non-Powerloss)*/
reclaimRef.userRequest = aUserRequest;
reclaimRef.startOperation = enStartOfParagraphReclaim;
reclaimRef.currentReclaimHeaderHandle = 0;
reclaimRef.currentReclaimTableHandle = 0;
status = RECLAIM_PARAGRAPH_StartReclaim(&reclaimRef);
if(status != ERR_NONE)
{
return status;
}
}
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?