msi-wmi: depend on backlight and fix corner-cases problems
[safe/jmp/linux-2.6] / fs / affs / super.c
index 6a52e78..104fdcb 100644 (file)
 #include <linux/init.h>
 #include <linux/statfs.h>
 #include <linux/parser.h>
+#include <linux/magic.h>
+#include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include "affs.h"
 
 extern struct timezone sys_tz;
 
-static int affs_statfs(struct super_block *sb, struct kstatfs *buf);
+static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
 static int affs_remount (struct super_block *sb, int *flags, char *data);
 
 static void
+affs_commit_super(struct super_block *sb, int clean)
+{
+       struct affs_sb_info *sbi = AFFS_SB(sb);
+       struct buffer_head *bh = sbi->s_root_bh;
+       struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh);
+
+       tail->bm_flag = cpu_to_be32(clean);
+       secs_to_datestamp(get_seconds(), &tail->disk_change);
+       affs_fix_checksum(sb, bh);
+       mark_buffer_dirty(bh);
+}
+
+static void
 affs_put_super(struct super_block *sb)
 {
        struct affs_sb_info *sbi = AFFS_SB(sb);
        pr_debug("AFFS: put_super()\n");
 
-       if (!(sb->s_flags & MS_RDONLY)) {
-               AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->bm_flag = cpu_to_be32(1);
-               secs_to_datestamp(get_seconds(),
-                                 &AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->disk_change);
-               affs_fix_checksum(sb, sbi->s_root_bh);
-               mark_buffer_dirty(sbi->s_root_bh);
-       }
+       lock_kernel();
+
+       if (!(sb->s_flags & MS_RDONLY))
+               affs_commit_super(sb, 1);
 
        kfree(sbi->s_prefix);
        affs_free_bitmap(sb);
        affs_brelse(sbi->s_root_bh);
        kfree(sbi);
        sb->s_fs_info = NULL;
-       return;
+
+       unlock_kernel();
 }
 
 static void
 affs_write_super(struct super_block *sb)
 {
        int clean = 2;
-       struct affs_sb_info *sbi = AFFS_SB(sb);
 
+       lock_super(sb);
        if (!(sb->s_flags & MS_RDONLY)) {
                //      if (sbi->s_bitmap[i].bm_bh) {
                //              if (buffer_dirty(sbi->s_bitmap[i].bm_bh)) {
                //                      clean = 0;
-               AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->bm_flag = cpu_to_be32(clean);
-               secs_to_datestamp(get_seconds(),
-                                 &AFFS_ROOT_TAIL(sb, sbi->s_root_bh)->disk_change);
-               affs_fix_checksum(sb, sbi->s_root_bh);
-               mark_buffer_dirty(sbi->s_root_bh);
+               affs_commit_super(sb, clean);
                sb->s_dirt = !clean;    /* redo until bitmap synced */
        } else
                sb->s_dirt = 0;
+       unlock_super(sb);
 
        pr_debug("AFFS: write_super() at %lu, clean=%d\n", get_seconds(), clean);
 }
 
-static kmem_cache_t * affs_inode_cachep;
+static int
+affs_sync_fs(struct super_block *sb, int wait)
+{
+       lock_super(sb);
+       affs_commit_super(sb, 2);
+       sb->s_dirt = 0;
+       unlock_super(sb);
+       return 0;
+}
+
+static struct kmem_cache * affs_inode_cachep;
 
 static struct inode *affs_alloc_inode(struct super_block *sb)
 {
-       struct affs_inode_info *ei;
-       ei = (struct affs_inode_info *)kmem_cache_alloc(affs_inode_cachep, SLAB_KERNEL);
-       if (!ei)
+       struct affs_inode_info *i;
+
+       i = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL);
+       if (!i)
                return NULL;
-       ei->vfs_inode.i_version = 1;
-       return &ei->vfs_inode;
+
+       i->vfs_inode.i_version = 1;
+       i->i_lc = NULL;
+       i->i_ext_bh = NULL;
+       i->i_pa_cnt = 0;
+
+       return &i->vfs_inode;
 }
 
 static void affs_destroy_inode(struct inode *inode)
@@ -82,16 +109,13 @@ static void affs_destroy_inode(struct inode *inode)
        kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
 }
 
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static void init_once(void *foo)
 {
        struct affs_inode_info *ei = (struct affs_inode_info *) foo;
 
-       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
-           SLAB_CTOR_CONSTRUCTOR) {
-               init_MUTEX(&ei->i_link_lock);
-               init_MUTEX(&ei->i_ext_lock);
-               inode_init_once(&ei->vfs_inode);
-       }
+       init_MUTEX(&ei->i_link_lock);
+       init_MUTEX(&ei->i_ext_lock);
+       inode_init_once(&ei->vfs_inode);
 }
 
 static int init_inodecache(void)
@@ -100,7 +124,7 @@ static int init_inodecache(void)
                                             sizeof(struct affs_inode_info),
                                             0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
-                                            init_once, NULL);
+                                            init_once);
        if (affs_inode_cachep == NULL)
                return -ENOMEM;
        return 0;
@@ -108,22 +132,21 @@ static int init_inodecache(void)
 
 static void destroy_inodecache(void)
 {
-       if (kmem_cache_destroy(affs_inode_cachep))
-               printk(KERN_INFO "affs_inode_cache: not all structures were freed\n");
+       kmem_cache_destroy(affs_inode_cachep);
 }
 
-static struct super_operations affs_sops = {
+static const struct super_operations affs_sops = {
        .alloc_inode    = affs_alloc_inode,
        .destroy_inode  = affs_destroy_inode,
-       .read_inode     = affs_read_inode,
        .write_inode    = affs_write_inode,
-       .put_inode      = affs_put_inode,
        .delete_inode   = affs_delete_inode,
        .clear_inode    = affs_clear_inode,
        .put_super      = affs_put_super,
        .write_super    = affs_write_super,
+       .sync_fs        = affs_sync_fs,
        .statfs         = affs_statfs,
        .remount_fs     = affs_remount,
+       .show_options   = generic_show_options,
 };
 
 enum {
@@ -132,7 +155,7 @@ enum {
        Opt_verbose, Opt_volume, Opt_ignore, Opt_err,
 };
 
-static match_table_t tokens = {
+static const match_table_t tokens = {
        {Opt_bs, "bs=%u"},
        {Opt_mode, "mode=%o"},
        {Opt_mufs, "mufs"},
@@ -160,8 +183,8 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s
 
        /* Fill in defaults */
 
-       *uid        = current->uid;
-       *gid        = current->gid;
+       *uid        = current_uid();
+       *gid        = current_gid();
        *reserved   = 2;
        *root       = -1;
        *blocksize  = -1;
@@ -200,7 +223,6 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s
                case Opt_prefix:
                        /* Free any previous prefix */
                        kfree(*prefix);
-                       *prefix = NULL;
                        *prefix = match_strdup(&args[0]);
                        if (!*prefix)
                                return 0;
@@ -234,6 +256,8 @@ parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, s
                        break;
                case Opt_volume: {
                        char *vol = match_strdup(&args[0]);
+                       if (!vol)
+                               return 0;
                        strlcpy(volume, vol, 32);
                        kfree(vol);
                        break;
@@ -271,6 +295,10 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
        int                      reserved;
        unsigned long            mount_flags;
        int                      tmp_flags;     /* fix remount prototype... */
+       u8                       sig[4];
+       int                      ret = -EINVAL;
+
+       save_mount_options(sb, data);
 
        pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options");
 
@@ -278,12 +306,11 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
        sb->s_op                = &affs_sops;
        sb->s_flags |= MS_NODIRATIME;
 
-       sbi = kmalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
+       sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
        sb->s_fs_info = sbi;
-       memset(sbi, 0, sizeof(*sbi));
-       init_MUTEX(&sbi->s_bmlock);
+       mutex_init(&sbi->s_bmlock);
 
        if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block,
                                &blocksize,&sbi->s_prefix,
@@ -370,8 +397,9 @@ got_root:
                printk(KERN_ERR "AFFS: Cannot read boot block\n");
                goto out_error;
        }
-       chksum = be32_to_cpu(*(__be32 *)boot_bh->b_data);
+       memcpy(sig, boot_bh->b_data, 4);
        brelse(boot_bh);
+       chksum = be32_to_cpu(*(__be32 *)sig);
 
        /* Dircache filesystems are compatible with non-dircache ones
         * when reading. As long as they aren't supported, writing is
@@ -420,11 +448,11 @@ got_root:
        }
 
        if (mount_flags & SF_VERBOSE) {
-               chksum = cpu_to_be32(chksum);
-               printk(KERN_NOTICE "AFFS: Mounting volume \"%*s\": Type=%.3s\\%c, Blocksize=%d\n",
-                       AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0],
+               u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
+               printk(KERN_NOTICE "AFFS: Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n",
+                       len > 31 ? 31 : len,
                        AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1,
-                       (char *)&chksum,((char *)&chksum)[3] + '0',blocksize);
+                       sig, sig[3] + '0', blocksize);
        }
 
        sb->s_flags |= MS_NODEV | MS_NOSUID;
@@ -444,7 +472,12 @@ got_root:
 
        /* set up enough so that it can read an inode */
 
-       root_inode = iget(sb, root_block);
+       root_inode = affs_iget(sb, root_block);
+       if (IS_ERR(root_inode)) {
+               ret = PTR_ERR(root_inode);
+               goto out_error_noinode;
+       }
+
        sb->s_root = d_alloc_root(root_inode);
        if (!sb->s_root) {
                printk(KERN_ERR "AFFS: Get root inode failed\n");
@@ -461,12 +494,13 @@ got_root:
 out_error:
        if (root_inode)
                iput(root_inode);
+out_error_noinode:
        kfree(sbi->s_bitmap);
        affs_brelse(root_bh);
        kfree(sbi->s_prefix);
        kfree(sbi);
        sb->s_fs_info = NULL;
-       return -EINVAL;
+       return ret;
 }
 
 static int
@@ -481,21 +515,30 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        int                      root_block;
        unsigned long            mount_flags;
        int                      res = 0;
+       char                    *new_opts = kstrdup(data, GFP_KERNEL);
 
        pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data);
 
        *flags |= MS_NODIRATIME;
 
-       if (!parse_options(data,&uid,&gid,&mode,&reserved,&root_block,
-           &blocksize,&sbi->s_prefix,sbi->s_volume,&mount_flags))
+       if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
+                          &blocksize, &sbi->s_prefix, sbi->s_volume,
+                          &mount_flags)) {
+               kfree(new_opts);
                return -EINVAL;
+       }
+       lock_kernel();
+       replace_mount_options(sb, new_opts);
+
        sbi->s_flags = mount_flags;
        sbi->s_mode  = mode;
        sbi->s_uid   = uid;
        sbi->s_gid   = gid;
 
-       if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
+       if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
+               unlock_kernel();
                return 0;
+       }
        if (*flags & MS_RDONLY) {
                sb->s_dirt = 1;
                while (sb->s_dirt)
@@ -504,13 +547,16 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        } else
                res = affs_init_bitmap(sb, flags);
 
+       unlock_kernel();
        return res;
 }
 
 static int
-affs_statfs(struct super_block *sb, struct kstatfs *buf)
+affs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
+       struct super_block *sb = dentry->d_sb;
        int              free;
+       u64              id = huge_encode_dev(sb->s_bdev->bd_dev);
 
        pr_debug("AFFS: statfs() partsize=%d, reserved=%d\n",AFFS_SB(sb)->s_partition_size,
             AFFS_SB(sb)->s_reserved);
@@ -521,6 +567,9 @@ affs_statfs(struct super_block *sb, struct kstatfs *buf)
        buf->f_blocks  = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
        buf->f_bfree   = free;
        buf->f_bavail  = free;
+       buf->f_fsid.val[0] = (u32)id;
+       buf->f_fsid.val[1] = (u32)(id >> 32);
+       buf->f_namelen = 30;
        return 0;
 }