davrcvpr.c

来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 844 行 · 第 1/3 页

C
844
字号
  ### UsePrevHeader  |    (A) 1,2         -------        -------
  ### UseCurrObject  |    (B) 5          (C) 1,2,4       (D) 3
  ### UseDummyObject |     -------       (E) 1           -------
  ###
  ### PARAMETERS:
  ###   none.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
*/
ERR_CODE RCVRPARA_SetupForParaReclaimRestart(BOOLEAN restart)
{
/* TO & FROM Address Calculation Methods */
enum
{
   UsePrevHeader,
   UseCurrObject,
   UseNextObject,
   UseDummyObject,
   UseNoObject
} to_addr_method = UseNoObject, from_addr_method = UseNoObject;
/* DAV- added initial values above for to_addr_method, from_addr_method */

int        in_block;
UINT32      pre_block_bytes;
FDI_Handle fhl_hdr_addr;
FDI_Handle top_of_from_block;
ERR_CODE status = ERR_NONE;

   /* Misc. local calculations to save time */
   fhl_hdr_addr = 
       RECTBL_GetFirstHeaderLocation((RecoverState.FHLReclaimStatus), 
                                               RecoverState.FHLBlock);

   top_of_from_block = Block2Handle((RecoverState.FROMBlock + 1)) - 1;
   
   in_block = IsInBlock(RecoverState.TOObject.ObjectAddress, 
                           top_of_from_block, RecoverState.FROMBlock);
   
   ReclaimState.SingleSkipRead = TRUE;
   ReclaimState.MarkHeaderCopyComplete = TRUE;

   /* Obtain the FROMInput and TOInput values for the lookup table. */
   status = LocateLastTOObject(&SearchInfo, restart);
   if (!status)
   {
      status = LocateLastFROMObject(&SearchInfo, restart);
   }
   
   if (status)
   {
      return status;
   }
   
   /*************************************************/
   /* Calculate the appropriate lookup table inputs */
   /*************************************************/
   if (RecoverState.FROMInput == HDR_ST_Normal)
   {
      RecoverState.FROMInput = FROM_ObjectNormal;   
   }
   else
   {
      RecoverState.FROMInput = FROM_ObjectReclaimInProgress;   
   }

   if (RecoverState.TOInput == HDR_ST_Normal)
   {
      RecoverState.TOInput = TO_ObjectNormal;   
   }
   else
   {
      if (RecoverState.TOInput == HDR_ST_CopyInProgress)
      {
         RecoverState.TOInput = TO_ObjectCopyInProgress;   
      }
      else
      {
         RecoverState.TOInput = TO_NoObject;   
      }
   }

   #ifdef PRINT_ON   
      printf("  RESTART STATE MACH: ");
   #endif
   
   /*************************************************/
   /*** TO & FROM Address Lookup Table            ***/
   /*************************************************/
   /*************************************************/
   /*** (1) Normal/Normal                         ***/
   /*************************************************/
   if ((RecoverState.FROMInput | RecoverState.TOInput) ==
                                 (FROM_ObjectNormal | TO_ObjectNormal))  
   {      
      #ifdef PRINT_ON   
         printf("(1) Norm/Norm");
      #endif
      
      /* Theres a possibility that the FROM object is invalid    */
      /*  in which we create a dummy object, or, that its valid, */
      /*  and we need to re-copy it.                             */
      
      EVT_CountOccurance(EVT_RECRCVR_State1);
      
      from_addr_method = UseCurrObject;
      to_addr_method = UseNextObject;
      if (RecoverState.FROMObject.HeaderAddress == fhl_hdr_addr)
      {
         if (RECTBL_IsPreviousValidObject(RecoverState.FHLReclaimStatus))
         {
            /* The TO Object refers to an object that has a header before */
            /*  the first block but a portion of that object resides in   */
            /*  a block under reclaim.                                    */
            if ((in_block == 0) && (RecoverState.FHLBlock == 
                                      ReclaimState.TableInfo.FirstBlock))
            {
               EVT_CountOccurance(EVT_RECRCVR_State1_a);
               
               from_addr_method = UsePrevHeader;
               to_addr_method = UseCurrObject;
            }
         }
         else
         {
            if (RecoverState.FHLBlock != RecoverState.FROMBlock)
            {
               EVT_CountOccurance(EVT_RECRCVR_State1_b);
               
               from_addr_method = UseDummyObject;
            }
         }
      }
   }   
      
   /*************************************************/
   /*** (2) Normal/CIP                            ***/
   /*************************************************/
   if ((RecoverState.FROMInput | RecoverState.TOInput) == 
                         (FROM_ObjectNormal | TO_ObjectCopyInProgress))
   {   
      #ifdef PRINT_ON   
         printf("(2) Norm/CIP");
      #endif
      
      /* Determine if there is any object prior to the from */
      /*  object that hasn't been copied.                   */
   
      EVT_CountOccurance(EVT_RECRCVR_State2);
               
      from_addr_method = UseCurrObject;
      to_addr_method = UseNextObject;
      
      if ((RecoverState.FROMObject.HeaderAddress == fhl_hdr_addr) &&
           RECTBL_IsPreviousValidObject(RecoverState.FHLReclaimStatus)
                                                    && (in_block == 0))
      {
         /* If there was a previous valid object, then finish copying */
         /*  it by calculating where the original header resided and  */
         /*  reading the object information stored in the TO object.  */
         EVT_CountOccurance(EVT_RECRCVR_State2_a);
      
         from_addr_method = UsePrevHeader;
         to_addr_method = UseCurrObject;
      }
      
      if (to_addr_method == UseNextObject)
      {
         /* Mark the TOObject header to Normal...Its already been     */
         /*  copied.                                                  */
         EVT_CountOccurance(EVT_RECRCVR_State2_b);
         
         TempHeader.HeaderId = HDR_ID_Normal;
         status = 
              FLASH_WriteBuffer(RecoverState.TOObject.HeaderAddress, 
                                    (MemBufferPtr)&TempHeader.HeaderId, 
                                             sizeof(TempHeader.HeaderId));
         if (status)
         {
            return status;
         }
      }
   }   
      
   /*************************************************/
   /*** (3) Normal/NoHdr  RIP/NoHdr               ***/
   /*************************************************/
   if (((RecoverState.FROMInput | RecoverState.TOInput) ==
                          (FROM_ObjectNormal | TO_NoObject)) ||
         ((RecoverState.FROMInput | RecoverState.TOInput) == 
                         (FROM_ObjectReclaimInProgress | TO_NoObject)))
   {
      #ifdef PRINT_ON   
         printf("(3) Norm/NoObj, RIP/NoObj");
      #endif
      EVT_CountOccurance(EVT_RECRCVR_State3);
      
      /* Processing the first object (special case) start  */
      /*  back at the beginning.                           */
      from_addr_method = UseCurrObject;
      to_addr_method = UseNoObject;
   }      
      
   /*************************************************/
   /*** (4) RIP/Normal                            ***/
   /*************************************************/
   if ((RecoverState.FROMInput | RecoverState.TOInput) ==
                      (FROM_ObjectReclaimInProgress | TO_ObjectNormal))
   {      
      #ifdef PRINT_ON   
         printf("(4) RIP/Norm");
      #endif
      EVT_CountOccurance(EVT_RECRCVR_State4);

      /* Haven't started copying the FROM object yet.      */
      from_addr_method = UseCurrObject;
      to_addr_method = UseNextObject;
   }      
      
   /*************************************************/
   /*** (5) RIP/CIP                               ***/
   /*************************************************/
   if ((RecoverState.FROMInput | RecoverState.TOInput) ==
              (FROM_ObjectReclaimInProgress | TO_ObjectCopyInProgress))
   {      
      #ifdef PRINT_ON   
         printf("(5) RIP/CIP");
      #endif
      EVT_CountOccurance(EVT_RECRCVR_State5);
      
      /* We were copying the from object to the to object. */
      from_addr_method = UseCurrObject;
      to_addr_method = UseCurrObject;
   }
   
   #ifdef PRINT_ON
      printf(", ");
   #endif
   
   /*************************************************/
   /*** Calculate actual TO & FROM address        ***/
   /*************************************************/
   /*************************************************/
   /*** (A) Previous From/Current To              ***/
   /*************************************************/
   if (from_addr_method == UsePrevHeader)
   {
      #ifdef PRINT_ON   
         printf("PrevFrom/CurrTO (A)");
      #endif
      EVT_CountOccurance(EVT_RECRCVR_StateA);
      
      if (to_addr_method != UseCurrObject)
      {
         return ERR_SYSTEM;
      }
      
      ReclaimState.HeaderCopied = TRUE;
      ReclaimState.MarkHeaderCopyComplete = TRUE;
      
      /* The FROMObject header has been erased, use the    */
      /*  header information from the TO object.           */
      FLASH_ReadBuffer(RecoverState.TOObject.HeaderAddress,
                   (MemBufferPtr)&SearchHeader, HDR_FixedSize);

      status = UINT16_HeaderFixISF_PLR( &(SearchHeader.Attr16), 
        (RecoverState.TOObject.HeaderAddress + HDR_OffsetToAttr16), restart);
      if(status)
      {
         return status;
      }    
      /*fix header ID*/
      status = UINT16_FixISF_PLR( &(SearchHeader.HeaderId), 
        (RecoverState.TOObject.HeaderAddress + HDR_OffsetToHeaderId), restart);             
      if(status)
      {
         return status;
      }  

      
      /* Adjust the FROM header address to point to the    */
      /*  location where the previous FROM object resided. */

⌨️ 快捷键说明

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