Checkpointing changes
[yaffs2.git] / yaffs_fs.c
index c2ab8888fe332edfa56b33912f2daa4cbab191a9..09591117f4f50a91ed323402d8c90ac23d6838bd 100644 (file)
@@ -31,7 +31,7 @@
  */
 
 const char *yaffs_fs_c_version =
  */
 
 const char *yaffs_fs_c_version =
-    "$Id: yaffs_fs.c,v 1.41 2006-01-27 23:54:21 tpoynor Exp $";
+    "$Id: yaffs_fs.c,v 1.46 2006-05-08 10:13:34 charles Exp $";
 extern const char *yaffs_guts_c_version;
 
 #include <linux/config.h>
 extern const char *yaffs_guts_c_version;
 
 #include <linux/config.h>
@@ -73,7 +73,10 @@ extern const char *yaffs_guts_c_version;
 #include "yportenv.h"
 #include "yaffs_guts.h"
 
 #include "yportenv.h"
 #include "yaffs_guts.h"
 
-unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS /* | 0xFFFFFFFF */; 
+unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | 
+                          YAFFS_TRACE_BAD_BLOCKS | 
+                          YAFFS_TRACE_CHECKPOINT
+                          /* | 0xFFFFFFFF */; 
 
 #include <linux/mtd/mtd.h>
 #include "yaffs_mtdif.h"
 
 #include <linux/mtd/mtd.h>
 #include "yaffs_mtdif.h"
@@ -838,6 +841,15 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
 
        curoffs = 1;
 
 
        curoffs = 1;
 
+       /* If the directory has changed since the open or last call to
+          readdir, rewind to after the 2 canned entries. */
+
+       if (f->f_version != inode->i_version) {
+               offset = 2;
+               f->f_pos = offset;
+               f->f_version = inode->i_version;
+       }
+
        list_for_each(i, &obj->variant.directoryVariant.children) {
                curoffs++;
                if (curoffs >= offset) {
        list_for_each(i, &obj->variant.directoryVariant.children) {
                curoffs++;
                if (curoffs >= offset) {
@@ -1006,15 +1018,15 @@ static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
 
        retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
 
 
        retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
 
-       yaffs_GrossUnlock(dev);
-
        if (retVal == YAFFS_OK) {
                dentry->d_inode->i_nlink--;
        if (retVal == YAFFS_OK) {
                dentry->d_inode->i_nlink--;
+               dir->i_version++;
+               yaffs_GrossUnlock(dev);
                mark_inode_dirty(dentry->d_inode);
                return 0;
                mark_inode_dirty(dentry->d_inode);
                return 0;
-       } else {
-               return -ENOTEMPTY;
        }
        }
+       yaffs_GrossUnlock(dev);
+       return -ENOTEMPTY;
 }
 
 /*
 }
 
 /*
@@ -1269,14 +1281,25 @@ static void yaffs_put_super(struct super_block *sb)
        yaffs_Device *dev = yaffs_SuperToDevice(sb);
 
        yaffs_GrossLock(dev);
        yaffs_Device *dev = yaffs_SuperToDevice(sb);
 
        yaffs_GrossLock(dev);
+       
+       yaffs_FlushEntireDeviceCache(dev);
+       
        if (dev->putSuperFunc) {
                dev->putSuperFunc(sb);
        }
        if (dev->putSuperFunc) {
                dev->putSuperFunc(sb);
        }
+       
+       yaffs_CheckpointSave(dev);
        yaffs_Deinitialise(dev);
        yaffs_Deinitialise(dev);
+       
        yaffs_GrossUnlock(dev);
 
        /* we assume this is protected by lock_kernel() in mount/umount */
        list_del(&dev->devList);
        yaffs_GrossUnlock(dev);
 
        /* we assume this is protected by lock_kernel() in mount/umount */
        list_del(&dev->devList);
+       
+       if(dev->spareBuffer){
+               YFREE(dev->spareBuffer);
+               dev->spareBuffer = NULL;
+       }
 
        kfree(dev);
 }
 
        kfree(dev);
 }
@@ -1396,7 +1419,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
                if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
                    mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
                        T(YAFFS_TRACE_ALWAYS,
                if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
                    mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
                        T(YAFFS_TRACE_ALWAYS,
-                         ("yaffs: MTD device does not support have the "
+                         ("yaffs: MTD device does not have the "
                           "right page sizes\n"));
                        return NULL;
                }
                           "right page sizes\n"));
                        return NULL;
                }
@@ -1467,7 +1490,9 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
                dev->nBytesPerChunk = mtd->oobblock;
                dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
                nBlocks = mtd->size / mtd->erasesize;
                dev->nBytesPerChunk = mtd->oobblock;
                dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
                nBlocks = mtd->size / mtd->erasesize;
-               dev->startBlock = 0;
+               dev->checkpointStartBlock = 0;
+               dev->checkpointEndBlock = 20;
+               dev->startBlock = dev->checkpointEndBlock + 1;
                dev->endBlock = nBlocks - 1;
        } else {
                dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
                dev->endBlock = nBlocks - 1;
        } else {
                dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
@@ -1891,5 +1916,5 @@ module_init(init_yaffs_fs)
 module_exit(exit_yaffs_fs)
 
 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
 module_exit(exit_yaffs_fs)
 
 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
-MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
+MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2006");
 MODULE_LICENSE("GPL");
 MODULE_LICENSE("GPL");