Skip to contentSkip to conversation

romfs: use different way to generate fsid for BLOCK or MTD

PATCH Superseded Coly Li 2 participants 2 messages Dec 28, 2016 VFS

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Coly Li

author
#0 lore raw

PATCH 1/1 romfs: use different way to generate fsid for BLOCK or MTD

'Commit 8a59f5d25265 ("fs/romfs: return f_fsid for statfs(2)")' generates a 64bit id from sb->s_bdev->bd_dev. This is only correct when romfs is defined with CONFIG_ROMFS_ON_BLOCK. If romfs is defined with CONFIG_ROMFS_ON_MTD, sb->s_bdev is NULL, referencing sb->s_bdev->bd_dev will triger an oops.

If romfs is built on top of a MTD abstracted block device, this MTD block device has a device ID generated by MTD_BLOCK_MAJOR and mtd index. This patch uses the same ID to generate fsid for the romfs on top of the MTD block device. Generally only one romfs can be built on single MTD block device, this method is enough to identify multiple romfs instances in a computer.

If romfs is built on top of a common block device, sb->s_bdev->bd_dev is used to generate the 64bit id, as previous commit did.

---
 fs/romfs/super.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
fs/romfs/super.c +14 -1
index d0f8a38..170f174 100644
@@ -416,8 +416,14 @@ static void romfs_destroy_inode(struct inode *inode)
 static int romfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct super_block *sb = dentry->d_sb;
-	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
+	u64 id = 0;
 
+#ifdef CONFIG_ROMFS_ON_BLOCK
+	id = huge_encode_dev(sb->s_bdev->bd_dev);
+#endif
+#ifdef CONFIG_ROMFS_ON_MTD
+	id = huge_encode_dev(sb->s_dev);
+#endif
 	buf->f_type = ROMFS_MAGIC;
 	buf->f_namelen = ROMFS_MAXFN;
 	buf->f_bsize = ROMBSIZE;
@@ -489,6 +495,13 @@ static int romfs_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_flags |= MS_RDONLY | MS_NOATIME;
 	sb->s_op = &romfs_super_ops;
 
+#ifdef CONFIG_ROMFS_ON_MTD
+	/* Use same dev ID from the underlying mtdblock device */
+	if (sb->s_mtd)
+		sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, sb->s_mtd->index);
+	else
+		sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, 0);
+#endif
 	/* read the image superblock and check it */
 	rsb = kmalloc(512, GFP_KERNEL);
 	if (!rsb)
Signature · 1 line
2.6.6
#1 lore raw
url: https://github.com/0day-ci/linux/commits/Coly-Li/romfs-use-different-way-to-generate-fsid-for-BLOCK-or-MTD/20161228-160154 config: i386-randconfig-x006-201652 (attached as .config) compiler…

Hi Coly,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.10-rc1 next-20161224]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Coly-Li/romfs-use-different-way-to-generate-fsid-for-BLOCK-or-MTD/20161228-160154
config: i386-randconfig-x006-201652 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

In file included from include/linux/fs.h:6:0,

                    from fs/romfs/super.c:63:
   fs/romfs/super.c: In function 'romfs_fill_super':
>> fs/romfs/super.c:501:21: error: 'MTD_BLOCK_MAJOR' undeclared (first use in this function)
      sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, sb->s_mtd->index);
                        ^
   include/linux/kdev_t.h:11:25: note: in definition of macro 'MKDEV'
    #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
                            ^~
   fs/romfs/super.c:501:21: note: each undeclared identifier is reported only once for each function it appears in
      sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, sb->s_mtd->index);
                        ^
   include/linux/kdev_t.h:11:25: note: in definition of macro 'MKDEV'
    #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
                            ^~

vim +/MTD_BLOCK_MAJOR +501 fs/romfs/super.c

495 sb->s_flags |= MS_RDONLY | MS_NOATIME;
496 sb->s_op = &romfs_super_ops;
497
498 #ifdef CONFIG_ROMFS_ON_MTD
499 /* Use same dev ID from the underlying mtdblock device */
500 if (sb->s_mtd)

 > 501			sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, sb->s_mtd->index);

502 else
503 sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, 0);
504 #endif

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation