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

📄 davrecpg.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 2 页
字号:
   
   /* 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);
   
   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; */
         }
         
      break;

      case RECLAIM_ST_ProcessInvalidObj:
         
         /* Save the deleted page object's size */
         if ((HDR_GetAlignmentAttr(SearchInfo.HeaderPtr->Attr16) == 
                    HDR_HA_AlignPage) && 
             (SearchInfo.HeaderPtr->ObjectType != 
                    FDI_HT_ReclaimTable))
         {
            /* Assuming that deallocated page objects will always be contiguous */
            ReclaimState.InvalidObjectSize = 
                          PAGE_TO_BYTES(SearchInfo.HeaderPtr->LoSize);
         }
         /* The object exists, is invalid and it spans future blocks. */
         if (Handle2Block((ReclaimState.ObjectEndAddr)) > 
                                    ReclaimState.CurrentBlock2Reclaim)
         {
            /* Must erase every block in between until the end of the */
            /*  object is within the current block.                   */
            exit_state_machine = TRUE;
            break;
            /* goto ExitPageReclaimStateMachine; */
         }
         
         /* Erase blocks until all blocks between this invalid object */
         /*  are erased.                                              */
         if (Handle2Block(ReclaimState.ObjectEndAddr) == 
                                    ReclaimState.CurrentBlock2Reclaim)
         {
            ReclaimState.NextState = (UINT16)RECLAIM_ST_ReadNextObj;
            
            if (ReclaimState.ObjectEndAddr == 
               Block2Handle((ReclaimState.CurrentBlock2Reclaim + 1)) - 1)
            {
               exit_state_machine = TRUE;
               break;
               /* goto ExitPageReclaimStateMachine; */
            }
         }
         else
         {
            exit_state_machine = TRUE;
            /* goto ExitPageReclaimStateMachine; */
         }
         
      break;
      
      case RECLAIM_ST_CalcParameters:
      
         ReclaimState.NextState = (UINT16)RECLAIM_ST_CopyOut;

         ReclaimState.ObjectLoAddr = ReclaimState.ObjectBaseAddr;
         ReclaimState.ObjectHiAddr = ReclaimState.ObjectEndAddr;
      /*lint -fallthrough*/
      case RECLAIM_ST_CopyOut:
      
         /* Locate section of the object that is in this block. */
         /*  Set the bytes_in_block variable accordingly.       */
         GetInBlockHiLoAddress(&ReclaimState.ObjectLoAddr, 
                                   &ReclaimState.ObjectHiAddr, 
                                      ReclaimState.CurrentBlock2Reclaim);
                                      
         bytes_in_block = (ReclaimState.ObjectHiAddr - 
                                           ReclaimState.ObjectLoAddr) + 1;
         
         /* Locate a place to copy this portion of the object to           */
         /*  either the reclaim block or free space or both.               */
         /*  This will attempt to fill free space first, if there's        */
         /*  not enough free space it will split it into two transactions, */
         /*  The first to free space, the second to the reclaim block.     */
         if (MemMap.FreeBlk.BytesFree > 0)
         {
            /* Use Free Space (cause its available) */
            if (bytes_in_block >= MemMap.FreeBlk.BytesFree)
            {
               bytes_in_free_block = MemMap.FreeBlk.BytesFree;
            }
            else
            {
               bytes_in_free_block = bytes_in_block;
            }
            
            bytes_in_block -= bytes_in_free_block;
         }
         else
         {
            /* No free space is available. */
            bytes_in_free_block = 0;
         }
         
         /* If there is any data left to copy out, use the */
         /*  reclaim block.                                */
         if (bytes_in_block > 0)
         {
            bytes_in_reclaim_block = bytes_in_block;
            bytes_in_block -= bytes_in_reclaim_block;
         }
         else
         {
            bytes_in_reclaim_block = 0;
         }
      
         /* Copy the body of the current object out of the current block. */
         ReclaimState.NextState = (UINT16)RECLAIM_ST_CalcParameters;


         /* Update the ReclaimState.OTTTblEntry fields. */
         /* If the OTT flag is set, the OTT_entry flag is set, and if the ReclaimState.ObjectLoAddr is 
            different from the MemMap.FreeBlk.BaseAddr, write the OTT entry. 
            Then set the OTT flag to FALSE to indicate that the  OTT entry 
            has been written for this object.*/
         if( (OTT_entry_flag) && 
             (ReclaimState.InvalidObjectSize != 0) )
         {

            /* Initialize the OTTTable */
            if(!OTT_flag/* && (HDR_GetStatusAttr(hdr_attr) == HDR_HA_Valid)*/)
            {
      
               /* Save the source address of the first object to be modified. */   
               ReclaimState.OTTTableInfo.src_addr = 
               ReclaimState.ObjectLoAddr;
      
               /* Save the destination address of the first object to be modified. */    
               ReclaimState.OTTTableInfo.dest_addr = 
                  (ReclaimState.OTTTableInfo.src_addr -
                  ReclaimState.InvalidObjectSize);
                  
               /* Initialize the page OTT table */
               status = RECPAGE_InitOTTTable(restart);
               if (status)
               {
                  if(status == ERR_PLR_TEST_FAILURE)
                  {
                     return(status);
                  }
                  else
                  {   
                     break;
                  }
               }
               OTT_flag = TRUE;
            }

            /* Read the current object entry. */
            status = OTTTBL_ReadTable(ReclaimState.OTTTblBaseAddr, 
                       ReclaimState.CurrentObject2Modify, 
                       &ReclaimState.OTTTblEntry, restart);
            if(status != ERR_NONE)
            {
               return status;
            }    

            ReclaimState.OTTTblEntry.objsize = SearchInfo.CurrObj.ObjectSize;
      
            /* Write the current object entry. */
            status = OTTTBL_WriteTable(ReclaimState.OTTTblBaseAddr, 
                        ReclaimState.CurrentObject2Modify, 
                               &ReclaimState.OTTTblEntry, restart);
            if(status != ERR_NONE)
            {
               return status;
            }   

            /* Mark the current object status to OTTTBL_MASK_OTTEntryValid. */    
            OTTTBL_MarkOTTEntryValid(ReclaimState.OTTTblEntry.status);
            status = OTTTBL_WriteTable(ReclaimState.OTTTblBaseAddr, 
                        ReclaimState.CurrentObject2Modify, 
                        &ReclaimState.OTTTblEntry, restart);
            if(status != ERR_NONE)
            {
               return status;
            }    
      
            /* Increment the object counter to indicate that the 
               status field of the OTT entry needs to be updated. */
            ReclaimState.CurrentObject2Modify++;  
         
            OTT_entry_flag = FALSE;
         }


         /* Copy the free block portion to free space. */
         if (bytes_in_free_block > 0)
         {
            /* Must copy the low portion of the object to free space. */
            status = FLASH_CopyFlash(ReclaimState.ObjectLoAddr, 
                                         MemMap.FreeBlk.BaseAddr, 
                                              bytes_in_free_block);
            if (status)
            {
               return(status);
            }
            ReclaimState.ObjectLoAddr += bytes_in_free_block;
            
            MemMap.FreeBlk.BaseAddr += bytes_in_free_block;
            MemMap.FreeBlk.BytesFree -= bytes_in_free_block;
         }
         
         /* Must mark the block done before copying to the */ 
         /*  reclaim block if the TO block gets filled.    */
         #ifdef ENABLE_RECLAIM_TESTS
            if (EVT_TestEvent(EVT_RECLAIM_StateF_4))
            {
               EVT_SetEnabled(EVT_RECLAIM_StateF_4a);
               /* EVT_SetEnabled(EVT_RECLAIM_StateF_4b); */
            }
         #endif
         
         status = RECLAIM_MarkBlockDone(FALSE, restart);
         if (status)
         {
            return status;
         }
         
         /* Copy any remaining data to the reclaim block. */
         if (bytes_in_reclaim_block > 0)
         {
            /* The recblk.baseaddr always points to the first */
            /*  free byte from the bottom of the block.       */
            status = FLASH_CopyFlash(ReclaimState.ObjectLoAddr, 
                                        MemMap.RecBlk.BaseAddr + 
                                          MemMap.RecBlk.BytesUsed,
                                           bytes_in_reclaim_block);
            if (status)
            {
               return status;
            }
            
            MemMap.RecBlk.BytesUsed += bytes_in_reclaim_block;
            
            EVT_Test4Crash(EVT_RECLAIM_StateF_3c);
         }
         
         /* Detect when entire object is copied out. */
         if (Handle2Block(ReclaimState.ObjectEndAddr) <=
                                ReclaimState.CurrentBlock2Reclaim)
         {
            /* We have finished this object so get the next one */
            /*  if there are more blocks to go.                 */
            ReclaimState.NextState = (UINT16)RECLAIM_ST_ReadNextObj;
           
            /* Check to see if the base address of the object */
            /*  falls just at the edge of the block.          */
            if (ReclaimState.ObjectEndAddr == 
               Block2Handle((ReclaimState.CurrentBlock2Reclaim + 1)) - 1)
            {
               exit_state_machine = TRUE;
               break;
               /* goto ExitPageReclaimStateMachine; */
            }
         }   
         else
         {
            /* We have not copied the object out of the next  */
            /*  block and there are more bytes in the object. */
            ReclaimState.NextState = (UINT16)RECLAIM_ST_CalcParameters;
            
            exit_state_machine = TRUE;
            break;
            /* goto ExitPageReclaimStateMachine; */
         }
                           
      break;

      default: 
         exit_state_machine = TRUE;
         /* goto ExitPageReclaimStateMachine; */
   }
   
   /* goto PageReclaimStateMachine; */
   } while (!exit_state_machine);
   
/* ExitPageReclaimStateMachine: */

   /* Erase the current block (if its not the last one!) */
   if ((ReclaimState.NextState != (UINT16)RECLAIM_ST_ReclaimComplete) && (!status))
   {
      #ifdef ENABLE_RECLAIM_TESTS
         if (EVT_TestEvent(EVT_RECLAIM_StateF_6))
         {
            /* Supported Crashes: 6a...6c */
            EVT_SetEnabled(EVT_RECLAIM_StateF_6a);
            /* EVT_SetEnabled(EVT_RECLAIM_StateF_6b); */
            /* EVT_SetEnabled(EVT_RECLAIM_StateF_6c); */
         }
      #endif
      status = RECLAIM_FinishBlock(ReclaimState.CurrentBlock2Reclaim, 
                                   FALSE, TRUE, restart);
   }
   
   return status;
}

#endif /* DIRECT_ACCESS_VOLUME */


⌨️ 快捷键说明

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