davparecl.c
来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 765 行 · 第 1/2 页
C
765 行
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### DAV Paragraph Reclaim
###
### Module: davparecl.c - Paragraph Block Reclaim Module
###
### $Workfile: DavPaRecl.c $
### $Revision: 9 $
### $NoKeywords: $
########################################################################### */
/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS. YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/
/*### Include Files
#########################*/
#include "DavLib.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
#include "DavCfgTbl.h"
#include "DavPaRecl.h"
#include "DavMem.h"
/*### Local Declarations
#########################*/
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
/*### Global Functions
#########################*/
/*=================================== RECLAIM =============================*/
/*#################################################################
### RECLAIM_PARAGRAPH_ParagraphHeaderRelocate
###
### DESCRIPTION:
### This function rewrite all of the fixed header based on what
### is in the system and what is in the ott table. It reads
### the fixed header until it reaches the new descripted headers
### in the ott table. It then writes headers based on that table.
### It then continues to write headers not included after the
### ott table.
###
### 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_ParagraphHeaderRelocate(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status = ERR_NONE;
SEARCH_SearchInfo result;
SEARCH_CompareInfo compare_info;
HDR_Header hdrhdr;
HDR_FixedHeader fixHeader;
UINT8 ottIndex;
OTTTBL_Leader ottLeader;
OTTTBL_Entry ottEntry;
OTTTBL_Entry ottEntryLast;
FDI_Handle ottEntryHandle;
/*Fix Start:SCR964 */
UINT16 rtIndex;
/*Fix End:SCR964 */
/* Headers are written from the top down */
/* Do not occupy the very first header because the CFGTBL uses it */
aRef->currentReclaimHeaderHandle =
(FDI_ReclaimBlockAddressTop - (FDI_Handle)(sizeof(HDR_FixedHeader)*2)) + 1;
/* Tables are written from the bottom up */
/* Do not occupy the very first table space because the CFGTBL uses it */
aRef->currentReclaimTableHandle = (UINT32)FDI_ReclaimBlockAddressBottom + (UINT32)sizeof(CFGTBL_ObjectTable);
/* Are we only reclaiming header space? */
if(aRef->userRequest == enPerformCfgEntryReclaim)
{
/* Yes. All we need is the starting address set as done above */
return ERR_NONE;
}
/* Only page reclaim (enPerformHeaderRelocate) requires us to rebuild the header */
/* The information about the first row is needed so part 1 knows where to stop */
status = OTTTBL_GetFirstOttEntry(&ottEntryHandle, &ottEntry, &ottLeader);
if(status != ERR_NONE)
{
return status;
}
/* Header Relocate (part 1 of 3 )*/
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
result.HeaderPtr = &hdrhdr;
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextPageObject, &compare_info, aRef->plrRestart); /*HR*/
if(status != ERR_NONE)
{
/* if search returned no more entries, then */
/* the page space is empty */
if (status != ERR_NO_MORE_ENTRIES)
{
return status;
}
}
/* [<- BottomBlock, MiddleBlock, OTTFirstBlock ->) */
for(rtIndex=0; rtIndex<OTTTBL_GetStartWorkBlockNumber(&ottLeader); rtIndex++)
{
while(status != ERR_NO_MORE_ENTRIES)
{
/* Does the header start in the current block? */
if(UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(&result.HeaderPtr->FHdr)) == rtIndex)
{
/* Yes. Then write a new header for it */
if(
(FHDR_IsUserChunk(&result.HeaderPtr->FHdr) == TRUE) ||
(FHDR_IsDirtyChunk(&result.HeaderPtr->FHdr) == TRUE) ||
(FHDR_IsFreeChunk(&result.HeaderPtr->FHdr) == TRUE)
)
{
/* HEADER RELOCATE from TOP Search (part 1)*/
status = FLASH_CopyFlash(result.CurrObj.HeaderAddress, aRef->currentReclaimHeaderHandle, sizeof(HDR_FixedHeader));
if(status != ERR_NONE)
{
return status;
}
aRef->currentReclaimHeaderHandle -= sizeof(HDR_FixedHeader);
}
else
{
/* The only other type we may run into is a backup */
return ERR_STATE;
}
}
else
{
break; /* while */
}
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextPageObject, &compare_info, aRef->plrRestart); /*HR*/
} /* while */
} /* for */
/* Header Relocate (part 2 of 3 )*/
status = OTTTBL_GetFirstOttEntry(&ottEntryHandle, &ottEntry, &ottLeader);
if(status != ERR_NONE)
{
return status;
}
/* [<- OTTFirstBlock, OTTMiddleBlock, OTTLastBlock ->] */
for(ottIndex=1; ottIndex<=OTTTBL_GetNumRows(&ottLeader); ottIndex++)
{
UTIL_ClearVariable((UINT8*)&fixHeader, sizeof(HDR_FixedHeader), 0xFF);
/* Copy fields that will not change */
FHDR_SetSize (&fixHeader, OTTTBL_GetOttEntrySize(&ottEntry));
FHDR_SetHeaderIndexOffset(&fixHeader, OTTTBL_GetOttEntryDestination(&ottEntry));
FHDR_SetType (&fixHeader, FDI_HT_NormalObject);
FHDR_SetHeaderStatus(&fixHeader, HDR_HEADER_VALID);
/* Set header status based on the ottEntry type */
if(OTTTBL_GetOttEntryType(&ottEntry) == OTTTBL_OttEntryType_UserObject)
{
/* HEADER RELOCATE from OTT */
FHDR_SetAllocationStatus(&fixHeader, HDR_ALLOC_VALID); /* Object */
}
else if(OTTTBL_GetOttEntryType(&ottEntry) == OTTTBL_OttEntryType_DirtyChunk)
{
/* Set to dirty */
FHDR_SetAllocationStatus(&fixHeader, HDR_ALLOC_INVALID); /* Dirty */
}
else if(OTTTBL_GetOttEntryType(&ottEntry) == OTTTBL_OttEntryType_FreeChunk)
{
/* Set to free */
FHDR_SetAllocationStatus(&fixHeader, HDR_ALLOC_EMPTY); /* Free */
}
else
{
/* do not anticipate seeing anyother objects. Backups are not in the ott */
return ERR_STATE;
}
/* Write the new header */
status = FLASH_WriteBuffer(aRef->currentReclaimHeaderHandle, (UINT8*)&fixHeader,
sizeof(HDR_FixedHeader));
if(status != ERR_NONE)
{
return status;
}
/* Compute the next handle */
aRef->currentReclaimHeaderHandle -= sizeof(HDR_FixedHeader);
/* If this is the last ottEntry, copy the last entry for part 3 */
if(ottIndex==OTTTBL_GetNumRows(&ottLeader))
{
UTIL_CopyVariable((UINT8*)&ottEntry, (UINT8*)&ottEntryLast, sizeof(ottEntry));
}
/* Get the next entry */
status = OTTTBL_GetNextOttEntry(&ottEntryHandle, &ottEntry, &ottEntryHandle);
if(status != ERR_NONE)
{
return status;
}
} /* for */
/* Header Relocate (part 3 of 3 )*/
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
result.HeaderPtr = &hdrhdr;
/* (<- OTTLastBlock, MiddleBlock, EndBlockBlock ->] */
rtIndex = OTTTBL_GetEndWorkBlockNumber(&ottLeader)+1;
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextPageObject, &compare_info, aRef->plrRestart);
while (status != ERR_NO_MORE_ENTRIES)
{
if(UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(&result.HeaderPtr->FHdr)) >= rtIndex)
{
/* HEADER RELOCATE from BOTTOM Search*/
status = FLASH_CopyFlash(result.CurrObj.HeaderAddress, aRef->currentReclaimHeaderHandle, sizeof(HDR_FixedHeader));
if(status != ERR_NONE)
{
return status;
}
aRef->currentReclaimHeaderHandle -= sizeof(HDR_FixedHeader);
}
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextPageObject, &compare_info, aRef->plrRestart);
} /* while */
status = ERR_NONE;
return status;
}
/*#################################################################
### RECLAIM_PARAGRAPH_CopyNormalFixedHeaders
###
### DESCRIPTION:
### This function rewrite all of the fixed header based on what
### is in the page space (objects in the paragraph space are
### skipped). It skips headers that are not longer valid.
###
### 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_CopyNormalFixedHeaders(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status;
BOOLEAN copyHeader;
SEARCH_SearchInfo result;
SEARCH_CompareInfo compare_info;
HDR_Header hdrhdr;
if(aRef->userRequest != enPerformHeaderRelocate)
{
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
result.HeaderPtr = &hdrhdr;
/* Get headers from normal paragraph area */
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextPageObject, &compare_info, aRef->plrRestart);
while(status != ERR_NO_MORE_ENTRIES)
{
copyHeader = FALSE;
if(FHDR_IsUserChunk(&result.HeaderPtr->FHdr) == TRUE)
{
copyHeader = TRUE;
}
else if(FHDR_IsDirtyChunk(&result.HeaderPtr->FHdr) == TRUE)
{
copyHeader = TRUE;
}
else if(FHDR_IsFreeChunk(&result.HeaderPtr->FHdr) == TRUE)
{
copyHeader = TRUE;
}
/* Do we need to copy the header? */
if(copyHeader == TRUE)
{
/* Yes. Copy the current header in it's new location */
status = FLASH_CopyFlash(result.CurrObj.HeaderAddress, aRef->currentReclaimHeaderHandle,
sizeof(HDR_FixedHeader));
if(status != ERR_NONE)
{
return status;
}
/* Set the next header position */
aRef->currentReclaimHeaderHandle -= sizeof(HDR_FixedHeader);
}
/* Get headers from normal paragraph area */
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextPageObject, &compare_info, aRef->plrRestart);
} /* while */
}
return ERR_NONE;
}
/*#################################################################
### RECLAIM_PARAGRAPH_CopySystemFixedHeaders
###
### DESCRIPTION:
### This function rewrite all of the system fixed header based on what
### is in the system.
###
### 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_CopySystemFixedHeaders(PARAGRAPH_RECLAIM_Address* aRef)
{
ERR_CODE status;
SEARCH_SearchInfo result;
SEARCH_CompareInfo compare_info;
HDR_Header hdrhdr;
/* Get VALID system headers from normal paragraph area */
result.CurrObj.HeaderAddress = 0;
result.CurrObj.ObjectAddress = 0;
result.CurrObj.ObjectSize = 0;
result.HeaderPtr = &hdrhdr;
status = SEARCH_GetNextHeader(&result, SEARCH_ByNextValidParaObject, &compare_info, aRef->plrRestart);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?