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

📄 davrecl.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 5 页
字号:
               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;
   UINT16          save_page_object_counter;
   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      */
         /*  by the allocate functions                            */
         status = RECTBL_CreateTable(&SearchInfo, 
            (BOOLEAN)(method == ReclaimPageObjects), restart);
         if(status)
         {
            return status;
         }

         EVT_Test4Crash(EVT_RECLAIM_StateB);

         /* Save off the base address of the reclaim table and the    */
         /*  address of the reclaim table header entry.               */
         /* NOTE: SearchInfo must reference the reclaim table object. */
         ReclaimState.RecTblBaseAddr = SearchInfo.CurrObj.ObjectAddress;
         ReclaimState.RecTblHdrAddr = SearchInfo.CurrObj.HeaderAddress;
      /*lint -fallthrough*/
      case RECRCVR_InitReclaimTable:


         status = LocateFirstBlock(method, &blk_num, restart);
         if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES))
         {
            return(status);
         }
         if(status == ERR_NONE)
         {
            ReclaimState.TableInfo.FirstBlock = (UINT16)blk_num;   
         }

         if(method == ReclaimPageObjects)
         {
            ReclaimState.TableInfo.TotalBlocks = (UINT16) 
               (Handle2Block((ReclaimState.RecTblBaseAddr + 
               RECTBL_PageRecTblSize - 1)) + 1) -
               ReclaimState.TableInfo.FirstBlock;
         }
         else
         {
            ReclaimState.TableInfo.TotalBlocks = (UINT16)(
               (ReclaimState.TableInfo.FirstBlock - 
               Handle2Block(ReclaimState.RecTblBaseAddr)) + 1);
         }

         status = RECTBL_WriteTableInfo(ReclaimState.RecTblBaseAddr, &ReclaimState.TableInfo, 
            (BOOLEAN)(method == ReclaimParagraphObjects));
         if(status)
         {
               break;
         }

         EVT_Test4Crash(EVT_RECLAIM_StateC);

         if(method == ReclaimParagraphObjects)
         {
            /* Write all of the block entries to the reclaim table. */
            status = RECPARA_InitReclaimTable(&SearchInfo, 
               ReclaimState.RecTblBaseAddr,
               &ReclaimState.TableInfo, restart);
            if(status)
            {
               break;
            }

            EVT_Test4Crash(EVT_RECLAIM_StateD);

            /* Write Reclaim Table offset + status of ReclaimInProgress */
            /*  to the configuration header.                            */
            status = CFGHDR_WriteTableOffset(ReclaimState.ConfigIndex, 
               ReclaimState.RecTblHdrAddr);
            if(status)
            {
                  break;
            }

            /* If we haven't already set the free block map, then */
            /*  point it to the top of the current erase block.   */
            MemMap.FreeBlk.BaseAddr = 
               Block2Handle(ReclaimState.TableInfo.FirstBlock) + 
               FDI_BlockSize - 1;
         }
         else
         {
            EVT_Test4Crash(EVT_RECLAIM_StateD);

            /* Initialize the page reclaim table */
            status = RECPAGE_InitReclaimTable(restart);
            if(status)
            {
               break;
            }

            /* If we haven't already set the free block map, then  */
            /*  point it to the bottom of the current erase block. */
            MemMap.FreeBlk.BaseAddr = 
               Block2Handle(ReclaimState.TableInfo.FirstBlock);
         }

         /* Start with first object in header space. */

⌨️ 快捷键说明

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