Don't allow mounting (or mounting R/W) of filesystems with unsupported
features (except for file types in directory entries, which will be supported soon). Centralized the magic number and compatibility checking. Dropped support for ancient (pre-0.2b) filesystems, as in the Linux version. Our "support" consisted of printing more details in the error message before failing at mount time.
This commit is contained in:
parent
f8515dd800
commit
6291b96b03
@ -101,9 +101,6 @@
|
||||
/*
|
||||
* The second extended file system magic number
|
||||
*/
|
||||
#ifndef notyet
|
||||
#define EXT2_PRE_02B_MAGIC 0xEF51
|
||||
#endif
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
|
||||
/*
|
||||
|
@ -107,6 +107,8 @@ VFS_SET(ext2fs_vfsops, ext2fs, 0);
|
||||
|
||||
static int ext2fs_inode_hash_lock;
|
||||
|
||||
static int ext2_check_sb_compat __P((struct ext2_super_block *es,
|
||||
dev_t dev, int ronly));
|
||||
static int compute_sb_data __P((struct vnode * devvp,
|
||||
struct ext2_super_block * es,
|
||||
struct ext2_sb_info * fs));
|
||||
@ -365,6 +367,36 @@ static int ext2_check_descriptors (struct ext2_sb_info * sb)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
ext2_check_sb_compat(es, dev, ronly)
|
||||
struct ext2_super_block *es;
|
||||
dev_t dev;
|
||||
int ronly;
|
||||
{
|
||||
|
||||
if (es->s_magic != EXT2_SUPER_MAGIC) {
|
||||
printf("ext2fs: %s: wrong magic number %#x (expected %#x)\n",
|
||||
devtoname(dev), es->s_magic, EXT2_SUPER_MAGIC);
|
||||
return (1);
|
||||
}
|
||||
if (es->s_rev_level > EXT2_GOOD_OLD_REV) {
|
||||
if (es->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPP) {
|
||||
printf(
|
||||
"WARNING: mount of %s denied due to unsupported optional features\n",
|
||||
devtoname(dev));
|
||||
return (1);
|
||||
}
|
||||
if (!ronly &&
|
||||
(es->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
|
||||
printf(
|
||||
"WARNING: R/W mount of %s denied due to unsupported optional features\n",
|
||||
devtoname(dev));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* this computes the fields of the ext2_sb_info structure from the
|
||||
* data in the ext2_super_block structure read in
|
||||
@ -506,14 +538,7 @@ ext2_reload(mountp, cred, p)
|
||||
if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
|
||||
return (error);
|
||||
es = (struct ext2_super_block *)bp->b_data;
|
||||
if (es->s_magic != EXT2_SUPER_MAGIC) {
|
||||
if(es->s_magic == EXT2_PRE_02B_MAGIC)
|
||||
printf("This filesystem bears the magic number of a pre "
|
||||
"0.2b version of ext2. This is not supported by "
|
||||
"Lites.\n");
|
||||
else
|
||||
printf("Wrong magic number: %x (expected %x for ext2 fs\n",
|
||||
es->s_magic, EXT2_SUPER_MAGIC);
|
||||
if (ext2_check_sb_compat(es, devvp->v_rdev, 0) != 0) {
|
||||
brelse(bp);
|
||||
return (EIO); /* XXX needs translation */
|
||||
}
|
||||
@ -629,14 +654,7 @@ ext2_mountfs(devvp, mp, p)
|
||||
if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
|
||||
goto out;
|
||||
es = (struct ext2_super_block *)bp->b_data;
|
||||
if (es->s_magic != EXT2_SUPER_MAGIC) {
|
||||
if(es->s_magic == EXT2_PRE_02B_MAGIC)
|
||||
printf("This filesystem bears the magic number of a pre "
|
||||
"0.2b version of ext2. This is not supported by "
|
||||
"Lites.\n");
|
||||
else
|
||||
printf("Wrong magic number: %x (expected %x for EXT2FS)\n",
|
||||
es->s_magic, EXT2_SUPER_MAGIC);
|
||||
if (ext2_check_sb_compat(es, dev, ronly) != 0) {
|
||||
error = EINVAL; /* XXX needs translation */
|
||||
goto out;
|
||||
}
|
||||
|
@ -101,9 +101,6 @@
|
||||
/*
|
||||
* The second extended file system magic number
|
||||
*/
|
||||
#ifndef notyet
|
||||
#define EXT2_PRE_02B_MAGIC 0xEF51
|
||||
#endif
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
|
||||
/*
|
||||
|
@ -107,6 +107,8 @@ VFS_SET(ext2fs_vfsops, ext2fs, 0);
|
||||
|
||||
static int ext2fs_inode_hash_lock;
|
||||
|
||||
static int ext2_check_sb_compat __P((struct ext2_super_block *es,
|
||||
dev_t dev, int ronly));
|
||||
static int compute_sb_data __P((struct vnode * devvp,
|
||||
struct ext2_super_block * es,
|
||||
struct ext2_sb_info * fs));
|
||||
@ -365,6 +367,36 @@ static int ext2_check_descriptors (struct ext2_sb_info * sb)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
ext2_check_sb_compat(es, dev, ronly)
|
||||
struct ext2_super_block *es;
|
||||
dev_t dev;
|
||||
int ronly;
|
||||
{
|
||||
|
||||
if (es->s_magic != EXT2_SUPER_MAGIC) {
|
||||
printf("ext2fs: %s: wrong magic number %#x (expected %#x)\n",
|
||||
devtoname(dev), es->s_magic, EXT2_SUPER_MAGIC);
|
||||
return (1);
|
||||
}
|
||||
if (es->s_rev_level > EXT2_GOOD_OLD_REV) {
|
||||
if (es->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPP) {
|
||||
printf(
|
||||
"WARNING: mount of %s denied due to unsupported optional features\n",
|
||||
devtoname(dev));
|
||||
return (1);
|
||||
}
|
||||
if (!ronly &&
|
||||
(es->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
|
||||
printf(
|
||||
"WARNING: R/W mount of %s denied due to unsupported optional features\n",
|
||||
devtoname(dev));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* this computes the fields of the ext2_sb_info structure from the
|
||||
* data in the ext2_super_block structure read in
|
||||
@ -506,14 +538,7 @@ ext2_reload(mountp, cred, p)
|
||||
if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
|
||||
return (error);
|
||||
es = (struct ext2_super_block *)bp->b_data;
|
||||
if (es->s_magic != EXT2_SUPER_MAGIC) {
|
||||
if(es->s_magic == EXT2_PRE_02B_MAGIC)
|
||||
printf("This filesystem bears the magic number of a pre "
|
||||
"0.2b version of ext2. This is not supported by "
|
||||
"Lites.\n");
|
||||
else
|
||||
printf("Wrong magic number: %x (expected %x for ext2 fs\n",
|
||||
es->s_magic, EXT2_SUPER_MAGIC);
|
||||
if (ext2_check_sb_compat(es, devvp->v_rdev, 0) != 0) {
|
||||
brelse(bp);
|
||||
return (EIO); /* XXX needs translation */
|
||||
}
|
||||
@ -629,14 +654,7 @@ ext2_mountfs(devvp, mp, p)
|
||||
if ((error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) != 0)
|
||||
goto out;
|
||||
es = (struct ext2_super_block *)bp->b_data;
|
||||
if (es->s_magic != EXT2_SUPER_MAGIC) {
|
||||
if(es->s_magic == EXT2_PRE_02B_MAGIC)
|
||||
printf("This filesystem bears the magic number of a pre "
|
||||
"0.2b version of ext2. This is not supported by "
|
||||
"Lites.\n");
|
||||
else
|
||||
printf("Wrong magic number: %x (expected %x for EXT2FS)\n",
|
||||
es->s_magic, EXT2_SUPER_MAGIC);
|
||||
if (ext2_check_sb_compat(es, dev, ronly) != 0) {
|
||||
error = EINVAL; /* XXX needs translation */
|
||||
goto out;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user