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

📄 davpageinit.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
   *aTopObjectSizeInPagesPtr = FHDR_GetSize(&currBkupHeader);
   /* walk through the backup objects to the last one, adjusting the top parameters as we go */
   do
   {
      status = SEARCH_CalcNextUserObjectHdrAddr(currBkupHeaderHandle, &currBkupHeaderHandle);
      if (status == ERR_NONE)
      {
         status = FHDR_ReadFixedHeader(currBkupHeaderHandle, &currBkupHeader, restart);
         if (status == ERR_NONE)
         {
            if (FHDR_GetReallocationStatus(&currBkupHeader) == HDR_REALLOC_BACKUP_COMPLETE)
            {
               *aGroupSizeInPagesPtr += FHDR_GetSize(&currBkupHeader);
               *aTopBlockPtr = UTIL_CalcBlockNumberForOffset(FHDR_GetHeaderIndexOffset(&currBkupHeader) + FHDR_GetSize(&currBkupHeader));
               *aTopObjectHandlePtr = FHDR_CalcObjectHandle(&currBkupHeader);
               *aTopObjectSizeInPagesPtr = FHDR_GetSize(&currBkupHeader);
            }
         }
         else
         {
            return status;
         }
      }
   }
   while (status == ERR_NONE && 
      FHDR_GetReallocationStatus(&currBkupHeader) == HDR_REALLOC_BACKUP_COMPLETE);

   if (status == ERR_NO_MORE_ENTRIES)
   {
      status = ERR_NONE;
   }
   return status;
}

 /*#################################################################
  ### RECLAIM_PAGE_SetBackupGroupAbsorbStatus
  ###
  ### DESCRIPTION:
  ###   Set the absorb status for each object in a backup group
  ###   to the specified value.  Assumes there is only one backup
  ###   group in memory at any given time.
  ###
  ### PARAMETERS:
  ###   aAbsorbStatus       -- IN: absorb status value
  ###   restart             -- IN: Flag used for PLR.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
ERR_CODE RECLAIM_PAGE_SetBackupGroupAbsorbStatus(HDR_AbsorbStatusEnum aAbsorbStatus,
                                                 BOOLEAN restart)
{
ERR_CODE status                 = ERR_NONE;
FDI_Handle currBkupHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader  currBkupHeader;


   /* walk the headers and set the absorb status for all backup  */
   /* objects; only one backup group should be in page at any    */
   /* moment in time.                                            */
   do
   {
      status = FHDR_ReadFixedHeader(currBkupHeaderHandle, &currBkupHeader, restart);
      if (status == ERR_NONE)
      {
         if (FHDR_GetHeaderStatus(&currBkupHeader) == HDR_HEADER_VALID)
         {
            if (FHDR_GetReallocationStatus(&currBkupHeader) == HDR_REALLOC_BACKUP_COMPLETE)
            {
               switch (aAbsorbStatus)
               {
               case 	HDR_ABSORBING:
                  if (FHDR_GetAbsorbStatus(&currBkupHeader) == HDR_NOT_ABSORBED)
                  {
                     status = FHDR_AbsorbingHeaderInFlash(currBkupHeaderHandle, &currBkupHeader);
                  }
                  break;
               case 	HDR_ABSORBED:
                  if (FHDR_GetAbsorbStatus(&currBkupHeader) == HDR_NOT_ABSORBED)
                  {
                     status = FHDR_AbsorbingHeaderInFlash(currBkupHeaderHandle, &currBkupHeader);
                     ExitOnError(status);
                  }
                  if (FHDR_GetAbsorbStatus(&currBkupHeader) != HDR_ABSORBED)
                  {
                     status = FHDR_AbsorbedHeaderInFlash(currBkupHeaderHandle, &currBkupHeader);
                     if (status == ERR_NONE)
                     {
                        /* decrement the reserves in use appropriately */
                        FDI_MemUsage.PageSpace.ReservesInUse -= (FHDR_GetSize(&currBkupHeader) * FDI_PageSize);
                     }
                  }
                  break;
               case 	HDR_NOT_ABSORBED:
                  if (FHDR_GetAbsorbStatus(&currBkupHeader) != HDR_NOT_ABSORBED)
                  {
                     return ERR_STATE;
                  }
               default:
                  return ERR_PARAM;
                  break;
               }
            }
         }
         else
         {
            break;
         }
      }
      currBkupHeaderHandle -= FHDR_CalcHeaderSize();
   }
   while (status == ERR_NONE && currBkupHeaderHandle > FDI_NextFreeHeaderEntry);

   if (status == ERR_NO_MORE_ENTRIES)
   {
      status = ERR_NONE;
   }

   return status;
}

 /*#################################################################
  ### RECLAIM_PAGE_ModifyBackupGroup
  ###
  ### DESCRIPTION:
  ###   Modify the objects in a backup group and write the modified
  ###   data to the final location of the object as specified by
  ###   the OTT.  Update the RAT status as needed.  Assumes there
  ###   is only one backup group in memory at any given time.
  ###
  ### PARAMETERS:
  ###   aRef          -- IN: ptr to OTT/RAT
  ###   aRatEntryPtr  -- IN/OUT: ptr to RAT entry for the group.
  ###   restart       -- IN: Flag used for PLR.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
ERR_CODE RECLAIM_PAGE_ModifyBackupGroup(PAGE_RECLAIM_Address* aRef,
                                        FDI_Handle            aRatEntryHandle,
                                        RATTBL_EntryPtr       aRatEntryPtr,
                                        BOOLEAN               restart)
{
ERR_CODE status                  = ERR_NONE;
FDI_Handle currObjectHandle      = FDI_InvalidObjAddress;
FDI_Handle currBkupHeaderHandle  = FDI_InvalidObjAddress;
FDI_Handle currBkupObjectHandle  = FDI_InvalidObjAddress;
HDR_FixedHeader  currBkupHeader;
HDR_ObjectHeader currObjectHeader;
UINT32 currObjectSizeInPages;
UINT16            ottIndex;
UINT16            ottBottomIndex = RATTBL_GetRatEntryBtmIndex(aRatEntryPtr);
UINT16            ottTopIndex    = RATTBL_GetRatEntryTopIndex(aRatEntryPtr);
OTTTBL_EntryPtr   ottEntryPtr;
UINT8*            bufferPtr      = 0;

   /* walk the headers in page space order from bottom to top to */
   /* find the first backup object; this should be the bottom of */
   /* the backup group; only one backup group should be in page  */
   /* space at any moment in time.                               */
   do
   {
      status = SEARCH_CalcNextUserObjectHdrAddr(currBkupHeaderHandle, &currBkupHeaderHandle);
      ExitOnError(status);

      status = FHDR_ReadFixedHeader(currBkupHeaderHandle, &currBkupHeader, restart);
      ExitOnError(status);
   }
   while (status == ERR_NONE && 
      FHDR_GetReallocationStatus(&currBkupHeader) != HDR_REALLOC_BACKUP_COMPLETE);

   /* at this point, the currBkupHeaderHandle should point to the header for   */
   /* the first backup object, and the current header should be the header */
   /* of the first backup object, so calculate the object handle           */
   currBkupObjectHandle = FHDR_CalcObjectHandle(&currBkupHeader);

   /* iterate through the OTT entries until the group is modified */
   for (ottIndex = ottBottomIndex; ottIndex <= ottTopIndex; ottIndex++)
   {
      ottEntryPtr    = &aRef->sramOttEntriesList[ottIndex];
      currObjectHandle = (OTTTBL_GetOttEntryDestination(ottEntryPtr) * FDI_PageSize) + FDI_PageSpaceAddressBottom;
      currObjectSizeInPages = OTTTBL_GetOttEntrySize(ottEntryPtr);
      /* Call FDI_ModifyObject to copy object to RAM and modify it. */
      status = FDI_ModifyObject((UINT8*)(currObjectHandle+OHDR_CalcHeaderSize()), /* new source pointer for object data */
                                ((currObjectSizeInPages * FDI_PageSize)-OHDR_CalcHeaderSize()), /* size of the object in bytes */
                                (UINT8*)((OTTTBL_GetOttEntrySource(ottEntryPtr) * FDI_PageSize + FDI_PageSpaceAddressBottom) + OHDR_CalcHeaderSize()), /* old source pointer for object data */
                                (void**)(&bufferPtr),
                                (UINT8*)(currBkupObjectHandle+OHDR_CalcHeaderSize()));/* pointer to backup object data */ 
      ExitOnError(status);
      /* Copy the modified object back into the original location */
      status = FLASH_WriteBuffer(currObjectHandle+OHDR_CalcHeaderSize(), bufferPtr, ((currObjectSizeInPages * FDI_PageSize)-OHDR_CalcHeaderSize()));
      /* Fix Start:SCR978 */
      FDI_FreeRam((void**)&bufferPtr);
      /*Fix End :SCR978 */
      if(status != ERR_NONE)
      {
         return status;
      }
      /* Read the object header w/name from the backup object header location */
      status = OHDR_ReadObjectHeader(currBkupObjectHandle, &currObjectHeader, TRUE);
      ExitOnError(status);
      /* Write the object header w/name to the original object header location */
      status = OHDR_WriteObjectHeader(currObjectHandle, &currObjectHeader);
      ExitOnError(status);

      /* find the next backup object if not the last OTT entry for this group */
      if (ottIndex < ottTopIndex)
      {
         status = SEARCH_CalcNextUserObjectHdrAddr(currBkupHeaderHandle, &currBkupHeaderHandle);
         ExitOnError(status);
         status = FHDR_ReadFixedHeader(currBkupHeaderHandle, &currBkupHeader, restart);
         ExitOnError(status);
         currBkupObjectHandle = FHDR_CalcObjectHandle(&currBkupHeader);
      }
   }

   return status;
}

 /*#################################################################
  ### RECLAIM_PAGE_BackupOriginalGroup
  ###
  ### DESCRIPTION:
  ###   Create a backup group for a group of original objects.
  ###
  ### PARAMETERS:
  ###   aRatLeaderPtr    -- IN:     ptr to RAT leader
  ###   aRatEntryPtr     -- IN/OUT: ptr to RAT entry for the group.
  ###   aTopObjectHandle -- IN:     handle of top object in group
  ###   aGroupSizeInPages   -- IN:     group size in pages.
  ###   aBottomObjectHandle -- IN/OUT: handle to btm object in group
  ###   restart          -- IN:     Flag used for PLR.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
ERR_CODE RECLAIM_PAGE_BackupOriginalGroup(RATTBL_LeaderPtr aRatLeaderPtr,
                                          FDI_Handle       aRatEntryHandle,
                                          RATTBL_EntryPtr  aRatEntryPtr,
                                          FDI_Handle       aTopObjectHandle, 
                                          UINT32           aGroupSizeInPages,
                                          FDI_Handle       aBottomObjectHandle,
                                          BOOLEAN          restart)
{
ERR_CODE status             = ERR_NONE;
FDI_Handle bkupChunkHandle  = FDI_InvalidObjAddress;
FDI_Handle currHeaderHandle = FDI_InvalidObjAddress;
FDI_Handle currObjectHandle = FDI_InvalidObjAddress;
HDR_FixedHeader currHeader;
SEARCH_CompareInfo compareInfo;

   /* extract the backup allocation parameters from the RAT */
   RECLAIM_PAGE_CalcBackupAllocation(aRatLeaderPtr, &bkupChunkHandle, &aGroupSizeInPages, restart);

   currObjectHandle = aBottomObjectHandle;
   do
   {
      /* Search for the object by object header address in order to get info for backup */
      FDI_SearchInfo.CurrObj.HeaderAddress = 0;
      FDI_SearchInfo.CurrObj.ObjectAddress = 0;
      SEARCH_Header2SearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));             
      compareInfo.CompareValue = currObjectHandle;                   
      status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByObjectHeaderAddress, &compareInfo, restart); 
      if (status != ERR_NONE)
      {
         if (status == ERR_NO_MORE_ENTRIES)
         {
            status = ERR_NOTEXISTS;

⌨️ 快捷键说明

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