Fix structure field assignments
[yaffs2.git] / yaffs_guts.h
index 506ecd63c5ef9fd470f747a079aac4994a220e22..1fb8b870d2746258ec0134fcdfc18297063885b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * YAFFS: Yet another FFS. A NAND-flash specific file system. 
+ * YAFFS: Yet another FFS. A NAND-flash specific file system.
  * yaffs_guts.h: Configuration etc for yaffs_guts
  *
  * Copyright (C) 2002 Aleph One Ltd.
@@ -14,7 +14,7 @@
  *
  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
  *
- * $Id: yaffs_guts.h,v 1.2 2004-11-16 02:36:15 charles Exp $
+ * $Id: yaffs_guts.h,v 1.9 2005-07-26 03:05:28 charles Exp $
  */
 
 #ifndef __YAFFS_GUTS_H__
@@ -50,6 +50,9 @@
 #define YAFFS_BYTES_PER_BLOCK          (YAFFS_CHUNKS_PER_BLOCK*YAFFS_BYTES_PER_CHUNK)
 #endif
 
+#define YAFFS_MIN_YAFFS2_CHUNK_SIZE    1024
+#define YAFFS_MIN_YAFFS2_SPARE_SIZE    32
+
 #define YAFFS_MAX_CHUNK_ID                     0x000FFFFF
 
 #define YAFFS_UNUSED_OBJECT_ID         0x0003FFFF
@@ -143,14 +146,27 @@ typedef enum
        YAFFS_ECC_RESULT_UNFIXED
 } yaffs_ECCResult;
 
+typedef enum
+{
+       YAFFS_OBJECT_TYPE_UNKNOWN,
+       YAFFS_OBJECT_TYPE_FILE,
+       YAFFS_OBJECT_TYPE_SYMLINK,
+       YAFFS_OBJECT_TYPE_DIRECTORY,
+       YAFFS_OBJECT_TYPE_HARDLINK,
+       YAFFS_OBJECT_TYPE_SPECIAL
+} yaffs_ObjectType;
+
+
 typedef struct
 {
 
        unsigned validMarker0;
        unsigned chunkUsed;                 //  Status of the chunk: used or unused
        unsigned objectId;                      // If 0 then this is not part of an object (unused)
-       unsigned chunkId;                       // If 0 then this is a header
+       unsigned chunkId;                       // If 0 then this is a header, else a data chunk
        unsigned byteCount;                 // Only valid for data chunks
+       
+       
        // The following stuff only has meaning when we read
        yaffs_ECCResult eccResult;  // Only valid when we read.
        unsigned blockBad;                      // Only valid on reading
@@ -162,7 +178,18 @@ typedef struct
        // YAFFS2 stuff
        unsigned sequenceNumber;        // The sequence number of this block
 
-       unsigned validMarker1;
+       // Extra info if this is an object header (YAFFS2 only)
+       
+       unsigned extraHeaderInfoAvailable; // There is extra info available if this is not zero
+       unsigned extraParentObjectId;      // The parent object
+       unsigned extraIsShrinkHeader;      // Is it a shrink header?
+       
+       yaffs_ObjectType extraObjectType;  // What object type?
+
+       unsigned extraFileLength;          // Length if it is a file
+       unsigned extraEquivalentObjectId;  // Equivalent object Id if it is a hard link
+
+       unsigned validMarker1;  
        
 } yaffs_ExtendedTags;
 
@@ -230,9 +257,9 @@ typedef enum {
 typedef struct
 {
 
-    int   softDeletions:8;  // number of soft deleted pages
-    int   pagesInUse:8;                // number of pages in use
-    __u32 blockState:4;        // One of the above block states
+    int   softDeletions:12;  // number of soft deleted pages
+    int   pagesInUse:12;       // number of pages in use
+    yaffs_BlockState blockState:4;     // One of the above block states
     __u32 needsRetiring:1;     // Data has failed on this block, need to get valid data off
                                                // and retire the block.
 #ifdef CONFIG_YAFFS_YAFFS2
@@ -246,16 +273,6 @@ typedef struct
 //////////////////// Object structure ///////////////////////////
 // This is the object structure as stored on NAND
 
-typedef enum
-{
-       YAFFS_OBJECT_TYPE_UNKNOWN,
-       YAFFS_OBJECT_TYPE_FILE,
-       YAFFS_OBJECT_TYPE_SYMLINK,
-       YAFFS_OBJECT_TYPE_DIRECTORY,
-       YAFFS_OBJECT_TYPE_HARDLINK,
-       YAFFS_OBJECT_TYPE_SPECIAL
-} yaffs_ObjectType;
-
 typedef struct
 {
        yaffs_ObjectType type;
@@ -266,16 +283,16 @@ typedef struct
        YCHAR  name[YAFFS_MAX_NAME_LENGTH + 1];
 
        // Thes following apply to directories, files, symlinks - not hard links
-       __u32 st_mode;  // protection
+       __u32 yst_mode;  // protection
 
 #ifdef CONFIG_YAFFS_WINCE
        __u32 notForWinCE[5];
 #else
-       __u32 st_uid;   // user ID of owner
-       __u32 st_gid;    // group ID of owner 
-       __u32 st_atime; // time of last access
-       __u32 st_mtime; // time of last modification
-       __u32 st_ctime; // time of last change
+       __u32 yst_uid;   // user ID of owner
+       __u32 yst_gid;    // group ID of owner 
+       __u32 yst_atime; // time of last access
+       __u32 yst_mtime; // time of last modification
+       __u32 yst_ctime; // time of last change
 #endif
 
        // File size  applies to files only
@@ -287,7 +304,7 @@ typedef struct
        // Alias is for symlinks only.
        YCHAR alias[YAFFS_MAX_ALIAS_LENGTH + 1];
        
-       __u32 st_rdev;  // device stuff for block and char devices (maj/min)
+       __u32 yst_rdev;  // device stuff for block and char devices (maj/min)
        
 #ifdef CONFIG_YAFFS_WINCE
        __u32 win_ctime[2];
@@ -342,6 +359,7 @@ typedef struct
 {
        __u32 fileSize;
        __u32 scannedFileSize;
+       __u32 shrinkSize;
        int   topLevel;
        yaffs_Tnode *top;
 } yaffs_FileStructure;
@@ -377,7 +395,7 @@ struct  yaffs_ObjectStruct
        __u8 softDeleted: 1;    // it has also been soft deleted
        __u8 unlinked: 1;               // An unlinked file. The file should be in the unlinked pseudo directory.
        __u8 fake:1;                    // A fake object has no presence on NAND.
-       __u8 renameAllowed:1;
+       __u8 renameAllowed:1;           // Some objects are not allowed to be renamed.
        __u8 unlinkAllowed:1;
        __u8 dirty:1;                   // the object needs to be written to flash
        __u8 valid:1;                   // When the file system is being loaded up, this 
@@ -387,9 +405,12 @@ struct  yaffs_ObjectStruct
 
        __u8  deferedFree: 1;           // For Linux kernel. Object is removed from NAND, but still in the inode cache.
                                        // Free of object is defered.
+                                       
+       __u8 lazyLoaded;                // Vital info has been loaded from tags. Not all info available.
+                                       // 
 
-                                                       // read back the old one to update.
-       __u16 sum;                              // sum of the name to speed searching
+                                       // read back the old one to update.
+       __u16 sum;                      // sum of the name to speed searching
        
        struct yaffs_DeviceStruct *myDev; // The device I'm on
        
@@ -404,15 +425,15 @@ struct  yaffs_ObjectStruct
        struct list_head siblings;      // siblings in a directory
                                                                // also used for linking up the free list
                
-       // Where's my data in NAND?
+       // Where's my object header in NAND?
        int chunkId;            // where it lives
 
-       int nDataChunks;        
+       int nDataChunks;        // Number of data chunks attached to the file.  
        
        __u32 objectId;         // the object id value
        
        
-       __u32 st_mode;          // protection
+       __u32 yst_mode;         // protection
 
 #ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
        YCHAR shortName[YAFFS_SHORT_NAME_LENGTH+1];
@@ -427,14 +448,14 @@ struct  yaffs_ObjectStruct
        __u32 win_mtime[2];
        __u32 win_atime[2];
 #else
-       __u32 st_uid;           // user ID of owner
-       __u32 st_gid;           // group ID of owner 
-       __u32 st_atime;         // time of last access
-       __u32 st_mtime;         // time of last modification
-       __u32 st_ctime;         // time of last change
+       __u32 yst_uid;          // user ID of owner
+       __u32 yst_gid;          // group ID of owner 
+       __u32 yst_atime;        // time of last access
+       __u32 yst_mtime;        // time of last modification
+       __u32 yst_ctime;        // time of last change
 #endif
 
-       __u32 st_rdev;      // device stuff for block and char devices
+       __u32 yst_rdev;             // device stuff for block and char devices
 
 
 
@@ -532,14 +553,18 @@ struct yaffs_DeviceStruct
 
        struct semaphore sem;// Semaphore for waiting on erasure.
        struct semaphore grossLock; // Gross locking semaphore
-
-#endif 
-#ifdef __KERNEL__
+       __u8 * spareBuffer; // For mtdif2 use. Don't know the size of the buffer at compile time so we have to allocate it.
        void (*putSuperFunc)(struct super_block *sb);
 #endif
 
        int isMounted;
        
+       // Stuff to support block offsetting to support start block zero
+       int internalStartBlock;
+       int internalEndBlock;
+       int blockOffset;
+       int chunkOffset;
+       
        // Block Info
        yaffs_BlockInfo *blockInfo;
        __u8 *chunkBits;   // bitmap of chunks in use
@@ -558,6 +583,7 @@ struct yaffs_DeviceStruct
        int  nFreeTnodes;
        yaffs_TnodeList *allocatedTnodeList;
 
+       int   isDoingGC;
 
        int   nObjectsCreated;
        yaffs_Object *freeObjects;
@@ -631,12 +657,12 @@ typedef struct yaffs_DeviceStruct yaffs_Device;
 // Function to manipulate block info
 static  Y_INLINE yaffs_BlockInfo* yaffs_GetBlockInfo(yaffs_Device *dev, int blk)
 {
-       if(blk < dev->startBlock || blk > dev->endBlock)
+       if(blk < dev->internalStartBlock || blk > dev->internalEndBlock)
        {
                T(YAFFS_TRACE_ERROR,(TSTR("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR),blk));
                YBUG();
        }
-       return &dev->blockInfo[blk - dev->startBlock];
+       return &dev->blockInfo[blk - dev->internalStartBlock];
 }
 
 
@@ -668,7 +694,7 @@ int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr);
 
 // File operations
 int yaffs_ReadDataFromFile(yaffs_Object *obj, __u8 *buffer, __u32 offset, int nBytes);
-int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, __u32 offset, int nBytes);
+int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, __u32 offset, int nBytes, int writeThrough);
 int yaffs_ResizeFile(yaffs_Object *obj, int newSize);
 
 yaffs_Object *yaffs_MknodFile(yaffs_Object *parent,const YCHAR *name, __u32 mode, __u32 uid, __u32 gid);