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

📄 davpin.c

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

/* ###########################################################################
###  DAV - Direct Access Volume Enhancement to FDI
###
###  Module: davpin.c - DAV Interface Function:  Pin Flash Module
###
###  $Workfile: davpin.c $
###  $Revision: 7 $
###  $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 "DavLib.h"

#if (DIRECT_ACCESS_VOLUME == TRUE)

/*### Include Files
#########################*/
#include "davext.h"
#include "davfhdr.h"
#include "davhdr.h"
#include "davsearch.h"
#include "davpin.h"

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

/*### Global Declarations
#########################*/
PinnedObject GlbPinObjectList[DAV_NUM_CLASS_FILES];
UINT8        GlbPinObjectListEntries = 0;
PinnedBlock  GlbPinBlockTable[DAV_MAX_BLOCKS];

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

#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 Functions
#########################*/

/*##################################################################
  ### FDI_PinFlash
  ###
  ### DESCRIPTION:
  ###   This function pins/unpins objects, which flags them to not
  ###   be moved during a defrag operation.
  ###
  ### PARAMETERS:
  ###   obj_info_ptr  IN:  obj_info is filled the object name.
  ###                 OUT: filled in with info about object found.
  ###   pin_flag      IN:  0 = Unpin object
  ###                      1 = Pin object
  ###
  ### 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 FDI_PinFlash(FDI_ObjectInfoPtr obj_info_ptr, UINT8 pin_flag)
{
ERR_CODE           status = ERR_NONE;
SEARCH_CompareInfo compare_info;
UINT8              ii;
UINT8              objectIndex = 0;
BOOL               foundEntry = FALSE;

   /* Check range of ObjectType */
   if(obj_info_ptr->ObjectType < FDI_HT_BeginReservedTypes)
   {
      return ERR_PARAM;
   }
   /* Check for Namesize passed in as zero and if the Name pointer is pointing to NULL */
   if((obj_info_ptr->NameSize == 0) || (obj_info_ptr->Name == 0))
   {
      return ERR_PARAM;
   }
   /* Check the pin range */
   switch(pin_flag)
   {
   case 0:
   case 1:
      break;
   default:
      return ERR_PARAM;
   } /* switch */

   /* 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();

   /* Clear Global flag for System State */
   ClrSystemState(FDI_SystemState, FDI_ST_ReclaimFlag);

   /* Search for object with specified name and type. */
   SEARCH_Header2SearchInfo(&FDI_SearchInfo, &FDI_SearchHeader);
   compare_info.CompareValue = obj_info_ptr->ObjectType;
   compare_info.NamePtr      = (HDR_NamePtr)(obj_info_ptr->Name);
   compare_info.NameSize     = obj_info_ptr->NameSize;
   status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByNameType, &compare_info, FALSE);
   if (status != ERR_NONE)
   {
      if (status == ERR_NO_MORE_ENTRIES)
      {
         status = ERR_NOTEXISTS;
      }
      ExitOnError(status);
   }

   if (FHDR_GetAllocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_ALLOC_WRITE_IN_PROGRESS)
   {
      status = ERR_WIP;
      ExitOnError(status);
   }

   /* search the existing list for the object */
   for (ii = 0, foundEntry = FALSE; 
        ii < GlbPinObjectListEntries && foundEntry == FALSE; 
        ii++)
   {
      if (GlbPinObjectList[ii] == FHDR_GetHeaderIndexOffset(&(FDI_SearchInfo.HeaderPtr->FHdr)))
      {
         foundEntry = TRUE;
         objectIndex = ii;
      }
   }

   if (foundEntry == TRUE)
   {
      /* entry was found in the list */
      if (pin_flag == 0)
      {
         /* remove from the list; pack the remaining entries towards the top */
         for(ii = objectIndex; ii < GlbPinObjectListEntries; ii++)
            GlbPinObjectList[ii] = GlbPinObjectList[ii+1];
         GlbPinObjectListEntries--;
         /* recompute pinned block list */
         status = PIN_LIST_CreateGlbPinBlockTableFromGlbPinObjectList();
         ExitOnError(status);
      }
      else
      {
         /* object is already in the pinned list; do nothing */
      }
   }
   else
   {
      /* entry was not found */
      /* if pinning, add to list */
      if (pin_flag == 1)
      {
         GlbPinObjectList[GlbPinObjectListEntries] = 
            FHDR_GetHeaderIndexOffset(&(FDI_SearchInfo.HeaderPtr->FHdr));
         GlbPinObjectListEntries++;
         /* recompute pinned block list */
         status = PIN_LIST_CreateGlbPinBlockTableFromGlbPinObjectList();
         ExitOnError(status);
      }
      else
      {
         /* object is not in the pinned list; do nothing */
      }
   }

   FDI_APIUnlock();
   return status;
}

/*##################################################################
  ### PIN_LIST_CreateGlbPinBlockTableFromGlbPinObjectList
  ###
  ### DESCRIPTION:
  ###   This function creates the pinned block list from the pinned
  ###   object list.
  ###
  ### PARAMETERS:
  ###
  ### 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 PIN_LIST_CreateGlbPinBlockTableFromGlbPinObjectList()
{
ERR_CODE           status = ERR_NONE;
/*Fix Start:SCR964 */
UINT16              ObjectIndex;
UINT16              BlockIndex;
UINT16              StartingBlockNumber;
UINT16              EndingBlockNumber;
/*Fix End:SCR964 */
UINT32             ObjectSize;
HDR_Header         aHeader;
SEARCH_SearchInfo  aSearchInfo;
SEARCH_CompareInfo aCompareInfo;

   /* initialize the list to all zeros */
   for (ObjectIndex = 0; ObjectIndex < DAV_MAX_BLOCKS; ObjectIndex++)
   {
      GlbPinBlockTable[ObjectIndex] = 0;
   }

   /* Fill out the block list, by checking which blocks are affected by each pinned object */
   for (ObjectIndex = 0; ObjectIndex < GlbPinObjectListEntries; ObjectIndex++)
   {
      /* get the size of the object at address GlbPinObjectList[ObjectIndex] */
      aSearchInfo.HeaderPtr = &aHeader;
      aSearchInfo.CurrObj.HeaderAddress = 0;
      aSearchInfo.CurrObj.ObjectAddress = 0;
      aCompareInfo.CompareValue = FDI_PageSpaceAddressBottom + (GlbPinObjectList[ObjectIndex]*FDI_PageSize);

      status = SEARCH_GetNextHeader(&aSearchInfo, SEARCH_ByObjectHeaderAddress, &aCompareInfo, FALSE);

      if (status != ERR_NONE)
      {
         return status;
      }
      
      ObjectSize = FHDR_GetSize(&(aSearchInfo.HeaderPtr->FHdr));
      
      StartingBlockNumber = UTIL_CalcBlockNumberForOffset(GlbPinObjectList[ObjectIndex]);
      EndingBlockNumber   = UTIL_CalcBlockNumberForOffset((GlbPinObjectList[ObjectIndex] + ObjectSize));
      if((GlbPinObjectList[ObjectIndex] + ObjectSize) == UTIL_CalcOffsetOfBlocksBoundary(EndingBlockNumber, enBottomBoundary))
      {
         EndingBlockNumber--;
      }

      for (BlockIndex = StartingBlockNumber; BlockIndex <= EndingBlockNumber; BlockIndex++)
      {
         GlbPinBlockTable[BlockIndex] = 1;
      }
   }
   return status;
}

/*##################################################################
  ### PIN_LIST_IsObjectPinned
  ###
  ### DESCRIPTION:
  ###   This function determines if the specified object is pinned
  ###   or unpinned, and which portion.
  ###
  ### PARAMETERS:
  ###   aObjectOffset       IN:  offset to object from fixed header
  ###   aObjectSizeInPages  IN:  size of object in pages
  ###
  ### RETURNS:
  ###   Enumeration indicating what part, if any, of the object
  ###   is pinned.
  ###*/
EnPinnedObjectPortion PIN_LIST_IsObjectPinned(UINT32 aObjectOffset, 
                                              UINT32 aObjectSizeInPages)
{
   /*Fix Start:SCR964 */
   UINT16 StartingBlockNumber;
   UINT16 EndingBlockNumber;
   /*Fix End:SCR964 */
   EnPinnedObjectPortion result = enNotPinned;

   StartingBlockNumber = UTIL_CalcBlockNumberForOffset(aObjectOffset);
   EndingBlockNumber   = UTIL_CalcBlockNumberForOffset(aObjectOffset + aObjectSizeInPages);

   /* If the objectsize added to its sourceoffset lands right on a block boundary, then we have to adjust this back to the previous block */
   if((aObjectSizeInPages > 0) && ((aObjectOffset + aObjectSizeInPages) == UTIL_CalcOffsetOfBlocksBoundary(EndingBlockNumber, enBottomBoundary)))
   {
      EndingBlockNumber--;
   }

   if((GlbPinBlockTable[StartingBlockNumber] == 1) && (GlbPinBlockTable[EndingBlockNumber] == 1))
   {
      result = enBothPinned;
   }
   else if (GlbPinBlockTable[StartingBlockNumber] == 1)
   {
      result = enStartPinned;
   }
   else if (GlbPinBlockTable[EndingBlockNumber] == 1)
   {
      result = enEndPinned;
   }

   return result;
}
/*##################################################################
  ### PIN_LIST_IsObjectPinned
  ###
  ### DESCRIPTION:
  ###   This function determines if the specified object is in the
  ###   pinned list.
  ###
  ### PARAMETERS:
  ###   aObjectOffset  IN:  offset to object from fixed header
  ###
  ### RETURNS:
  ###   TRUE, if object is in the pinned list; FALSE, if not.
  ###*/
BOOLEAN PIN_LIST_IsObjectInList(UINT32 aObjectOffset)
{
int ii;
BOOLEAN foundEntry = FALSE;

   /* search the existing list for the object */
   for (ii = 0, foundEntry = FALSE; 
        ii < GlbPinObjectListEntries && foundEntry == FALSE; 
        ii++)
   {
      if (GlbPinObjectList[ii] == aObjectOffset)
      {
         foundEntry = TRUE;
      }
   }

   return foundEntry;
}


#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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