yaffs: Tweaks to summary code
[yaffs2.git] / yaffs_vfs_multi.c
index 85df2d75ff1ead531a1a5d0c66b6f845d76c2974..15ff4ffdfb838d5ef00f2f0a946228d1ebb635f9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  *
- * Copyright (C) 2002-2010 Aleph One Ltd.
+ * Copyright (C) 2002-2011 Aleph One Ltd.
  *   for Toby Churchill Ltd and Brightstar Engineering
  *
  * Created by Charles Manning <charles@aleph1.co.uk>
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10))
 #define YAFFS_COMPILE_BACKGROUND
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6, 23))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23))
 #define YAFFS_COMPILE_FREEZER
 #endif
 #endif
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
 #define YAFFS_COMPILE_EXPORTFS
 #endif
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35))
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
 #define YAFFS_USE_SETATTR_COPY
 #define YAFFS_USE_TRUNCATE_SETSIZE
 #endif
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35))
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35))
 #define YAFFS_HAS_EVICT_INODE
 #endif
 
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
 #define YAFFS_NEW_FOLLOW_LINK 1
 #else
 #define YAFFS_NEW_FOLLOW_LINK 0
 #define YPROC_ROOT  NULL
 #endif
 
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26))
 #define Y_INIT_TIMER(a)        init_timer(a)
 #else
 #define Y_INIT_TIMER(a)        init_timer_on_stack(a)
@@ -210,7 +210,8 @@ static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
 #define yaffs_inode_to_obj_lv(iptr) ((iptr)->u.generic_ip)
 #endif
 
-#define yaffs_inode_to_obj(iptr) ((struct yaffs_obj *)(yaffs_inode_to_obj_lv(iptr)))
+#define yaffs_inode_to_obj(iptr) \
+       ((struct yaffs_obj *)(yaffs_inode_to_obj_lv(iptr)))
 #define yaffs_dentry_to_obj(dptr) yaffs_inode_to_obj((dptr)->d_inode)
 
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
@@ -221,12 +222,12 @@ static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
 
 #define update_dir_time(dir) do {\
                        (dir)->i_ctime = (dir)->i_mtime = CURRENT_TIME; \
-               } while(0)
+               } while (0)
 
 static void yaffs_put_super(struct super_block *sb);
 
 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
-                               loff_t * pos);
+                               loff_t *pos);
 static ssize_t yaffs_hold_space(struct file *f);
 static void yaffs_release_space(struct file *f);
 
@@ -309,8 +310,8 @@ static int yaffs_writepage(struct page *page);
 #ifdef CONFIG_YAFFS_XATTR
 static int yaffs_setxattr(struct dentry *dentry, const char *name,
                   const void *value, size_t size, int flags);
-static ssize_t yaffs_getxattr(struct dentry *dentry, const char *name, void *buff,
-                      size_t size);
+static ssize_t yaffs_getxattr(struct dentry *dentry, const char *name,
+                               void *buff, size_t size);
 static int yaffs_removexattr(struct dentry *dentry, const char *name);
 static ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size);
 #endif
@@ -396,7 +397,7 @@ static const struct file_operations yaffs_file_operations = {
 };
 #endif
 
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
 static void zero_user_segment(struct page *page, unsigned start, unsigned end)
 {
        void *kaddr = kmap_atomic(page, KM_USER0);
@@ -479,7 +480,7 @@ static const struct super_operations yaffs_super_ops = {
 
 static int yaffs_vfs_setattr(struct inode *inode, struct iattr *attr)
 {
-#ifdef  YAFFS_USE_SETATTR_COPY
+#ifdef YAFFS_USE_SETATTR_COPY
        setattr_copy(inode, attr);
        return 0;
 #else
@@ -490,7 +491,7 @@ static int yaffs_vfs_setattr(struct inode *inode, struct iattr *attr)
 
 static int yaffs_vfs_setsize(struct inode *inode, loff_t newsize)
 {
-#ifdef  YAFFS_USE_TRUNCATE_SETSIZE
+#ifdef YAFFS_USE_TRUNCATE_SETSIZE
        truncate_setsize(inode, newsize);
        return 0;
 #else
@@ -692,11 +693,9 @@ static void yaffs_remove_obj_callback(struct yaffs_obj *obj)
         * the search context to the next object to prevent a hanging pointer.
         */
        list_for_each(i, search_contexts) {
-               if (i) {
-                       sc = list_entry(i, struct yaffs_search_context, others);
-                       if (sc->next_return == obj)
-                               yaffs_search_advance(sc);
-               }
+               sc = list_entry(i, struct yaffs_search_context, others);
+               if (sc->next_return == obj)
+                       yaffs_search_advance(sc);
        }
 
 }
@@ -793,7 +792,7 @@ static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
        if (current != yaffs_dev_to_lc(dev)->readdir_process)
                yaffs_gross_lock(dev);
 
-       yaffs_trace(YAFFS_TRACE_OS,"yaffs_lookup for %d:%s",
+       yaffs_trace(YAFFS_TRACE_OS, "yaffs_lookup for %d:%s",
                yaffs_inode_to_obj(dir)->obj_id, dentry->d_name.name);
 
        obj = yaffs_find_by_name(yaffs_inode_to_obj(dir), dentry->d_name.name);
@@ -866,7 +865,7 @@ static void yaffs_evict_inode(struct inode *inode)
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_evict_inode: ino %d, count %d %s",
                (int)inode->i_ino, atomic_read(&inode->i_count),
-               obj ? "object exists" : "null object"));
+               obj ? "object exists" : "null object");
 
        if (!inode->i_nlink && !is_bad_inode(inode))
                deleteme = 1;
@@ -1421,6 +1420,12 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
 
        obj = yaffs_dentry_to_obj(f->f_dentry);
 
+       if (!obj) {
+               yaffs_trace(YAFFS_TRACE_OS,
+                       "yaffs_file_write: hey obj is null!");
+                return -EINVAL;
+        }
+
        dev = obj->my_dev;
 
        yaffs_gross_lock(dev);
@@ -1432,13 +1437,9 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
        else
                ipos = *pos;
 
-       if (!obj)
-               yaffs_trace(YAFFS_TRACE_OS,
-                       "yaffs_file_write: hey obj is null!");
-       else
-               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_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);
 
        n_written = yaffs_wr_file(obj, buf, ipos, n, 0);
 
@@ -2226,7 +2227,7 @@ static int yaffs_do_sync_fs(struct super_block *sb, int request_checkpoint)
  * yaffs_bg_start() launches the background thread.
  * yaffs_bg_stop() cleans up the background thread.
  *
- * NB: 
+ * NB:
  * The thread should only run after the yaffs is initialised
  * The thread should be stopped before yaffs is unmounted.
  * The thread should not do any writing while the fs is in read only.
@@ -2533,6 +2534,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
@@ -2574,6 +2576,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;
@@ -2623,6 +2627,11 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
        struct yaffs_linux_context *context_iterator;
        struct list_head *l;
 
+       if (!sb) {
+               printk(KERN_INFO "yaffs: sb is NULL\n");
+               return NULL;
+        }
+
        sb->s_magic = YAFFS_MAGIC;
        sb->s_op = &yaffs_super_ops;
        sb->s_flags |= MS_NOATIME;
@@ -2633,9 +2642,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
        sb->s_export_op = &yaffs_export_ops;
 #endif
 
-       if (!sb)
-               printk(KERN_INFO "yaffs: sb is NULL\n");
-       else if (!sb->s_dev)
+       if (!sb->s_dev)
                printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
        else if (!yaffs_devname(sb, devname_buf))
                printk(KERN_INFO "yaffs: devname is NULL\n");
@@ -2869,6 +2876,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
 #ifdef CONFIG_YAFFS__ALWAYS_CHECK_CHUNK_ERASED
        param->always_check_erased = 1;
 #endif
+       param->disable_summary = options.disable_summary;
 
        if (options.empty_lost_and_found_overridden)
                param->empty_lost_n_found = options.empty_lost_and_found;
@@ -2879,7 +2887,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
                param->read_chunk_tags_fn = nandmtd2_read_chunk_tags;
                param->bad_block_fn = nandmtd2_mark_block_bad;
                param->query_block_fn = nandmtd2_query_block;
-               yaffs_dev_to_lc(dev)->spare_buffer = 
+               yaffs_dev_to_lc(dev)->spare_buffer =
                                kmalloc(mtd->oobsize, GFP_NOFS);
                param->is_yaffs2 = 1;
 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
@@ -2957,7 +2965,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
 
        err = yaffs_guts_initialise(dev);
 
-       yaffs_trace(YAFFS_TRACE_OS, 
+       yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_read_super: guts initialised %s",
                (err == YAFFS_OK) ? "OK" : "FAILED");
 
@@ -3164,6 +3172,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;
 }
@@ -3462,5 +3472,5 @@ module_init(init_yaffs_fs)
     module_exit(exit_yaffs_fs)
 
     MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
-MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2010");
+MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2011");
 MODULE_LICENSE("GPL");