yaffs_guts.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. /*
  2. * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
  3. *
  4. * Copyright (C) 2002-2007 Aleph One Ltd.
  5. * for Toby Churchill Ltd and Brightstar Engineering
  6. *
  7. * Created by Charles Manning <charles@aleph1.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License version 2.1 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
  14. */
  15. #ifndef __YAFFS_GUTS_H__
  16. #define __YAFFS_GUTS_H__
  17. #include "devextras.h"
  18. #include "yportenv.h"
  19. #define YAFFS_OK 1
  20. #define YAFFS_FAIL 0
  21. /* Give us a Y=0x59,
  22. * Give us an A=0x41,
  23. * Give us an FF=0xFF
  24. * Give us an S=0x53
  25. * And what have we got...
  26. */
  27. #define YAFFS_MAGIC 0x5941FF53
  28. #define YAFFS_NTNODES_LEVEL0 16
  29. #define YAFFS_TNODES_LEVEL0_BITS 4
  30. #define YAFFS_TNODES_LEVEL0_MASK 0xf
  31. #define YAFFS_NTNODES_INTERNAL (YAFFS_NTNODES_LEVEL0 / 2)
  32. #define YAFFS_TNODES_INTERNAL_BITS (YAFFS_TNODES_LEVEL0_BITS - 1)
  33. #define YAFFS_TNODES_INTERNAL_MASK 0x7
  34. #define YAFFS_TNODES_MAX_LEVEL 6
  35. #ifndef CONFIG_YAFFS_NO_YAFFS1
  36. #define YAFFS_BYTES_PER_SPARE 16
  37. #define YAFFS_BYTES_PER_CHUNK 512
  38. #define YAFFS_CHUNK_SIZE_SHIFT 9
  39. #define YAFFS_CHUNKS_PER_BLOCK 32
  40. #define YAFFS_BYTES_PER_BLOCK (YAFFS_CHUNKS_PER_BLOCK*YAFFS_BYTES_PER_CHUNK)
  41. #endif
  42. #define YAFFS_MIN_YAFFS2_CHUNK_SIZE 1024
  43. #define YAFFS_MIN_YAFFS2_SPARE_SIZE 32
  44. #define YAFFS_MAX_CHUNK_ID 0x000FFFFF
  45. #define YAFFS_UNUSED_OBJECT_ID 0x0003FFFF
  46. #define YAFFS_ALLOCATION_NOBJECTS 100
  47. #define YAFFS_ALLOCATION_NTNODES 100
  48. #define YAFFS_ALLOCATION_NLINKS 100
  49. #define YAFFS_NOBJECT_BUCKETS 256
  50. #define YAFFS_OBJECT_SPACE 0x40000
  51. #define YAFFS_CHECKPOINT_VERSION 3
  52. #ifdef CONFIG_YAFFS_UNICODE
  53. #define YAFFS_MAX_NAME_LENGTH 127
  54. #define YAFFS_MAX_ALIAS_LENGTH 79
  55. #else
  56. #define YAFFS_MAX_NAME_LENGTH 255
  57. #define YAFFS_MAX_ALIAS_LENGTH 159
  58. #endif
  59. #define YAFFS_SHORT_NAME_LENGTH 15
  60. /* Some special object ids for pseudo objects */
  61. #define YAFFS_OBJECTID_ROOT 1
  62. #define YAFFS_OBJECTID_LOSTNFOUND 2
  63. #define YAFFS_OBJECTID_UNLINKED 3
  64. #define YAFFS_OBJECTID_DELETED 4
  65. /* Sseudo object ids for checkpointing */
  66. #define YAFFS_OBJECTID_SB_HEADER 0x10
  67. #define YAFFS_OBJECTID_CHECKPOINT_DATA 0x20
  68. #define YAFFS_SEQUENCE_CHECKPOINT_DATA 0x21
  69. /* */
  70. #define YAFFS_MAX_SHORT_OP_CACHES 20
  71. #define YAFFS_N_TEMP_BUFFERS 4
  72. /* We limit the number attempts at sucessfully saving a chunk of data.
  73. * Small-page devices have 32 pages per block; large-page devices have 64.
  74. * Default to something in the order of 5 to 10 blocks worth of chunks.
  75. */
  76. #define YAFFS_WR_ATTEMPTS (5*64)
  77. /* Sequence numbers are used in YAFFS2 to determine block allocation order.
  78. * The range is limited slightly to help distinguish bad numbers from good.
  79. * This also allows us to perhaps in the future use special numbers for
  80. * special purposes.
  81. * EFFFFF00 allows the allocation of 8 blocks per second (~1Mbytes) for 15 years,
  82. * and is a larger number than the lifetime of a 2GB device.
  83. */
  84. #define YAFFS_LOWEST_SEQUENCE_NUMBER 0x00001000
  85. #define YAFFS_HIGHEST_SEQUENCE_NUMBER 0xEFFFFF00
  86. /* ChunkCache is used for short read/write operations.*/
  87. typedef struct {
  88. struct yaffs_ObjectStruct *object;
  89. int chunkId;
  90. int lastUse;
  91. int dirty;
  92. int nBytes; /* Only valid if the cache is dirty */
  93. int locked; /* Can't push out or flush while locked. */
  94. #ifdef CONFIG_YAFFS_YAFFS2
  95. __u8 *data;
  96. #else
  97. __u8 data[YAFFS_BYTES_PER_CHUNK];
  98. #endif
  99. } yaffs_ChunkCache;
  100. /* Tags structures in RAM
  101. * NB This uses bitfield. Bitfields should not straddle a u32 boundary otherwise
  102. * the structure size will get blown out.
  103. */
  104. #ifndef CONFIG_YAFFS_NO_YAFFS1
  105. typedef struct {
  106. unsigned chunkId:20;
  107. unsigned serialNumber:2;
  108. unsigned byteCount:10;
  109. unsigned objectId:18;
  110. unsigned ecc:12;
  111. unsigned unusedStuff:2;
  112. } yaffs_Tags;
  113. typedef union {
  114. yaffs_Tags asTags;
  115. __u8 asBytes[8];
  116. } yaffs_TagsUnion;
  117. #endif
  118. /* Stuff used for extended tags in YAFFS2 */
  119. typedef enum {
  120. YAFFS_ECC_RESULT_UNKNOWN,
  121. YAFFS_ECC_RESULT_NO_ERROR,
  122. YAFFS_ECC_RESULT_FIXED,
  123. YAFFS_ECC_RESULT_UNFIXED
  124. } yaffs_ECCResult;
  125. typedef enum {
  126. YAFFS_OBJECT_TYPE_UNKNOWN,
  127. YAFFS_OBJECT_TYPE_FILE,
  128. YAFFS_OBJECT_TYPE_SYMLINK,
  129. YAFFS_OBJECT_TYPE_DIRECTORY,
  130. YAFFS_OBJECT_TYPE_HARDLINK,
  131. YAFFS_OBJECT_TYPE_SPECIAL
  132. } yaffs_ObjectType;
  133. #define YAFFS_OBJECT_TYPE_MAX YAFFS_OBJECT_TYPE_SPECIAL
  134. typedef struct {
  135. unsigned validMarker0;
  136. unsigned chunkUsed; /* Status of the chunk: used or unused */
  137. unsigned objectId; /* If 0 then this is not part of an object (unused) */
  138. unsigned chunkId; /* If 0 then this is a header, else a data chunk */
  139. unsigned byteCount; /* Only valid for data chunks */
  140. /* The following stuff only has meaning when we read */
  141. yaffs_ECCResult eccResult;
  142. unsigned blockBad;
  143. /* YAFFS 1 stuff */
  144. unsigned chunkDeleted; /* The chunk is marked deleted */
  145. unsigned serialNumber; /* Yaffs1 2-bit serial number */
  146. /* YAFFS2 stuff */
  147. unsigned sequenceNumber; /* The sequence number of this block */
  148. /* Extra info if this is an object header (YAFFS2 only) */
  149. unsigned extraHeaderInfoAvailable; /* There is extra info available if this is not zero */
  150. unsigned extraParentObjectId; /* The parent object */
  151. unsigned extraIsShrinkHeader; /* Is it a shrink header? */
  152. unsigned extraShadows; /* Does this shadow another object? */
  153. yaffs_ObjectType extraObjectType; /* What object type? */
  154. unsigned extraFileLength; /* Length if it is a file */
  155. unsigned extraEquivalentObjectId; /* Equivalent object Id if it is a hard link */
  156. unsigned validMarker1;
  157. } yaffs_ExtendedTags;
  158. /* Spare structure for YAFFS1 */
  159. typedef struct {
  160. __u8 tagByte0;
  161. __u8 tagByte1;
  162. __u8 tagByte2;
  163. __u8 tagByte3;
  164. __u8 pageStatus; /* set to 0 to delete the chunk */
  165. __u8 blockStatus;
  166. __u8 tagByte4;
  167. __u8 tagByte5;
  168. __u8 ecc1[3];
  169. __u8 tagByte6;
  170. __u8 tagByte7;
  171. __u8 ecc2[3];
  172. } yaffs_Spare;
  173. /*Special structure for passing through to mtd */
  174. struct yaffs_NANDSpare {
  175. yaffs_Spare spare;
  176. int eccres1;
  177. int eccres2;
  178. };
  179. /* Block data in RAM */
  180. typedef enum {
  181. YAFFS_BLOCK_STATE_UNKNOWN = 0,
  182. YAFFS_BLOCK_STATE_SCANNING,
  183. YAFFS_BLOCK_STATE_NEEDS_SCANNING,
  184. /* The block might have something on it (ie it is allocating or full, perhaps empty)
  185. * but it needs to be scanned to determine its true state.
  186. * This state is only valid during yaffs_Scan.
  187. * NB We tolerate empty because the pre-scanner might be incapable of deciding
  188. * However, if this state is returned on a YAFFS2 device, then we expect a sequence number
  189. */
  190. YAFFS_BLOCK_STATE_EMPTY,
  191. /* This block is empty */
  192. YAFFS_BLOCK_STATE_ALLOCATING,
  193. /* This block is partially allocated.
  194. * At least one page holds valid data.
  195. * This is the one currently being used for page
  196. * allocation. Should never be more than one of these
  197. */
  198. YAFFS_BLOCK_STATE_FULL,
  199. /* All the pages in this block have been allocated.
  200. */
  201. YAFFS_BLOCK_STATE_DIRTY,
  202. /* All pages have been allocated and deleted.
  203. * Erase me, reuse me.
  204. */
  205. YAFFS_BLOCK_STATE_CHECKPOINT,
  206. /* This block is assigned to holding checkpoint data.
  207. */
  208. YAFFS_BLOCK_STATE_COLLECTING,
  209. /* This block is being garbage collected */
  210. YAFFS_BLOCK_STATE_DEAD
  211. /* This block has failed and is not in use */
  212. } yaffs_BlockState;
  213. #define YAFFS_NUMBER_OF_BLOCK_STATES (YAFFS_BLOCK_STATE_DEAD + 1)
  214. typedef struct {
  215. int softDeletions:10; /* number of soft deleted pages */
  216. int pagesInUse:10; /* number of pages in use */
  217. unsigned blockState:4; /* One of the above block states. NB use unsigned because enum is sometimes an int */
  218. __u32 needsRetiring:1; /* Data has failed on this block, need to get valid data off */
  219. /* and retire the block. */
  220. __u32 skipErasedCheck: 1; /* If this is set we can skip the erased check on this block */
  221. __u32 gcPrioritise: 1; /* An ECC check or blank check has failed on this block.
  222. It should be prioritised for GC */
  223. __u32 chunkErrorStrikes:3; /* How many times we've had ecc etc failures on this block and tried to reuse it */
  224. #ifdef CONFIG_YAFFS_YAFFS2
  225. __u32 hasShrinkHeader:1; /* This block has at least one shrink object header */
  226. __u32 sequenceNumber; /* block sequence number for yaffs2 */
  227. #endif
  228. } yaffs_BlockInfo;
  229. /* -------------------------- Object structure -------------------------------*/
  230. /* This is the object structure as stored on NAND */
  231. typedef struct {
  232. yaffs_ObjectType type;
  233. /* Apply to everything */
  234. int parentObjectId;
  235. __u16 sum__NoLongerUsed; /* checksum of name. No longer used */
  236. YCHAR name[YAFFS_MAX_NAME_LENGTH + 1];
  237. /* Thes following apply to directories, files, symlinks - not hard links */
  238. __u32 yst_mode; /* protection */
  239. #ifdef CONFIG_YAFFS_WINCE
  240. __u32 notForWinCE[5];
  241. #else
  242. __u32 yst_uid;
  243. __u32 yst_gid;
  244. __u32 yst_atime;
  245. __u32 yst_mtime;
  246. __u32 yst_ctime;
  247. #endif
  248. /* File size applies to files only */
  249. int fileSize;
  250. /* Equivalent object id applies to hard links only. */
  251. int equivalentObjectId;
  252. /* Alias is for symlinks only. */
  253. YCHAR alias[YAFFS_MAX_ALIAS_LENGTH + 1];
  254. __u32 yst_rdev; /* device stuff for block and char devices (major/min) */
  255. #ifdef CONFIG_YAFFS_WINCE
  256. __u32 win_ctime[2];
  257. __u32 win_atime[2];
  258. __u32 win_mtime[2];
  259. __u32 roomToGrow[4];
  260. #else
  261. __u32 roomToGrow[10];
  262. #endif
  263. int shadowsObject; /* This object header shadows the specified object if > 0 */
  264. /* isShrink applies to object headers written when we shrink the file (ie resize) */
  265. __u32 isShrink;
  266. } yaffs_ObjectHeader;
  267. /*--------------------------- Tnode -------------------------- */
  268. union yaffs_Tnode_union {
  269. #ifdef CONFIG_YAFFS_TNODE_LIST_DEBUG
  270. union yaffs_Tnode_union *internal[YAFFS_NTNODES_INTERNAL + 1];
  271. #else
  272. union yaffs_Tnode_union *internal[YAFFS_NTNODES_INTERNAL];
  273. #endif
  274. /* __u16 level0[YAFFS_NTNODES_LEVEL0]; */
  275. };
  276. typedef union yaffs_Tnode_union yaffs_Tnode;
  277. struct yaffs_TnodeList_struct {
  278. struct yaffs_TnodeList_struct *next;
  279. yaffs_Tnode *tnodes;
  280. };
  281. typedef struct yaffs_TnodeList_struct yaffs_TnodeList;
  282. /*------------------------ Object -----------------------------*/
  283. /* An object can be one of:
  284. * - a directory (no data, has children links
  285. * - a regular file (data.... not prunes :->).
  286. * - a symlink [symbolic link] (the alias).
  287. * - a hard link
  288. */
  289. typedef struct {
  290. __u32 fileSize;
  291. __u32 scannedFileSize;
  292. __u32 shrinkSize;
  293. int topLevel;
  294. yaffs_Tnode *top;
  295. } yaffs_FileStructure;
  296. typedef struct {
  297. struct list_head children; /* list of child links */
  298. } yaffs_DirectoryStructure;
  299. typedef struct {
  300. YCHAR *alias;
  301. } yaffs_SymLinkStructure;
  302. typedef struct {
  303. struct yaffs_ObjectStruct *equivalentObject;
  304. __u32 equivalentObjectId;
  305. } yaffs_HardLinkStructure;
  306. typedef union {
  307. yaffs_FileStructure fileVariant;
  308. yaffs_DirectoryStructure directoryVariant;
  309. yaffs_SymLinkStructure symLinkVariant;
  310. yaffs_HardLinkStructure hardLinkVariant;
  311. } yaffs_ObjectVariant;
  312. struct yaffs_ObjectStruct {
  313. __u8 deleted:1; /* This should only apply to unlinked files. */
  314. __u8 softDeleted:1; /* it has also been soft deleted */
  315. __u8 unlinked:1; /* An unlinked file. The file should be in the unlinked directory.*/
  316. __u8 fake:1; /* A fake object has no presence on NAND. */
  317. __u8 renameAllowed:1; /* Some objects are not allowed to be renamed. */
  318. __u8 unlinkAllowed:1;
  319. __u8 dirty:1; /* the object needs to be written to flash */
  320. __u8 valid:1; /* When the file system is being loaded up, this
  321. * object might be created before the data
  322. * is available (ie. file data records appear before the header).
  323. */
  324. __u8 lazyLoaded:1; /* This object has been lazy loaded and is missing some detail */
  325. __u8 deferedFree:1; /* For Linux kernel. Object is removed from NAND, but is
  326. * still in the inode cache. Free of object is defered.
  327. * until the inode is released.
  328. */
  329. __u8 serial; /* serial number of chunk in NAND. Cached here */
  330. __u16 sum; /* sum of the name to speed searching */
  331. struct yaffs_DeviceStruct *myDev; /* The device I'm on */
  332. struct list_head hashLink; /* list of objects in this hash bucket */
  333. struct list_head hardLinks; /* all the equivalent hard linked objects */
  334. /* directory structure stuff */
  335. /* also used for linking up the free list */
  336. struct yaffs_ObjectStruct *parent;
  337. struct list_head siblings;
  338. /* Where's my object header in NAND? */
  339. int chunkId;
  340. int nDataChunks; /* Number of data chunks attached to the file. */
  341. __u32 objectId; /* the object id value */
  342. __u32 yst_mode;
  343. #ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
  344. YCHAR shortName[YAFFS_SHORT_NAME_LENGTH + 1];
  345. #endif
  346. /* XXX U-BOOT XXX */
  347. /* #ifndef __KERNEL__ */
  348. __u32 inUse;
  349. /* #endif */
  350. #ifdef CONFIG_YAFFS_WINCE
  351. __u32 win_ctime[2];
  352. __u32 win_mtime[2];
  353. __u32 win_atime[2];
  354. #else
  355. __u32 yst_uid;
  356. __u32 yst_gid;
  357. __u32 yst_atime;
  358. __u32 yst_mtime;
  359. __u32 yst_ctime;
  360. #endif
  361. __u32 yst_rdev;
  362. /* XXX U-BOOT XXX */
  363. /* #ifndef __KERNEL__ */
  364. struct inode *myInode;
  365. /* #endif */
  366. yaffs_ObjectType variantType;
  367. yaffs_ObjectVariant variant;
  368. };
  369. typedef struct yaffs_ObjectStruct yaffs_Object;
  370. struct yaffs_ObjectList_struct {
  371. yaffs_Object *objects;
  372. struct yaffs_ObjectList_struct *next;
  373. };
  374. typedef struct yaffs_ObjectList_struct yaffs_ObjectList;
  375. typedef struct {
  376. struct list_head list;
  377. int count;
  378. } yaffs_ObjectBucket;
  379. /* yaffs_CheckpointObject holds the definition of an object as dumped
  380. * by checkpointing.
  381. */
  382. typedef struct {
  383. int structType;
  384. __u32 objectId;
  385. __u32 parentId;
  386. int chunkId;
  387. yaffs_ObjectType variantType:3;
  388. __u8 deleted:1;
  389. __u8 softDeleted:1;
  390. __u8 unlinked:1;
  391. __u8 fake:1;
  392. __u8 renameAllowed:1;
  393. __u8 unlinkAllowed:1;
  394. __u8 serial;
  395. int nDataChunks;
  396. __u32 fileSizeOrEquivalentObjectId;
  397. }yaffs_CheckpointObject;
  398. /*--------------------- Temporary buffers ----------------
  399. *
  400. * These are chunk-sized working buffers. Each device has a few
  401. */
  402. typedef struct {
  403. __u8 *buffer;
  404. int line; /* track from whence this buffer was allocated */
  405. int maxLine;
  406. } yaffs_TempBuffer;
  407. /*----------------- Device ---------------------------------*/
  408. struct yaffs_DeviceStruct {
  409. struct list_head devList;
  410. const char *name;
  411. /* Entry parameters set up way early. Yaffs sets up the rest.*/
  412. int nDataBytesPerChunk; /* Should be a power of 2 >= 512 */
  413. int nChunksPerBlock; /* does not need to be a power of 2 */
  414. int nBytesPerSpare; /* spare area size */
  415. int startBlock; /* Start block we're allowed to use */
  416. int endBlock; /* End block we're allowed to use */
  417. int nReservedBlocks; /* We want this tuneable so that we can reduce */
  418. /* reserved blocks on NOR and RAM. */
  419. /* Stuff used by the shared space checkpointing mechanism */
  420. /* If this value is zero, then this mechanism is disabled */
  421. int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */
  422. int nShortOpCaches; /* If <= 0, then short op caching is disabled, else
  423. * the number of short op caches (don't use too many)
  424. */
  425. int useHeaderFileSize; /* Flag to determine if we should use file sizes from the header */
  426. int useNANDECC; /* Flag to decide whether or not to use NANDECC */
  427. void *genericDevice; /* Pointer to device context
  428. * On an mtd this holds the mtd pointer.
  429. */
  430. void *superBlock;
  431. /* NAND access functions (Must be set before calling YAFFS)*/
  432. int (*writeChunkToNAND) (struct yaffs_DeviceStruct * dev,
  433. int chunkInNAND, const __u8 * data,
  434. const yaffs_Spare * spare);
  435. int (*readChunkFromNAND) (struct yaffs_DeviceStruct * dev,
  436. int chunkInNAND, __u8 * data,
  437. yaffs_Spare * spare);
  438. int (*eraseBlockInNAND) (struct yaffs_DeviceStruct * dev,
  439. int blockInNAND);
  440. int (*initialiseNAND) (struct yaffs_DeviceStruct * dev);
  441. #ifdef CONFIG_YAFFS_YAFFS2
  442. int (*writeChunkWithTagsToNAND) (struct yaffs_DeviceStruct * dev,
  443. int chunkInNAND, const __u8 * data,
  444. const yaffs_ExtendedTags * tags);
  445. int (*readChunkWithTagsFromNAND) (struct yaffs_DeviceStruct * dev,
  446. int chunkInNAND, __u8 * data,
  447. yaffs_ExtendedTags * tags);
  448. int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo);
  449. int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo,
  450. yaffs_BlockState * state, int *sequenceNumber);
  451. #endif
  452. int isYaffs2;
  453. /* The removeObjectCallback function must be supplied by OS flavours that
  454. * need it. The Linux kernel does not use this, but yaffs direct does use
  455. * it to implement the faster readdir
  456. */
  457. void (*removeObjectCallback)(struct yaffs_ObjectStruct *obj);
  458. /* Callback to mark the superblock dirsty */
  459. void (*markSuperBlockDirty)(void * superblock);
  460. int wideTnodesDisabled; /* Set to disable wide tnodes */
  461. /* End of stuff that must be set before initialisation. */
  462. /* Checkpoint control. Can be set before or after initialisation */
  463. __u8 skipCheckpointRead;
  464. __u8 skipCheckpointWrite;
  465. /* Runtime parameters. Set up by YAFFS. */
  466. __u16 chunkGroupBits; /* 0 for devices <= 32MB. else log2(nchunks) - 16 */
  467. __u16 chunkGroupSize; /* == 2^^chunkGroupBits */
  468. /* Stuff to support wide tnodes */
  469. __u32 tnodeWidth;
  470. __u32 tnodeMask;
  471. /* Stuff to support various file offses to chunk/offset translations */
  472. /* "Crumbs" for nDataBytesPerChunk not being a power of 2 */
  473. __u32 crumbMask;
  474. __u32 crumbShift;
  475. __u32 crumbsPerChunk;
  476. /* Straight shifting for nDataBytesPerChunk being a power of 2 */
  477. __u32 chunkShift;
  478. __u32 chunkMask;
  479. /* XXX U-BOOT XXX */
  480. #if 0
  481. #ifndef __KERNEL__
  482. struct semaphore sem; /* Semaphore for waiting on erasure.*/
  483. struct semaphore grossLock; /* Gross locking semaphore */
  484. void (*putSuperFunc) (struct super_block * sb);
  485. #endif
  486. #endif
  487. __u8 *spareBuffer; /* For mtdif2 use. Don't know the size of the buffer
  488. * at compile time so we have to allocate it.
  489. */
  490. int isMounted;
  491. int isCheckpointed;
  492. /* Stuff to support block offsetting to support start block zero */
  493. int internalStartBlock;
  494. int internalEndBlock;
  495. int blockOffset;
  496. int chunkOffset;
  497. /* Runtime checkpointing stuff */
  498. int checkpointPageSequence; /* running sequence number of checkpoint pages */
  499. int checkpointByteCount;
  500. int checkpointByteOffset;
  501. __u8 *checkpointBuffer;
  502. int checkpointOpenForWrite;
  503. int blocksInCheckpoint;
  504. int checkpointCurrentChunk;
  505. int checkpointCurrentBlock;
  506. int checkpointNextBlock;
  507. int *checkpointBlockList;
  508. int checkpointMaxBlocks;
  509. __u32 checkpointSum;
  510. __u32 checkpointXor;
  511. /* Block Info */
  512. yaffs_BlockInfo *blockInfo;
  513. __u8 *chunkBits; /* bitmap of chunks in use */
  514. unsigned blockInfoAlt:1; /* was allocated using alternative strategy */
  515. unsigned chunkBitsAlt:1; /* was allocated using alternative strategy */
  516. int chunkBitmapStride; /* Number of bytes of chunkBits per block.
  517. * Must be consistent with nChunksPerBlock.
  518. */
  519. int nErasedBlocks;
  520. int allocationBlock; /* Current block being allocated off */
  521. __u32 allocationPage;
  522. int allocationBlockFinder; /* Used to search for next allocation block */
  523. /* Runtime state */
  524. int nTnodesCreated;
  525. yaffs_Tnode *freeTnodes;
  526. int nFreeTnodes;
  527. yaffs_TnodeList *allocatedTnodeList;
  528. int isDoingGC;
  529. int nObjectsCreated;
  530. yaffs_Object *freeObjects;
  531. int nFreeObjects;
  532. yaffs_ObjectList *allocatedObjectList;
  533. yaffs_ObjectBucket objectBucket[YAFFS_NOBJECT_BUCKETS];
  534. int nFreeChunks;
  535. int currentDirtyChecker; /* Used to find current dirtiest block */
  536. __u32 *gcCleanupList; /* objects to delete at the end of a GC. */
  537. int nonAggressiveSkip; /* GC state/mode */
  538. /* Statistcs */
  539. int nPageWrites;
  540. int nPageReads;
  541. int nBlockErasures;
  542. int nErasureFailures;
  543. int nGCCopies;
  544. int garbageCollections;
  545. int passiveGarbageCollections;
  546. int nRetriedWrites;
  547. int nRetiredBlocks;
  548. int eccFixed;
  549. int eccUnfixed;
  550. int tagsEccFixed;
  551. int tagsEccUnfixed;
  552. int nDeletions;
  553. int nUnmarkedDeletions;
  554. int hasPendingPrioritisedGCs; /* We think this device might have pending prioritised gcs */
  555. /* Special directories */
  556. yaffs_Object *rootDir;
  557. yaffs_Object *lostNFoundDir;
  558. /* Buffer areas for storing data to recover from write failures TODO
  559. * __u8 bufferedData[YAFFS_CHUNKS_PER_BLOCK][YAFFS_BYTES_PER_CHUNK];
  560. * yaffs_Spare bufferedSpare[YAFFS_CHUNKS_PER_BLOCK];
  561. */
  562. int bufferedBlock; /* Which block is buffered here? */
  563. int doingBufferedBlockRewrite;
  564. yaffs_ChunkCache *srCache;
  565. int srLastUse;
  566. int cacheHits;
  567. /* Stuff for background deletion and unlinked files.*/
  568. yaffs_Object *unlinkedDir; /* Directory where unlinked and deleted files live. */
  569. yaffs_Object *deletedDir; /* Directory where deleted objects are sent to disappear. */
  570. yaffs_Object *unlinkedDeletion; /* Current file being background deleted.*/
  571. int nDeletedFiles; /* Count of files awaiting deletion;*/
  572. int nUnlinkedFiles; /* Count of unlinked files. */
  573. int nBackgroundDeletions; /* Count of background deletions. */
  574. yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS];
  575. int maxTemp;
  576. int unmanagedTempAllocations;
  577. int unmanagedTempDeallocations;
  578. /* yaffs2 runtime stuff */
  579. unsigned sequenceNumber; /* Sequence number of currently allocating block */
  580. unsigned oldestDirtySequence;
  581. };
  582. typedef struct yaffs_DeviceStruct yaffs_Device;
  583. /* The static layout of bllock usage etc is stored in the super block header */
  584. typedef struct {
  585. int StructType;
  586. int version;
  587. int checkpointStartBlock;
  588. int checkpointEndBlock;
  589. int startBlock;
  590. int endBlock;
  591. int rfu[100];
  592. } yaffs_SuperBlockHeader;
  593. /* The CheckpointDevice structure holds the device information that changes at runtime and
  594. * must be preserved over unmount/mount cycles.
  595. */
  596. typedef struct {
  597. int structType;
  598. int nErasedBlocks;
  599. int allocationBlock; /* Current block being allocated off */
  600. __u32 allocationPage;
  601. int nFreeChunks;
  602. int nDeletedFiles; /* Count of files awaiting deletion;*/
  603. int nUnlinkedFiles; /* Count of unlinked files. */
  604. int nBackgroundDeletions; /* Count of background deletions. */
  605. /* yaffs2 runtime stuff */
  606. unsigned sequenceNumber; /* Sequence number of currently allocating block */
  607. unsigned oldestDirtySequence;
  608. } yaffs_CheckpointDevice;
  609. typedef struct {
  610. int structType;
  611. __u32 magic;
  612. __u32 version;
  613. __u32 head;
  614. } yaffs_CheckpointValidity;
  615. /* Function to manipulate block info */
  616. static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk)
  617. {
  618. if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) {
  619. T(YAFFS_TRACE_ERROR,
  620. (TSTR
  621. ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR),
  622. blk));
  623. YBUG();
  624. }
  625. return &dev->blockInfo[blk - dev->internalStartBlock];
  626. }
  627. /*----------------------- YAFFS Functions -----------------------*/
  628. int yaffs_GutsInitialise(yaffs_Device * dev);
  629. void yaffs_Deinitialise(yaffs_Device * dev);
  630. int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev);
  631. int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName,
  632. yaffs_Object * newDir, const YCHAR * newName);
  633. int yaffs_Unlink(yaffs_Object * dir, const YCHAR * name);
  634. int yaffs_DeleteFile(yaffs_Object * obj);
  635. int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize);
  636. int yaffs_GetObjectFileLength(yaffs_Object * obj);
  637. int yaffs_GetObjectInode(yaffs_Object * obj);
  638. unsigned yaffs_GetObjectType(yaffs_Object * obj);
  639. int yaffs_GetObjectLinkCount(yaffs_Object * obj);
  640. int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr);
  641. int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr);
  642. /* File operations */
  643. int yaffs_ReadDataFromFile(yaffs_Object * obj, __u8 * buffer, loff_t offset,
  644. int nBytes);
  645. int yaffs_WriteDataToFile(yaffs_Object * obj, const __u8 * buffer, loff_t offset,
  646. int nBytes, int writeThrough);
  647. int yaffs_ResizeFile(yaffs_Object * obj, loff_t newSize);
  648. yaffs_Object *yaffs_MknodFile(yaffs_Object * parent, const YCHAR * name,
  649. __u32 mode, __u32 uid, __u32 gid);
  650. int yaffs_FlushFile(yaffs_Object * obj, int updateTime);
  651. /* Flushing and checkpointing */
  652. void yaffs_FlushEntireDeviceCache(yaffs_Device *dev);
  653. int yaffs_CheckpointSave(yaffs_Device *dev);
  654. int yaffs_CheckpointRestore(yaffs_Device *dev);
  655. /* Directory operations */
  656. yaffs_Object *yaffs_MknodDirectory(yaffs_Object * parent, const YCHAR * name,
  657. __u32 mode, __u32 uid, __u32 gid);
  658. yaffs_Object *yaffs_FindObjectByName(yaffs_Object * theDir, const YCHAR * name);
  659. int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir,
  660. int (*fn) (yaffs_Object *));
  661. yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number);
  662. /* Link operations */
  663. yaffs_Object *yaffs_Link(yaffs_Object * parent, const YCHAR * name,
  664. yaffs_Object * equivalentObject);
  665. yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object * obj);
  666. /* Symlink operations */
  667. yaffs_Object *yaffs_MknodSymLink(yaffs_Object * parent, const YCHAR * name,
  668. __u32 mode, __u32 uid, __u32 gid,
  669. const YCHAR * alias);
  670. YCHAR *yaffs_GetSymlinkAlias(yaffs_Object * obj);
  671. /* Special inodes (fifos, sockets and devices) */
  672. yaffs_Object *yaffs_MknodSpecial(yaffs_Object * parent, const YCHAR * name,
  673. __u32 mode, __u32 uid, __u32 gid, __u32 rdev);
  674. /* Special directories */
  675. yaffs_Object *yaffs_Root(yaffs_Device * dev);
  676. yaffs_Object *yaffs_LostNFound(yaffs_Device * dev);
  677. #ifdef CONFIG_YAFFS_WINCE
  678. /* CONFIG_YAFFS_WINCE special stuff */
  679. void yfsd_WinFileTimeNow(__u32 target[2]);
  680. #endif
  681. /* XXX U-BOOT XXX */
  682. #if 0
  683. #ifndef __KERNEL__
  684. void yaffs_HandleDeferedFree(yaffs_Object * obj);
  685. #endif
  686. #endif
  687. /* Debug dump */
  688. int yaffs_DumpObject(yaffs_Object * obj);
  689. void yaffs_GutsTest(yaffs_Device * dev);
  690. /* A few useful functions */
  691. void yaffs_InitialiseTags(yaffs_ExtendedTags * tags);
  692. void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn);
  693. int yaffs_CheckFF(__u8 * buffer, int nBytes);
  694. void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi);
  695. #endif