El dom, 29-06-2008 a las 23:19 +0200, Robert Millan escribió: > On Sun, Jun 29, 2008 at 09:53:50PM +0200, Javier Martín wrote: > > Ext4 is as of today in development and unstable; in fact, the FS name in > > Linux is "ext4dev", but I _think_ the on-disk format is already frozen > > and thus a readonly driver can be written. I'm not saying that we should > > delay the implementation of such a driver, just the we first need to > > address the potentially fatal problem of an ext4 FS mounted as ext3/2. > > No distro enables ext4 by default. > > Yep. update-grub heavily relies on grub-probe to figure out if a filesystem > will be accessible, and therefore whether to enable optional features. >
Here is the patch I was talking about, one step farther than I had first envisioned, i.e. not just about ext4 but an (solid?) implementation of "xenophobia" in the filesystem driver. This code checks the superblock backwards-incompatible features bitfield against a predefined set of features that we do support, and refuses to mount the filesystem if there are any that we don't. In particular, this makes the driver reject ext4 filesystems with the "extents" option enabled. As I don't know what INCOMPAT_* features are implemented, I've added the one I'm sure we do support because it is used in the code: "filetype". However, someone with insight in the ext2 driver should take a look at the patch and add all INCOMPAT_* features that we support to the new define created to that effect: EXT2_DRIVER_SUPPORTED_INCOMPAT. Just OR the new flags with the one in there. Failure to do so might cause regressions if this patch is committed (i.e. FS that mounted fine before will now refuse to do so), but will ensure that we only try to read what we can. I've copied the EXTn_FEATURE_* #defines from the Linux kernel headers, but only two are actually used (filetype and has_journal, which was already there, presumably to detect ext3 filesystems) - the rest are there for completion, but can be removed if you deem it better, though I'd suggest keeping at least the EXTn_FEATURE_INCOMPAT_* macros. This patch has been tested on a qemu virtual machine, with two ext2 partitions that started identical. I mounted one of them as ext4dev with the extents option and copied a new file to it, thus enabling the "extents" bit in the superblock. Without the patch, GRUB would happily read both partitions as ext2 (I didn't try to read the new file, but most probably that would have caused some havoc). With the patch, the ext4 partition is shown as "unknown filesystem". A good changelog entry might be "fs/ext2.c: ext2 driver will now reject filesystems with unknown incompatible features". This patch detects only "incompatible" features, so ext3 devices with internal journal should continue to work as they did. Phew, that was all (I hope) Cheers! Habbit
Index: fs/ext2.c =================================================================== RCS file: /sources/grub/grub2/fs/ext2.c,v retrieving revision 1.26 diff -u -r1.26 ext2.c --- fs/ext2.c 16 Jun 2008 19:02:07 -0000 1.26 +++ fs/ext2.c 30 Jun 2008 02:36:13 -0000 @@ -71,7 +71,33 @@ ? EXT2_GOOD_OLD_INODE_SIZE \ : grub_le_to_cpu16 (data->sblock.inode_size)) -#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 +/* Superblock filesystem feature flags (RW compatible) */ +#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 +#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 +#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008 +#define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010 +#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 +/* Superblock filesystem feature flags (RO compatible) */ +#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 +#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 +#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 +#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 +#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 +/* Superblock filesystem feature flags (back-incompatible) */ +#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ +#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 +#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */ +#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 +#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 + +/* The set of back-incompatible features this driver DOES support. Add (OR) + * flags here as the related features are implemented into the driver */ +#define EXT2_DRIVER_SUPPORTED_INCOMPAT ( EXT2_FEATURE_INCOMPAT_FILETYPE ) #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U @@ -394,6 +420,11 @@ if (grub_le_to_cpu16 (data->sblock.magic) != EXT2_MAGIC) goto fail; + /* Check the FS doesn't have feature bits enabled that we don't support */ + if (grub_le_to_cpu32 (data->sblock.feature_incompat) + & ~EXT2_DRIVER_SUPPORTED_INCOMPAT) + goto fail; + data->disk = disk; data->diropen.data = data; @@ -409,7 +440,8 @@ return data; fail: - grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem"); + grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem, or incompatible" + "features enabled (extents, etc.)"); grub_free (data); return 0; }
signature.asc
Description: Esta parte del mensaje está firmada digitalmente
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel