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

📄 davalloc.c

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

/* ###########################################################################
###  DAV - Direct Access Volume Enhancement to FDI
###
###  Module: dav_alloc.c - DAV Interface Function:  Allocate Flash Module
###
###  $Workfile: davalloc.c $
###  $Revision: 78 $
###  $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 "davhdr.h"
#include "davmem.h"
#include "davsearch.h"
#include "DavCfgTbl.h"
#include "DavPaRecl.h"
#include "davalloc.h"

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

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

/*### 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_AllocateFlash
  ###
  ### DESCRIPTION:
  ###   This function allocates memory for a new object by creating 
  ###   a new header with the characteristics defined by 
  ###   obj_info_ptr.  For objects with recovery Level0 or 1, the
  ###   header will be written as WriteInProgress and will need to 
  ###   have WriteComplete called.  Objects with recovery Level 2 
  ###   will have a the header written as Valid.
  ###
  ### PARAMETERS:
  ###   obj_info_ptr  IN:  obj_info is filled with all fields.
  ###                 OUT: Not used.
  ###
  ### 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_AllocateFlash( FDI_ObjectInfoPtr obj_info_ptr, UINT8 option )
{
UINT32     requiredParaSpace, requiredPageSpace;
UINT32     availParaSpace;
UINT32     availPageSpace;
FDI_Handle handle;
FDI_Handle paraHandle;
FDI_Handle pageHandle;
ERR_CODE   status;
BOOLEAN    convertingFreeChunk = FALSE;
UINT32     newObjectSizeInPages;
UINT32     freeChunkSizeInPages;
UINT16     ii; /* loop counter */
HDR_ObjectHeader  objHeader;

SEARCH_SearchInfo  searchInfo;
SEARCH_CompareInfo compareInfo;

   /* Check range of ObjectType */
   if(obj_info_ptr->ObjectType < FDI_HT_BeginUserTypes )
   {
      return ERR_PARAM;
   }

   /* Check for invalid Namesize and if the Name pointer is pointing to NULL */
   if((obj_info_ptr->NameSize <= 0 ) || 
      (obj_info_ptr->NameSize > FDI_MaxNameLength ) || 
      (obj_info_ptr ->Name == 0))
   {
      return ERR_PARAM;
   }

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

   /* If allocating memory for a new object, check if maximum number of objects
      is reached */
   if (!FDI_ReAllocateOverrideFlag)
   {
      if (FDI_PageObjectCounter >= DAV_NUM_CLASS_FILES)
      {
         status = ERR_MAX_EXISTS;
         ExitOnError(status);
      }
   }

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

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

   /* Parameter Checking *
    **********************
    */
    
   /* Make sure that the interface cannot see any system objects. */
   if (obj_info_ptr->ObjectType < FDI_HT_EndReservedTypes)
   {
      status = ERR_PARAM;
      ExitOnError(status);
   }
   
   /* Check the min limits on the size. */
   if (obj_info_ptr->ObjectSize == 0)
   {
      status = ERR_PARAM;
      ExitOnError(status);
   }
   
   /* Check the max limits on the size. */
#ifndef DISABLE_BACKUP_RESERVE
   if (obj_info_ptr->ObjectSize > (((FDI_TotalObjectSpace-OHDR_CalcHeaderSize())/FDI_PageSize)/2))  /* enough room for object plus backup */
#else
   if (obj_info_ptr->ObjectSize > ((FDI_TotalObjectSpace-OHDR_CalcHeaderSize())/FDI_PageSize)) /* enough room for object */
#endif
   {
      status = ERR_FLASH_FULL;
      ExitOnError(status);
   }
   
     /* Check to see that option is valid */
/*#if (PERF_TEST == FALSE)*/
   if (option != ALLOC_FIRST_FIT)
   {
      status = ERR_PARAM;
      ExitOnError(status);
   }

/*unsupported option start*/
/*
#else
   if (
      option != ALLOC_FIRST_FIT &&
      option != ALLOC_BEST_FIT  &&
      option != ALLOC_FREE_POOL
      )
   {
      status = ERR_PARAM;
      ExitOnError(status);
   }
#endif
*/
/*unsupported option End*/
   
   /** ==================================================================== **/
   /** Check for an object with the same name & type.                       **/
   /**   (not allowed - accept for re-allocate)                             **/
   /** ==================================================================== **/
   SEARCH_Header2SearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));             
   compareInfo.CompareValue = obj_info_ptr->ObjectType;                   
   compareInfo.NamePtr      = (HDR_NamePtr)(obj_info_ptr->Name);
   compareInfo.NameSize     = obj_info_ptr->NameSize;
   status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByNameType, &compareInfo, FALSE); 
   if (status == ERR_NONE)
   {                                                                       
      /* Found an existing object */
                                                                           
      /* There was no override of duplicate object checking and */         
      /*  we found a duplicate object.                          */         
      if (!FDI_ReAllocateOverrideFlag)                                     
      {                                                                    
         status =  ERR_EXISTS;                                   
         ExitOnError(status);
      }                                                                    
   }                                                                       
   else                                                                    
   {                                                                       
      /* Object was not found */
                                                                           
      /* There was no duplicate and some error was returned, or */         
      /*  there was no duplicate and we were expecting one!     */         
      if ((status != ERR_NO_MORE_ENTRIES) || FDI_ReAllocateOverrideFlag)     
      {                                                                    
         FDI_APIUnlock();
         ExitOnError(status);
      }                                                                    
   }                                                                       
   
   /* Calculate Required Memory  *
    ******************************
    */
    
   /* This will contain the total page space requested */
   requiredPageSpace = obj_info_ptr->ObjectSize;
   /* add appropriate pages for object header (containing name) */
   requiredPageSpace += OHDR_CalcHeaderSize()/FDI_PageSize;
   if (OHDR_CalcHeaderSize() % FDI_PageSize)
   {
      requiredPageSpace++;
   }
   
   /* This will contain the total paragraph space requested */
   requiredParaSpace = FHDR_CalcHeaderSize();


   /* Calculate Available Memory  *
    ******************************
    */
   status = MEM_CalcSizeAndHandleOfFreePoolInParaSpace(&availParaSpace, &paraHandle);
   ExitOnError(status);

   if (availParaSpace < requiredParaSpace)
   {
      /* trigger a paragraph reclaim instead of returning error */
      status = RECLAIM_PARAGRAPH_PerformReclaim(enPerformCfgEntryReclaim, FALSE);
      ExitOnError(status);
   }

   switch (option)
   {
   case ALLOC_FIRST_FIT:
      status = MEM_FindFirstFitFreeChunkInPageSpace(&pageHandle, requiredPageSpace, &availPageSpace);
      ExitOnError(status);
      break;
/*Unsupported Option Start*/
/*
#if (PERF_TEST == TRUE)
   case ALLOC_BEST_FIT:*/
      /* ALLOC_BEST_FIT not implemented; shouldn't have gotten this */
      /*status = ERR_PARAM;

⌨️ 快捷键说明

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