yaffs Mark superblock dirty on writes
[yaffs2.git] / yaffs_fs.c
index 8d1f3aa8da71cdd6670e6b2412c6eb4525721cf8..8e39ce251d5513557cb93130c760a11fa2e5040c 100644 (file)
@@ -311,6 +311,8 @@ static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
 #endif
 
+static void yaffs_MarkSuperBlockDirty(yaffs_Device *dev);
+
 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin);
 
 static struct address_space_operations yaffs_file_address_operations = {
@@ -951,6 +953,7 @@ static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
 static int yaffs_writepage(struct page *page)
 #endif
 {
+       yaffs_Device *dev;
        struct address_space *mapping = page->mapping;
        struct inode *inode;
        unsigned long end_index;
@@ -998,7 +1001,8 @@ static int yaffs_writepage(struct page *page)
        buffer = kmap(page);
 
        obj = yaffs_InodeToObject(inode);
-       yaffs_GrossLock(obj->myDev);
+       dev = obj->myDev;
+       yaffs_GrossLock(dev);
 
        T(YAFFS_TRACE_OS,
                (TSTR("yaffs_writepage at %08x, size %08x\n"),
@@ -1010,11 +1014,13 @@ static int yaffs_writepage(struct page *page)
        nWritten = yaffs_WriteDataToFile(obj, buffer,
                        page->index << PAGE_CACHE_SHIFT, nBytes, 0);
 
+       yaffs_MarkSuperBlockDirty(dev);
+
        T(YAFFS_TRACE_OS,
                (TSTR("writepag1: obj = %05x, ino = %05x\n"),
                (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
 
-       yaffs_GrossUnlock(obj->myDev);
+       yaffs_GrossUnlock(dev);
 
        kunmap(page);
        set_page_writeback(page);
@@ -1350,6 +1356,8 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
 
        nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
 
+       yaffs_MarkSuperBlockDirty(dev);
+
        T(YAFFS_TRACE_OS,
                (TSTR("yaffs_file_write: %d(%x) bytes written\n"),
                (unsigned )n,(unsigned)n));
@@ -2275,6 +2283,9 @@ static int yaffs_BackgroundStart(yaffs_Device *dev)
        int retval = 0;
        struct yaffs_LinuxContext *context = yaffs_DeviceToLC(dev);
 
+       if(dev->readOnly)
+               return -1;
+
        context->bgRunning = 1;
 
        context->bgThread = kthread_run(yaffs_BackgroundThread,
@@ -2566,6 +2577,8 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
        struct yaffs_LinuxContext *context = NULL;
        yaffs_DeviceParam *param;
 
+       int readOnly = 0;
+
        yaffs_options options;
 
        unsigned mount_id;
@@ -2577,6 +2590,9 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
        sb->s_op = &yaffs_super_ops;
        sb->s_flags |= MS_NOATIME;
 
+       readOnly =((sb->s_flags & MS_RDONLY) != 0);
+
+
 #ifdef YAFFS_COMPILE_EXPORTFS
        sb->s_export_op = &yaffs_export_ops;
 #endif
@@ -2588,9 +2604,10 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
        else if (!yaffs_devname(sb, devname_buf))
                printk(KERN_INFO "yaffs: devname is NULL\n");
        else
-               printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
+               printk(KERN_INFO "yaffs: dev is %d name is \"%s\" %s\n",
                       sb->s_dev,
-                      yaffs_devname(sb, devname_buf));
+                      yaffs_devname(sb, devname_buf),
+                      readOnly ? "ro" : "rw");
 
        if (!data_str)
                data_str = "";
@@ -2730,6 +2747,12 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
         * Set the yaffs_Device up for mtd
         */
 
+       if (!readOnly && !(mtd->flags & MTD_WRITEABLE)){
+               readOnly = 1;
+               printk(KERN_INFO "yaffs: mtd is read only, setting superblock read only");
+               sb->s_flags |= MS_RDONLY;
+       }
+
        dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
        context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
        
@@ -2758,7 +2781,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion,
        context->dev = dev;
        context->superBlock = sb;
 
-       
+       dev->readOnly = readOnly;
 
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
        sb->s_fs_info = dev;