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

📄 davdefrag.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential                        */

/* ###########################################################################
###  DAV - Direct Access Volume Enhancement to FDI
###
###  Module: dav_defrag.c - DAV Interface Function:  Defrag Flash Module
###
###  $Workfile: davdefrag.c $
###  $Revision: 12 $
###  $NoKeywords: $
########################################################################### */

/*                                                               
 *****************************************************************
 * NOTICE OF LICENSE AGREEMENT                                    
 *                                                                
 * This code is provided by Intel Corp., and the use is governed  
 * under the terms of a license agreement. See license agreement  
 * for complete terms of license.                                 
 *                                                                
 * YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS.  YOUR 
 * USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY 
 * PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN  
 * INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE   
 * FROM INTEL LICENSING ANY SUCH USE.                             
 *****************************************************************
 */

/*### Include Files
#########################*/
#include "DavLib.h"

#if (DIRECT_ACCESS_VOLUME == TRUE)

#include "davext.h"
#include "davmem.h"
#include "davpin.h"
#include "DavPageRecl.h"
#include "davdefrag.h"

/*### Local Declarations
#########################*/

#define ExitOnError(status) \
   if (status != ERR_NONE) \
   {  FDI_APIUnlock(); \
      return status;  }
      
/* E5.5.962 Begin */    
#define CleanupAndExitOnError(status)   \
   if(status != ERR_NONE)               \
   {                                    \
      FDI_APIUnlock();                  \
      mDEBUG_CHECK_ERRCODE(status)      \
      MEM_CalcMemoryStatistics(FALSE);  \
      return status;                    \
  }
/* E5.5.962 End */ 

/*### Global Declarations
#########################*/

/*### Local Functions
#########################*/

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


ERR_CODE FDI_DefragFlash(UINT16 aDesiredPageSize, UINT32* aMaxAvailPages, UINT8 aOption)
{
ERR_CODE              status = ERR_NONE;

UINT16                adjustedPageSize;
FDI_Handle            aHandle;
UINT32                Size;
PAGE_RECLAIM_Address* ptrReclaimRef = &GlbReclaimRef;
   
   UTIL_ClearVariable((UINT8*)ptrReclaimRef, sizeof(PAGE_RECLAIM_Address), 0x00);

   /* Multitasking API exclusivity.  (This may not be necessary to the
      full extent as it is done here, but for now it is the safest way.) */
   FDI_APILock();

   /* A WIP object exists, do not allow defrag 
    * until the object is complete.      
    */
   if (FDI_LockoutObjectAllocation)
   {
      status = ERR_NODEFRAGWHILEWIP;
      ExitOnError(status);
   }

#ifndef DISABLE_BACKUP_RESERVE
   if (aDesiredPageSize < FDI_MemUsage.PageSpace.Reserves)
   {
      adjustedPageSize = aDesiredPageSize + (FDI_MemUsage.PageSpace.Reserves/FDI_PageSize);
   }
   else
   {
      adjustedPageSize = aDesiredPageSize * 2;
   }

#else
   adjustedPageSize = aDesiredPageSize;
#endif

   /* Set the defrag type */
   switch (aOption)
   {
   case FDI_PARTIAL_DEFRAG: /* 0 */
      /* first, check to see if this is necessary */
      /* Call first fit.  If it fails then go on, else exit with status = ERR_NONE. (This is step two from the general */
      /* approach outlined above.) */
      status = MEM_FindFirstFitFreeChunkInPageSpace(&aHandle, adjustedPageSize, &Size);
      if (status == ERR_NONE)
      {
         status = ERR_NOTNEEDED;
         /* E5.5.958 START */
         FDI_APIUnlock();
         /* E5.5.958 END */
         return status;
      }

      ptrReclaimRef->reclaimType     = enPageReclaimPartial; /* Partial Defrag Opr */
      ptrReclaimRef->desiredPageSize = adjustedPageSize;     /* Partial Defrag Opr */
      ptrReclaimRef->relocObjHandle  = 0;                    /* Partial Defrag Opr */
      ptrReclaimRef->bkupObjHandle   = 0;
      break;
   case FDI_FULL_DEFRAG:    /* 1 */
      ptrReclaimRef->reclaimType     = enPageReclaimFull;    /* Full Defrag Opr */
      ptrReclaimRef->desiredPageSize = 0;                    /* Full Defrag Opr */
      ptrReclaimRef->relocObjHandle  = 0;                    /* Full Defrag Opr */
      ptrReclaimRef->bkupObjHandle   = 0;
      break;
   default:
      status = ERR_PARAM;
      ExitOnError(status);
      break;
   }

   /* Pass the pin list */
   ptrReclaimRef->sramPinEntriesListPtr = &GlbPinObjectList[0];
   ptrReclaimRef->sramPinEntries        = GlbPinObjectListEntries;

   /* Other Initialization */
   ptrReclaimRef->startOperation        = enStartOfPageReclaim;
   ptrReclaimRef->sramOttEntries        = 0;                    /* We have nothing in memory */
   ptrReclaimRef->plrRestart            = FALSE;                /* Used for PLR              */


   /* Start the reclaim (Non-Powerloss)*/
   *aMaxAvailPages = 0;
   status = RECLAIM_PAGE_StartReclaim(ptrReclaimRef);
   CleanupAndExitOnError(status);

   /* Get the desired page size */
   status = MEM_CalcReclaimablePageSpace(aMaxAvailPages);
   CleanupAndExitOnError(status);

   status = MEM_CalcMemoryStatistics(FALSE);
   FDI_APIUnlock();
   return status;
}

#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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