Btrfs: enable discard support
[safe/jmp/linux-2.6] / fs / befs / linuxvfs.c
index 07f7144..615d549 100644 (file)
@@ -35,7 +35,7 @@ static int befs_get_block(struct inode *, sector_t, struct buffer_head *, int);
 static int befs_readpage(struct file *file, struct page *page);
 static sector_t befs_bmap(struct address_space *mapping, sector_t block);
 static struct dentry *befs_lookup(struct inode *, struct dentry *, struct nameidata *);
-static void befs_read_inode(struct inode *ino);
+static struct inode *befs_iget(struct super_block *, unsigned long);
 static struct inode *befs_alloc_inode(struct super_block *sb);
 static void befs_destroy_inode(struct inode *inode);
 static int befs_init_inodecache(void);
@@ -52,23 +52,24 @@ static int befs_statfs(struct dentry *, struct kstatfs *);
 static int parse_options(char *, befs_mount_options *);
 
 static const struct super_operations befs_sops = {
-       .read_inode     = befs_read_inode,      /* initialize & read inode */
        .alloc_inode    = befs_alloc_inode,     /* allocate a new inode */
        .destroy_inode  = befs_destroy_inode, /* deallocate an inode */
        .put_super      = befs_put_super,       /* uninit super */
        .statfs         = befs_statfs,  /* statfs */
        .remount_fs     = befs_remount,
+       .show_options   = generic_show_options,
 };
 
 /* slab cache for befs_inode_info objects */
-static kmem_cache_t *befs_inode_cachep;
+static struct kmem_cache *befs_inode_cachep;
 
 static const struct file_operations befs_dir_operations = {
        .read           = generic_read_dir,
        .readdir        = befs_readdir,
+       .llseek         = generic_file_llseek,
 };
 
-static struct inode_operations befs_dir_inode_operations = {
+static const struct inode_operations befs_dir_inode_operations = {
        .lookup         = befs_lookup,
 };
 
@@ -78,7 +79,7 @@ static const struct address_space_operations befs_aops = {
        .bmap           = befs_bmap,
 };
 
-static struct inode_operations befs_symlink_inode_operations = {
+static const struct inode_operations befs_symlink_inode_operations = {
        .readlink       = generic_readlink,
        .follow_link    = befs_follow_link,
        .put_link       = befs_put_link,
@@ -198,9 +199,9 @@ befs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
                return ERR_PTR(-ENODATA);
        }
 
-       inode = iget(dir->i_sb, (ino_t) offset);
-       if (!inode)
-               return ERR_PTR(-EACCES);
+       inode = befs_iget(dir->i_sb, (ino_t) offset);
+       if (IS_ERR(inode))
+               return ERR_CAST(inode);
 
        d_add(dentry, inode);
 
@@ -212,7 +213,7 @@ befs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
 static int
 befs_readdir(struct file *filp, void *dirent, filldir_t filldir)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct super_block *sb = inode->i_sb;
        befs_data_stream *ds = &BEFS_I(inode)->i_data.ds;
        befs_off_t value;
@@ -222,7 +223,7 @@ befs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        char keybuf[BEFS_NAME_LEN + 1];
        char *nlsname;
        int nlsnamelen;
-       const char *dirname = filp->f_dentry->d_name.name;
+       const char *dirname = filp->f_path.dentry->d_name.name;
 
        befs_debug(sb, "---> befs_readdir() "
                   "name %s, inode %ld, filp->f_pos %Ld",
@@ -277,7 +278,7 @@ befs_alloc_inode(struct super_block *sb)
 {
         struct befs_inode_info *bi;
         bi = (struct befs_inode_info *)kmem_cache_alloc(befs_inode_cachep,
-                                                       SLAB_KERNEL);
+                                                       GFP_KERNEL);
         if (!bi)
                 return NULL;
         return &bi->vfs_inode;
@@ -289,27 +290,30 @@ befs_destroy_inode(struct inode *inode)
         kmem_cache_free(befs_inode_cachep, BEFS_I(inode));
 }
 
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static void init_once(void *foo)
 {
         struct befs_inode_info *bi = (struct befs_inode_info *) foo;
-       
-               if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
-                           SLAB_CTOR_CONSTRUCTOR) {
-                       inode_init_once(&bi->vfs_inode);
-               }
+
+       inode_init_once(&bi->vfs_inode);
 }
 
-static void
-befs_read_inode(struct inode *inode)
+static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
 {
        struct buffer_head *bh = NULL;
        befs_inode *raw_inode = NULL;
 
-       struct super_block *sb = inode->i_sb;
        befs_sb_info *befs_sb = BEFS_SB(sb);
        befs_inode_info *befs_ino = NULL;
+       struct inode *inode;
+       long ret = -EIO;
+
+       befs_debug(sb, "---> befs_read_inode() " "inode = %lu", ino);
 
-       befs_debug(sb, "---> befs_read_inode() " "inode = %lu", inode->i_ino);
+       inode = iget_locked(sb, ino);
+       if (IS_ERR(inode))
+               return inode;
+       if (!(inode->i_state & I_NEW))
+               return inode;
 
        befs_ino = BEFS_I(inode);
 
@@ -374,7 +378,8 @@ befs_read_inode(struct inode *inode)
                inode->i_size = 0;
                inode->i_blocks = befs_sb->block_size / VFS_BLOCK_SIZE;
                strncpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
-                       BEFS_SYMLINK_LEN);
+                       BEFS_SYMLINK_LEN - 1);
+               befs_ino->i_data.symlink[BEFS_SYMLINK_LEN - 1] = '\0';
        } else {
                int num_blks;
 
@@ -405,19 +410,20 @@ befs_read_inode(struct inode *inode)
 
        brelse(bh);
        befs_debug(sb, "<--- befs_read_inode()");
-       return;
+       unlock_new_inode(inode);
+       return inode;
 
       unacquire_bh:
        brelse(bh);
 
       unacquire_none:
-       make_bad_inode(inode);
+       iget_failed(inode);
        befs_debug(sb, "<--- befs_read_inode() - Bad inode");
-       return;
+       return ERR_PTR(ret);
 }
 
 /* Initialize the inode cache. Called at fs setup.
- * 
+ *
  * Taken from NFS implementation by Al Viro.
  */
 static int
@@ -427,7 +433,7 @@ befs_init_inodecache(void)
                                              sizeof (struct befs_inode_info),
                                              0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
-                                             init_once, NULL);
+                                             init_once);
        if (befs_inode_cachep == NULL) {
                printk(KERN_ERR "befs_init_inodecache: "
                       "Couldn't initalize inode slabcache\n");
@@ -472,6 +478,8 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)
                        kfree(link);
                        befs_error(sb, "Failed to read entire long symlink");
                        link = ERR_PTR(-EIO);
+               } else {
+                       link[len - 1] = '\0';
                }
        } else {
                link = befs_ino->i_data.symlink;
@@ -485,9 +493,9 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
 {
        befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
        if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
-               char *p = nd_get_link(nd);
-               if (!IS_ERR(p))
-                       kfree(p);
+               char *link = nd_get_link(nd);
+               if (!IS_ERR(link))
+                       kfree(link);
        }
 }
 
@@ -505,7 +513,7 @@ befs_utf2nls(struct super_block *sb, const char *in,
 {
        struct nls_table *nls = BEFS_SB(sb)->nls;
        int i, o;
-       wchar_t uni;
+       unicode_t uni;
        int unilen, utflen;
        char *result;
        /* The utf8->nls conversion won't make the final nls string bigger
@@ -531,16 +539,16 @@ befs_utf2nls(struct super_block *sb, const char *in,
        for (i = o = 0; i < in_len; i += utflen, o += unilen) {
 
                /* convert from UTF-8 to Unicode */
-               utflen = utf8_mbtowc(&uni, &in[i], in_len - i);
-               if (utflen < 0) {
+               utflen = utf8_to_utf32(&in[i], in_len - i, &uni);
+               if (utflen < 0)
                        goto conv_err;
-               }
 
                /* convert from Unicode to nls */
+               if (uni > MAX_WCHAR_T)
+                       goto conv_err;
                unilen = nls->uni2char(uni, &result[o], in_len - o);
-               if (unilen < 0) {
+               if (unilen < 0)
                        goto conv_err;
-               }
        }
        result[o] = '\0';
        *out_len = o;
@@ -611,15 +619,13 @@ befs_nls2utf(struct super_block *sb, const char *in,
 
                /* convert from nls to unicode */
                unilen = nls->char2uni(&in[i], in_len - i, &uni);
-               if (unilen < 0) {
+               if (unilen < 0)
                        goto conv_err;
-               }
 
                /* convert from unicode to UTF-8 */
-               utflen = utf8_wctomb(&result[o], uni, 3);
-               if (utflen <= 0) {
+               utflen = utf32_to_utf8(uni, &result[o], 3);
+               if (utflen <= 0)
                        goto conv_err;
-               }
        }
 
        result[o] = '\0';
@@ -645,7 +651,7 @@ enum {
        Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err,
 };
 
-static match_table_t befs_tokens = {
+static const match_table_t befs_tokens = {
        {Opt_uid, "uid=%d"},
        {Opt_gid, "gid=%d"},
        {Opt_charset, "iocharset=%s"},
@@ -739,7 +745,6 @@ befs_put_super(struct super_block *sb)
 
        kfree(sb->s_fs_info);
        sb->s_fs_info = NULL;
-       return;
 }
 
 /* Allocate private field of the superblock, fill it.
@@ -755,10 +760,12 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
        befs_sb_info *befs_sb;
        befs_super_block *disk_sb;
        struct inode *root;
-
+       long ret = -EINVAL;
        const unsigned long sb_block = 0;
        const off_t x86_sb_off = 512;
 
+       save_mount_options(sb, data);
+
        sb->s_fs_info = kmalloc(sizeof (*befs_sb), GFP_KERNEL);
        if (sb->s_fs_info == NULL) {
                printk(KERN_ERR
@@ -802,8 +809,8 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
 
        /* account for offset of super block on x86 */
        disk_sb = (befs_super_block *) bh->b_data;
-       if ((le32_to_cpu(disk_sb->magic1) == BEFS_SUPER_MAGIC1) ||
-           (be32_to_cpu(disk_sb->magic1) == BEFS_SUPER_MAGIC1)) {
+       if ((disk_sb->magic1 == BEFS_SUPER_MAGIC1_LE) ||
+           (disk_sb->magic1 == BEFS_SUPER_MAGIC1_BE)) {
                befs_debug(sb, "Using PPC superblock location");
        } else {
                befs_debug(sb, "Using x86 superblock location");
@@ -836,7 +843,11 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
        /* Set real blocksize of fs */
        sb_set_blocksize(sb, (ulong) befs_sb->block_size);
        sb->s_op = (struct super_operations *) &befs_sops;
-       root = iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
+       root = befs_iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
+       if (IS_ERR(root)) {
+               ret = PTR_ERR(root);
+               goto unacquire_priv_sbp;
+       }
        sb->s_root = d_alloc_root(root);
        if (!sb->s_root) {
                iput(root);
@@ -871,7 +882,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
 
       unacquire_none:
        sb->s_fs_info = NULL;
-       return -EINVAL;
+       return ret;
 }
 
 static int
@@ -886,6 +897,7 @@ static int
 befs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
        struct super_block *sb = dentry->d_sb;
+       u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
 
        befs_debug(sb, "---> befs_statfs()");
 
@@ -896,6 +908,8 @@ befs_statfs(struct dentry *dentry, struct kstatfs *buf)
        buf->f_bavail = buf->f_bfree;
        buf->f_files = 0;       /* UNKNOWN */
        buf->f_ffree = 0;       /* UNKNOWN */
+       buf->f_fsid.val[0] = (u32)id;
+       buf->f_fsid.val[1] = (u32)(id >> 32);
        buf->f_namelen = BEFS_NAME_LEN;
 
        befs_debug(sb, "<--- befs_statfs()");