📄 davwrcmp.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### DAV - Direct Access Volume Enhancement to FDI
###
### Module: davwrcmp.c - DAV Interface Function: Write Complete Module
###
### $Workfile: davwrcmp.c $
### $Revision: 71 $
### $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 "davext.h"
#include "davmem.h"
#include "davwrcmp.h"
/*### Local Declarations
#########################*/
#define ExitOnError(status) \
if (status != ERR_NONE) \
{ FDI_APIUnlock(); \
return status; }
/* E5.5.962 Begin */
#define CleanupAndExitOnError(status) \
if(status != ERR_NONE) \
{ \
FDI_APIUnlock(); \
mDEBUG_CHECK_ERRCODE(status) \
MEM_CalcMemoryStatistics(FALSE); \
return status; \
}
/* E5.5.962 End */
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
/*### Global Functions
#########################*/
/*###################################################################
### FDI_WriteComplete
###
### DESCRIPTION:
### This function tells the DAV that the object has been updated
### and the user is done with the old object. It modifies the
### status field of the header entry specified by by obj_name
### and obj_type. It must detect whether an allocate or re-allocate
### was being performed. When one header entry exists, an allocate
### was being performed and WriteComplete will modify the status
### from WriteInProgress to Valid. If two header entries are found
### with the same name and type, a reallocate was being performed
### and the second entry is modified from WriteInProgress to Invalid.
###
### PARAMETERS:
### obj_name - Name of object.
### name_size - Length of the name field in bytes.
### obj_type - Type of the object
###
### 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 FDI_WriteComplete( UINT8* obj_name_ptr,
UINT8 name_size,
UINT32 obj_type )
{
ERR_CODE status = ERR_NONE;
SEARCH_CompareInfo compare_info;
FDI_Handle origHeaderHandle = FDI_InvalidObjAddress;
HDR_FixedHeader origHeader;
FDI_Handle bkupHeaderHandle = FDI_InvalidObjAddress;
HDR_FixedHeader bkupHeader;
BOOLEAN two_copies = FALSE;
/* Check range of ObjectType */
if(obj_type < FDI_HT_BeginUserTypes)
{
return ERR_PARAM;
}
/* Check for invalid Namesize and if the Name pointer is pointing to NULL */
if((name_size <= 0 ) ||
(name_size > FDI_MaxNameLength ) ||
(obj_name_ptr == 0))
{
return ERR_PARAM;
}
/* Multitasking API exclusivity. (This may not be necessary to the
full extent as it is done here, but for now it is the safest way.) */
FDI_APILock();
/* Clear Global flag for System State */
ClrSystemState(FDI_SystemState, FDI_ST_ReclaimFlag);
/* Start from the beginning of the header table and */
/* search for the first occurrence of the header. There */
/* may be two headers or only one header. */
SEARCH_Header2SearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));
/* Search for the object by name and type and calculate the base address. */
compare_info.CompareValue = obj_type;
compare_info.CompareValue2 = FHDR_GetHeaderIndexOffset(&(FDI_SearchInfo.HeaderPtr->FHdr));
compare_info.NameSize = name_size;
compare_info.NamePtr = (HDR_NamePtr)(obj_name_ptr);
status = SEARCH_GetNextHeader(
&FDI_SearchInfo,
SEARCH_ByNameType,
&compare_info, FALSE);
if (status != ERR_NONE)
{
if (status == ERR_NO_MORE_ENTRIES)
{
status = ERR_NOTEXISTS;
}
ExitOnError(status);
}
if (FHDR_GetAllocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) != HDR_ALLOC_WRITE_IN_PROGRESS)
{
if (FHDR_GetAllocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_ALLOC_VALID)
{
/* is this object a backup, or does it have a backup? */
if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_NOT_COMPLETE)
{
/* this is an original object, but is there a backup? */
origHeaderHandle = FDI_SearchInfo.CurrObj.HeaderAddress;
origHeader.Attr1 = FDI_SearchInfo.HeaderPtr->FHdr.Attr1;
origHeader.Attr2 = FDI_SearchInfo.HeaderPtr->FHdr.Attr2;
/* search for the backup */
status = SEARCH_GetNextHeader(
&FDI_SearchInfo,
SEARCH_ByNameType,
&compare_info, FALSE);
if (status == ERR_NONE)
{
/* is this a backup? */
if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_COMPLETE)
{
bkupHeaderHandle = FDI_SearchInfo.CurrObj.HeaderAddress;
bkupHeader.Attr1 = FDI_SearchInfo.HeaderPtr->FHdr.Attr1;
bkupHeader.Attr2 = FDI_SearchInfo.HeaderPtr->FHdr.Attr2;
two_copies = TRUE;
}
else
{
/* we found two valid objects!! */
status = ERR_STATE;
ExitOnError(status);
}
}
else
{
/* E.5.3.1/881 START */
/* caller is trying to write-complete a valid object */
status = ERR_NONE;
/* E.5.5.959 START */
FDI_APIUnlock();
/* E.5.5.959 END */
return(status);
/* E.5.3.1/881 END */
}
}
else
{
/* this is a backup, we want to find the original object */
bkupHeaderHandle = FDI_SearchInfo.CurrObj.HeaderAddress;
bkupHeader.Attr1 = FDI_SearchInfo.HeaderPtr->FHdr.Attr1;
bkupHeader.Attr2 = FDI_SearchInfo.HeaderPtr->FHdr.Attr2;
status = SEARCH_GetNextHeader(
&FDI_SearchInfo,
SEARCH_ByNameType,
&compare_info, FALSE);
if (status == ERR_NONE)
{
/* is this an original? */
if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_NOT_COMPLETE)
{
/* this is the original object */
origHeaderHandle = FDI_SearchInfo.CurrObj.HeaderAddress;
origHeader.Attr1 = FDI_SearchInfo.HeaderPtr->FHdr.Attr1;
origHeader.Attr2 = FDI_SearchInfo.HeaderPtr->FHdr.Attr2;
two_copies = TRUE;
}
else
{
/* we found two backup objects!!! */
status = ERR_STATE;
ExitOnError(status);
}
}
else
{
/* we found a backup object but no original object */
status = ERR_STATE;
ExitOnError(status);
}
}
}
else
{
/* we found a header, but the header's not valid! */
status = ERR_STATE;
ExitOnError(status);
}
}
else
{
origHeaderHandle = FDI_SearchInfo.CurrObj.HeaderAddress;
origHeader.Attr1 = FDI_SearchInfo.HeaderPtr->FHdr.Attr1;
origHeader.Attr2 = FDI_SearchInfo.HeaderPtr->FHdr.Attr2;
}
if (status != ERR_NONE)
{
/* If any error occurs, then no headers with the name and */
/* type exist; exit. */
status = ERR_NOTEXISTS;
ExitOnError(status);
}
/* the original header is the WIP header (valid in the case of reallocation) and should be validated */
status = FHDR_ValidateHeaderInFlash(origHeaderHandle, &origHeader);
CleanupAndExitOnError(status);
/* if a lockout of the WIP object was in place, we can now */
/* remove it */
FDI_LockoutObjectAllocation = FALSE;
if (two_copies == TRUE)
{
/* the backup header should be invalidated if it exists */
status = FHDR_InvalidateHeaderInFlash(
bkupHeaderHandle,
&bkupHeader);
CleanupAndExitOnError(status);
}
/* update memory statistics */
status = MEM_CalcMemoryStatistics(FALSE);
FDI_APIUnlock();
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -