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

📄 fdi_int.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ###########################################################################
###  Intel Confidential
###  Copyright (c) Intel Corporation 1995-2002
###  All Rights Reserved.
###  -------------------------------------------------------------------------
###  Project: Flash Data Integrator
###
###  Module: FDI_INT.C - This module is a collection of all the low level FDI
###                      functions used by the API functions.
###
###  $Archive: /FDI/SRC/FDI/fdi_int.c $
###  $Revision: 180 $
###  $Date: 10/15/04 12:06p $
###  $Author: Wtiso $
###  $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.                             
 *****************************************************************
 */
 

#define CURRENT_FILE_BEING_COMPILED FDI_INT

/* ### Include Files
######################## */
/* E.5.0.690 Begin */ 
/*remove include FDI_type.h, and fdi_int.h, add fdi_lowl.h */
#include "fdi_ext.h"
#include "fdi_lowl.h"
#include "fdi_que.h"
/* E.5.0.690 End */ 

#ifdef CUSTOM_SEM_MTX
#include "fdi_mutx.h"
#endif

#ifdef TIMING
#include "logLib.h"
#else
#ifdef TEST_MSGS
#include "logLib.h"
#endif
#endif

#if (PACKET_DATA == TRUE)
#include "fdi_pckt.h"
#endif /* PACKET_DATA */



/* ### Local Declarations
######################## */
#define  NONE_IN_Q               0
#define  DELETE_IN_Q             1
#define  APPEND_IN_Q             2
#define  REPLACE_IN_Q            4
#define  FOUND_IN_Q_MASK         7
#define  SCAN_FULL_Q             8
#define  NUM_LOGICAL_BLOCKS      MAX_DATA_BLOCKS
#define  VALID_BLOCK_RANGE(x)    ((x<MAX_DATA_BLOCKS)?1:0)

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

static ERR_CODE MultiInstanceRecovery(DWORD);

#if (INCLUDE_FRAGMENTED_DATA == TRUE)

/* E.5.0.652 Begin */
#if (PACKET_DATA == TRUE)
ERR_CODE ScanEntryTables(UNIT_HEADER *, DWORD, WORD, WORD, WORD);
#else /* PACKET_DATA */
static ERR_CODE ScanEntryTables(UNIT_HEADER *, DWORD, WORD, WORD, WORD); /* E.5.0.591 */
#endif /* PACKET_DATA */
/* E.5.0.652 End */

#endif /* INCLUDE_FRAGMENTED_DATA */
/*#if ( ADD_BLOCK == TRUE) */
#if (ADD_BLOCK != FALSE)
   ERR_CODE AddBlock(void);
#endif
void ClearTables(BYTE);

ERR_CODE ScanBlockInfo(RECL_INFO *);

ERR_CODE ScanHeaders(CORRUPT_HDR *);

/* E.5.0.652 Begin */
ERR_CODE FinishReclaim(RECL_INFO *, CORRUPT_HDR *);

ERR_CODE ReclaimBlock(RECL_INFO *, CORRUPT_HDR *);
/* E.5.0.652 End */

void UpdateFreeDirty (WORD , WORD , BYTE );

/* E.5.0.652 Begin */
ERR_CODE CopyBlock(DWORD , DWORD , CORRUPT_HDR *);
/* E.5.0.652 End */

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

extern SEM_MTX_ID  SEM_LookupTable;
extern SEM_MTX_ID  SEM_BlockTable;

DATA_LOCATION FDI_GetDataFound;

OPEN_PARAM *  FDI_OpenParamPtr;

/* E.5.0.660 Begin */
WORD FDI_MaxGrpUnit;
/* E.5.0.660 End */

LOGICAL_BLOCK FDI_LogicalBlockTable[MAX_DATA_BLOCKS];
extern WORD NUM_PARMS[];

extern DATA_LOOKUP_PTR FDI_DataLookupPtrTable[];

extern HW_ERROR FlashDevReadHeader(DWORD_PTR, UNIT_HDR_PTR, DWORD, WORD, BYTE);

extern Q_ID FDI_QueueIdentifier;

WORD FDI_SpareBlock;

/* E.5.0.738 start */
/* #if (INCLUDE_FRAGMENTED_DATA == TRUE) */
/* E.5.0.738 end */

extern DWORD FDI_OpenTotalSize[];  /*MOF*/
extern SEM_MTX_ID  SEM_TotalSize;

/* E.5.0.738 start */
/* #endif */ /* INCLUDE_FRAGMENTED_DATA */
/* E.5.0.738 end */


/*
#############################################################################
### InitUnit
###
### DESCRIPTION:
###   InitUnit performs the following operations by scanning through the
###   whole media just once.
###   * Does power loss recovery.
###   * Updates the Data Lookup table.
###   * Updates the Logical Block table.
###
### PARAMETERS:
###    IN:
###        None.
###
###    OUT:
###        error                : a descriptive error code
###
### RETURNS:
###        ERR_NONE   ERR_WRITE
###
*/

ERR_CODE
InitUnit(void)
{

   RECL_INFO ReclInfo;        /* Reclaim tracking structure */
   CORRUPT_HDR CorruptHdr;    /* Header corruption structure */
   ERR_CODE status;

   /* Clear spare block. */
   FDI_SpareBlock = WORDMAX;

   /* Clear the FDI_GetDataFound structure. */
   FDI_GetDataFound.identifier = WORDMAX;
   FDI_GetDataFound.type_attribute = BYTEMAX;

   /* Completely clear the Logical Block and Data Lookup tables. */
   ClearTables(TRUE);

   /*#if ( ADD_BLOCK == TRUE) */
#if (ADD_BLOCK != FALSE) 
   /* Update the block information structure of the newly added blocks */
   if( (status = AddBlock()) != ERR_NONE )
      return status;
#endif


   /* Scan through the block information structures and determine the
      logical to physical block translation.  Also recover blocks if
      found in the midst of reclaim.  Update the ReclInfo structure if
      a block is found in the erasing or updating state.  (The final
      steps of reclaim must be done after the header scan, to support
      the erase count parameter.) */
   if ( (status = ScanBlockInfo(&ReclInfo) ) != ERR_NONE )
   {
     return status;
   }

   /* Scan through all the headers of all the blocks to build the
      data lookup table.  Look for a corrupted header along the way.
      (A corrupted header status could exist if a Flash program cycle
      was aborted by the cpu during an asynchronous reset and the Flash
      still had time to commence programming with invalid data that it
      latched during the aborted cycle.) If a corrupted header is found,
      it must be fixed via reclaim since the corruption could have cleared
      status bits that should always be set. Also the headers will require
      a re-scan. */
   do
   {
     if ( (status = ScanHeaders(&CorruptHdr)) != ERR_NONE )
     {
       return status;
     }

     /* Check if there was a block found in the updating state (If it was
        in the erasing state it was advanced to the updating state).  If so,
        complete the final reclamation steps.  This could be either from
        the ScanBlockInfo() above, if it found a block in the updating state,
        or from ReclaimBlock() below if a corrupted header exists. */
     if (ReclInfo.updating_blk_addr != DWORDMAX)
     {
       /* Complete the final reclaim steps */
       if ( (status = FinishReclaim(&ReclInfo, &CorruptHdr)) != ERR_NONE )
       {
         return status;
       }
     }

     /* If a corrupted header status field was found process it and
      rescan headers. */
     if (CorruptHdr.Exists)
     {
        /* To eliminate the corrupted header, the block where the header
           resides must be reclaimed. */
        if ( (status = ReclaimBlock(&ReclInfo, &CorruptHdr)) != ERR_NONE )
        {
           return (status);
        }

        /* Clear the Logical Block and Data Lookup tables, except for
           the physical block numbers of the Logical Block table. */
        ClearTables(FALSE);
     }
     /* If a header corruption had to be processed, rescan headers */
   } while (CorruptHdr.Exists);

   return ERR_NONE;

}                                      /* END InitUnit */

/*
 *############################################################################
 *### DataFind
 *###
 *### DESCRIPTION:
 *### Verifies the existance of data in the media just by looking at the type
 *### nibble of the DataLookupTable entry.
 *###
 *### PARAMETERS:
 *###    IN:
 *###       cmd_cntrl: Pointer to the Command Control structure.
 *###
 *###    OUT:
 *###        error                : a descriptive error code
 *###
 *### RETURNS:
 *###        ERR_NONE   ERR_NOTEXISTS
 *###
 */

/* Verifies the existance of data in the media. */
ERR_CODE
DataFind(IDTYPE identifier, BYTE type, BYTE command)
{
   WORD start_index;
   WORD index;
   /*
    * Check to see if the passed in parameter sub command is GET_MATCHED.
    */
   if (command == GET_MATCHED)
      /*
       * Set the starting index into the data lookup table by the identifier
       * input field.
       */
      start_index = identifier;

   else
   {
      /*
       * Check to see if the passed in parameter sub command is GET_FIRST.
       */
      if (command == GET_FIRST)
      {
         /*
          * Set the starting index into the data lookup table to 0 or
          * FIRST_STREAM for type parameter and data stream respectively.
          */
         start_index = 0;
      }

      /* Check to see if the passed in parametersub command is GET_NEXT. */
      else if (command == GET_NEXT)
      {
         /*
          * If datafind with GET_FIRST did not preceed the datafind call with
          * GET_NEXT sub command, return error.
          */

         if ((FDI_GetDataFound.identifier >= \
              NUM_PARMS[NIBBLE_HIGH(FDI_GetDataFound.type_attribute)]) ||
             (NIBBLE_HIGH(FDI_GetDataFound.type_attribute) != type))
          return ERR_NOTEXISTS;
         /*
          * Set the starting index into the data lookup table to the
          * identifier next to the last data found identifier.
          */
         start_index = FDI_GetDataFound.identifier + 1;
      }
      else
         return ERR_PARAM;

   }

   /* lock the global_sem_cntrl_mutex. */
   SEM_MTX_WAIT(SEM_LookupTable);

   /* Scan the entire data lookup table for appropriate data match. */

   for (index = start_index; index < NUM_PARMS[type]; index ++)
   {
      if (NOT_EMPTY_LOOKUP_TABLE(type, index) &&
          !TEST_LOOKUP_TABLE_DELETE_PENDING(type, index) )
      {
         /*
          * If FDI_Get tries to get first or next item, the identifier is
          * an output field and if DataFind finds the erase count
          * parameter, it ignores and gets the next data.
          */
         if (command != GET_MATCHED)
         {
            if (type == ERASE_COUNT_TYPE && index == ERASE_COUNT_ID)

⌨️ 快捷键说明

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