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

📄 davrecl.c

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

/* ###########################################################################
###  RECLAIM
###
###  Module: reclaim.c - Object reclamation module
###
###  $Workfile: davrecl.c $
###  $Revision: 90 $
###  $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 "dav.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)

/*### Local Declarations
//#########################*/

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

HDR_Header                SearchHeader;
HDR_SearchInfo            SearchInfo;

HDR_Header                OTT_SearchHeader;

RECLAIM_InfoStruct        ReclaimState;
RECLAIM_MemTrackingStruct MemMap;

/* Flag to indicate the OTT table needs to be initialized. */
extern BOOLEAN OTT_flag;

/* E.5.0.600.START */
HDR_Name HeaderNamePtr;
/* E.5.0.600.END */

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

ERR_CODE LocateFirstBlock(RECLAIM_Method method, UINT32 *blk_num, 
                          BOOLEAN restart);

ERR_CODE ExecuteCleanup(BOOLEAN restart, RECLAIM_Method method);
   
/*########################################################################
  ### LocateFirstBlock
  ###
  ### DESCRIPTION:
  ###   This function will search the headers for the first block
  ###   containing an invalid object.
  ###
  ### PARAMETERS:
  ###   method  - Method of reclaim (page or paragraph)
  ###
  ###   NOTE: must not set method to ReclaimAllObjects
  ###
  ### RETURNS:
  ###   Block number of the first block to be reclaimed.
  ###
*/
ERR_CODE LocateFirstBlock(RECLAIM_Method method, UINT32 *blk_num, BOOLEAN restart)
{
   UINT32      block_number;
   ERR_CODE status = ERR_NONE;

   SearchInfo.CurrObj.HeaderAddress = 0;
   SearchInfo.CurrObj.ConfigEntry.Status = 0;
   SearchInfo.CurrObj.ConfigEntry.Offset = 0;

   while(!status)
   {
      status = GetNextHeader((HDR_SearchInfoPtr)&SearchInfo, 
         HDR_ByNextObject, 0, restart);
      if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
          (status != ERR_PARAM))
      {
         return(status);
      }

      if(!(status))
      {
         if(method == ReclaimParagraphObjects)
         {
            /* Search for invalid or absorbed headers.              */
            /*  When one is found locate the first block to reclaim */
            /*  based on the method of reclaim.                     */
            if(((HDR_GetHdrState((SearchInfo.HeaderPtr->Attr16)) == 
               HDR_HA_STATE_Invalid) &&
               (HDR_GetAlignmentAttr((SearchInfo.HeaderPtr->Attr16)) == 
               HDR_HA_AlignPara)) ||
               (HDR_GetAbsorbedAttr((SearchInfo.HeaderPtr->Attr16)) ==
               HDR_HA_Absorbed))
            {
               /* Use the header address to determine the block number */
               /*  to start from.                                      */
               block_number = 
                  Handle2Block((SearchInfo.CurrObj.HeaderAddress));
               *blk_num = block_number; 
               return(status);
            }
         }
         else
         {
            if((HDR_GetHdrState((SearchInfo.HeaderPtr->Attr16)) == 
               HDR_HA_STATE_Invalid) &&
               (HDR_GetAlignmentAttr((SearchInfo.HeaderPtr->Attr16)) == 
               HDR_HA_AlignPage))
            {
               /* Use the base address of the object to determine */
               /*  the block number to start from.                */
               block_number = 
                  Handle2Block(SearchInfo.CurrObj.ObjectAddress);
               *blk_num = block_number; 
               return(status);
            }
         }
      }
   }


   *blk_num = FDI_InvalidBlockNumber; 
   return(status);

}

/*########################################################################
  ### ExecuteCleanup
  ###
  ### DESCRIPTION:
  ###   This is the main reclaim flow that is common betwen both
  ###   page and paragraph reclaim methods.  It performs all 
  ###   initialization and setup of reclaim and all finishing up
  ###   of reclaim.  It is also responsible for invoking the
  ###   main reclaim state machines of both page and paragraph
  ###   reclaim.
  ###
  ### PARAMETERS:
  ###   restart - If a restart is detected by system init
  ###              this parameter should be set to TRUE.
  ###             Normal operation should be FALSE.
  ###   method  - Method of reclaim (page or paragraph only.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE ExecuteCleanup(BOOLEAN restart, RECLAIM_Method method)
{

   FDI_ObjectInfo old_obj_info;   
   FDI_ObjectInfo obj_info = Init_FDI_ObjectInfo;   
   HDR_CompareInfo  compare_info = Init_HDR_CompareInfo;
   HDR_SearchInfo  OTT_SearchInfo;
   BYTE_PTR buffer_ptr;
   static FDI_Handle prev_hdr_addr;
   static UINT8 prev_hdr_NameSize;
   UINT32 current_dest_addr=DWORDMAX;
   UINT32 current_src_addr=DWORDMAX;
   UINT16            header_size;

   UINT16       last_block_2_reclaim;
   BYTE entry;
   ERR_CODE status = ERR_NONE;

   BOOLEAN         WIP_obj_found = FALSE;
   BOOLEAN         WIP_BC_obj_found = FALSE;
   BOOLEAN         invalid_backup_found = FALSE;
   HDR_Header      old_obj_SearchHeader;
   HDR_SearchInfo  old_obj_SearchInfo;
   HDR_SearchInfo  BC_SearchInfo = Init_HDR_SearchInfo;
   int             name_index;
/* E.5.1.790 */
   UINT32          blk_num = FDI_InvalidBlockNumber;
   UINT8           modify_object_status = TRUE; 

   if(!restart)
   {
      /* If there aren't any invalid objects to reclaim, then */
      /*  why bother!                                         */
      if(method == ReclaimParagraphObjects)
      {
         if(RECLAIM_CalcReclaimableParas() == 0)
         {
            return ERR_NONE;
         }
      }
      else
      {
         if(RECLAIM_CalcReclaimablePages() == 0)
         {
            return ERR_NONE;
         }
      }
   }
   else
   {
      prev_hdr_addr = 0;
      prev_hdr_NameSize = 0;
   }

   /* Init main reclaim search structure */
   HDR_InitSearchInfo((&SearchInfo), (&SearchHeader));

   /* Init main reclaim search structure */
   HDR_InitSearchInfo((&OTT_SearchInfo), (&OTT_SearchHeader));
   /* Set the reclaim state to a known set of values. */
   ReclaimState.SingleSkipRead = FALSE;
   ReclaimState.HeaderInRecBlk = FALSE;
   ReclaimState.TargetHeaderAddress = 0;
   ReclaimState.CurrentBlock2Reclaim = FDI_InvalidBlockNumber;
   ReclaimState.CurrentObject2Modify = 0;
   ReclaimState.InvalidObjectSize = 0;
   ReclaimState.OTTTblHdrAddr = 0;
   ReclaimState.OTTTblBaseAddr = 0;
   ReclaimState.RecTblHdrAddr = 0;
   ReclaimState.RecTblBaseAddr = 0;
   ReclaimState.NextState = (UINT16)RECLAIM_ST_ReadNextObj;
   ReclaimState.MarkHeaderCopyComplete = FALSE;

   /* Init reclaim block parameters */
   MemMap.FreeBlk.BytesFree = 0;
   MemMap.RecBlk.BytesUsed = 0;

   if(method == ReclaimParagraphObjects)
   {
      RecoverState.State = RECRCVR_AllocateConfigEntry;
      MemMap.RecBlk.BaseAddr = FDI_ReclaimBlockAddress + 
         FDI_BlockSize - 1;
   }
   else
   {
      RecoverState.State = RECRCVR_CreateOTTTable; 
      MemMap.RecBlk.BaseAddr = FDI_ReclaimBlockAddress;
   }

   if(restart)
   {
      /* Reclaim must be restarted, setup any vars and continue */
      /*  where we left off.                                    */
      status = 
         RECRCVR_CalcReclaimRestartState((BOOLEAN)(method == ReclaimParagraphObjects), restart);
      if(status)
      {
         return status;
      }
   }

   switch(RecoverState.State)
   {
      case RECRCVR_AllocateConfigEntry:

         /* Allocate configuration header reclaim state entry.  */
         status = 
         CFGHDR_AllocateConfigurationEntry(&ReclaimState.ConfigIndex,
            &ReclaimState.ConfigEntry,
            CFGHDR_TYPE_ReclaimTable, restart);
         if(status)
         {
            break;
         }

         EVT_Test4Crash(EVT_RECLAIM_StateA);
      /*lint -fallthrough*/
      case RECRCVR_CreateOTTTable:
         if(method == ReclaimPageObjects)
         {
            /* Create the OTT table and return the base address! */
            /* The space for the OTT table must be reserved      */
            /* by the allocate functions */
            status = OTTTBL_CreateTable(&OTT_SearchInfo, restart);
            if(status)
            {
               return status;
            }

            /* Save off the base address of the OTT table and the    */ /*
            address of the OTT table header entry.               */ /* NOTE:
            SearchInfo must reference the OTT table object. */
            ReclaimState.OTTTblBaseAddr = OTT_SearchInfo.CurrObj.ObjectAddress;
            ReclaimState.OTTTblHdrAddr = OTT_SearchInfo.CurrObj.HeaderAddress;

            /* Initialize the OTT table entries */for(entry = 0; entry <
               NUM_OTT_ENTRIES; entry++)
            {
                  /* Expand the object size from 2 bytes to 4 bytes to prevent the */
                  /* DAV flash corrupt following deallocate of object larger than 64KB; */
                  /* therefore, the value for the object size is changed from 0xFFFF to */
                  /* 0xFFFFFFFF */ 
                  ReclaimState.OTTTableInfo.OTTTBL_TableEntry[entry].objsize = DWORDMAX;
                  ReclaimState.OTTTableInfo.OTTTBL_TableEntry[entry].status = WORDMAX;
            }

            /* Initialize the OTT table ID to 0xFFFF */
            ReclaimState.OTTTableInfo.TableId = WORDMAX;

            /* Initialize the OTT table source address of the first object to be modified. */
            ReclaimState.OTTTableInfo.src_addr = DWORDMAX;

            /* Initialize the OTT table destination address of the first object to be modified. */
            ReclaimState.OTTTableInfo.dest_addr = DWORDMAX;

            status = OTTTBL_WriteTableInfo(ReclaimState.OTTTblBaseAddr, 
               (OTTTBL_TableInfoPtr)&ReclaimState.OTTTableInfo);
            if(status)
            {
                  break;
            }
         }
      /*lint -fallthrough*/
      case RECRCVR_CreateReclaimTable:

         /* Create the reclaim table and return the base address! */
         /* The space for the reclaim table must be reserved      */

⌨️ 快捷键说明

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