*** empty log message ***
[yaffs/.git] / yaffs_fs.c
index b0608f9198953893df6a591077b2753962a5b1d3..d669793752559559e71b3083f781b01927ae5c93 100644 (file)
@@ -20,7 +20,7 @@
  *
  *
  * Acknowledgements:
- * * Luc van OostenRyck for O_APPEND patch.
+ * * Luc van OostenRyck for numerous patches.
  * * Nick Bane for patches marked NCB.
  * * Some code bodily lifted from JFFS2.
  */
 
 #include "yaffs_guts.h"
 
-#ifdef YAFFS_RAM_ENABLED
+#ifdef CONFIG_YAFFS_RAM_ENABLED
 #include "yaffs_nandemul.h" 
 // 2 MB of RAM for emulation
 #define YAFFS_RAM_EMULATION_SIZE  0x200000
-#endif //YAFFS_RAM_ENABLED
+#endif //CONFIG_YAFFS_RAM_ENABLED
 
-#ifdef YAFFS_MTD_ENABLED
+#ifdef CONFIG_YAFFS_MTD_ENABLED
 #include <linux/mtd/mtd.h>
 #include "yaffs_mtdif.h"
-#endif //YAFFS_MTD_ENABLED
+#endif //CONFIG_YAFFS_MTD_ENABLED
 
 #define T(x) printk x
 
@@ -70,6 +70,7 @@ static void yaffs_put_super(struct super_block *sb);
 
 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
+static int yaffs_file_flush(struct file* file);
 
 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
 
@@ -102,7 +103,7 @@ static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
 
 
 static struct address_space_operations yaffs_file_address_operations = {
-       readpage:       yaffs_readpage,
+       readpage:               yaffs_readpage,
        prepare_write:  yaffs_prepare_write,
        commit_write:   yaffs_commit_write
 };
@@ -117,6 +118,7 @@ static struct file_operations yaffs_file_operations = {
        write:          yaffs_file_write,
 #endif
        mmap:           generic_file_mmap,
+       flush:          yaffs_file_flush,
        fsync:          yaffs_sync_object,
 };
 
@@ -243,11 +245,24 @@ static void yaffs_put_inode(struct inode *inode)
 {
        T(("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
        
-       yaffs_FlushFile(yaffs_InodeToObject(inode));
+       // yaffs_FlushFile(yaffs_InodeToObject(inode));
        
 }
 
 
+static int yaffs_file_flush(struct file* file)
+{
+       yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
+       
+       T((KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
+                               obj->dirty ? "dirty" : "clean"));
+
+    yaffs_FlushFile(obj);
+
+    return 0;
+}
+
+
 
 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
 {
@@ -338,6 +353,10 @@ static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
                SetPageError(pg);
                ClearPageUptodate(pg);
        }
+       else
+       {
+               SetPageUptodate(pg);
+       }
 
        T((KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
        
@@ -660,7 +679,7 @@ static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
 {
        
-       T((KERN_DEBUG"yaffs_unlink\n"));
+       T((KERN_DEBUG"yaffs_unlink %d:%s\n",dir->i_ino,dentry->d_name.name));
        
        if(yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name) == YAFFS_OK)
        {
@@ -755,7 +774,7 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
        struct inode *inode = dentry->d_inode;
        int error;
        
-       T((KERN_DEBUG"yaffs_setattr\n"));
+       T((KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
        
        if((error = inode_change_ok(inode,attr)) == 0)
        {
@@ -812,10 +831,12 @@ static void yaffs_put_super(struct super_block *sb)
        {
                 dev->putSuperFunc(sb);
        }
+       yaffs_Deinitialise(dev);
+       kfree(dev);
 }
 
 
-#ifdef YAFFS_MTD_ENABLED
+#ifdef CONFIG_YAFFS_MTD_ENABLED
 
 static void  yaffs_MTDPutSuper(struct super_block *sb)
 {
@@ -852,7 +873,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
 
        
 
-#if CONFIG_YAFFS_USE_CHUNK_SIZE
+#ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
        sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
        sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
 #else
@@ -861,11 +882,16 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
 #endif
        T(("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",sb->s_blocksize));
 
+#ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
+       T(("yaffs: Write verification disabled. All guarantees null and void\n");
+#endif
+
+
        
        if(useRam)
        {
 
-#ifdef YAFFS_RAM_ENABLED
+#ifdef CONFIG_YAFFS_RAM_ENABLED
                // Set the yaffs_Device up for ram emulation
 
                sb->u.generic_sbp =     dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
@@ -893,7 +919,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
        }
        else
        {       
-#ifdef YAFFS_MTD_ENABLED
+#ifdef CONFIG_YAFFS_MTD_ENABLED
                struct mtd_info *mtd;
                
                printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
@@ -999,7 +1025,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
        return sb;
 }
 
-#ifdef YAFFS_MTD_ENABLED
+#ifdef CONFIG_YAFFS_MTD_ENABLED
 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
 {
        return yaffs_internal_read_super(0,sb,data,silent);
@@ -1008,7 +1034,7 @@ static struct super_block *yaffs_read_super(struct super_block * sb, void * data
 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
 #endif
 
-#ifdef YAFFS_RAM_ENABLED
+#ifdef CONFIG_YAFFS_RAM_ENABLED
 
 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
 {
@@ -1016,7 +1042,7 @@ static struct super_block *yaffs_ram_read_super(struct super_block * sb, void *
 }
 
 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
-#endif // YAFFS_RAM_ENABLED
+#endif // CONFIG_YAFFS_RAM_ENABLED
 
 
 static struct proc_dir_entry *my_proc_entry;
@@ -1051,7 +1077,7 @@ static int __init init_yaffs_fs(void)
        int error = 0;
        
        printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n");
-#if CONFIG_YAFFS_USE_GENERIC_RW
+#ifdef CONFIG_YAFFS_USE_GENERIC_RW
        printk(KERN_DEBUG "yaffs is using generic read/write (caching)\n");
 #else
        printk(KERN_DEBUG "yaffs is using direct read/write (uncached)\n");
@@ -1069,24 +1095,24 @@ static int __init init_yaffs_fs(void)
        return -ENOMEM;
     }
 
-#ifdef YAFFS_RAM_ENABLED
+#ifdef CONFIG_YAFFS_RAM_ENABLED
 
     error = register_filesystem(&yaffs_ram_fs_type);
     if(error)
     {
        return error;
     }
-#endif //YAFFS_RAM_ENABLED
+#endif //CONFIG_YAFFS_RAM_ENABLED
 
-#ifdef YAFFS_MTD_ENABLED
+#ifdef CONFIG_YAFFS_MTD_ENABLED
        error = register_filesystem(&yaffs_fs_type);
        if(error)
        {
-#ifdef YAFFS_RAM_ENABLED
+#ifdef CONFIG_YAFFS_RAM_ENABLED
                unregister_filesystem(&yaffs_ram_fs_type);
-#endif //YAFFS_RAM_ENABLED
+#endif //CONFIG_YAFFS_RAM_ENABLED
        }
-#endif // YAFFS_MTD_ENABLED
+#endif // CONFIG_YAFFS_MTD_ENABLED
 
        return error;
 }
@@ -1097,10 +1123,10 @@ static void __exit exit_yaffs_fs(void)
 
     remove_proc_entry("yaffs",&proc_root);
     
-#ifdef YAFFS_RAM_ENABLED
+#ifdef CONFIG_YAFFS_RAM_ENABLED
        unregister_filesystem(&yaffs_ram_fs_type);
 #endif
-#ifdef YAFFS_MTD_ENABLED
+#ifdef CONFIG_YAFFS_MTD_ENABLED
        unregister_filesystem(&yaffs_fs_type);
 #endif