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

📄 davwrobj.c

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

/* ###########################################################################
###  DAV - Direct Access Volume Enhancement to FDI
###
###  Module: davwrobj.c - DAV Interface Function: Write Object Module
###
###  $Workfile: davwrobj.c $
###  $Revision: 66 $
###  $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 "davwrobj.h"

/*### Local 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_WriteObject
  ###
  ### DESCRIPTION:
  ###   This function writes data to the object specified
  ###   by obj_name and obj_type.
  ###
  ### PARAMETERS:
  ###   obj_name   - Name of the allocated object.
  ###   name_size  - Length of the name field in bytes.
  ###   obj_type   - Type of the object.
  ###   buffer_ptr - IN:  The physical address of the buffer to copy 
  ###                     bytes from RAM to flash.
  ###                OUT: Not used.
  ###   byte_count - The number of bytes to copy from the buffer to 
  ###                the object data space.
  ###   offset     - The offset from the beginning of the object to 
  ###                begin writing bytes, 0 being the first address.
  ###
  ### 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_WriteObject(   UINT8* obj_name,
                            UINT8  name_size,
                            UINT32 obj_type,
                            UINT8* buffer_ptr,
                            UINT32 byte_count,
                            UINT32 offset )
{
   ERR_CODE              status;
   SEARCH_CompareInfo    compare_info;
   FDI_Handle            origObjectHandle = FDI_InvalidObjAddress;
   UINT32                origObjectSize = 0;

#ifdef ENABLE_EVENT_TESTS
   EVT_EventElement tmp_event_value;
#endif

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

   /* Check for invalid Namesize and if the Name pointer is pointing to NULL */
   if((name_size <= 0 ) || 
      (name_size > FDI_MaxNameLength ) || 
      (obj_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_EVENT_TESTS
   /* Get Current State of Random Powerloss */
   tmp_event_value = EVT_EventList[EVT_FLASH_RandomFail];
   
   /* Disable PowerLoss */
   EVT_ClrEnabled(EVT_FLASH_RandomFail);
#endif

   /* Start from the beginning of the header table and      */
   /* search for the first occurrence of the header.  There */ 
   /* may be two headers or only one header.                */
   SEARCH_Header2SearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader));
    
   /* Search for the object by name and type and calculate the base address. */
   compare_info.CompareValue  = obj_type;
   compare_info.CompareValue2 = FHDR_GetHeaderIndexOffset(&(FDI_SearchInfo.HeaderPtr->FHdr));
   compare_info.NameSize      = name_size;
   compare_info.NamePtr       = (HDR_NamePtr)(obj_name);
   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)
   {
      if (FHDR_GetAllocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_ALLOC_VALID)
      {
         /* is this object a backup, or does it have a backup? */
         if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_NOT_COMPLETE)
         {
            /* this is an original object, but is there a backup? */
            origObjectHandle = FDI_SearchInfo.CurrObj.ObjectAddress;
            origObjectSize   = FDI_SearchInfo.CurrObj.ObjectSize;
            /* search for the backup */
            status = SEARCH_GetNextHeader(
                            &FDI_SearchInfo, 
                            SEARCH_ByNameType, 
                            &compare_info, FALSE);
            if (status == ERR_NONE)
            {
               /* is this a backup? */
               if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_COMPLETE)
               {
               }
               else
               {
                  /* we found two original objects!! */
                  status = ERR_STATE;
                  ExitOnError(status);
               }
            }
            else
            {
               /* caller is trying to write to valid object with no backup */
               /* according to DuPage STS, this is allowed                 */
               status = ERR_NONE;
            }
         }
         else
         {
            /* this is a backup, we want to find the original object */
            status = SEARCH_GetNextHeader(
                            &FDI_SearchInfo, 
                            SEARCH_ByNameType, 
                            &compare_info, FALSE);
            if (status == ERR_NONE)
            {
               /* is this an original? */
               if (FHDR_GetReallocationStatus(&(FDI_SearchInfo.HeaderPtr->FHdr)) == HDR_REALLOC_BACKUP_NOT_COMPLETE)
               {
                  /* this is the original object */
                  origObjectHandle = FDI_SearchInfo.CurrObj.ObjectAddress;
                  origObjectSize   = FDI_SearchInfo.CurrObj.ObjectSize;
               }
               else
               {
                  /* we found two backup objects!!! */
                  status = ERR_STATE;
                  ExitOnError(status);
               }
            }
            else
            {
               /* we found a backup object but no original object */
               status = ERR_STATE;
               ExitOnError(status);
            }
         }
      }
      else
      {
         /* we found a header, but the header's not valid! */
         status = ERR_STATE;
         ExitOnError(status);
      }
   }
   else
   {
      origObjectHandle = FDI_SearchInfo.CurrObj.ObjectAddress;
      origObjectSize   = FDI_SearchInfo.CurrObj.ObjectSize;
   }

   if ( status == ERR_NONE )
   {
      /* Check upper bounds of the write, if it goes beyond the */
      /*  size of the object then return an error.              */
      if ((OHDR_CalcHeaderSize() + offset + byte_count) > origObjectSize)
      {
         status = ERR_PARAM;
         ExitOnError(status);
      }

      /* Write the data object */
      status = FLASH_WriteBuffer(
         origObjectHandle+OHDR_CalcHeaderSize()+offset,
         buffer_ptr, 
         byte_count);
      ExitOnError(status);

#ifdef ENABLE_EVENT_TESTS
      /* Restore original event state */
      EVT_EventList[EVT_FLASH_RandomFail] = tmp_event_value;
#endif

   }
   
   FDI_APIUnlock(); 
   return status;
} 

#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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