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

📄 davraloc.c

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

/* ###########################################################################
###  DAV - Direct Access Volume
###
###  Module: dav_realoc.c - DAV Interface Function:  ReAllocate Flash Module
###
###  $Workfile: davraloc.c $
###  $Revision: 75 $
###  $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 "davsearch.h"
#include "davext.h"
#include "DavPageRecl.h"

/*
#define DISABLE_REALLOCATE_POWERLOSS
*/

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

/*###################################################################
  ### ReAllocateFlash
  ###
  ### DESCRIPTION:
  ###   This function updates an object in place.  If the object is 
  ###   Level0 or Level1, a duplicate header with the same 
  ###   characteristics as the orignal header is created with status 
  ###   WriteInProgress. The contents of the old object are copied to
  ###   the new object.  Once the WriteComplete function is called
  ###   on the object, the old object is erased.  If the object is of 
  ###   type Level2, no copies are made and the object's data is 
  ###   erased from object space.
  ###
  ### PARAMETERS:
  ###   obj_info_ptr - IN:  Info structure contains valid name, 
  ###                       type, security key,and privilege level.
  ###                  OUT: All information on the new header state 
  ###                       is returned.
  ###
  ### 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_ReAllocateFlash( FDI_ObjectInfoPtr obj_info_ptr )
{
   FDI_Handle            objHandle;
   ERR_CODE              status;
   SEARCH_CompareInfo    compare_info;

   PAGE_RECLAIM_Address* ptrReclaimRef = &GlbReclaimRef;
   UTIL_ClearVariable((UINT8*)ptrReclaimRef, sizeof(PAGE_RECLAIM_Address), 0x00);

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

#ifdef ENABLE_REALLOCATE_TESTS
   #ifdef DISABLE_REALLOCATE_POWERLOSS
      EVT_EventElement tmp_event_value;

         //Get Current State of Random Powerloss
         tmp_event_value = EVT_EventList[EVT_FLASH_RandomFail];
         //Disable PowerLoss
         EVT_ClrEnabled(EVT_FLASH_RandomFail);
   #endif
#endif

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

   /* Verify that the desired object exists and calculate */
   /*  its address range.                                 */
   SEARCH_Header2SearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));
   
   compare_info.NamePtr       = (HDR_NamePtr)obj_info_ptr->Name;
   compare_info.NameSize      = obj_info_ptr->NameSize;
   compare_info.CompareValue  = obj_info_ptr->ObjectType;
   compare_info.CompareValue2 = 0;
   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_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_COMPLETE)
   {
      /* a backup already is in place */
      status = ERR_EXISTS;
      ExitOnError(status);
   }

   /* check now to see if this object is pinned or in any part of a pinned block */
   if (PIN_LIST_IsObjectPinned(
         FHDR_GetHeaderIndexOffset(&(FDI_SearchInfo.HeaderPtr->FHdr)),
         FHDR_GetSize(&(FDI_SearchInfo.HeaderPtr->FHdr)) ) != enNotPinned)
   {
      /* this object is pinned or intersects with a pinned block */
      status = ERR_PINNED;
      ExitOnError(status);
   }

   /* Save the object to reallocate */
   objHandle = FDI_SearchInfo.CurrObj.ObjectAddress;

   /* Store information from search into obj_info_ptr, for creating a backup */
   SEARCH_SearchInfo2ObjectInfo(obj_info_ptr, &FDI_SearchInfo);

   /* Make sure the object does not have WriteInProgress for */
   /*  status.                                               */
   if (FHDR_GetAllocationStatus(&FDI_SearchInfo.HeaderPtr->FHdr) == 
                                                  HDR_ALLOC_WRITE_IN_PROGRESS)
   {
      status = ERR_PARAM;
      ExitOnError(status);
   }                                               
   else
   {
      /* Prevent from Reallocating the same object twice at once.
       * Search for another object after the first.
       */
      status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByNameType, &compare_info, FALSE);
      if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
          (status != ERR_PARAM))
      {
         ExitOnError(status);
      }

      if (status == ERR_NONE)
      {
         /* Found a second header already existing */
         status = ERR_EXISTS;
         ExitOnError(status);
      }
      else
      {
         /* Didn't find a second header, reset FDI_SearchInfo to original */
         /* This is done below */
      }
   }

   /* Allocate a new object. */
   FDI_ReAllocateOverrideFlag = TRUE;
                                
   /* Start the reclaim (Non-Powerloss)*/

   /* Set the defrag type */
   ptrReclaimRef->reclaimType     = enPageReallocate;    /* Reallocate Defrag Opr */
   ptrReclaimRef->desiredPageSize = 0;                   /* Reallocate Defrag Opr */
   ptrReclaimRef->relocObjHandle  = objHandle;
   ptrReclaimRef->bkupObjHandle   = 0;

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

   status = RECLAIM_PAGE_StartReclaim(ptrReclaimRef);
   CleanupAndExitOnError(status);

   FDI_ReAllocateOverrideFlag = FALSE;

   /* Must re-read the original object              */
   /*  May of had reclaim for level 0 or 1.         */
   /*  Also re-finds original for error check above */
   FDI_SearchInfo.CurrObj.HeaderAddress = 0;
   status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByNameType, &compare_info, FALSE);
   if (status != ERR_NONE)
   {
      if (status == ERR_NO_MORE_ENTRIES)
      {
         /* At this point the original header has already been found once */
         status = ERR_SYSTEM;
      }
      CleanupAndExitOnError(status);
   }

   if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_COMPLETE)
   {
      /* the first search returned the backup, so search again */
      status = SEARCH_GetNextHeader(&FDI_SearchInfo, SEARCH_ByNameType, &compare_info, FALSE);
      if (status != ERR_NONE)
      {
         if (status == ERR_NO_MORE_ENTRIES)
         {
            /* couldn't find the original object */
            status = ERR_SYSTEM;
         } 
         CleanupAndExitOnError(status);
      }
   }

   /* A WIP object exists, do not allow allocation or */
   /*  reallocation until the object is complete.      */
   FDI_LockoutObjectAllocation = TRUE; /* E.5.1.849 */
 
   /* Load obj_info with current location of orignal object */
   SEARCH_SearchInfo2ObjectInfo(obj_info_ptr, &FDI_SearchInfo);

#ifdef ENABLE_REALLOCATE_TESTS
   #ifdef DISABLE_REALLOCATE_POWERLOSS
      //Restore original event state
      EVT_EventList[EVT_FLASH_RandomFail] = tmp_event_value;
   #endif
#endif

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

#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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