Merge tag 'befs-v4.9-rc1' of git://github.com/luisbg/linux-befs
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Oct 2016 19:09:13 +0000 (12:09 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 15 Oct 2016 19:09:13 +0000 (12:09 -0700)
Pull befs fixes from Luis de Bethencourt:
 "I recently took maintainership of the befs file system [0]. This is
  the first time I send you a git pull request, so please let me know if
  all the below is OK.

  Salah Triki and myself have been cleaning the code and fixing a few
  small bugs.

  Sorry I couldn't send this sooner in the merge window, I was waiting
  to have my GPG key signed by kernel members at ELCE in Berlin a few
  days ago."

[0] https://lkml.org/lkml/2016/7/27/502

* tag 'befs-v4.9-rc1' of git://github.com/luisbg/linux-befs: (39 commits)
  befs: befs: fix style issues in datastream.c
  befs: improve documentation in datastream.c
  befs: fix typos in datastream.c
  befs: fix typos in btree.c
  befs: fix style issues in super.c
  befs: fix comment style
  befs: add check for ag_shift in superblock
  befs: dump inode_size superblock information
  befs: remove unnecessary initialization
  befs: fix typo in befs_sb_info
  befs: add flags field to validate superblock state
  befs: fix typo in befs_find_key
  befs: remove unused BEFS_BT_PARMATCH
  fs: befs: remove ret variable
  fs: befs: remove in vain variable assignment
  fs: befs: remove unnecessary *befs_sb variable
  fs: befs: remove useless initialization to zero
  fs: befs: remove in vain variable assignment
  fs: befs: Insert NULL inode to dentry
  fs: befs: Remove useless calls to brelse in befs_find_brun_dblindirect
  ...

1  2 
fs/befs/linuxvfs.c

diff --combined fs/befs/linuxvfs.c
@@@ -120,7 -120,7 +120,7 @@@ befs_get_block(struct inode *inode, sec
        struct super_block *sb = inode->i_sb;
        befs_data_stream *ds = &BEFS_I(inode)->i_data.ds;
        befs_block_run run = BAD_IADDR;
-       int res = 0;
+       int res;
        ulong disk_off;
  
        befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld",
@@@ -179,15 -179,16 +179,16 @@@ befs_lookup(struct inode *dir, struct d
                kfree(utfname);
  
        } else {
-               ret = befs_btree_find(sb, ds, dentry->d_name.name, &offset);
+               ret = befs_btree_find(sb, ds, name, &offset);
        }
  
        if (ret == BEFS_BT_NOT_FOUND) {
                befs_debug(sb, "<--- %s %pd not found", __func__, dentry);
+               d_add(dentry, NULL);
                return ERR_PTR(-ENOENT);
  
        } else if (ret != BEFS_OK || offset == 0) {
-               befs_warning(sb, "<--- %s Error", __func__);
+               befs_error(sb, "<--- %s Error", __func__);
                return ERR_PTR(-ENODATA);
        }
  
@@@ -211,56 -212,55 +212,55 @@@ befs_readdir(struct file *file, struct 
        befs_off_t value;
        int result;
        size_t keysize;
-       unsigned char d_type;
        char keybuf[BEFS_NAME_LEN + 1];
  
        befs_debug(sb, "---> %s name %pD, inode %ld, ctx->pos %lld",
                  __func__, file, inode->i_ino, ctx->pos);
  
- more:
-       result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1,
-                                keybuf, &keysize, &value);
+       while (1) {
+               result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1,
+                                        keybuf, &keysize, &value);
  
-       if (result == BEFS_ERR) {
-               befs_debug(sb, "<--- %s ERROR", __func__);
-               befs_error(sb, "IO error reading %pD (inode %lu)",
-                          file, inode->i_ino);
-               return -EIO;
-       } else if (result == BEFS_BT_END) {
-               befs_debug(sb, "<--- %s END", __func__);
-               return 0;
-       } else if (result == BEFS_BT_EMPTY) {
-               befs_debug(sb, "<--- %s Empty directory", __func__);
-               return 0;
-       }
+               if (result == BEFS_ERR) {
+                       befs_debug(sb, "<--- %s ERROR", __func__);
+                       befs_error(sb, "IO error reading %pD (inode %lu)",
+                                  file, inode->i_ino);
+                       return -EIO;
  
-       d_type = DT_UNKNOWN;
+               } else if (result == BEFS_BT_END) {
+                       befs_debug(sb, "<--- %s END", __func__);
+                       return 0;
  
-       /* Convert to NLS */
-       if (BEFS_SB(sb)->nls) {
-               char *nlsname;
-               int nlsnamelen;
-               result =
-                   befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen);
-               if (result < 0) {
-                       befs_debug(sb, "<--- %s ERROR", __func__);
-                       return result;
+               } else if (result == BEFS_BT_EMPTY) {
+                       befs_debug(sb, "<--- %s Empty directory", __func__);
+                       return 0;
                }
-               if (!dir_emit(ctx, nlsname, nlsnamelen,
-                                (ino_t) value, d_type)) {
+               /* Convert to NLS */
+               if (BEFS_SB(sb)->nls) {
+                       char *nlsname;
+                       int nlsnamelen;
+                       result =
+                           befs_utf2nls(sb, keybuf, keysize, &nlsname,
+                                        &nlsnamelen);
+                       if (result < 0) {
+                               befs_debug(sb, "<--- %s ERROR", __func__);
+                               return result;
+                       }
+                       if (!dir_emit(ctx, nlsname, nlsnamelen,
+                                     (ino_t) value, DT_UNKNOWN)) {
+                               kfree(nlsname);
+                               return 0;
+                       }
                        kfree(nlsname);
-                       return 0;
+               } else {
+                       if (!dir_emit(ctx, keybuf, keysize,
+                                     (ino_t) value, DT_UNKNOWN))
+                               return 0;
                }
-               kfree(nlsname);
-       } else {
-               if (!dir_emit(ctx, keybuf, keysize,
-                                (ino_t) value, d_type))
-                       return 0;
+               ctx->pos++;
        }
-       ctx->pos++;
-       goto more;
  }
  
  static struct inode *
@@@ -299,7 -299,6 +299,6 @@@ static struct inode *befs_iget(struct s
        struct befs_sb_info *befs_sb = BEFS_SB(sb);
        struct befs_inode_info *befs_ino;
        struct inode *inode;
-       long ret = -EIO;
  
        befs_debug(sb, "---> %s inode = %lu", __func__, ino);
  
                   befs_ino->i_inode_num.allocation_group,
                   befs_ino->i_inode_num.start, befs_ino->i_inode_num.len);
  
-       bh = befs_bread(sb, inode->i_ino);
+       bh = sb_bread(sb, inode->i_ino);
        if (!bh) {
                befs_error(sb, "unable to read inode block - "
                           "inode = %lu", inode->i_ino);
        unacquire_none:
        iget_failed(inode);
        befs_debug(sb, "<--- %s - Bad inode", __func__);
-       return ERR_PTR(ret);
+       return ERR_PTR(-EIO);
  }
  
  /* Initialize the inode cache. Called at fs setup.
@@@ -436,10 -435,9 +435,9 @@@ befs_init_inodecache(void
                                              0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD|SLAB_ACCOUNT),
                                              init_once);
-       if (befs_inode_cachep == NULL) {
-               pr_err("%s: Couldn't initialize inode slabcache\n", __func__);
+       if (befs_inode_cachep == NULL)
                return -ENOMEM;
-       }
        return 0;
  }
  
@@@ -524,8 -522,6 +522,6 @@@ befs_utf2nls(struct super_block *sb, co
  
        *out = result = kmalloc(maxlen, GFP_NOFS);
        if (!*out) {
-               befs_error(sb, "%s cannot allocate memory", __func__);
-               *out_len = 0;
                return -ENOMEM;
        }
  
@@@ -604,7 -600,6 +600,6 @@@ befs_nls2utf(struct super_block *sb, co
  
        *out = result = kmalloc(maxlen, GFP_NOFS);
        if (!*out) {
-               befs_error(sb, "%s cannot allocate memory", __func__);
                *out_len = 0;
                return -ENOMEM;
        }
        return -EILSEQ;
  }
  
- /**
-  * Use the
-  *
-  */
  enum {
        Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err,
  };
@@@ -760,19 -751,19 +751,19 @@@ befs_fill_super(struct super_block *sb
        long ret = -EINVAL;
        const unsigned long sb_block = 0;
        const off_t x86_sb_off = 512;
+       int blocksize;
  
        save_mount_options(sb, data);
  
        sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL);
-       if (sb->s_fs_info == NULL) {
-               pr_err("(%s): Unable to allocate memory for private "
-                      "portion of superblock. Bailing.\n", sb->s_id);
+       if (sb->s_fs_info == NULL)
                goto unacquire_none;
-       }
        befs_sb = BEFS_SB(sb);
  
        if (!parse_options((char *) data, &befs_sb->mount_opts)) {
-               befs_error(sb, "cannot parse mount options");
+               if (!silent)
+                       befs_error(sb, "cannot parse mount options");
                goto unacquire_priv_sbp;
        }
  
         * Will be set to real fs blocksize later.
         *
         * Linux 2.4.10 and later refuse to read blocks smaller than
 -       * the hardsect size for the device. But we also need to read at 
 +       * the logical block size for the device. But we also need to read at
         * least 1k to get the second 512 bytes of the volume.
         * -WD 10-26-01
         */ 
-       sb_min_blocksize(sb, 1024);
+       blocksize = sb_min_blocksize(sb, 1024);
+       if (!blocksize) {
+               if (!silent)
+                       befs_error(sb, "unable to set blocksize");
+               goto unacquire_priv_sbp;
+       }
  
        if (!(bh = sb_bread(sb, sb_block))) {
-               befs_error(sb, "unable to read superblock");
+               if (!silent)
+                       befs_error(sb, "unable to read superblock");
                goto unacquire_priv_sbp;
        }
  
        brelse(bh);
  
        if( befs_sb->num_blocks > ~((sector_t)0) ) {
-               befs_error(sb, "blocks count: %llu "
-                       "is larger than the host can use",
-                       befs_sb->num_blocks);
+               if (!silent)
+                       befs_error(sb, "blocks count: %llu is larger than the host can use",
+                                       befs_sb->num_blocks);
                goto unacquire_priv_sbp;
        }
  
        }
        sb->s_root = d_make_root(root);
        if (!sb->s_root) {
-               befs_error(sb, "get root inode failed");
+               if (!silent)
+                       befs_error(sb, "get root inode failed");
                goto unacquire_priv_sbp;
        }
  
        unacquire_priv_sbp:
        kfree(befs_sb->mount_opts.iocharset);
        kfree(sb->s_fs_info);
+       sb->s_fs_info = NULL;
  
        unacquire_none:
-       sb->s_fs_info = NULL;
        return ret;
  }