Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
9.2 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/NFTLLITE.H_V $
  3. *
  4. * Rev 1.6 Apr 15 2002 07:38:34 oris
  5. * Added the following fields to Anand record -
  6. * - verifyBuffer pointer.
  7. * - invalidReplacement.
  8. * Added support for VERIFY_ERASED_SECTOR compilation flag.
  9. *
  10. * Rev 1.5 Jan 28 2002 21:26:20 oris
  11. * Removed the use of back-slashes in macro definitions.
  12. *
  13. * Rev 1.4 Jan 17 2002 23:04:34 oris
  14. * Added SECTORS_VERIFIED_PER_FOLDING - defines the number of sectors verified per folding when using FL_OFF verify write mode
  15. * Added DOUBLE_MAX_UNIT_CHAIN instead of MAX_UNIT_CHAIN*2
  16. * Added MAX_FOLDING_TRIES - For improved power failures algorithm
  17. * Added S_CACHE_4_SECTORS_FREE for quicker cache initialization.
  18. * Added new macros :
  19. * - distanceOf : Counting bit difference between 2 bytes.
  20. * - isValidSectorFlags : one of the valid sector flags (not including IGNORE)
  21. * Changed Anand record :
  22. * - Added socketNo field storing the socket number used by the TL.
  23. * - Changed RAM tables pointer to FAR1 for BIOS driver far malloc.
  24. * - Changed FLFlash record to a pointer (TrueFFS now uses a single FLFlash record per socket).
  25. * - Added verifiedSectorNo and curSectorWrite fields for FL_OFF verify write mode.
  26. *
  27. * Rev 1.3 May 16 2001 21:21:34 oris
  28. * Added the FL_ prefix to the following defines: MALLOC and FREE.
  29. * Changed wear level counter from 0xFF to 0xFFF0
  30. * Change "data" named variables to flData to avoid name clashes.
  31. *
  32. * Rev 1.2 Apr 01 2001 07:52:36 oris
  33. * copywrite notice.
  34. * Alligned left all # directives.
  35. *
  36. * Rev 1.1 Feb 14 2001 02:05:30 oris
  37. * Changed MAX_CHAIN_LENGTH to an environment variable.
  38. *
  39. * Rev 1.0 Feb 05 2001 12:26:30 oris
  40. * Initial revision.
  41. *
  42. */
  43. /***********************************************************************************/
  44. /* M-Systems Confidential */
  45. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  46. /* All Rights Reserved */
  47. /***********************************************************************************/
  48. /* NOTICE OF M-SYSTEMS OEM */
  49. /* SOFTWARE LICENSE AGREEMENT */
  50. /* */
  51. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  52. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  53. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  54. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  55. /* E-MAIL = [email protected] */
  56. /***********************************************************************************/
  57. #ifndef NFTLLITE_H
  58. #define NFTLLITE_H
  59. #include "flbuffer.h"
  60. #include "flflash.h"
  61. #include "fltl.h"
  62. typedef long int ANANDVirtualAddress;
  63. typedef unsigned char ANANDPhysUnit;
  64. typedef unsigned short ANANDUnitNo;
  65. #define ANAND_UNASSIGNED_ADDRESS 0xffffffffl
  66. #define ANAND_SPARE_SIZE 16
  67. #define UNIT_DATA_OFFSET 8
  68. #define SECTOR_DATA_OFFSET 6
  69. #define UNIT_TAILER_OFFSET (SECTOR_SIZE + 8)
  70. #define FOLD_MARK_OFFSET (2 * SECTOR_SIZE + 8)
  71. #define ERASE_MARK 0x3c69
  72. #ifdef ENVIRONMENT_VARS
  73. #define SECTORS_VERIFIED_PER_FOLDING flSectorsVerifiedPerFolding
  74. #define MAX_UNIT_CHAIN flMaxUnitChain
  75. #else
  76. #define SECTORS_VERIFIED_PER_FOLDING 64
  77. #define MAX_UNIT_CHAIN 20
  78. #endif /* ENVIRONMENT_VARS */
  79. #define DOUBLE_MAX_UNIT_CHAIN 64 /* Double max unit chain */
  80. #define MAX_FOLDING_TRIES 20
  81. #define ANAND_UNIT_FREE 0xff
  82. #define UNIT_REPLACED 0x80
  83. #define UNIT_COUNT 0x7f
  84. #define UNIT_ORPHAN 0x10
  85. #define UNIT_UNAVAIL 0x6a /* Illegal count denoting unit not available */
  86. #define UNIT_BAD_MOUNT 0x6b /* Bad unit sign after mount */
  87. #define UNIT_MAX_COUNT 0x40 /* Largest valid count */
  88. #define IS_BAD(u) ( u == UNIT_BAD_MOUNT )
  89. #define UNIT_BAD_ORIGINAL 0
  90. #define distanceOf(read, expected) (onesCount((byte)(read ^ expected)))
  91. #define isValidSectorFlag(sectorFlag) ((sectorFlag==SECTOR_FREE)||(sectorFlag==SECTOR_USED)||(sectorFlag==SECTOR_DELETED))
  92. #define countOf(unitNo) (vol.physicalUnits[unitNo] & UNIT_COUNT)
  93. #define isAvailable(unitNo) ((vol.physicalUnits[unitNo] == ANAND_UNIT_FREE) || (vol.physicalUnits[unitNo] == (ANAND_UNIT_FREE & ~UNIT_ORPHAN)) || (countOf(unitNo) <= UNIT_MAX_COUNT))
  94. #define setUnavail(unitNo) {vol.physicalUnits[unitNo] &= ~UNIT_COUNT; vol.physicalUnits[unitNo] |= UNIT_UNAVAIL; }
  95. #define isReplaced(unitNo) (vol.physicalUnits[unitNo] & UNIT_REPLACED)
  96. #define setUnitCount(unitNo,unitCount) { vol.physicalUnits[unitNo] &= ~UNIT_COUNT; vol.physicalUnits[unitNo] |= (ANANDPhysUnit)unitCount; }
  97. #define isLegalUnit(unitNo) ((unitNo < vol.noOfUnits) || (unitNo == ANAND_NO_UNIT))
  98. #define MAX_UNIT_SIZE_BITS 15
  99. #define MORE_UNIT_BITS_MASK 3
  100. #define ANAND_BAD_PERCENTAGE 2
  101. #define ANAND_NO_UNIT 0xffff
  102. #define ANAND_REPLACING_UNIT 0x8000
  103. #define MAX_UNIT_NUM (12 * 1024)
  104. /* Block flags */
  105. #define SECTOR_FREE 0xff
  106. #define SECTOR_USED 0x55
  107. #define SECTOR_IGNORE 0x11
  108. #define SECTOR_DELETED 0x00
  109. #ifdef NFTL_CACHE
  110. /* values for 2-bit entries in Sector Flags cache */
  111. #define S_CACHE_SECTOR_DELETED 0x00
  112. #define S_CACHE_SECTOR_IGNORE 0x01
  113. #define S_CACHE_SECTOR_USED 0x02
  114. #define S_CACHE_SECTOR_FREE 0x03
  115. #define S_CACHE_4_SECTORS_FREE 0xff
  116. #endif /* NFTL_CACHE */
  117. #define FOLDING_IN_PROGRESS 0x5555
  118. #define FOLDING_COMPLETE 0x1111
  119. #define ERASE_NOT_IN_PROGRESS -1
  120. #ifdef NFTL_CACHE
  121. /* Unit Header cache entry, close relative of struct UnitHeader */
  122. typedef struct {
  123. unsigned short virtualUnitNo;
  124. unsigned short replacementUnitNo;
  125. } ucacheEntry;
  126. #endif /* NFTL_CACHE */
  127. /* erase record */
  128. typedef struct {
  129. LEulong eraseCount;
  130. LEushort eraseMark;
  131. LEushort eraseMark1;
  132. } UnitTailer;
  133. /* unit header */
  134. typedef struct {
  135. LEushort virtualUnitNo;
  136. LEushort replacementUnitNo;
  137. LEushort spareVirtualUnitNo;
  138. LEushort spareReplacementUnitNo;
  139. } ANANDUnitHeader;
  140. /* Medium Boot Record */
  141. typedef struct {
  142. char bootRecordId[6]; /* = "ANAND" */
  143. LEushort noOfUnits;
  144. LEushort bootUnits;
  145. Unaligned4 virtualMediumSize;
  146. #ifdef EXTRA_LARGE
  147. unsigned char anandFlags;
  148. #endif /* EXTRA_LARGE */
  149. } ANANDBootRecord;
  150. #ifndef FL_MALLOC
  151. #define ANAND_HEAP_SIZE (0x100000l / ASSUMED_NFTL_UNIT_SIZE) * (sizeof(ANANDUnitNo) + sizeof(ANANDPhysUnit)) * MAX_VOLUME_MBYTES
  152. #ifdef NFTL_CACHE
  153. #define U_CACHE_SIZE ((MAX_VOLUME_MBYTES * 0x100000l) / ASSUMED_NFTL_UNIT_SIZE)
  154. #define S_CACHE_SIZE ((MAX_VOLUME_MBYTES * 0x100000l) / (SECTOR_SIZE * 4))
  155. #endif
  156. #endif /* FL_MALLOC */
  157. #define WLnow 0xfff0
  158. typedef struct {
  159. unsigned short alarm;
  160. ANANDUnitNo currUnit;
  161. } WLdata;
  162. struct tTLrec{
  163. byte socketNo;
  164. FLBoolean badFormat; /* true if TFFS format is bad */
  165. ANANDUnitNo orgUnit, /* Unit no. of boot record */
  166. spareOrgUnit; /* ... and spare copy of it */
  167. ANANDUnitNo freeUnits; /* Free units on media */
  168. unsigned int erasableBlockSizeBits; /* log2 of erasable block size */
  169. ANANDUnitNo noOfVirtualUnits;
  170. ANANDUnitNo noOfTransferUnits;
  171. unsigned long unitOffsetMask; /* = 1 << unitSizeBits - 1 */
  172. unsigned int sectorsPerUnit;
  173. ANANDUnitNo noOfUnits,
  174. bootUnits;
  175. unsigned int unitSizeBits;
  176. SectorNo virtualSectors;
  177. ANANDUnitNo roverUnit, /* Starting point for allocation search */
  178. countsValid; /* Number of units with valid unit count */
  179. ANANDPhysUnit FAR1 *physicalUnits; /* unit table by physical no. */
  180. ANANDUnitNo FAR1 *virtualUnits; /* unit table by logical no. */
  181. #ifdef NFTL_CACHE
  182. ucacheEntry FAR1 *ucache; /* Unit Header cache */
  183. byte FAR1 *scache; /* Sector Flags cache */
  184. #endif
  185. SectorNo mappedSectorNo;
  186. const void FAR0 *mappedSector;
  187. CardAddress mappedSectorAddress;
  188. #if (defined(VERIFY_WRITE) || defined(VERIFY_VOLUME) || defined(VERIFY_ERASED_SECTOR))
  189. SectorNo verifiedSectorNo; /* Largest sector verified so far */
  190. SectorNo curSectorWrite;
  191. #endif /* VERIFY_WRITE || VERIFY_VOLUME || VERIFY_ERASED_SECTOR */
  192. /* Accumulated statistics. */
  193. long int sectorsRead,
  194. sectorsWritten,
  195. sectorsDeleted,
  196. parasiteWrites,
  197. unitsFolded;
  198. FLFlash *flash;
  199. FLBuffer *buffer;
  200. dword *verifyBuffer; /* Pointer to socket verify buffer */
  201. #ifndef FL_MALLOC
  202. char heap[ANAND_HEAP_SIZE];
  203. #ifdef NFTL_CACHE
  204. ucacheEntry ucacheBuf[U_CACHE_SIZE];
  205. unsigned char scacheBuf[S_CACHE_SIZE];
  206. #endif
  207. #endif /* FL_MALLOC */
  208. WLdata wearLevel;
  209. unsigned long eraseSum;
  210. ANANDUnitNo invalidReplacement; /* Unit with bad header - for mount */
  211. };
  212. typedef TLrec Anand;
  213. #define nftlBuffer vol.buffer->flData
  214. #endif