|
74 | 74 | #include <linux/highmem.h>
|
75 | 75 | #include <linux/pagemap.h>
|
76 | 76 | #include <linux/uaccess.h>
|
| 77 | +#include <linux/major.h> |
77 | 78 | #include "internal.h"
|
78 | 79 |
|
79 | 80 | static struct kmem_cache *romfs_inode_cachep;
|
@@ -416,7 +417,22 @@ static void romfs_destroy_inode(struct inode *inode)
|
416 | 417 | static int romfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
417 | 418 | {
|
418 | 419 | struct super_block *sb = dentry->d_sb;
|
419 |
| - u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 420 | + u64 id = 0; |
| 421 | + |
| 422 | + /* When calling huge_encode_dev(), |
| 423 | + * use sb->s_bdev->bd_dev when, |
| 424 | + * - CONFIG_ROMFS_ON_BLOCK defined |
| 425 | + * use sb->s_dev when, |
| 426 | + * - CONFIG_ROMFS_ON_BLOCK undefined and |
| 427 | + * - CONFIG_ROMFS_ON_MTD defined |
| 428 | + * leave id as 0 when, |
| 429 | + * - CONFIG_ROMFS_ON_BLOCK undefined and |
| 430 | + * - CONFIG_ROMFS_ON_MTD undefined |
| 431 | + */ |
| 432 | + if (sb->s_bdev) |
| 433 | + id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 434 | + else if (sb->s_dev) |
| 435 | + id = huge_encode_dev(sb->s_dev); |
420 | 436 |
|
421 | 437 | buf->f_type = ROMFS_MAGIC;
|
422 | 438 | buf->f_namelen = ROMFS_MAXFN;
|
@@ -489,6 +505,11 @@ static int romfs_fill_super(struct super_block *sb, void *data, int silent)
|
489 | 505 | sb->s_flags |= MS_RDONLY | MS_NOATIME;
|
490 | 506 | sb->s_op = &romfs_super_ops;
|
491 | 507 |
|
| 508 | +#ifdef CONFIG_ROMFS_ON_MTD |
| 509 | + /* Use same dev ID from the underlying mtdblock device */ |
| 510 | + if (sb->s_mtd) |
| 511 | + sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, sb->s_mtd->index); |
| 512 | +#endif |
492 | 513 | /* read the image superblock and check it */
|
493 | 514 | rsb = kmalloc(512, GFP_KERNEL);
|
494 | 515 | if (!rsb)
|
|
0 commit comments