fdi_int.h

来自「FDI Intel开发的FLASH文件系统,功能很强大」· C头文件 代码 · 共 1,171 行 · 第 1/4 页

H
1,171
字号
 * in bytes minus size of MULTI_INSTANCE structure) divided by
 * (parameter size plus a byte for status)
 */
#define INSTANCES(a,b)        (((a)-sizeof(MULTI_INSTANCE))/((b)+1))
#define GRAN_REMAINING(a)     (UNIT_GRANULARITY-((a)%UNIT_GRANULARITY))

#define  MAX_DATA_BLOCKS (FDV_BLOCKCOUNT-1) /* last block to skip */
#define  BLOCK_INTEGRITY 0xf0f0        /* block's data integrity */
#define  BLK_INTEGRITY_INVALID 0xf0c0  /* invalidated block data integrity */
#define  LAST_BLOCK_ADDR (FDV_BLOCK_SIZE-1)   /* maximum block offset value */
#define  MAX_QUEUE_ITEM_SIZE ((((FDI_QUEUE_SIZE-sizeof(COMMAND))-\
sizeof(Q_DESCRIPTOR))-sizeof(Q_PRIORITY_HEADER))-sizeof(Q_ITEM_INFO))     
  

/* maximum number of sequence table entries in one unit = 16 */                         
#define  MAX_SEQ_ENTRY (UNIT_GRANULARITY/sizeof(ENTRY_TABLE))

#define  ERASE_COUNT_UNIT_SIZE (TO_BYTES(TO_SIZE((sizeof(MULTI_INSTANCE)+\
(sizeof(DWORD)*MIN_INSTANCES)+TO_SIZE(MIN_INSTANCES,2)),UNIT_GRANULARITY))+\
sizeof(UNIT_HEADER))

#if (BUFFER_SIZE > 0)
#define  BUFFER_OFFSET_MASK BUFFER_SIZE-1
#define  BUFFER_OFFSET(a)  ((BYTE)BUFFER_SIZE - (BYTE)((DWORD)(a)&((DWORD)BUFFER_OFFSET_MASK)))
                        /* returns 0 if on buffer boundary.  Otherwise,
                           the number of bytes from the next boundary */ 
#endif

#if ((DATA_STREAM == TRUE) && (INCLUDE_FRAGMENTED_DATA == TRUE))
/* in B/S */
#define DATA_RATE (14400/8) 

/* derived from excel spreadsheet in seconds */
#if PARTITIONS == SINGLE
#define RECLAIM_TIME 10
#else
#define RECLAIM_TIME 8
#endif 
/* in Bytes */
#define DATA_STREAM_OVERHEAD (RECLAIM_TIME*DATA_RATE)

/* number of fragments */
#define  FDI_DATA_STREAM_FRAG ((DATA_STREAM_OVERHEAD)/\
              (UNIT_GRANULARITY+sizeof(UNIT_HEADER)))

/* maximum number of sequence table units = 20 */
#define  FDI_DATA_STREAM_SEQ_UNIT ((FDI_DATA_STREAM_FRAG/MAX_SEQ_ENTRY)+\
             (((FDI_DATA_STREAM_FRAG/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
             ((FDI_DATA_STREAM_FRAG/MAX_SEQ_ENTRY)?0:1))

/* maximum units needed based on biggest sequence table unit = 20 */
#define  FDI_DATA_STREAM_GRP_UNIT ((FDI_DATA_STREAM_SEQ_UNIT/MAX_SEQ_ENTRY)+\
         (((FDI_DATA_STREAM_SEQ_UNIT/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
         ((FDI_DATA_STREAM_SEQ_UNIT/MAX_SEQ_ENTRY)?0:1))
/* in Bytes */
#define FDI_DATA_STREAM_STRUCTURE_OVERHEAD ((FDI_DATA_STREAM_SEQ_UNIT+\
        FDI_DATA_STREAM_GRP_UNIT)*(UNIT_GRANULARITY+sizeof(UNIT_HEADER)))+\
        (FDI_DATA_STREAM_FRAG*sizeof(UNIT_HEADER))

#define FDI_OVERHEAD_PER_BLOCK (DATA_STREAM_OVERHEAD+\
        FDI_DATA_STREAM_STRUCTURE_OVERHEAD)

/* available space for the data after format */
#define  MAX_MEDIA_SIZE ((MAX_DATA_BLOCKS*(FDV_BLOCK_SIZE-sizeof(BLOCK_INFO)-\
         FDI_OVERHEAD_PER_BLOCK-sizeof(UNIT_HEADER)))-ERASE_COUNT_UNIT_SIZE) 
                          /* for erase count parameter and it's header */                    

#define FDI_THRESHOLD (MAX_DATA_BLOCKS*FDI_OVERHEAD_PER_BLOCK)

#endif /* DATA_STREAM and FRAGMENTED_DATA*/


/* 
 * There are 8 data blocks defined in fdi_type.h, 7 are used for storing data 
 * and one is used for the spare block. Each of the 7 data blocks has a 16 
 * byte block information structure and a 8 byte unit header terminator used  
 * to separate unit headers and data. On the flash a 1 byte parameter is used  
 * to store the flash wear leveling cycle count. This byte is maintained by  
 * the FDI software system. Since unit granularity is defined as 128 bytes, it 
 * will take 128 bytes of flash to store this parameter, plus 8 bytes for the 
 * associated unit header.
 * Therefore, the free units after format is...
 * (7 blocks for data)(8192 bytes per block - 16 bytes per block info struc. - 
 * 8 bytes per unit header/data separator) -
 * 128 bytes for wear leveling cycle count parameter - 8 bytes for unit header 
 * equals 57,040 free bytes (0xded0)
 */

#if ((DATA_STREAM == FALSE) && (INCLUDE_FRAGMENTED_DATA == TRUE))
/* available space for the data after format */
#define  MAX_MEDIA_SIZE ((MAX_DATA_BLOCKS*(FDV_BLOCK_SIZE-sizeof(BLOCK_INFO)-\
sizeof(UNIT_HEADER)))-ERASE_COUNT_UNIT_SIZE) 
                          /* for erase count parameter and it's header */                    

#endif /* !DATA_STREAM && INCLUDE_FRAGMENTED_DATA */

#if (INCLUDE_FRAGMENTED_DATA == FALSE)
/* available space for the data after format */
#define  MAX_MEDIA_SIZE ((MAX_DATA_BLOCKS*(FDV_BLOCK_SIZE-sizeof(BLOCK_INFO)-\
sizeof(UNIT_HEADER)))-ERASE_COUNT_UNIT_SIZE) 
                          /* for erase count parameter and it's header */                    
#endif /* !INCLUDE_FRAGMENTED_DATA */

/* maximum 3 unit chunks of data that can be queued = 3 */
/* E.5.1.759 Begin */
#define  MAX_FRAG ((MAX_QUEUE_ITEM_SIZE/\
        FDI_MAX_FRAG_SIZE)+((MAX_QUEUE_ITEM_SIZE%\
        FDI_MAX_FRAG_SIZE!=0)?1:0))
/* E.5.1.759 End */

/*maximum units needed for the fragments of the biggest data in the media=21*/
#define  MAX_FRAG_UNITS ((MAX_DATA_BLOCKS*MAX_NUM_UNITS_PER_FRAG)*\
          ((MAX_FRAG/MAX_DATA_BLOCKS)+1)) 
 
/* maximum fragment units of a biggest data possible in the media = 419 */
/* 
 * maximum number of fragments and associated headers that can fit in 
 * MAX_MEDIA_SIZE 
 */
#define  MAX_MEDIA_FRAG (MAX_MEDIA_SIZE-sizeof(UNIT_HEADER))/\
         (UNIT_GRANULARITY+sizeof(UNIT_HEADER))

#if (INCLUDE_FRAGMENTED_DATA == TRUE)

/*The Maximum Number of Entries in a Group Table is limited to a BYTE*/
/* Based on the Above limitation the size of the Group table is calculated*/
/*This define is added to limit the MAX_GRP_UNIT to 65536 */

/* E.5.0.728 Begin */
/*the original definition miss 2* before the last sizeof(UINT_HEADER)*/
#define MAX_GRP_UNIT_ENTRIES (((((FDV_BLOCK_SIZE - sizeof(BLOCK_INFO)) - 2*sizeof(UNIT_HEADER))  \
                             /sizeof(ENTRY_TABLE)) < 65536)? (((FDV_BLOCK_SIZE -       \
                             sizeof(BLOCK_INFO)) - 2*sizeof(UNIT_HEADER))  \
                             /sizeof(ENTRY_TABLE)): 65536 )
 /* E.5.0.728 End */
#define MAX_GRP_UNIT_SIZE ((((MAX_GRP_UNIT_ENTRIES *(sizeof(ENTRY_TABLE)))+ \
                                   sizeof(UNIT_HEADER))/UNIT_GRANULARITY))

/* maximum number of sequence table units = 20 */
#define  MAX_SEQ_UNIT  ((MAX_MEDIA_FRAG/MAX_SEQ_ENTRY)+\
          (((MAX_MEDIA_FRAG/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
          ((MAX_MEDIA_FRAG/MAX_SEQ_ENTRY)?0:1))
          
/* maximum units needed based on biggest sequence table unit = 20 */
/*Maximum size of a Group Table based on the Size of the Media*/
#define  MAX_GRP_UNIT_MEDIA_SIZE  ((MAX_SEQ_UNIT/MAX_SEQ_ENTRY)+\
          (((MAX_SEQ_UNIT/MAX_SEQ_ENTRY)%UNIT_GRANULARITY)?1:0)+\
          ((MAX_SEQ_UNIT/MAX_SEQ_ENTRY)?0:1))

/* Size of the Maximum Group Table is fixed based on whether 
   the size of the Group Table exceeds 65536 entries  or not  */
#define MAX_GRP_UNIT ((MAX_GRP_UNIT_MEDIA_SIZE>MAX_GRP_UNIT_SIZE)?\
                       MAX_GRP_UNIT_SIZE:MAX_GRP_UNIT_MEDIA_SIZE)

#endif /* INCLUDE_FRAGMENTED_DATA */

#if (DATA_STREAM == FALSE)
#if (INCLUDE_FRAGMENTED_DATA == TRUE)

#define SEQ_REPLACE_UNITS     ((MAX_FRAG/MAX_SEQ_ENTRY)+1+\
                              ((MAX_FRAG%MAX_SEQ_ENTRY)?1:0))
              
#define  MAX_THRESHOLD_UNIT   (MAX_FRAG_UNITS+FDI_MaxGrpUnit+SEQ_REPLACE_UNITS)

#else /* !INCLUDE_FRAGMENTED_DATA */

/* threshold in units = 21 */
#define  MAX_THRESHOLD_UNIT  ((MAX_MEDIA_FRAG<MAX_FRAG_UNITS)?\
MAX_MEDIA_FRAG:MAX_FRAG_UNITS)
#endif /* !INCLUDE_FRAGMENTED_DATA */

#if (INCLUDE_FRAGMENTED_DATA == TRUE)
/* threshold in bytes = 2688 */
#define  FDI_THRESHOLD ((MAX_THRESHOLD_UNIT*UNIT_GRANULARITY)+\
                   UNIT_GRANULARITY+sizeof(UNIT_HEADER))
                                       /* for replacing wearleveling parameter 
                                        * unit and it's header. This defines 
                                        * the absolute free space limit before 
                                        * the background task pends on reclaim 
                                        */
#else

/* threshold in bytes */
#define  FDI_THRESHOLD (((MAX_NUM_UNITS_PER_FRAG*MAX_DATA_BLOCKS)*\
UNIT_GRANULARITY)+sizeof(UNIT_HEADER)+(UNIT_GRANULARITY+sizeof(UNIT_HEADER)))
#endif /* INCLUDE_FRAGMENTED_DATA */

#endif /* !DATA_STREAM */

#if ((INCLUDE_FRAGMENTED_DATA == TRUE) && (DATA_STREAM == FALSE))
#define MAX_DATA_SIZE (((MAX_MEDIA_FRAG-MAX_SEQ_UNIT-FDI_MaxGrpUnit)*\
UNIT_GRANULARITY)-FDI_THRESHOLD)
#endif

#if ((INCLUDE_FRAGMENTED_DATA == TRUE) && (DATA_STREAM == TRUE))
#define MAX_DATA_SIZE ((MAX_MEDIA_FRAG-MAX_SEQ_UNIT-FDI_MaxGrpUnit)*\
UNIT_GRANULARITY)
#endif

#if (INCLUDE_FRAGMENTED_DATA == FALSE)
#define MAX_DATA_SIZE (MAX_MEDIA_SIZE-FDI_THRESHOLD)
#endif


#define  MAX_HEADERS    ((FDV_BLOCK_SIZE - sizeof(BLOCK_INFO)) / \
                         sizeof(UNIT_HEADER))

/* make sure if the block lock support is disabled all defines are false */
#if (BLOCK_LOCK_SUPPORT == FALSE)
#undef ENABLE_NONFDI_BLOCKLOCKING
#undef ENABLE_FDI_BLOCKLOCKING
#define ENABLE_NONFDI_BLOCKLOCKING  FALSE
#define ENABLE_FDI_BLOCKLOCKING     FALSE
#endif /* BLOCK_LOCK_SUPPORT */

/* 
 * unit header status types. Changed for ISF to take bits down from right 
   to left
 */
#define  HDR_EMPTY                0xFFFF
#define  HDR_ALLOCATING           0xFFFC
#define  HDR_VALID_HDR            0xFFF0
#define  HDR_ALLOCATED            0xFFC0
#define  HDR_VALID                0xFF00
#define  HDR_INVALIDATING         0xFC00
#define  HDR_INVALID              0xF000

#define  HDR_CORRUPT(status)      ((((status) & HDR_INVALID) != HDR_INVALID) ? 1:0 )
#define  INVALIDATE_HDR           0xF3FF
#define  INVALID_HDR(status)      (((status) & 0x0800) == 0)

/* HDR_READ_MASK is used to mask the higher status bit of each status cell
 * during status read.  HDR_STATE returns 1 if the status is in this state,
 * otherwise 0. */
#define  HDR_READ_MASK                      0xFAAA
#define  HDR_STATE(state, status)           (((status) & HDR_READ_MASK) == \
                                             ((state) & HDR_READ_MASK))

/* To determine if a status is in an intermediate state, the status can be
 * shifted 1 bit and exclusive-or'd with itself to overlay each cell's bits
 * over each other to determine if the cell was '10' or '01'.
 * HDR_INTERMEDIATE_MASK is used to mask the exclusive-or'd cell status bits
 * from the shift.  HDR_INTERMEDIATE returns a non-zero value if the status
 * is in an intermediate state.  The non-zero return value can be passed as
 * inter into HDR_FIX_INTERMEDIATE with status to return the fixed status. */
#define  HDR_INTERMEDIATE_MASK               0x0AAA
#define  HDR_INTERMEDIATE(status)            (((status) ^ ((status) << 1)) & \
                                              HDR_INTERMEDIATE_MASK)
#define  HDR_FIX_INTERMEDIATE(inter, status) ((~((inter) | ((inter) >> 1))) \
                                              & (status))

/* 
 * sequence table status types
 */
#define  SEQ_EMPTY                0xFF
#define  SEQ_ALLOCATING           0xFC
#define  SEQ_VALID_ENTRY          0xF0
#define  SEQ_VALID                0xC0
#define  SEQ_INVALID              0x00
#define  GRP_EMPTY                SEQ_EMPTY
#define  GRP_ALLOCATING           SEQ_ALLOCATING
#define  GRP_VALID_ENTRY          SEQ_VALID_ENTRY
#define  GRP_VALID                SEQ_VALID
#define  GRP_INVALID              SEQ_INVALID

#define  INVALIDATE_ENTRY         0x3F
#define  INVALID_ENTRY(status)    (((status) & 0x80) == 0)

/* ENTRY_READ_MASK is used to mask the higher status bit of each status cell
 * during status read.  ENTRY_STATE returns 1 if the status is in this state,
 * otherwise 0. */
#define  ENTRY_READ_MASK                    0xAA
#define  ENTRY_STATE(state, status)         (((status) & ENTRY_READ_MASK) == \
                                             ((state) & ENTRY_READ_MASK))

/* To determine if a status is in an intermediate state, the status can be
 * shifted 1 bit and exclusive-or'd with itself to overlay each cell's bits
 * over each other to determine if the cell was '10' or '01'.
 * ENTRY_INTERMEDIATE_MASK is used to mask the exclusive-or'd cell status bits
 * from the shift.  ENTRY_INTERMEDIATE returns a non-zero value if the status
 * is in an intermediate state.  The non-zero return value can be passed as
 * inter into ENTRY_FIX_INTERMEDIATE with status to return the fixed status. */
#define  ENTRY_INTERMEDIATE_MASK               0xAA
#define  ENTRY_INTERMEDIATE(status)            (((status) ^ ((status) << 1)) & \
                                                ENTRY_INTERMEDIATE_MASK)
#define  ENTRY_FIX_INTERMEDIATE(inter, status) ((~((inter) | ((inter) >> 1))) \
                                                & (status))

/*
 * Mask to check the reclamation status and queue status. 
 */
#define  RECLAIM_PENDING          0x01
#define  QUEUE_PENDING            0x02

⌨️ 快捷键说明

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