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

📄 davrecrv.c

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

/* ###########################################################################
###  RECRCVR
###
###  Module: recrcvr.c - Reclaim Recovery Module
###
###  $Workfile: davrecrv.c $
###  $Revision: 53 $
###  $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
//#########################*/

/* Recover State Lookup Table inputs */
enum
{
   RSLT_HeaderWTable  = 0x0,
   RSLT_HeaderNoTable = 0x1,
   RSLT_NoTable       = 0x2,
   
   RSLT_RBWTable      = 0x4,
   RSLT_RBNoTable     = 0x8
};                             

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

RECRCVR_StateInfo RecoverState;

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


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

/*########################################################################
  ### LookupRecoverState
  ###
  ### DESCRIPTION:
  ###   This function will determine the state of the main reclaim
  ###   state table see, "Recover State Definitions" table in the
  ###   CSPEC.  The table definitions are described in the
  ###   "Recover State Lookup Table" of the CSPEC.
  ###
  ### PARAMETERS:
  ###   HT_input           - Header Table block input
  ###   RT_input           - Reclaim Table block input
  ###   paragraph_reclaim  - TRUE: paragraph reclaim state lookup
  ###                      - FALSE: page reclaim state lookup
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE LookupRecoverState(UINT16    HT_input, 
                              UINT16    RB_input, 
                              BOOLEAN paragraph_reclaim)
{
   /* Recover State Lookup Table (RSLT) */
   switch ((HT_input | RB_input))
   {
      case (RSLT_HeaderWTable | RSLT_RBWTable):
      
         RecoverState.State = RECRCVR_RelocateReclaimTable;
      
      break;
      
      case (RSLT_HeaderNoTable | RSLT_RBWTable):
      
         RecoverState.State = RECRCVR_FinishRemainingBlocks;
      
      break;
      
      case (RSLT_NoTable | RSLT_RBWTable):
      
         RecoverState.State = RECRCVR_FinishRemainingBlocks;
      
      break;
      
      case (RSLT_HeaderWTable | RSLT_RBNoTable):
         /* All kinds of possibilities here ! */
         
         if (paragraph_reclaim)
         {
            if (HDR_ID_GetReclaimState(SearchHeader.HeaderId) ==
                                          HDR_ST_ReclaimInProgress)
            {
               RecoverState.State = RECRCVR_RelocateReclaimTable;
            }
            else 
            {
               if (HDR_ID_GetReclaimState(SearchHeader.HeaderId) ==
                                                      HDR_ST_Normal)
               {                            
                  RecoverState.State = RECRCVR_StartStateMachine;
               }
               else
               {
                  return ERR_SYSTEM;
               }
            }
         }
         else
         {
            if (HDR_GetStatusAttr(SearchHeader.Attr16) == 
                                         HDR_HA_WriteInProgress)
            {
               RecoverState.State = RECRCVR_InitReclaimTable;
            }
            else
            {
               if (HDR_GetStatusAttr(SearchHeader.Attr16) == 
                                                   HDR_HA_Valid)
               {
                  RecoverState.State = RECRCVR_StartStateMachine;
               }
               else
               {
                  return ERR_SYSTEM;
               }
            }
         }
         
      break;
      
      case (RSLT_HeaderNoTable | RSLT_RBNoTable):
         
         /* Could have been creating the reclaim table and */
         /*  not finished the header.                      */
         if (paragraph_reclaim)
         {
            /* The configuration header offset would indicate this */
            /*  state before getting here.                         */
            return ERR_SYSTEM;
         }
         else
         {
            if (HDR_GetStatusAttr(SearchHeader.Attr16) == 
                                         HDR_HA_WriteInProgress)
            {
               RecoverState.State = RECRCVR_InitReclaimTable;
            }
            else
            {
               /* Table was not being created, the headers */
               /*  haven't been absorbed.                  */
               RecoverState.State = RECRCVR_FinishUpReclaim;
            }
         }
         
      break;
      
      case (RSLT_NoTable | RSLT_RBNoTable):
      
         /* Must have not finished marking the config offset to */
         /*  reclaim complete.                                  */
         if (paragraph_reclaim)
         {
            RecoverState.State = RECRCVR_FinishUpReclaim;
         }
         else
         {
            return ERR_SYSTEM;
         }
      
      break;
  
      default:
      {};
   }
   
   return ERR_NONE;
}   

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

/*########################################################################
  ### RECRCVR_LocateTO_N_FROMBlocks
  ###
  ### DESCRIPTION:
  ###   This function will go through the reclaim table and locate
  ###   the TO and FROM block information.  For paragraph reclaim
  ###   it will also locate the FirstHeaderLocation.
  ###
  ###  NOTE:  ReclaimState.RecTblBaseAddr must contain a 
  ###         completely initialized reclaim table.
  ### 
  ### PARAMETERS:
  ###   paragraph_reclaim  - Indicates special processing for
  ###                        page vs. paragraph reclaim.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECRCVR_LocateTO_N_FROMBlocks(BOOLEAN paragraph_reclaim, BOOLEAN restart)
{
UINT32             ii;
UINT32             current_block;
ERR_CODE        status = ERR_NONE;
RECTBL_TableEntry prev_entry;

   RecoverState.TOBlock = FDI_InvalidBlockNumber;
   RecoverState.FHLBlock = FDI_InvalidBlockNumber;
   RecoverState.FROMBlock = FDI_InvalidBlockNumber;
   
   RECTBL_InitStatusEntry(prev_entry);
   
   /* Loop through the reclaim table looking for certain properties. */
   current_block = ReclaimState.TableInfo.FirstBlock;
   for (ii = 0; ii < ReclaimState.TableInfo.TotalBlocks; ii++)
   {
      RECTBL_ReadTable(ReclaimState.RecTblBaseAddr, current_block, 
                          &ReclaimState.RecTblEntry, paragraph_reclaim, restart);
                                             
      /* Search the reclaim table for any blocks marked EraseInProgress */
      /*  and no EraseComplete or CopyComplete and no EraseInProgress.  */
      if ((RECTBL_IsEraseInProgress(ReclaimState.RecTblEntry) && 
             !RECTBL_IsEraseComplete(ReclaimState.RecTblEntry)) ||
                (RECTBL_IsCopyComplete(ReclaimState.RecTblEntry) && 
                   !RECTBL_IsEraseInProgress(ReclaimState.RecTblEntry)))
      {
         /* Mark the block as EraseInProgress. */
         RECTBL_MarkEraseInProgress(ReclaimState.RecTblEntry);
         status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr, 
                           current_block, &ReclaimState.RecTblEntry,
                                                     paragraph_reclaim, restart);
         if (status)
         {
            return status;
         }
         
         /* Erase the block. */
         status = FLASH_EraseBlock(Block2Handle(current_block), FALSE);
         if (status)
         {
            return status;
         }
         
         /* Mark the block as EraseComplete. */
         RECTBL_MarkEraseComplete(ReclaimState.RecTblEntry);
         status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr, 
                        current_block, &ReclaimState.RecTblEntry,
                                                 paragraph_reclaim, restart);
         if (status)
         {
            return status;
         }
      }
      
      /* Check to see if the block has been erased and there is */
      /*  data in the reclaim block to be copied back.          */
      if (RECTBL_IsEraseComplete(ReclaimState.RecTblEntry) && 
                  !RECTBL_IsCopyComplete(ReclaimState.RecTblEntry))
      {
         /* Pretend the entire block contains valid data. */
         MemMap.RecBlk.BytesUsed = FDI_BlockSize;
         MemMap.RecBlk.BaseAddr = FDI_ReclaimBlockAddress;
         MemMap.FreeBlk.BaseAddr = Block2Handle(current_block);

         if (Handle2Block(ReclaimState.RecTblBaseAddr) == 
                             Handle2Block(FDI_ReclaimBlockAddress))
         {
            if (paragraph_reclaim)
            {
               MemMap.RecBlk.BytesUsed -= RECTBL_ParaRecTblSize;
               MemMap.RecBlk.BaseAddr += RECTBL_ParaRecTblSize;
               MemMap.FreeBlk.BaseAddr += RECTBL_ParaRecTblSize;
            }
            else
            {
               MemMap.RecBlk.BytesUsed -= RECTBL_PageRecTblSize;
            }
         }
         
         status = FLASH_CopyFlash(MemMap.RecBlk.BaseAddr, 
                  MemMap.FreeBlk.BaseAddr, MemMap.RecBlk.BytesUsed);
         if (status)
         {
            return status;
         }
   
         RECTBL_MarkCopyComplete((ReclaimState.RecTblEntry));
         status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr, 
                         current_block, &ReclaimState.RecTblEntry,
                                                 paragraph_reclaim, restart);
         if (status)
         {
            return status;
         }
      }

      /* Check to see if there is a possibility that the reclaim */
      /*  block did not finish getting erased.                   */
      if ((!RECTBL_IsReclaimInProgress(ReclaimState.RecTblEntry)) &&
                                   RECTBL_IsCopyComplete(prev_entry))
      {
         if (Handle2Block(FDI_ReclaimBlockAddress) != 
                           Handle2Block(ReclaimState.RecTblBaseAddr))
         {
            status = FLASH_EraseBlock(FDI_ReclaimBlockAddress, FALSE);
            if (status)
            {
               return status;
            }
         }
         
         /* Mark the current block to RIP so we don't erase the */
         /*  reclaim block again.                               */
         RECTBL_MarkReclaimInProgress((ReclaimState.RecTblEntry));
         status = RECTBL_WriteTable(ReclaimState.RecTblBaseAddr, 
                         current_block, &ReclaimState.RecTblEntry,
                                                 paragraph_reclaim, restart);
         if (status)
         {
            return status;
         }
      }
   
      if (RecoverState.TOBlock == FDI_InvalidBlockNumber)
      {
         /* Locate the first entry in the reclaim table with */
         /*  TOBlock = no [Done] bit marked.                 */
         if (!RECTBL_IsBlockDone(ReclaimState.RecTblEntry))
         {
            RecoverState.TOBlock = current_block;
            RecoverState.TOReclaimStatus = ReclaimState.RecTblEntry;
         }
      }
      
      if (RecoverState.FROMBlock == FDI_InvalidBlockNumber)
      {
         /* Locate the first entry in the reclaim table with */
         /*  no [CC] bit marked = FROMBlock.                 */
         if (!RECTBL_IsCopyComplete(ReclaimState.RecTblEntry) &&
                       !RECTBL_IsBlockDone(ReclaimState.RecTblEntry))
         {
            RecoverState.FROMBlock = current_block;
            RecoverState.FROMReclaimStatus = ReclaimState.RecTblEntry;
         }
      }

⌨️ 快捷键说明

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