📄 davrecrv.c
字号:
###
### RETURNS:
### ERR_NONE - When operation is successful.
###
*/
ERR_CODE RECRCVR_CalcReclaimRestartState(BOOLEAN paragraph_reclaim, BOOLEAN restart)
{
UINT16 HT_input, RB_input;
ERR_CODE status = ERR_NONE;
FDI_Handle RB_table_addr = RECTBL_RBAddrInPageReclaim;
RECTBL_TableInfo RB_table_info;
HDR_CompareInfo compare_info;
HDR_Header OTT_FixedHeader;
HDR_InitSearchInfo(&SearchInfo, &SearchHeader);
/* Make sure that the reclaim table is initialized */
if (paragraph_reclaim)
{
if (CFGHDR_GetOffsetStatus(ReclaimState.ConfigEntry) ==
CFGHDR_STATUS_InvalidOffset)
{
status = HDR_FindLastAuthenticHeader(&SearchInfo, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES))
{
return(status);
}
if ((SearchInfo.HeaderPtr->ObjectType != FDI_HT_ReclaimTable) ||
(HDR_GetHdrState(SearchInfo.HeaderPtr->Attr16) !=
HDR_HA_STATE_Valid))
{
FDI_NextFreeHeaderEntry = HDR_CalcNextHdrAddr(
SearchInfo.CurrObj.HeaderAddress,
(UINT16)HDR_GetAlignmentAttr((SearchInfo.HeaderPtr->Attr16)),
SearchInfo.HeaderPtr->NameSize,
SearchInfo.CurrObj.ObjectSize);
}
else
{
FDI_NextFreeHeaderEntry = SearchInfo.CurrObj.HeaderAddress;
}
RecoverState.State = RECRCVR_CreateReclaimTable;
return ERR_NONE;
}
/* Calculate the header address of the reclaim table from */
/* the configuration header entry. */
ReclaimState.RecTblHdrAddr =
CFGHDR_GetOffset(ReclaimState.ConfigEntry);
/* Calculate the "possible" base address based on the */
/* header address for paragraph reclaim recovery. */
ReclaimState.RecTblBaseAddr =
HDR_HdrAddr2ParaObjAddr(ReclaimState.RecTblHdrAddr,
RECTBL_HeaderNameLength, RECTBL_ParaRecTblSize);
FLASH_ReadBuffer(ReclaimState.RecTblHdrAddr,
(MemBufferPtr)&SearchHeader, HDR_FixedSize);
status = UINT16_HeaderFixISF_PLR( &(SearchHeader.Attr16),
(ReclaimState.RecTblHdrAddr+HDR_OffsetToAttr16), restart);
if(status)
{
return status;
}
/*fix header ID*/
status = UINT16_FixISF_PLR( &(SearchHeader.HeaderId),
(ReclaimState.RecTblHdrAddr+HDR_OffsetToHeaderId), restart);
if(status)
{
return status;
}
RB_table_addr = RECTBL_RBAddrInParaReclaim;
}
else
{
/*## Check if there is a valid reclaim table */
compare_info.CompareValue = FDI_HT_ReclaimTable;
status = GetNextHeader(&SearchInfo, HDR_ByTypeOnly, &compare_info,
restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
/* if a valid Reclaim Table header is not found */
if ((status) ||
(HDR_GetHdrState(SearchInfo.HeaderPtr->Attr16) != HDR_HA_STATE_Valid))
{
/*## Check if there is a valid OTT table */
HDR_InitSearchInfo(&SearchInfo, &SearchHeader);
compare_info.CompareValue = FDI_HT_ObjTrkTable;
status = GetNextHeader(&SearchInfo, HDR_ByTypeOnly, &compare_info, restart);
if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) &&
(status != ERR_PARAM))
{
return(status);
}
}
/*If a PLR happens after the reclaim table header has been marked
* absorbed, the OTT header could still be valid. There could be
* objects with modification not complete
*/
if (SearchInfo.HeaderPtr->ObjectType == FDI_HT_ObjTrkTable)
{
/* Calculate the address of the header and table based on */
/* the search for a page reclaim table. */
ReclaimState.OTTTblHdrAddr = SearchInfo.CurrObj.HeaderAddress;
ReclaimState.OTTTblBaseAddr = SearchInfo.CurrObj.ObjectAddress;
status = OTTTBL_GetTableInfo( ReclaimState.OTTTblBaseAddr,
(OTTTBL_TableInfoPtr)&ReclaimState.OTTTableInfo, restart);
RecoverState.State = RECRCVR_ModifyMovedObjects;
return (status);
}
else if (SearchInfo.HeaderPtr->ObjectType == FDI_HT_ReclaimTable)
{
/* Calculate the address of the header and table based on */
/* the search for a page reclaim table. */
ReclaimState.RecTblHdrAddr = SearchInfo.CurrObj.HeaderAddress;
ReclaimState.RecTblBaseAddr = SearchInfo.CurrObj.ObjectAddress;
RB_table_addr = RECTBL_RBAddrInPageReclaim;
/* Calculate the address of the header and OTT table based on */
/* the search for a page reclaim table. */
ReclaimState.OTTTblBaseAddr = (ReclaimState.RecTblHdrAddr +
HDR_FixedSize);
ReclaimState.OTTTblHdrAddr = (ReclaimState.OTTTblBaseAddr +
RoundUp(OTTTBL_TableInfoSize, FDI_ParagraphLength) +
RoundUp(OTTTBL_HeaderNameLength, FDI_ParagraphLength));
status = OTTTBL_GetTableInfo( ReclaimState.OTTTblBaseAddr,
(OTTTBL_TableInfoPtr)&ReclaimState.OTTTableInfo, restart);
if (status)
{
return (status);
}
status=HDR_ReadFixedHeader(ReclaimState.OTTTblHdrAddr, &OTT_FixedHeader, restart);
if (status)
{
return (status);
}
if (HDR_GetStatusAttr(OTT_FixedHeader.Attr16) == HDR_HA_Valid)
{
OTT_flag = TRUE;
}
}
}
/* Read the TableInfo of the reclaim table that may be in */
/* the reclaim block */
RECTBL_GetTableInfo(ReclaimState.RecTblBaseAddr,
&ReclaimState.TableInfo, paragraph_reclaim, restart);
/* Calculate the Header Table (HT) input value for the */
/* Recover State Lookup Table (RSLT). */
HT_input = RSLT_NoTable;
if (HDR_AuthenticateHeader(&SearchInfo) != HDR_STATUS_NoHeader)
{
if (ReclaimState.TableInfo.TableId == RECTBL_TableDataValid)
{
HT_input = RSLT_HeaderWTable;
}
else
{
HT_input = RSLT_HeaderNoTable;
}
}
/* Read the TableInfo of the reclaim table that may be in */
/* the reclaim block */
RECTBL_GetTableInfo(RB_table_addr, &RB_table_info, paragraph_reclaim, restart);
/* Calculate the Reclaim Block (RB) input value for the */
/* Recover State Lookup Table (RSLT). */
RB_input = RSLT_RBNoTable;
if (RB_table_info.TableId == RECTBL_TableDataValid)
{
RB_input = RSLT_RBWTable;
}
status = LookupRecoverState(HT_input, RB_input, paragraph_reclaim);
if (status)
{
return status;
}
switch (RecoverState.State)
{
case RECRCVR_CreateReclaimTable:
break;
case RECRCVR_InitReclaimTable:
break;
case RECRCVR_StartStateMachine:
ReclaimState.SingleSkipRead = TRUE;
/* Search the reclaim table for the TO & FROM blocks and */
/* Erase any blocks that were started but not finished */
/* being erased. */
status = RECRCVR_LocateTO_N_FROMBlocks(paragraph_reclaim, restart);
if (status)
{
return status;
}
/* Locate the object being copied TO and FROM and find */
/* out which portion was being copied. */
if (paragraph_reclaim)
{
status = RCVRPARA_SetupForParaReclaimRestart(restart);
}
else
{
status = RCVRPAGE_SetupForPageReclaimRestart(restart);
}
break;
case RECRCVR_FinishUpReclaim:
ReclaimState.RecTblBaseAddr = RB_table_addr;
ReclaimState.TableInfo.FirstBlock = RB_table_info.FirstBlock;
ReclaimState.TableInfo.TotalBlocks = RB_table_info.TotalBlocks;
ReclaimState.TableInfo.TableId = RB_table_info.TableId;
break;
case RECRCVR_FinishRemainingBlocks:
ReclaimState.RecTblBaseAddr = RB_table_addr;
ReclaimState.TableInfo.FirstBlock = RB_table_info.FirstBlock;
ReclaimState.TableInfo.TotalBlocks = RB_table_info.TotalBlocks;
ReclaimState.TableInfo.TableId = RB_table_info.TableId;
/*lint -fallthrough*/
case RECRCVR_RelocateReclaimTable:
status = RECRCVR_LocateTO_N_FROMBlocks(paragraph_reclaim, restart);
if (status)
{
return status;
}
SearchInfo.HeaderPtr->ObjectType = FDI_HT_ReclaimTable;
if (paragraph_reclaim)
{
MemMap.RecBlk.BaseAddr = FDI_ReclaimBlockAddress +
FDI_BlockSize - 1;
MemMap.FreeBlk.BaseAddr =
Block2Handle((RecoverState.TOBlock + 1)) - 1;
}
else
{
MemMap.RecBlk.BaseAddr = FDI_ReclaimBlockAddress;
MemMap.FreeBlk.BaseAddr =
Block2Handle(RecoverState.TOBlock);
}
/* If there is data in the RB it would have gone back */
/* to the FROM block (which is = TO block) so, set the */
/* free space to the FROM block. Assume that the RB */
/* contains valid data minus the reclaim table. */
MemMap.FreeBlk.BytesFree = 0;
MemMap.RecBlk.BytesUsed = 0;
if (RecoverState.FROMBlock == RecoverState.TOBlock)
{
if (paragraph_reclaim)
{
MemMap.RecBlk.BytesUsed =
FDI_BlockSize - RECTBL_ParaRecTblSize;
MemMap.RecBlk.BaseAddr -= MemMap.RecBlk.BytesUsed;
}
else
{
MemMap.RecBlk.BytesUsed =
FDI_BlockSize - RECTBL_PageRecTblSize;
}
}
break;
case RECRCVR_AllocateConfigEntry:
case RECRCVR_CreateOTTTable:
case RECRCVR_ModifyMovedObjects:
case RECRCVR_ObjectModified:
case RECRCVR_ExitWithFailure:
default:
status = ERR_SYSTEM;
break;
}
ReclaimState.CurrentBlock2Reclaim = RecoverState.FROMBlock;
ReclaimState.CurrentDoneBlock = RecoverState.TOBlock;
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -