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