davsearch.c
来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 1,358 行 · 第 1/4 页
C
1,358 行
if (objHeaderRead)
{
if(
(aSrchInfoPtr->HeaderPtr->OHdr.NameSize == aCompareInfoPtr->NameSize) &&
(FHDR_GetAllocationStatus(&(aSrchInfoPtr->HeaderPtr->FHdr)) != HDR_ALLOC_INVALID)
)
{
found = 1;
/* Do the comparison */
for (ii=0; ii<aCompareInfoPtr->NameSize; ii++)
{
if (aSrchInfoPtr->HeaderPtr->OHdr.Name[ii] != ((UINT8*)aCompareInfoPtr->NamePtr)[ii])
{
found = 0;
break;
}
}
}
else
{
found = 0;
}
}
else
{
found = 0;
}
break;
case SEARCH_ByObjectAddress:
if (
((FHDR_CalcObjectHandle(&(aSrchInfoPtr->HeaderPtr->FHdr)) + OHDR_CalcHeaderSize()) == aCompareInfoPtr->CompareValue)
)
{
found = 1;
}
break;
case SEARCH_ByObjectHeaderAddress:
if (
(FHDR_CalcObjectHandle(&(aSrchInfoPtr->HeaderPtr->FHdr)) == aCompareInfoPtr->CompareValue)
)
{
found = 1;
}
break;
case SEARCH_ByNextValidParaObject:
if (
(FHDR_GetAllocationStatus(&(aSrchInfoPtr->HeaderPtr->FHdr)) == HDR_ALLOC_VALID) &&
(FHDR_GetHeaderStatus(&(aSrchInfoPtr->HeaderPtr->FHdr)) == HDR_HEADER_VALID) &&
(FHDR_IsParaObject(&(aSrchInfoPtr->HeaderPtr->FHdr)))
)
{
found = 1;
}
break;
default: {};
}
}
else /* header is absorbed and doesn't point to anything */
{
found = 0;
}
*aFoundValPtr = found;
return status;
}
/*#################################################################
### SEARCH_GetNextHeaderHandle
###
### DESCRIPTION:
### This function provides the search routines with a fast method
### of scanning the header table. It only returns the fixed header,
### header address, object address, and object size.
### The HDR_ReadFullHeader function
### can then be used along with the handle of the header, to
### read the entire header. This loads the aSrchInfoPtr
### header(partial), object size, and header address.
###
### PARAMETERS:
### aSrchInfoPtr - Structure containing search information.
### IN: - CurrObj.HeaderAddress references a valid header
### and value of 0 will start the search from the
### beginning of the header table.
### - HeaderPtr points to a valid header for temporary
### use.
###
### OUT: - CurrObj.HeaderAddress will reference the header
### address of the next header matching the type of
### search performed.
### - CurrObj.ObjectSize will contain the size, in bytes,
### of the object and the object header combined.
### - HeaderPtr will contain the contents of the
### minimum information necessary to locate any
### one object in memory space.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###
### ERR_NONE - Entry was found and the aSrchInfoPtr
### contains valid header information.
###
### ERR_NO_MORE_ENTRIES - The entry was not found after searching
### the entire header table.
###*/
ERR_CODE SEARCH_GetNextHeaderHandle(SEARCH_SearchInfoPtr aSrchInfoPtr,
SEARCH_SpecialConditionEnum aSpecialCondition,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
FDI_Handle nextHeader = FDI_InvalidObjAddress; /* DAV - init to invalid value */
/* Set start_addr to either the top of Flash memory or to *handle_ptr */
if ((aSrchInfoPtr->CurrObj.HeaderAddress == 0) ||
(aSpecialCondition == SEARCH_StartAtCurrent))
{
if (aSrchInfoPtr->CurrObj.HeaderAddress == 0)
{
/* Read the first header entry. */
nextHeader = aSrchInfoPtr->CurrObj.HeaderAddress =
DAV_MEM_FirstHeaderAddr;
}
}
else
{
if (aSpecialCondition == SEARCH_Normal)
{
nextHeader = SEARCH_CalcNextHdrAddr(aSrchInfoPtr->CurrObj.HeaderAddress);
}
}
if (aSpecialCondition == SEARCH_StartAtCurrent)
{
nextHeader = aSrchInfoPtr->CurrObj.HeaderAddress;
}
/* Read the header */
status = FHDR_ReadFixedHeader(nextHeader, &(aSrchInfoPtr->HeaderPtr->FHdr), restart);
ExitOnError(status);
/* Calculate Next Header's Header Base Address */
aSrchInfoPtr->CurrObj.HeaderAddress = nextHeader;
if (FHDR_GetHeaderStatus(&(aSrchInfoPtr->HeaderPtr->FHdr)) == HDR_HEADER_UNUSED)
{
status = ERR_NO_MORE_ENTRIES;
ExitOnError(status);
}
/* Authenticate that the header is in a good state if required */
if (FHDR_AuthenticateHeader(&(aSrchInfoPtr->HeaderPtr->FHdr)) != HDR_STATUS_Authentic)
{
status = ERR_PARAM;
ExitOnError(status);
}
else
{
if (FHDR_GetAbsorbStatus(&(aSrchInfoPtr->HeaderPtr->FHdr)) != HDR_ABSORBED)
{
/* Store object address */
aSrchInfoPtr->CurrObj.ObjectAddress =
FHDR_CalcObjectHandle(&(aSrchInfoPtr->HeaderPtr->FHdr));
/* Store object size */
aSrchInfoPtr->CurrObj.ObjectSize =
FHDR_CalcObjectSize(&(aSrchInfoPtr->HeaderPtr->FHdr));
}
}
return status;
}
/*#################################################################
### SEARCH_GetNextHeader
###
### DESCRIPTION:
### This function will return information about the next object
### in the header table, calculate the address of the object and
### keep track of the search state using the aSrchInfoPtr.
### Header information is returned in its raw state.
###
### The start point is determined by the HeaderAddress in the
### aSrchInfoPtr. This value can be from a previous call
### or from previous knowledge of the location of a particular
### header entry. The next object that matches (depends on
### search method) will be returned in the aSrchInfoPtr.
### The restart parameter is used to start from and includes the
### first object in the header table without knowing the address
### of the first entry.
###
### PARAMETERS:
### aSrchInfoPtr - Structure containing detailed information
### about the desired object.
### IN: The CurrObj.HeaderAddress field must contain a valid
### start address to begin searching from. A value of 0
### will start the search from the beginning of the header
### table.
###
### OUT: The state of the search will be completely stored
### in this structure upon return. This will allow
### the caller to return to a previous search state
### no matter what other functions might have called
### it (this function is re-entrant).
###
### All information about an object is returned including
### the entire contents of the header (minus name). The
### HDR_ReadFullHeader function must be used to get the
### name and any other fields that are not essential to
### the search algorithm.
###
### aCompareMethod - Search for the next object with the
### following qualities:
###
### SEARCH_ByNextObject //Return next object in the header
### // table.
### SEARCH_ByNextValidObject //Return the next valid object in
### // the header table.
### SEARCH_ByNextParaObject //Return next para object in the
### // header table.
### SEARCH_ByNextPageObject //Return next page object in the
### // header table.
### SEARCH_ByValidType //Return the next valid object with
### // the specified type.
### SEARCH_ByHeaderAddress //Return the next object that matches the
### // specified header address (fast search).
### SEARCH_ByTypeOnly //Return the next object of the specified
### // type.
### SEARCH_ByNameType //Return the next object with the specified
### // name + type.
### SEARCH_ByName //Return the next object with the specified
### // name.
###
### compare_value - Used to compare header values based
### on the method chosen.
### e.g. Using the SearchByHeaderAddress,
### the calling function would place
### the desired header address in the
### compare_value parameter.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###
### ERR_NONE - Entry was found and the aSrchInfoPtr
### contains valid header information.
###
### ERR_NO_MORE_ENTRIES - The entry was not found after searching
### the entire header table.
###*/
ERR_CODE SEARCH_GetNextHeader(SEARCH_SearchInfoPtr aSrchInfoPtr,
SEARCH_SearchMethodEnum aCompareMethod,
SEARCH_CompareInfoPtr aCompareInfoPtr,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
UINT8 foundVal = 0;
while (status != ERR_NO_MORE_ENTRIES)
{
status = SEARCH_GetNextHeaderHandle(aSrchInfoPtr, SEARCH_Normal, restart);
if (!status)
{
/* Since we need data from the obj header, the obj header was also read */
status = IsFound(aSrchInfoPtr, aCompareMethod, aCompareInfoPtr,
&foundVal, restart);
if(status)
{
return(status);
}
if (foundVal)
{
return ERR_NONE;
}
}
}
return status;
}
/*#################################################################
### SEARCH_CalcNextHdrAddr
###
### DESCRIPTION:
### This function will take the current header handle and use it to
### calculate the address of the next header just below it in
### paragraph space.
###
### PARAMETERS:
### aCurrentHeaderHandle - Address of the current header.
### nextHeaderHandle - Ptr to address of the next header.
###
### RETURNS:
### Handle to next header.
###*/
FDI_Handle SEARCH_CalcNextHdrAddr(FDI_Handle aCurrentHeaderHandle)
{
return (aCurrentHeaderHandle - FHDR_CalcHeaderSize());
}
/*#################################################################
### SEARCH_CalcFirstUserObjectHdrAddr
###
### DESCRIPTION:
### This function will compute the address of the header of
### the first user object, dirty chunk, or free chunk that
### exists in page space.
###
### PARAMETERS:
### aCurrentHeaderHandle - Address of the current header.
### aNextHeaderHandlePtr - Ptr to address of the next header.
###
### RETURNS:
### Error status.
###*/
ERR_CODE SEARCH_CalcFirstUserObjectHdrAddr(FDI_HandlePtr aHandlePtr)
{
ERR_CODE status = ERR_NONE;
FDI_Handle currHeaderHandle = DAV_MEM_FirstHeaderAddr;
FDI_Handle lastHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader currHeader;
UINT32 currOffset = HDR_INDEX_OFFSET_UNUSED;
UINT32 candidateOffset = 0;
HDR_InitHeaderAttr1(currHeader.Attr1);
HDR_InitHeaderAttr2(currHeader.Attr2);
do
{
status = FHDR_ReadFixedHeader(currHeaderHandle, &currHeader, FALSE);
/* if the header points to a real user object, dirty chunk, or free chunk in page space */
if (
(status == ERR_NONE) &&
(FHDR_GetHeaderStatus(&currHeader) == HDR_HEADER_VALID) &&
(FHDR_GetAbsorbStatus(&currHeader) != HDR_ABSORBED) &&
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?