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

📄 davrecl.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 5 页
字号:

                           /* Add PLR State Recording Support */
                           RECOVER_MarkDatabaseReady();

                           /* Write new (modified) data to new location */
                           status = FLASH_WriteBuffer(obj_info.ObjectAddress, 
                                                      (UINT8_PTR)buffer_ptr, 
                                                      PAGE_TO_BYTES(obj_info.ObjectSize));

                           /* Mark the OTT Table entry status for this item
                           * "object update complete"
                           */
                           OTTTBL_MarkObjectModified(ReclaimState.OTTTblEntry.status) ;
                           status = OTTTBL_WriteTable(ReclaimState.OTTTblBaseAddr, 
                              ReclaimState.CurrentObject2Modify, 
                              &ReclaimState.OTTTblEntry, restart); 
                           if(status)
                           {
                              return status;
                           }

                        }/* if to be modified. */
                     }/* if not already modified. */

                     if(modify_object_status == TRUE)
                     {
                        compare_info.CompareValue = OTT_SearchInfo.HeaderPtr->ObjectType;
  
                        /* If power loss occurs right after mark the OTT Table entry */
                        /* to object update complete, the name and name size of the  */
                        /* object will be lost, so they need to be recoverred for    */
                        /* searching next header of the object by name and type.     */
                        if(restart)
                        {                          
                           compare_info.NameSize = OTT_SearchInfo.HeaderPtr->NameSize;
/* E.5.0.600.START */
                           if(compare_info.NamePtr == NULL)
                           {
                              compare_info.NamePtr = (HDR_NamePtr)HeaderNamePtr;
                           }
/* E.5.0.600.END */
                           for (name_index = 0; 
                                name_index < OTT_SearchInfo.HeaderPtr->NameSize;           
                                name_index++)
                           {
                              ((UINT8_PTR)compare_info.NamePtr)[name_index] = 
                                 OTT_SearchInfo.HeaderPtr->Name[name_index];

                           }
                        }
  
                        status = GetNextHeader(&OTT_SearchInfo, HDR_ByNameType, 
                                               &compare_info, restart);
                        if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
                            (status != ERR_PARAM))
                        {
                           return(status);
                        }

                        /* This means all information is valid in OTT_SearchInfo */
                        OTT_SearchInfo.HeaderPtr->Attr16 = 
                           HDR_SetStatusAttr(OTT_SearchInfo.HeaderPtr->Attr16, 
                                             HDR_HA_Invalid);
                        header_size = 
                           HDR_CalcHeaderSize(OTT_SearchInfo.HeaderPtr);
                        FDI_MemUsage.PageSpace.Invalid += 
                           OTT_SearchInfo.CurrObj.ObjectSize;
                        FDI_MemUsage.PageSpace.Valid   -= 
                           OTT_SearchInfo.CurrObj.ObjectSize;
                        FDI_MemUsage.PageOverhead.Invalid += header_size;
                        FDI_MemUsage.PageOverhead.Valid   -= header_size;

                        /* Mark backup copy of old data invalid */
                        status = FLASH_WriteBuffer(
                              (OTT_SearchInfo.CurrObj.HeaderAddress + 
                               ((UINT32)HDR_Attrib16Offset)),
                              (MemBufferPtr)&OTT_SearchInfo.HeaderPtr->Attr16,
                              HDR_Attrib16Size);
                        if(status == ERR_NONE)
                        {
                           /* Put Page reserves back, if they were considered, in use */
                           FDI_MemUsage.PageSpace.Reserves += 
                              FDI_MemUsage.PageSpace.ReservesInUse;

                           FDI_MemUsage.PageSpace.ReservesInUse = 0;
   
                           /* Put Para reserves back, if they were considered, in use */
                           FDI_MemUsage.ParaSpace.Reserves += 
                              FDI_MemUsage.ParaSpace.ReservesInUse;

                           FDI_MemUsage.ParaSpace.ReservesInUse = 0;
                        }
                        else
                        {
                           return status;
                        }
                        /* Add PLR State Recording Support */
                        RECOVER_MarkDatabaseBusy();
                     }                   }
                  else /* The backup object is invalid */
                  {
                     compare_info.CompareValue = BC_SearchInfo.CurrObj.HeaderAddress;
                     status = GetNextHeader(&OTT_SearchInfo, HDR_ByHeaderAddress, 
                                            &compare_info, restart);
                     if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
                         (status != ERR_PARAM))
                     {
                        return(status);
                     }
                  } 

                  if(modify_object_status == TRUE)
                  {
                     /* If the backup object header has already marked absorbeb, */
                     /* don't need to erase the space associated with the backup object. */
                     if (!(HDR_GetAbsorbedAttr(OTT_SearchInfo.HeaderPtr->Attr16) ==
                           HDR_HA_Absorbed))
                     {
   
                        /* Erase the space associated with the new object. */
                        status = RECINPLC_ReclaimObjectInPlace(&OTT_SearchInfo, FALSE);
                        if(status)
                        {
                           return status;
                        }

                        /* Add PLR State Recording Support */
                        RECOVER_MarkDatabaseReady();

                        /* Mark the backup object header absorbed. */
                        status = HDR_AbsorbHeader(OTT_SearchInfo.CurrObj.HeaderAddress,
                                                  OTT_SearchInfo.HeaderPtr);
                        if(status)
                        {
                           return(status);
                        }
                     }
                  }  
                  /* Mark the OTT Table entry status for this item
                  * "OTT entry invalid"
                  */
                  OTTTBL_MarkOTTEntryInvalid(ReclaimState.OTTTblEntry.status) ;
                  status = OTTTBL_WriteTable(ReclaimState.OTTTblBaseAddr, 
                                             ReclaimState.CurrentObject2Modify, 
                                             &ReclaimState.OTTTblEntry, restart); 
                  if(status)
                  {
                     return status;
                  }

               }/* if entry is valid. */

               OTT_SearchInfo.CurrObj.HeaderAddress = prev_hdr_addr;
               OTT_SearchInfo.HeaderPtr->NameSize = prev_hdr_NameSize;

               /* Search for the next valid object header. If one is found, this is the
               * next object to be moved.
               */
               for (;;)
               {
                  status = GetNextHeader(&OTT_SearchInfo, HDR_ByNextPageObject, &compare_info, restart);
                  if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
                      (status != ERR_PARAM))
                  {
                     return(status);
                  }

                  if(!status)
                  {
                     /* Make sure that the interface cannot see any system objects. */
                     if(OTT_SearchInfo.HeaderPtr->ObjectType > FDI_HT_EndReservedTypes)
                     {
                        break;
                     }
                  }
                  else
                  {
                     break;
                  }
               }

               if(!status)
               {
                  /* Need to read full header for this type of search */
                  status = HDR_ReadFullHeader(OTT_SearchInfo.CurrObj.HeaderAddress, 
                     OTT_SearchInfo.HeaderPtr, restart);
                  if(status)
                  {
                      return status;
                  }   
               }

               /* Found the object, now translate the object information to */
               /*  the interface function equivalent.                       */
               HDR_SearchInfo2ObjectInfo(&obj_info, &OTT_SearchInfo);

               prev_hdr_addr = OTT_SearchInfo.CurrObj.HeaderAddress;
               prev_hdr_NameSize = OTT_SearchInfo.HeaderPtr->NameSize;

               /* Increment the object counter to indicate that the 
               status field of the OTT entry needs to be updated. */
               ReclaimState.CurrentObject2Modify++;  

               /* Calculate the source  and the destination address of the
                * current object.
                */
               current_dest_addr += ReclaimState.OTTTblEntry.objsize;
               current_src_addr += ReclaimState.OTTTblEntry.objsize;

               /* Process all the valid OTT table entries one by one and
                * call the call back function API, provided by the user 
                * application.
                */
               status = OTTTBL_ReadTable(ReclaimState.OTTTblBaseAddr, 
                  ReclaimState.CurrentObject2Modify, 
                  &ReclaimState.OTTTblEntry, restart); 
               if(status)
               {
                  return status;
               }
               FDI_LockoutObjectAllocation = FALSE;

               /* Clear flags before doing the reallocation for the next object */
               restart = FALSE;
               WIP_BC_obj_found = FALSE;
               WIP_obj_found = FALSE;
               invalid_backup_found = FALSE;

            }while(OTTTBL_IsOTTEntryValid(ReclaimState.OTTTblEntry.status)); 
         }
      /*lint -fallthrough*/
      case RECRCVR_ObjectModified:

         if(method == ReclaimPageObjects)
         {
            /* Need to read full header for this type of search */
            status = HDR_ReadFullHeader(ReclaimState.OTTTblHdrAddr, 
               OTT_SearchInfo.HeaderPtr, restart);
            if(status)
            {
               return status;
            }   

            /* Mark the OTT table header to Invalid. */
            status = HDR_InvalidateHeader(ReclaimState.OTTTblHdrAddr, 
               OTT_SearchInfo.HeaderPtr);
            if(status)
            {
               return status;
            }
         }
      /*lint -fallthrough*/
      case RECRCVR_ExitWithFailure:
      default:
      {};
   }

   return status;
}

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

/*########################################################################
  ### RECLAIM_MarkBlockDone
  ###
  ### DESCRIPTION:
  ###   This function will detect when the free space pointer crosses
  ###   a block boundary and will mark the CurrentDoneBlock to done
  ###   in the reclaim table.
  ###
  ### PARAMETERS:
  ###   paragraph_reclaim  - Indicates special processing depending
  ###                        on the method of reclaim.
  ###
  ### RETURNS:
  ###   ERR_NONE  - When operation is successful.
  ###
*/
ERR_CODE RECLAIM_MarkBlockDone(BOOLEAN paragraph_reclaim, BOOLEAN restart)
{
   BOOLEAN           mark_it_done;
   ERR_CODE        status = ERR_NONE;
   RECTBL_TableEntry done_block_status;

   mark_it_done = FALSE;

   /* Mark the block done once the target is full */
   if(paragraph_reclaim)
   {
      if(Handle2Block(MemMap.FreeBlk.BaseAddr) < 
         ReclaimState.CurrentDoneBlock)
      {
         mark_it_done = TRUE;
      }
   }
   else
   {
      if(Handle2Block(MemMap.FreeBlk.BaseAddr) > 
         ReclaimState.CurrentDoneBlock)
      {
         mark_it_done = TRUE;
      }
   }

   if(mark_it_done)
   {
      EVT_Test4Crash(EVT_RECLAIM_StateF_4a);

      /* Mark the current block to DONE */
      RECTBL_ReadTable(ReclaimState.RecTblBaseAddr, 
         ReclaimState.CurrentDoneBlock, 

⌨️ 快捷键说明

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