davrecpg.c

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

C
591
字号
      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)
               {
               	  /* E5.5.970 Start */ 
                  mDEBUG_CHECK_ERRCODE(status); 
                  /* E5.5.970 End */ 
                  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 + =
减小字号Ctrl + -
显示快捷键?