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

📄 davrecpg.c

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

/* ###########################################################################
###  RECPAGE
###
###  Module: recpage.c - Page Reclaim Specific Code
###
###  $Workfile: davrecpg.c $
###  $Revision: 65 $
###  $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
#########################*/

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

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

/* E.5.0.652 Begin */
static BOOLEAN QualifyObjectInfo(HDR_SearchInfo *search_info_ptr,
                                 UINT32               block_number);
/* E.5.0.652 End */

/*########################################################################
  ### QualifyObjectInfo
  ###
  ### DESCRIPTION:
  ###   This function is used to determine whether an object has
  ###   some portion of itself in a block, and if that portion is
  ###   valid in order to copy.  It also determines when reclaim
  ###   is done (by the reclaim table object).
  ###
  ### PARAMETERS:
  ###   search_info_ptr  - Current object information.
  ###   block_number     - Current block under reclaim.
  ###
  ### RETURNS:
  ###   TRUE  - block is complete (nothing to copy in curr block)
  ###   FALSE - continue copying valid data and reading headers.
  ###
*/
/* E.5.0.652 Begin */
static BOOLEAN QualifyObjectInfo(HDR_SearchInfo *search_info_ptr,
                                 UINT32               block_number)
/* E.5.0.652 End */
{
int    in_block;
UINT32  curr_obj_size;

   curr_obj_size = SearchInfo.CurrObj.ObjectSize;
   
   if ((HDR_GetAbsorbedAttr(search_info_ptr->HeaderPtr->Attr16) == 
                                                  HDR_HA_Exists) &&
                  (HDR_GetAlignmentAttr(SearchInfo.HeaderPtr->Attr16) == 
                                                       HDR_HA_AlignPage))
   {
      /* Make sure that some portion of this object is in the block. */
      ReclaimState.ObjectBaseAddr = SearchInfo.CurrObj.ObjectAddress;
      ReclaimState.ObjectEndAddr = ReclaimState.ObjectBaseAddr + 
                                                   curr_obj_size - 1;
                                    
      in_block = IsInBlock(ReclaimState.ObjectBaseAddr, 
                           ReclaimState.ObjectEndAddr, block_number);
      if (in_block == -1)
      {
         /* This object is completely before this block, thus, */
         /*  read the next object.                             */
         return FALSE;
      }
   
      /* If we have a Valid object, copy it out of the block. */
      if (HDR_GetHdrState(search_info_ptr->HeaderPtr->Attr16) == 
                                                        HDR_HA_STATE_Valid)
      {
         ReclaimState.NextState = (UINT16)RECLAIM_ST_CalcParameters;
         
         if (search_info_ptr->HeaderPtr->ObjectType == FDI_HT_ReclaimTable)
         {
            ReclaimState.NextState = (UINT16)RECLAIM_ST_ReclaimComplete;
            return TRUE;
         }
         
         /* in_block == 0 thus, Some portion of the object is */ 
         /*     in this block.                                */
         if (in_block == 1)
         {
            /* This object is completely above this block number, thus,   */
            /*  move on to the next block, but don't read the next object */
            /*  when the block that this object is in gets there.         */
            return TRUE;
         }
      }
      else
      {
         ReclaimState.NextState = (UINT16)RECLAIM_ST_ProcessInvalidObj;
      }
   }
   
   return FALSE;
}

/*### Global Functions
#########################*/


/*########################################################################
  ### RECPAGE_InitOTTTable
  ###
  ### DESCRIPTION:
  ###   This function simply marks the OTT table as complete.
  ###
  ### PARAMETERS:
  ###   none.
  ###  
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECPAGE_InitOTTTable(BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;

   /* At present there is no initialization of the actual OTT */
   /*  table for page reclaim.  This is a place holder in the     */
   /*  event that it changes.                                     */
   
   /* Tell Recovery that the table is initialized */
   /*#ifdef ENABLE_RECLAIM_TESTS
      if (EVT_TestEvent(EVT_RECLAIM_StateE_SP1))
      {
         EVT_SetEnabled(EVT_RECLAIM_StateE_SP2);
      }
   #endif*/
            
   status = OTTTBL_WriteTableInfo( ReclaimState.OTTTblBaseAddr, 
              (OTTTBL_TableInfoPtr)&ReclaimState.OTTTableInfo);
   /* E5.5.970 Start */ 
   mDEBUG_CHECK_ERRCODE(status);
   /* E5.5.970 End */ 
   if (!status)
   {
      status = OTTTBL_MarkTableComplete(ReclaimState.OTTTblHdrAddr, 
                                ReclaimState.OTTTblBaseAddr, TRUE, restart);
   }

   return status;
}


/*########################################################################
  ### RECPAGE_InitReclaimTable
  ###
  ### DESCRIPTION:
  ###   This function simply marks the reclaim table as complete.
  ###
  ### PARAMETERS:
  ###   none.
  ###  
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECPAGE_InitReclaimTable(BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;

   /* At present there is no initialization of the actual reclaim */
   /*  table for page reclaim.  This is a place holder in the     */
   /*  event that it changes.                                     */
   
   /* Tell Recovery that the table is initialized */
   #ifdef ENABLE_RECLAIM_TESTS
      if (EVT_TestEvent(EVT_RECLAIM_StateE_SP1))
      {
         EVT_SetEnabled(EVT_RECLAIM_StateE_SP2);
      }
   #endif
            
   status = RECTBL_MarkTableComplete(ReclaimState.RecTblHdrAddr, 
                                ReclaimState.RecTblBaseAddr, TRUE, restart);

   return status;
}

/*########################################################################
  ### RECPAGE_SaveValidObjsInCurrBlock
  ###
  ### DESCRIPTION:
  ###   This is the main paragraph reclaim state machine.  It is
  ###   responsible for copying valid objects out of a block,
  ###   erasing it, and copying any valid objects back from the
  ###   reclaim block when it is used.
  ###
  ### PARAMETERS:
  ###   none.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECPAGE_SaveValidObjsInCurrBlock(BOOLEAN restart)
{
UINT32 bytes_in_block;
UINT32 bytes_in_free_block;
UINT32 bytes_in_reclaim_block;

BOOLEAN exit_state_machine = FALSE;

/* Flag to indicate the OTT entry needs to written. */
BOOLEAN OTT_entry_flag = FALSE;

ERR_CODE status = ERR_NONE;

   /* Mark the current block status to ReclaimInProgress. */
   RECTBL_ReadTable(ReclaimState.RecTblBaseAddr, 
                          ReclaimState.CurrentBlock2Reclaim, 
                               &ReclaimState.RecTblEntry, FALSE, restart);
                     
   RECTBL_MarkReclaimInProgress(ReclaimState.RecTblEntry);
                     
   RECTBL_WriteTable(ReclaimState.RecTblBaseAddr, 
                        ReclaimState.CurrentBlock2Reclaim, 
                               &ReclaimState.RecTblEntry, FALSE, restart);
   /* E5.5.970 Start */ 
   if(status)
   {
      return status;
   }
   /* E5.5.970 End */ 
   EVT_Test4Crash(EVT_RECLAIM_StateF_1);

   status = ERR_NONE;

/* PageReclaimStateMachine: */
   do
   {
   switch (ReclaimState.NextState)
   {
      case RECLAIM_ST_ReadNextObj:
      
         if (!ReclaimState.SingleSkipRead)
         {
            /* Just read the next object & calculate its base address */
            status = GetNextHeader((HDR_SearchInfoPtr)&SearchInfo, 
                                                      HDR_ByNextObject, 0, restart);
            if (status)
            {
               return status;
            }

            /* If the object is valid, set the flag to indicate the 
               OTT entry needs to written */
            OTT_entry_flag = TRUE;

         }
         else
         {
            ReclaimState.SingleSkipRead = FALSE;
         }

         if (QualifyObjectInfo(&SearchInfo, 
                                    ReclaimState.CurrentBlock2Reclaim))
         {
            exit_state_machine = TRUE;
            /* goto ExitPageReclaimStateMachine; */
         }
         

⌨️ 快捷键说明

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