yaffs large file support: Saves and restores large files fine under yaffs direct.
[yaffs2.git] / yaffs_vfs_multi.c
index 7e28c40514242dbf3c8dbf624a9a12f2fba78a17..70ddce9bc5f770faa0f638912352a9e29be6be28 100644 (file)
@@ -72,7 +72,9 @@
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39))
 #include <linux/smp_lock.h>
+#endif
 #include <linux/pagemap.h>
 #include <linux/mtd/mtd.h>
 #include <linux/interrupt.h>
@@ -237,7 +239,9 @@ static int yaffs_file_flush(struct file *file, fl_owner_t id);
 static int yaffs_file_flush(struct file *file);
 #endif
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+static int yaffs_sync_object(struct file *file, loff_t start, loff_t end, int datasync);
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
 static int yaffs_sync_object(struct file *file, int datasync);
 #else
 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
@@ -1064,9 +1068,9 @@ static int yaffs_writepage(struct page *page)
 
                if (page->index > end_index || !n_bytes) {
                        yaffs_trace(YAFFS_TRACE_OS,
-                               "yaffs_writepage at %08x, inode size = %08x!!",
-                               (unsigned)(page->index << PAGE_CACHE_SHIFT),
-                               (unsigned)inode->i_size);
+                               "yaffs_writepage at %lld, inode size = %lld!!",
+                               ((loff_t)page->index) << PAGE_CACHE_SHIFT,
+                               inode->i_size);
                        yaffs_trace(YAFFS_TRACE_OS,
                                "                -> don't care!!");
 
@@ -1090,11 +1094,11 @@ static int yaffs_writepage(struct page *page)
        yaffs_gross_lock(dev);
 
        yaffs_trace(YAFFS_TRACE_OS,
-               "yaffs_writepage at %08x, size %08x",
-               (unsigned)(page->index << PAGE_CACHE_SHIFT), n_bytes);
+               "yaffs_writepage at %lld, size %08x",
+               ((loff_t)page->index) << PAGE_CACHE_SHIFT, n_bytes);
        yaffs_trace(YAFFS_TRACE_OS,
-               "writepag0: obj = %05x, ino = %05x",
-               (int)obj->variant.file_variant.file_size, (int)inode->i_size);
+               "writepag0: obj = %lld, ino = %lld",
+               obj->variant.file_variant.file_size, inode->i_size);
 
        n_written = yaffs_wr_file(obj, buffer,
                                  page->index << PAGE_CACHE_SHIFT, n_bytes, 0);
@@ -1102,8 +1106,8 @@ static int yaffs_writepage(struct page *page)
        yaffs_touch_super(dev);
 
        yaffs_trace(YAFFS_TRACE_OS,
-               "writepag1: obj = %05x, ino = %05x",
-               (int)obj->variant.file_variant.file_size, (int)inode->i_size);
+               "writepag1: obj = %lld, ino = %lld",
+               obj->variant.file_variant.file_size, inode->i_size);
 
        yaffs_gross_unlock(dev);
 
@@ -1202,8 +1206,8 @@ static int yaffs_write_end(struct file *filp, struct address_space *mapping,
        addr = kva + offset_into_page;
 
        yaffs_trace(YAFFS_TRACE_OS,
-               "yaffs_write_end addr %p pos %x n_bytes %d",
-               addr, (unsigned)pos, copied);
+               "yaffs_write_end addr %p pos %lld n_bytes %d",
+               addr, pos, copied);
 
        ret = yaffs_file_write(filp, addr, copied, &pos);
 
@@ -1232,17 +1236,12 @@ static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
        int n_bytes = to - offset;
        int n_written;
 
-       unsigned spos = pos;
-       unsigned saddr;
-
        kva = kmap(pg);
        addr = kva + offset;
 
-       saddr = (unsigned)addr;
-
        yaffs_trace(YAFFS_TRACE_OS,
-               "yaffs_commit_write addr %x pos %x n_bytes %d",
-               saddr, spos, n_bytes);
+               "yaffs_commit_write addr %p pos %lld n_bytes %d",
+               addr, pos, n_bytes);
 
        n_written = yaffs_file_write(f, addr, n_bytes, &pos);
 
@@ -1329,9 +1328,9 @@ static void yaffs_fill_inode_from_obj(struct inode *inode,
                inode->i_nlink = yaffs_get_obj_link_count(obj);
 
                yaffs_trace(YAFFS_TRACE_OS,
-                       "yaffs_fill_inode mode %x uid %d gid %d size %d count %d",
+                       "yaffs_fill_inode mode %x uid %d gid %d size %lld count %d",
                        inode->i_mode, inode->i_uid, inode->i_gid,
-                       (int)inode->i_size, atomic_read(&inode->i_count));
+                       inode->i_size, atomic_read(&inode->i_count));
 
                switch (obj->yst_mode & S_IFMT) {
                default:        /* fifo, device or socket */
@@ -1406,7 +1405,8 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
                                loff_t * pos)
 {
        struct yaffs_obj *obj;
-       int n_written, ipos;
+       int n_written;
+       loff_t ipos;
        struct inode *inode;
        struct yaffs_dev *dev;
 
@@ -1430,8 +1430,8 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
                ipos = *pos;
 
        yaffs_trace(YAFFS_TRACE_OS,
-               "yaffs_file_write about to write writing %u(%x) bytes to object %d at %d(%x)",
-               (unsigned)n, (unsigned)n, obj->obj_id, ipos, ipos);
+               "yaffs_file_write about to write writing %u(%x) bytes to object %d at %lld",
+               (unsigned)n, (unsigned)n, obj->obj_id, ipos);
 
        n_written = yaffs_wr_file(obj, buf, ipos, n, 0);
 
@@ -1449,7 +1449,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
                        inode->i_blocks = (ipos + 511) >> 9;
 
                        yaffs_trace(YAFFS_TRACE_OS,
-                               "yaffs_file_write size updated to %d bytes, %d blocks",
+                               "yaffs_file_write size updated to %lld bytes, %d blocks",
                                ipos, (int)(inode->i_blocks));
                }
 
@@ -1826,7 +1826,9 @@ static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
        return -ENOMEM;
 }
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+static int yaffs_sync_object(struct file *file, loff_t start, loff_t end, int datasync)
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
 static int yaffs_sync_object(struct file *file, int datasync)
 #else
 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
@@ -1914,10 +1916,11 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_setattr of object %d",
                yaffs_inode_to_obj(inode)->obj_id);
-
+#if 0
        /* Fail if a requested resize >= 2GB */
        if (attr->ia_valid & ATTR_SIZE && (attr->ia_size >> 31))
                error = -EINVAL;
+#endif
 
        if (error == 0)
                error = inode_change_ok(inode, attr);
@@ -2524,6 +2527,7 @@ struct yaffs_options {
        int lazy_loading_overridden;
        int empty_lost_and_found;
        int empty_lost_and_found_overridden;
+       int disable_summary;
 };
 
 #define MAX_OPT_LEN 30
@@ -2565,6 +2569,8 @@ static int yaffs_parse_options(struct yaffs_options *options,
                } else if (!strcmp(cur_opt, "lazy-loading-on")) {
                        options->lazy_loading_enabled = 1;
                        options->lazy_loading_overridden = 1;
+               } else if (!strcmp(cur_opt, "disable-summary")) {
+                       options->disable_summary = 1;
                } else if (!strcmp(cur_opt, "empty-lost-and-found-off")) {
                        options->empty_lost_and_found = 0;
                        options->empty_lost_and_found_overridden = 1;
@@ -2809,6 +2815,8 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
        sb->u.generic_sbp = dev;
 #endif
 
+       sb->s_maxbytes = 35000000000LL;
+
        dev->driver_context = mtd;
        param->name = mtd->name;
 
@@ -2837,6 +2845,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
 
        param->empty_lost_n_found = 1;
        param->refresh_period = 500;
+       param->disable_summary = options.disable_summary;
 
        if (options.empty_lost_and_found_overridden)
                param->empty_lost_n_found = options.empty_lost_and_found;
@@ -2969,7 +2978,13 @@ static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
        return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
 }
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+static struct dentry *yaffs_mount(struct file_system_type *fs_type, int flags,
+        const char *dev_name, void *data)
+{
+    return mount_bdev(fs_type, flags, dev_name, data, yaffs_internal_read_super_mtd);
+}
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
 static int yaffs_read_super(struct file_system_type *fs,
                            int flags, const char *dev_name,
                            void *data, struct vfsmount *mnt)
@@ -2992,8 +3007,12 @@ static struct super_block *yaffs_read_super(struct file_system_type *fs,
 static struct file_system_type yaffs_fs_type = {
        .owner = THIS_MODULE,
        .name = "yaffs",
-       .get_sb = yaffs_read_super,
-       .kill_sb = kill_block_super,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+        .mount = yaffs_mount,
+#else
+        .get_sb = yaffs_read_super,
+#endif
+       .kill_sb = kill_block_super,
        .fs_flags = FS_REQUIRES_DEV,
 };
 #else
@@ -3015,7 +3034,13 @@ static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
        return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
 }
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+static struct dentry *yaffs2_mount(struct file_system_type *fs_type, int flags,
+        const char *dev_name, void *data)
+{
+        return mount_bdev(fs_type, flags, dev_name, data, yaffs2_internal_read_super_mtd);
+}
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
 static int yaffs2_read_super(struct file_system_type *fs,
                             int flags, const char *dev_name, void *data,
                             struct vfsmount *mnt)
@@ -3037,8 +3062,12 @@ static struct super_block *yaffs2_read_super(struct file_system_type *fs,
 static struct file_system_type yaffs2_fs_type = {
        .owner = THIS_MODULE,
        .name = "yaffs2",
-       .get_sb = yaffs2_read_super,
-       .kill_sb = kill_block_super,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
+        .mount = yaffs2_mount,
+#else
+        .get_sb = yaffs2_read_super,
+#endif
+       .kill_sb = kill_block_super,
        .fs_flags = FS_REQUIRES_DEV,
 };
 #else
@@ -3108,8 +3137,8 @@ static char *yaffs_dump_dev_part1(char *buf, struct yaffs_dev *dev)
                                dev->oldest_dirty_gc_count);
        buf += sprintf(buf, "n_gc_blocks.......... %u\n", dev->n_gc_blocks);
        buf += sprintf(buf, "bg_gcs............... %u\n", dev->bg_gcs);
-       buf += sprintf(buf, "n_retired_writes..... %u\n",
-                               dev->n_retired_writes);
+       buf += sprintf(buf, "n_retried_writes..... %u\n",
+                               dev->n_retried_writes);
        buf += sprintf(buf, "n_retired_blocks..... %u\n",
                                dev->n_retired_blocks);
        buf += sprintf(buf, "n_ecc_fixed.......... %u\n", dev->n_ecc_fixed);
@@ -3124,6 +3153,8 @@ static char *yaffs_dump_dev_part1(char *buf, struct yaffs_dev *dev)
                                dev->n_unlinked_files);
        buf += sprintf(buf, "refresh_count........ %u\n", dev->refresh_count);
        buf += sprintf(buf, "n_bg_deletions....... %u\n", dev->n_bg_deletions);
+       buf += sprintf(buf, "tags_used............ %u\n", dev->tags_used);
+       buf += sprintf(buf, "summary_used......... %u\n", dev->summary_used);
 
        return buf;
 }