Leaked source code of windows server 2003
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.

410 lines
16 KiB

  1. /*
  2. * $Log: V:/Flite/archives/TrueFFS5/Src/inftl.h_V $
  3. *
  4. * Rev 1.17 Apr 15 2002 07:37:28 oris
  5. * Added pointer to verify write in Bnand record.
  6. * Added support for VERIFY_ERASED_SECTOR compilation flag.
  7. *
  8. * Rev 1.16 Feb 19 2002 21:00:30 oris
  9. * Added FL_NORMAL_FOLDING / FL_FORCE_FOLDING / FL_NOT_IN_PLACE / CLEAR_DISCARD and UNIT_TAILER_OFFSET_2
  10. *
  11. * Rev 1.15 Jan 28 2002 21:25:56 oris
  12. * Removed the use of back-slashes in macro definitions.
  13. * Changed constants to Unsigned Long.
  14. *
  15. * Rev 1.14 Jan 23 2002 23:33:26 oris
  16. * Added definition of QUICK_MOUNT_VALID_SING_OFFSET.
  17. *
  18. * Rev 1.13 Jan 20 2002 10:50:44 oris
  19. * Added new defintions :
  20. * - MAX_CREATE_UNIT_COUNT
  21. * - SECTORS_VERIFIED_PER_FOLDING
  22. * - ANAND_BAD_CHAIN_ADDRESS
  23. * - ANAND_BAD_CHAIN_UNIT
  24. * Changed FL_BAD_ERASE_MARK to 0
  25. * Reorganized Bnand structure.
  26. * - Changed fields order
  27. * - Changed memory tables pointers to FAR1 pointers - for BIOS driver FAR heap.
  28. * - Added fields to Bnand structure : verifiedSectorNo / curSectorWrite / firstMediaWrite
  29. * - Removed badFormat field
  30. * Added verifiedSectorNo to quick mount record.
  31. *
  32. * Rev 1.12 Nov 16 2001 00:22:54 oris
  33. * Remove warnings.
  34. * removed QUICK_MOUNT_FEATURE ifdef.
  35. *
  36. * Rev 1.11 Nov 08 2001 10:49:58 oris
  37. * Reorganized Bnand structure and added debug state field.
  38. * Added INFTL_FAILED_MOUNT, ALL_PARITY_BITS_OK , DISCARD_UNIT_OFFSET definitions.
  39. *
  40. * Rev 1.10 Sep 24 2001 18:23:56 oris
  41. * Changed UNIT_UNAVAIL from 0x6a to 0x60 in order not to loose sector count.
  42. *
  43. * Rev 1.9 Sep 16 2001 21:48:02 oris
  44. * changed the MAX_UNIT_NUM to 32K
  45. *
  46. * Rev 1.8 Sep 15 2001 23:47:04 oris
  47. * Added MAX_FOLDING_LOOP definition.
  48. * Changed MAX_UNIT_NUM to cause 576MB to group 2 physical units to a single virtual unit.
  49. *
  50. * Rev 1.7 Jul 13 2001 01:06:24 oris
  51. * Changed second header offset to page 4 to prevent 6 PPP.
  52. *
  53. * Rev 1.6 Jun 17 2001 08:18:16 oris
  54. * Changed recusive include define to INFTL_H.
  55. * Added FL_BAD_ERASE_MARK definition for units without the erase mark on mount operation.
  56. *
  57. * Rev 1.5 May 16 2001 21:20:20 oris
  58. * Added the FL_ prefix to the following defines: MALLOC and FREE.
  59. * Changed wear level counter from 0xFF to 0xFFF0
  60. * Change "data" named variables to flData to avoid name clashes.
  61. *
  62. * Rev 1.4 Apr 16 2001 13:51:10 oris
  63. * Changed stack allocation of multi-sector buffers to dynamic allocation.
  64. *
  65. * Rev 1.3 Apr 09 2001 15:14:18 oris
  66. * End with an empty line.
  67. *
  68. * Rev 1.2 Apr 01 2001 07:56:52 oris
  69. * copywrite notice.
  70. * Removed nested comments.
  71. * Moved macroes to the c file.
  72. * Changed variable types to standard flite types.
  73. * Compilation problem for big endien fixed.
  74. * Aliggned unit header structure (SecondANANDUnitHeader) to 8 bytes.
  75. * Changed BAD_UNIT define.
  76. * Added FL_VALID, FL_FIRST_VALID, FL_PRELIMINARY, FL_FIRST_PRELIMINARY defines.
  77. *
  78. * Rev 1.1 Feb 14 2001 02:06:24 oris
  79. * Changed MAX_CHAIN_LENGTH to an environment variable.
  80. *
  81. * Rev 1.0 Feb 13 2001 02:16:00 oris
  82. * Initial revision.
  83. *
  84. */
  85. /***********************************************************************************/
  86. /* M-Systems Confidential */
  87. /* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2001 */
  88. /* All Rights Reserved */
  89. /***********************************************************************************/
  90. /* NOTICE OF M-SYSTEMS OEM */
  91. /* SOFTWARE LICENSE AGREEMENT */
  92. /* */
  93. /* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
  94. /* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
  95. /* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
  96. /* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
  97. /* E-MAIL = [email protected] */
  98. /***********************************************************************************/
  99. /*************************************************/
  100. /* T r u e F F S 5.0 S o u r c e F i l e s */
  101. /* --------------------------------------------- */
  102. /*************************************************/
  103. /*****************************************************************************
  104. * File Header *
  105. * ----------- *
  106. * Name : inftl.h *
  107. * *
  108. * Description : Data strucute and genreal defintions for INFTL flash *
  109. * translation layer. *
  110. * *
  111. *****************************************************************************/
  112. #ifndef INFTL_H
  113. #define INFTL_H
  114. #include "flbuffer.h"
  115. #include "flflash.h"
  116. #include "fltl.h"
  117. typedef Sdword ANANDVirtualAddress;
  118. typedef byte ANANDPhysUnit;
  119. typedef word ANANDUnitNo;
  120. /* Partition flags */
  121. #define INFTL_BINARY 0x20000000L
  122. #define INFTL_BDTL 0x40000000L
  123. #define INFTL_LAST 0x80000000L
  124. /* PROTECTABLE defined in flbase.h as 1 */
  125. /* READ_PROTECTED defined in flbase.h as 2 */
  126. /* WRITE_PROTECTED defined in flbase.h as 4 */
  127. /* LOCK_ENABLED defined in flbase.h as 8 */
  128. /* LOCK_ASSERTED defined in flbase.h as 16 */
  129. /* KEY_INSERTED defined in flbase.h as 32 */
  130. /* CHANGEABLE_PROTECTION defined in flbase.h as 64 */
  131. /* Media flags */
  132. #define QUICK_MOUNT 1
  133. /* TL limits */
  134. #define MAX_NO_OF_FLOORS 4
  135. #define MAX_VOLUMES_PER_DOC 4
  136. #define MAX_FOLDING_LOOP 10
  137. #define MAX_CREATE_UNIT_COUNT 1024
  138. #define MAX_QUICK_MOUNT_UNITS 10
  139. #ifdef ENVIRONMENT_VARS
  140. #if (defined(VERIFY_WRITE) || defined (VERIFY_VOLUME) || defined(VERIFY_ERASED_SECTOR))
  141. #define SECTORS_VERIFIED_PER_FOLDING flSectorsVerifiedPerFolding
  142. #endif /* VERIFY_WRITE || VERIFY_VOLUME || VERIFY_ERASED_SECTOR */
  143. #define MAX_UNIT_CHAIN flMaxUnitChain
  144. #else
  145. #define SECTORS_VERIFIED_PER_FOLDING 64UL
  146. #define MAX_UNIT_CHAIN 20
  147. #endif /* ENVIRONMENT_VARS */
  148. #define DOUBLE_MAX_UNIT_CHAIN 64 /* Double max unit chain */
  149. /* Folding flags */
  150. #define FL_NORMAL_FOLDING 0
  151. #define FL_FORCE_FOLDING 1
  152. #define FL_NOT_IN_PLACE 2
  153. /* General defines */
  154. #define NO_OF_MEDIA_HEADERS 2
  155. #define HEADERS_SPACING (8UL<<SECTOR_SIZE_BITS)
  156. #define RAM_FACTOR 3L /* byte per erasable block for ram tables */
  157. #define HEADER_SEARCH_BOUNDRY 16 /* must be a multiplication of 8 */
  158. #define QUICK_MOUNT_VALID_SIGN 0xaaaa5555L
  159. #define ANAND_UNASSIGNED_ADDRESS 0xffffffffL
  160. #define ANAND_BAD_CHAIN_ADDRESS 0xfffffffeL
  161. #define ANAND_SPARE_SIZE 16
  162. #define UNIT_DATA_OFFSET 8UL
  163. #define SECTOR_DATA_OFFSET 6UL
  164. #define SECOND_HEADER_OFFSET (4UL*SECTOR_SIZE)
  165. #define UNIT_TAILER_OFFSET (2UL*SECTOR_SIZE + 8UL)
  166. #define UNIT_TAILER_OFFSET_2 (6UL*SECTOR_SIZE + 8UL)
  167. #define DISCARD_UNIT_OFFSET (UNIT_DATA_OFFSET + 7UL)
  168. #define QUICK_MOUNT_VALID_SIGN_OFFSET 44UL
  169. #define FL_VALID 0x1
  170. #define FL_FIRST_VALID 0x81
  171. #define FL_PRELIMINARY 0x2
  172. #define FL_FIRST_PRELIMINARY 0x82
  173. #define ERASE_MARK 0x3c69
  174. #define FL_BAD_ERASE_MARK 0x0
  175. #define ANAND_UNIT_FREE 0xff
  176. #define UNIT_COUNT 0x7f
  177. #define FIRST_IN_CHAIN 0x80
  178. #define UNIT_UNAVAIL 0x60 /* Illegal count denoting unit not available */
  179. #define UNIT_BAD 0x6B
  180. #define UNIT_MAX_COUNT 0x40 /* Largest valid count */
  181. #define DISCARD 0xAA /* Valid used unit signature */
  182. #define CLEAR_DISCARD 0x0 /* Mark unit as discarded */
  183. #define ANAND_BAD_PERCENTAGE 2 /* Maximum bad units */
  184. /* Parity bits for unit header fields */
  185. #define VU_PARITY_BIT 8 /* virtual Unit number */
  186. #define PU_PARITY_BIT 4 /* previous Unit number */
  187. #define ANAC_PARITY_BIT 2 /* ANAC field */
  188. #define NAC_PARITY_BIT 1 /* NAC field */
  189. #define ALL_PARITY_BITS_OK 0xf /* All parity bits */
  190. #define IS_BAD(u) ( u == UNIT_BAD_MOUNT )
  191. /*#define UNIT_BAD_MARKED 7*/
  192. #define MAX_UNIT_SIZE_BITS 15
  193. #define MORE_UNIT_BITS_MASK 3
  194. #define ANAND_NO_UNIT 0xffff
  195. #define ANAND_BAD_CHAIN_UNIT 0xfffe
  196. #define MAX_UNIT_NUM 32768L
  197. /* Block flags */
  198. #define SECTOR_FREE 0xff
  199. #define SECTOR_USED 0x55
  200. #define SECTOR_IGNORE 0x11
  201. #define SECTOR_DELETED 0x00
  202. /* Debug modes flags */
  203. #define INFTL_FAILED_MOUNT 1
  204. #ifdef NFTL_CACHE
  205. /* values for 2-bit entries in Sector Flags cache */
  206. #define S_CACHE_SECTOR_DELETED 0x00
  207. #define S_CACHE_SECTOR_IGNORE 0x01
  208. #define S_CACHE_SECTOR_USED 0x02
  209. #define S_CACHE_SECTOR_FREE 0x03
  210. #define S_CACHE_4_SECTORS_FREE 0xff
  211. #endif /* NFTL_CACHE */
  212. #ifdef NFTL_CACHE
  213. /* Unit Header cache entry, close relative of struct UnitHeader */
  214. typedef struct {
  215. word virtualUnitNo;
  216. word prevUnitNo;
  217. byte ANAC;
  218. byte NAC;
  219. } ucacheEntry; /* See doc2exb.c uses this value */
  220. #endif /* NFTL_CACHE */
  221. /* erase record */
  222. typedef struct {
  223. LEulong eraseCount;
  224. LEushort eraseMark;
  225. LEushort eraseMark1;
  226. } UnitTailer;
  227. /* unit header */
  228. typedef struct {
  229. LEushort virtualUnitNo;
  230. LEushort prevUnitNo;
  231. byte ANAC;
  232. byte NAC;
  233. byte parityPerField;
  234. byte discarded;
  235. } ANANDUnitHeader;
  236. /* Second copy of unitHeader */
  237. typedef struct {
  238. byte parityPerField;
  239. byte ANAC;
  240. LEushort prevUnitNo;
  241. LEushort virtualUnitNo;
  242. byte NAC;
  243. byte junk; /* alignment filed for int - 2 */
  244. } SecondANANDUnitHeader;
  245. /* Medium Boot Record */
  246. typedef struct {
  247. LEmin bootRecordId[2]; /* "BNAND" */
  248. LEmin noOfBootImageBlocks; /* number of good blocks in the boot image area */
  249. LEmin noOfBinaryPartitions; /* number of binary partitions */
  250. LEmin noOfBDTLPartitions; /* number of BDTL partitions */
  251. LEmin blockMultiplierBits; /* number of bits used to represent the
  252. times a flash erasable block fits inside
  253. an INFTL erasable unit. */
  254. LEmin formatFlags; /* QUICK_MOUNT */
  255. LEmin osakVersion; /* version of osak used to format the media */
  256. LEmin percentUsed;
  257. } BNANDBootRecord;
  258. /* Volume record */
  259. typedef struct {
  260. LEmin virtualUnits; /* Virtual size exported by the trasnaltion layer */
  261. LEmin firstUnit; /* First unit of the partition */
  262. LEmin lastUnit; /* Last unit of the partition */
  263. LEmin flags; /* PROTECTABLE,CHANGEABLE_PROTECTION,INFTL_BINARY,INFTL_BDTL,INFTL_LAST */
  264. LEmin spareUnits; /* Number of spare garanteed units for INFTL partition */
  265. LEmin firstQuickMountUnit; /* first unit used for the quick mount data */
  266. LEmin protectionArea; /* Number of protection area */
  267. } BNANDVolumeHeaderRecord;
  268. #ifndef FL_MALLOC
  269. #define ANAND_HEAP_SIZE (0x100000l / ASSUMED_NFTL_UNIT_SIZE) * (sizeof(ANANDUnitNo) + sizeof(ANANDPhysUnit)) * MAX_VOLUME_MBYTES
  270. #ifdef NFTL_CACHE
  271. #define U_CACHE_SIZE ((MAX_VOLUME_MBYTES * 0x100000l) / ASSUMED_NFTL_UNIT_SIZE)
  272. #define S_CACHE_SIZE ((MAX_VOLUME_MBYTES * 0x100000l) / (SECTOR_SIZE * 4))
  273. #endif
  274. #endif /* FL_MALLOC */
  275. #define WLnow 0xfff0
  276. typedef struct {
  277. word alarm;
  278. ANANDUnitNo currUnit;
  279. } WLdata;
  280. struct tTLrec{
  281. FLFlash *flash; /* Poniter to MTD record */
  282. dword *verifyBuffer; /* Pointer to socket verify buffer */
  283. FLBuffer *buffer; /* Pointer to socket buffer */
  284. ANANDPhysUnit FAR1 *physicalUnits; /* unit table by physical no. */
  285. ANANDUnitNo FAR1 *virtualUnits; /* unit table by logical no. */
  286. const void FAR0 *mappedSector;
  287. #ifdef NFTL_CACHE
  288. ucacheEntry FAR1 *ucache; /* Unit Header cache */
  289. byte FAR1 *scache; /* Sector Flags cache */
  290. #endif
  291. #ifndef FL_MALLOC
  292. char* heap;
  293. #endif /* FL_MALLOC */
  294. CardAddress mappedSectorAddress;
  295. /* Accumulated statistics. */
  296. Sdword sectorsRead,
  297. sectorsWritten,
  298. sectorsDeleted,
  299. parasiteWrites,
  300. unitsFolded;
  301. WLdata wearLevel;
  302. dword eraseSum;
  303. #ifdef NFTL_CACHE
  304. dword firstUnitAddress; /* address of the first unit of the volume */
  305. #endif /* NFTL_CACHE */
  306. ANANDUnitNo firstQuickMountUnit; /* The quick mount first unit */
  307. ANANDUnitNo firstUnit; /* first unit number of the volume */
  308. ANANDUnitNo freeUnits; /* Free units on media */
  309. ANANDUnitNo noOfVirtualUnits; /* No of units exported by the TL */
  310. ANANDUnitNo noOfUnits; /* No of units in the partition */
  311. ANANDUnitNo bootUnits; /* No of boot units of the media */
  312. ANANDUnitNo roverUnit; /* Starting point for allocation search */
  313. ANANDUnitNo countsValid; /* Number of units for which unit count was set */
  314. word sectorsPerUnit; /* Number of 512 bytes in a unit */
  315. word sectorsPerUnitBits; /* Bits used for no of sectors per unit */
  316. word sectorsPerUnitMask; /* Number of 512 bytes in a unit - 1 */
  317. SectorNo virtualSectors; /* No of sectors exported by the TL */
  318. SectorNo mappedSectorNo; /* Currently mapped sector */
  319. #if (defined(VERIFY_WRITE) || defined (VERIFY_VOLUME) || defined(VERIFY_ERASED_SECTOR))
  320. SectorNo verifiedSectorNo; /* Largest sector verified so far */
  321. SectorNo curSectorWrite; /* Current update sector */
  322. #endif /* VERIFY_WRITE || VERIFY_VOLUME || VERIFY_ERASED_SECTOR */
  323. byte flags; /* QUICK_MOUNT or not */
  324. byte socketNo; /* The volumes socket serial number */
  325. byte blockMultiplierBits; /* the number of ersable blocks in */
  326. /* an INFTL unit */
  327. byte erasableBlockSizeBits; /* log2 of erasable block size */
  328. byte unitSizeBits; /* log2 of TL unit size */
  329. FLBoolean firstMediaWrite;
  330. #ifdef CHECK_MOUNT
  331. dword debugState; /* Used for internal debug */
  332. #endif /* CHECK_MOUNT */
  333. };
  334. typedef TLrec Bnand;
  335. typedef struct {
  336. LEulong freeUnits;
  337. LEulong roverUnit;
  338. LEulong countsValid;
  339. LEulong sectorsRead;
  340. LEulong sectorsWritten;
  341. LEulong sectorsDeleted;
  342. LEulong parasiteWrites;
  343. LEulong unitsFolded;
  344. LEulong wearLevel_1;
  345. LEulong wearLevel_2;
  346. LEulong eraseSum;
  347. LEulong validate; /* QUICK_MOUNT_VALID_SIGN */
  348. LEulong checksum; /* checksum of entire quick mount info should be 55 */
  349. LEulong verifiedSectorNo; /* Largest sector verified so far */
  350. }savedBnand;
  351. #define VALIDATE_OFFSET 11*sizeof(LEmin)
  352. #define inftlBuffer vol.buffer->flData
  353. #endif /* INFTL_H */