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

📄 davmem.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 3 页
字号:
      status = MEM_CalcSizeAndHandleOfFreePoolInPageSpace(&freePoolSizeInPages, &freePoolHandle);
      ExitOnError(status);
      /* if free pool has enough space, return the handle to it */
      if (freePoolSizeInPages > aRequestedSizeInPages)
      {
         *aFreeChunkHandlePtr  = freePoolHandle;
         *aReturnedSizeInPages = freePoolSizeInPages;
      }
      else
      {
         /* give up, requested size not available */
         status = ERR_FLASH_FULL;
         *aReturnedSizeInPages = 
            (freePoolSizeInPages > maxFreeChunkSizeInPages) ? freePoolSizeInPages : maxFreeChunkSizeInPages;
      }
   }

   return status;
}

/*#################################################################
  ### MEM_FindBestFitFreeChunkInPageSpace
  ### 
  ### DESCRIPTION:
  ###   This function will find a free chunk that is as close to 
  ###   the requested size as possible without being less than the
  ###   requested size.
  ### 
  ### PARAMETERS:
  ### 
  ### RETURNS:
  ###   Error status.
  ###*/
ERR_CODE MEM_FindBestFitFreeChunkInPageSpace(FDI_HandlePtr aFreeChunkHandlePtr,
                                             UINT32 aaRequestedSizeInPages,
                                             UINT32* aaReturnedSizeInPages)
{
ERR_CODE status = ERR_NOT_DONE;

   /* Not implemented */
   return status;
}

/*#################################################################
  ### MEM_CalcTotalFreeSpaceInPageSpace
  ### 
  ### DESCRIPTION:
  ###   This function will calculate the total free space in page
  ###   space, including the free pool, in pages.
  ### 
  ### PARAMETERS:
  ### 
  ### RETURNS:
  ###   Error status.
  ###*/
ERR_CODE MEM_CalcTotalFreeSpaceInPageSpace(UINT32* aSizeInPages)
{
ERR_CODE                  status = ERR_NONE;
FDI_Handle                currHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader           currHeader;
UINT32                    freePoolSizeInPages = 0;
FDI_Handle                freePoolHandle;

   *aSizeInPages = 0;
   do
   {
      status = FHDR_ReadFixedHeader(currHeaderHandle, &currHeader, FALSE);
      /* if the header points to a free chunk in page space */
      if (
            (status == ERR_NONE) &&
            (FHDR_GetHeaderStatus(&currHeader) == HDR_HEADER_VALID) && 
            (FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_EMPTY) && 
            (FHDR_GetAbsorbStatus(&currHeader) == HDR_NOT_ABSORBED) && 
            (FHDR_GetHeaderIndexOffset(&currHeader) != HDR_INDEX_OFFSET_UNUSED) && 
            (FHDR_IsPageObject(&currHeader))
         )
      {
	      *aSizeInPages += FHDR_GetSize(&currHeader);
      }
      currHeaderHandle = SEARCH_CalcNextHdrAddr(currHeaderHandle);
   } while ((status == ERR_NONE) && 
            (FHDR_GetHeaderStatus(&currHeader) != HDR_HEADER_UNUSED));

   ExitOnError(status);

   /* get size of free pool in page space */
   status = MEM_CalcSizeAndHandleOfFreePoolInPageSpace(&freePoolSizeInPages, &freePoolHandle);
   ExitOnError(status);

	*aSizeInPages += freePoolSizeInPages;

   return status;
}

/*#################################################################
  ### MEM_CalcTotalFreeSpaceInParaSpace
  ### 
  ### DESCRIPTION:
  ###   This function will calculate the total free space in para
  ###   space, including the free pool, in bytes.
  ### 
  ### PARAMETERS:
  ### 
  ### RETURNS:
  ###   Error status.
  ###*/
ERR_CODE MEM_CalcTotalFreeSpaceInParaSpace(UINT32* aSizeInBytes)
{
ERR_CODE                  status = ERR_NONE;
FDI_Handle                currHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader           currHeader;
UINT32                    freePoolSizeInBytes = 0;
FDI_Handle                freePoolHandle;

   *aSizeInBytes = 0;
   do
   {
      status = FHDR_ReadFixedHeader(currHeaderHandle, &currHeader, FALSE);
      /* if the header points to a free chunk in para space */
      if (
            (status == ERR_NONE) &&
            (FHDR_GetHeaderStatus(&currHeader) == HDR_HEADER_VALID) && 
            (FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_EMPTY) && 
            (FHDR_GetAbsorbStatus(&currHeader) == HDR_NOT_ABSORBED) && 
            (FHDR_GetHeaderIndexOffset(&currHeader) != HDR_INDEX_OFFSET_UNUSED) && 
            (FHDR_IsParaObject(&currHeader))
         )
      {
	      *aSizeInBytes += FHDR_GetSize(&currHeader);
      }
      currHeaderHandle = SEARCH_CalcNextHdrAddr(currHeaderHandle);
   } while ((status == ERR_NONE) && 
            (FHDR_GetHeaderStatus(&currHeader) != HDR_HEADER_UNUSED));

   ExitOnError(status);

   /* get size of free pool in para space */
   status = MEM_CalcSizeAndHandleOfFreePoolInParaSpace(&freePoolSizeInBytes, &freePoolHandle);
   ExitOnError(status);

	*aSizeInBytes += freePoolSizeInBytes;

   return status;
}


/*#################################################################
  ### MEM_CalcTotalDirtySpaceInPageSpace
  ### 
  ### DESCRIPTION:
  ###   This function will calculate the total dirty space in page
  ###   space in pages.
  ### 
  ### PARAMETERS:
  ### 
  ### RETURNS:
  ###   Error status.
  ###*/
ERR_CODE MEM_CalcTotalDirtySpaceInPageSpace(UINT32* aSizeInPages)
{
ERR_CODE                  status = ERR_NONE;
FDI_Handle                currHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader           currHeader;

   *aSizeInPages = 0;
   do
   {
      status = FHDR_ReadFixedHeader(currHeaderHandle, &currHeader, FALSE);
      /* if the header points to a dirty chunk in page space */
      if (
            (status == ERR_NONE) &&
            (FHDR_GetHeaderStatus(&currHeader) == HDR_HEADER_VALID) && 
            (FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_INVALID) && 
            (FHDR_GetAbsorbStatus(&currHeader) == HDR_NOT_ABSORBED) && 
            (FHDR_GetHeaderIndexOffset(&currHeader) != HDR_INDEX_OFFSET_UNUSED) && 
            (FHDR_IsPageObject(&currHeader))
         )
      {
	      *aSizeInPages += FHDR_GetSize(&currHeader);
      }
      currHeaderHandle = SEARCH_CalcNextHdrAddr(currHeaderHandle);
   } while ((status == ERR_NONE) && 
            (FHDR_GetHeaderStatus(&currHeader) != HDR_HEADER_UNUSED));

   ExitOnError(status);

   return status;
}

/*#################################################################
  ### MEM_CalcTotalDirtySpaceInParaSpace
  ### 
  ### DESCRIPTION:
  ###   This function will calculate the total dirty space in para
  ###   space in bytes.
  ### 
  ### PARAMETERS:
  ### 
  ### RETURNS:
  ###   Error status.
  ###*/
ERR_CODE MEM_CalcTotalDirtySpaceInParaSpace(UINT32* aSizeInBytes)
{
ERR_CODE                  status = ERR_NONE;
FDI_Handle                currHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader           currHeader;

   *aSizeInBytes = 0;
   do
   {
      status = FHDR_ReadFixedHeader(currHeaderHandle, &currHeader, FALSE);
      /* if the header points to a dirty chunk in para space */
      if (
            (status == ERR_NONE) &&
            (FHDR_GetHeaderStatus(&currHeader) == HDR_HEADER_VALID) && 
            (FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_INVALID) && 
            (FHDR_GetAbsorbStatus(&currHeader) == HDR_NOT_ABSORBED) && 
            (FHDR_GetHeaderIndexOffset(&currHeader) != HDR_INDEX_OFFSET_UNUSED) && 
            (FHDR_IsParaObject(&currHeader))
         )
      {
	      *aSizeInBytes += FHDR_GetSize(&currHeader);
      }
      currHeaderHandle = SEARCH_CalcNextHdrAddr(currHeaderHandle);
   } while ((status == ERR_NONE) && 
            (FHDR_GetHeaderStatus(&currHeader) != HDR_HEADER_UNUSED));

   ExitOnError(status);

   return status;
}

/*#################################################################
  ### MEM_CalcReclaimablePageSpace
  ### 
  ### DESCRIPTION:
  ###   This function will calculate the total space available in
  ###   pages if a full volume defrag were performed.
  ### 
  ### PARAMETERS:
  ### 
  ### RETURNS:
  ###   Error status.
  ###*/
ERR_CODE MEM_CalcReclaimablePageSpace(UINT32* aReclaimablePages)
{
ERR_CODE status = ERR_NONE;
FDI_Handle                currHeaderHandle = DAV_MEM_FirstHeaderAddr;
HDR_FixedHeader           currHeader;
UINT32                    freePoolSizeInPages = 0;
FDI_Handle                freePoolHandle;
EnPinnedObjectPortion     pinStatus;
FDI_Handle                objectHandle;

   *aReclaimablePages = 0;
   do
   {
      status = FHDR_ReadFixedHeader(currHeaderHandle, &currHeader, FALSE);
      /* if the header points to a dirty or free chunk in page space */
      if (
            (status == ERR_NONE) &&
            (FHDR_GetHeaderStatus(&currHeader) == HDR_HEADER_VALID) && 
            ((FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_INVALID) || 
             (FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_EMPTY)) && 
            (FHDR_GetAbsorbStatus(&currHeader) == HDR_NOT_ABSORBED) && 
            (FHDR_GetHeaderIndexOffset(&currHeader) != HDR_INDEX_OFFSET_UNUSED) && 
            (FHDR_IsPageObject(&currHeader))
         )
      {
         /* if this is a free chunk, it is already reclaimed/reclaimable */
         if (FHDR_GetAllocationStatus(&currHeader) == HDR_ALLOC_EMPTY)
         {
            *aReclaimablePages += FHDR_GetSize(&currHeader);
         }
         else
         {
	         /* determine if any portion of this dirty
               chunk is not reclaimable because it spans a pinned block */
            pinStatus = PIN_LIST_IsObjectPinned(FHDR_GetHeaderIndexOffset(&currHeader), FHDR_GetSize(&currHeader));
            switch (pinStatus)
            {
            case enNotPinned:
               /* entire chunk is reclaimable */
               *aReclaimablePages += FHDR_GetSize(&currHeader);
               break;
            case enStartPinned:
               /* Cycle through the blocks occupied by the object to determine how much is reclaimable */
               objectHandle = FHDR_CalcObjectHandle(&currHeader);
               while (pinStatus != enNotPinned)
               {
                  pinStatus = PIN_LIST_IsObjectPinned((objectHandle - FDI_FirstObjectAddress)/FDI_PageSize, 1);
                  if (pinStatus != enNotPinned)
                  {
                     objectHandle = 
                        ((UTIL_CalcBlockNumberForOffset((objectHandle - FDI_FirstObjectAddress)/FDI_PageSize)+1) * FDI_BlockSize) 
                        + FDI_FirstObjectAddress;
                  }
               }
               *aReclaimablePages += (((FHDR_CalcObjectHandle(&currHeader) + (FHDR_GetSize(&currHeader)*FDI_PageSize)) - objectHandle)/FDI_PageSize);
               break;
            case enEndPinned:
               /* Cycle through the blocks occupied by the object to determine how much is reclaimable */
               objectHandle = FHDR_CalcObjectHandle(&currHeader);
			  /*Fix Start :SCR989*/
               do
               {
                  pinStatus = PIN_LIST_IsObjectPinned((objectHandle - FDI_FirstObjectAddress)/FDI_PageSize, 1);
                  if (pinStatus == enNotPinned)
                  {
                     *aReclaimablePages += ((((UTIL_CalcBlockNumberForOffset((objectHandle - FDI_FirstObjectAddress)/FDI_PageSize)+1) * FDI_BlockSize) - (objectHandle-FDI_FirstObjectAddress))/FDI_PageSize);
                     objectHandle = 
                        ((UTIL_CalcBlockNumberForOffset((objectHandle - FDI_FirstObjectAddress)/FDI_PageSize)+1) * FDI_BlockSize) 
                        + FDI_FirstObjectAddress;
                  }
               }while (pinStatus == enNotPinned);
			  /*Fix End :SCR989*/
               break;
            case enBothPinned:
               /* none of the chunk is reclaimable */
               break;
            }
         }
      }
      currHeaderHandle = SEARCH_CalcNextHdrAddr(currHeaderHandle);
   } while ((status == ERR_NONE) && 
            (FHDR_GetHeaderStatus(&currHeader) != HDR_HEADER_UNUSED));

   ExitOnError(status);

   /* get size of free pool in page space */
   status = MEM_CalcSizeAndHandleOfFreePoolInPageSpace(&freePoolSizeInPages, &freePoolHandle);
   ExitOnError(status);

	*aReclaimablePages += freePoolSizeInPages;
   return status;
}

#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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