⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 davpageinit.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential                        */

/* ###########################################################################
###  DAV Page Reclaim
###
###  Module: davpageinit.c - table initialization, backup and modification
####                         functions for objects and object groups.
###
###  $Workfile: DavPageInit.c $
###  $Revision: 28 $
###  $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 "DavSearch.h"
#include "DavRtTbl.h"
#include "DavRatTbl.h"
#include "davmodob.h"
#include "davbkup.h"
#include "DavPageRecl.h"

/*### Local Declarations
#########################*/
ERR_CODE RECLAIM_PAGE_ModifyBackupGroup(PAGE_RECLAIM_Address* aRef,
                                        FDI_Handle            aRatEntryHandle,
                                        RATTBL_EntryPtr       aRatEntryPtr,
                                        BOOLEAN               restart);

ERR_CODE RECLAIM_PAGE_BackupOriginalGroup(RATTBL_LeaderPtr aRatLeaderPtr,
                                          FDI_Handle       aRatEntryHandle,
                                          RATTBL_EntryPtr  aRatEntryPtr,
                                          FDI_Handle       aTopObjectHandle, 
                                          UINT32           aGroupSizeInPages,
                                          FDI_Handle       aBottomObjectHandle,
                                          BOOLEAN          restart);

ERR_CODE RECLAIM_PAGE_EraseOriginalGroup(FDI_Handle      aRatEntryHandle,
                                         RATTBL_EntryPtr aRatEntryPtr,
                                         UINT16           aTopBlock, 
                                         UINT32          aTopObjectHandle, 
                                         UINT32          aTopObjectSizeInPages,
                                         UINT32          aGroupSizeInPages,
                                         UINT16           aBottomBlock,
                                         UINT32          aBottomObjectHandle,
                                         BOOLEAN         restart);

ERR_CODE RECLAIM_PAGE_EraseBackupGroup(FDI_Handle      aRatEntryHandle,
                                       RATTBL_EntryPtr aRatEntryPtr,
                                       UINT16           aTopBlock, 
                                       FDI_Handle      aTopObjectHandle, 
                                       UINT32          aTopObjectSizeInPages,
                                       UINT32          aGroupSizeInPages,
                                       UINT16           aBottomBlock,
                                       FDI_Handle      aBottomObjectHandle,
                                       BOOLEAN         restart);


/*### Global Declarations
#########################*/

/*### Local Functions
#########################*/

#define ExitOnError(status) \
   if (status != ERR_NONE) \
   {  return status;  }
   

 /*#################################################################
  ### RECLAIM_PAGE_CleanUpBackupAllocation
  ###
  ### DESCRIPTION:
  ###   This function cleans up a given backup area in page space,
  ###   absorbing and replacing free chunks as necessary
  ###
  ### PARAMETERS:
  ###   aBottomObjectHandle -- IN: bottom handle of backup area
  ###   aGroupSizeInPages   -- IN: size of backup area used
  ###   restart             -- IN: Flag used for PLR.
  ###
  ### 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_PAGE_CleanUpBackupAllocation(FDI_Handle aBottomObjectHandle,
                                              UINT32     aGroupSizeInPages,
                                              BOOLEAN    restart)
{
ERR_CODE           status       = ERR_NONE;
UINT32             newFreeChunkSizeInPages;
SEARCH_CompareInfo compareInfo;
BOOLEAN            absorbingFreeChunk = FALSE;

   newFreeChunkSizeInPages = aGroupSizeInPages;

   /* Search for a free chunk just beyond the end of the backup group */
   FDI_SearchInfo.CurrObj.HeaderAddress = 0;
   FDI_SearchInfo.CurrObj.ObjectAddress = 0;
   SEARCH_Header2SearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));             
   compareInfo.CompareValue = aBottomObjectHandle + (aGroupSizeInPages * FDI_PageSize);
   if (compareInfo.CompareValue > FDI_LastObjectAddress)
   {
      /* we're at the end of page space, so there is nothing to clean up */
      return ERR_NONE;
   }                   
   status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByObjectHeaderAddress, &compareInfo, restart); 
   if (status != ERR_NONE) 
   {
      if (status != ERR_NO_MORE_ENTRIES)
      {
         ExitOnError(status);
      }
      if (status == ERR_NO_MORE_ENTRIES)
      {
         /* there is no object on top of the backup group, so we don't need to do this */
         return ERR_NONE;
      }
   }
   else
   {
      absorbingFreeChunk = TRUE;
   }

   if (absorbingFreeChunk == TRUE)
   {
      /* if there is a free chunk, we need to combine it with the new free chunk for */
      /* the backup area and absorb the header */
      if (FHDR_GetAllocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_ALLOC_EMPTY)
      {
         newFreeChunkSizeInPages += FHDR_GetSize(&(FDI_SearchInfo.HeaderPtr->FHdr));
         status = FHDR_AbsorbingHeaderInFlash(FDI_SearchInfo.CurrObj.HeaderAddress,
                                              &(FDI_SearchInfo.HeaderPtr->FHdr));
         ExitOnError(status);
      }
   }

   /* create a free chunk at the start of the backup group area */
   FDI_LastHeaderEntry = FDI_NextFreeHeaderEntry;                    
   FDI_NextFreeHeaderEntry -= FHDR_CalcHeaderSize();
   status = FHDR_CreateFreeChunkHeader( FDI_LastHeaderEntry,
                        (aBottomObjectHandle - FDI_PageSpaceAddressBottom)/FDI_PageSize,
                        newFreeChunkSizeInPages);
   ExitOnError(status);

   if (absorbingFreeChunk == TRUE)
   {
      if (FHDR_GetAllocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_ALLOC_EMPTY)
      {
         status = FHDR_AbsorbedHeaderInFlash(FDI_SearchInfo.CurrObj.HeaderAddress,
                                              &(FDI_SearchInfo.HeaderPtr->FHdr));
         ExitOnError(status);
      }
   }

   return status;
}

 /*#################################################################
  ### RECLAIM_PAGE_CalcBackupAllocation
  ###
  ### DESCRIPTION:
  ###   Extract the backup area parameters from the RAT.
  ###
  ### PARAMETERS:
  ###   aRatLeaderPtr        -- IN:     ptr to RAT leader
  ###   aBkupHandlePtr       -- IN/OUT: ptr to handle to backup area
  ###   aBkupSizeInPagesPtr  -- IN/OUT: ptr to bkup size in pages.
  ###   restart              -- IN: Flag used for PLR.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
void RECLAIM_PAGE_CalcBackupAllocation(RATTBL_LeaderPtr aRatLeaderPtr,
                                       FDI_HandlePtr    aBkupHandlePtr,
                                       UINT32*          aBkupSizeInPagesPtr,
                                       BOOLEAN          restart)
{
   /* backup handle */
   *aBkupHandlePtr = (RATTBL_GetBackupOffset(aRatLeaderPtr) * FDI_PageSize) + FDI_PageSpaceAddressBottom;

   /* backup size */
   *aBkupSizeInPagesPtr = RATTBL_GetBackupSize(aRatLeaderPtr);
}

 /*#################################################################
  ### RECLAIM_PAGE_CalcBackupGroupParms
  ###
  ### DESCRIPTION:
  ###   Search for a group of backup objects in page space and
  ###   compute the given parameters for the backup area.  Note that
  ###   this function assumes there is only one group of backup
  ###   objects in page space at any given time.
  ###
  ### PARAMETERS:
  ###   aTopBlockPtr        -- IN/OUT: ptr to top block number
  ###   aTopObjectHandlePtr -- IN/OUT: ptr to top object handle
  ###   aTopObjectSizeInPagesPtr  -- IN/OUT: ptr to top object size
  ###                                        in pages.
  ###   aGroupSizeInPagesPtr  -- IN/OUT: ptr to group size in pages.
  ###   aBottomBlockPtr        -- IN/OUT: ptr to btm block number
  ###   aBottomObjectHandlePtr -- IN/OUT: ptr to btm object handle
  ###   restart             -- IN: Flag used for PLR.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
/*Fix Start:SCR964 */
ERR_CODE RECLAIM_PAGE_CalcBackupGroupParms( UINT16*        aTopBlockPtr,
                                            FDI_HandlePtr aTopObjectHandlePtr,
                                            UINT32*       aTopObjectSizeInPagesPtr,
                                            UINT32*       aGroupSizeInPagesPtr,
                                            UINT16*        aBottomBlockPtr,
                                            FDI_HandlePtr aBottomObjectHandlePtr,
                                            BOOLEAN       restart)
/*Fix End:SCR964 */
{
ERR_CODE status                 = ERR_NONE;
FDI_Handle currBkupHeaderHandle = FDI_InvalidObjAddress;
HDR_FixedHeader  currBkupHeader;

   /* walk the headers in page space order from bottom to top to */
   /* find the first backup object; this should be the bottom of */
   /* the backup group; only one backup group should be in page  */
   /* space at any moment in time.                               */
   do
   {
      status = SEARCH_CalcNextUserObjectHdrAddr(currBkupHeaderHandle, &currBkupHeaderHandle);
      ExitOnError(status); /* if we couldn't find a backup object, something is very wrong */

      status = FHDR_ReadFixedHeader(currBkupHeaderHandle, &currBkupHeader, restart);
      ExitOnError(status);
   }
   while (status == ERR_NONE && 
      FHDR_GetReallocationStatus(&currBkupHeader) != HDR_REALLOC_BACKUP_COMPLETE);

   /* at this point, the currHeaderHandle should point to the header for   */
   /* the first backup object, and the current header should be the header */
   /* of the first backup object, so calculate the object handle           */
   *aBottomBlockPtr = UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(&currBkupHeader));
   *aBottomObjectHandlePtr = FHDR_CalcObjectHandle(&currBkupHeader);
   *aGroupSizeInPagesPtr = FHDR_GetSize(&currBkupHeader);
   /* initialize the top parameters using the first backup object */
   *aTopBlockPtr = UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(&currBkupHeader) + FHDR_GetSize(&currBkupHeader));
   *aTopObjectHandlePtr = *aBottomObjectHandlePtr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -