Bug 206059 - [ext2fs][patch] EXT4: cannot mount filesystems < 512 MiB in size: "ext2fs: no space for extra inode timestamps"
Summary: [ext2fs][patch] EXT4: cannot mount filesystems < 512 MiB in size: "ext2fs: no...
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-fs mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-01-09 07:51 UTC by Damjan Jovanovic
Modified: 2016-01-14 01:58 UTC (History)
2 users (show)

See Also:


Attachments
Allow inode size < sizeof(struct ext2fs_dinode) when EXT2F_ROCOMPAT_EXTRA_ISIZE is set (998 bytes, patch)
2016-01-09 07:51 UTC, Damjan Jovanovic
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Damjan Jovanovic 2016-01-09 07:51:22 UTC
Created attachment 165293 [details]
Allow inode size < sizeof(struct ext2fs_dinode) when EXT2F_ROCOMPAT_EXTRA_ISIZE is set

When making the EXT4 filesystem, mkfs.ext4 uses different inode sizes depending on the filesystem file.

For a large filesystem, "dumpe2fs" returns these relevant fields:

Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Inode size:	          256
Required extra isize:     28
Desired extra isize:      28

For a small filesystem, "dumpe2fs" returns this instead, and "Required extra isize" and "Desired extra isize" are missing:

Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Inode size:	          128

Bisection searching with different filesystem sizes ("dd if=/dev/zero of=/tmp/filesystem bs=1M count=..." + "mkfs.ext4 /tmp/filesystem" + "dumpe2fs -h /tmp/filesystem") shows inode size 256 is used for filesystems >= 512 MiB, and smaller filesystems use inode size 128.

Attemping to mount the small filesystems fails with this error (and unless you've patched ext2fs with the patch from bug 206056, also panics the kernel!!):

ext2fs: no space for extra inode timestamps

That message comes from compute_sb_data() in ext2_vfsops.c, which does

       /* Check for extra isize in big inodes. */
       if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_EXTRA_ISIZE) &&
           EXT2_INODE_SIZE(fs) < sizeof(struct ext2fs_dinode)) {
               printf("ext2fs: no space for extra inode timestamps\n");
               return (EINVAL);
       }

which must be wrong, because even small filesystems have the extra_isize feature set, yet the inode size is 128 which is smaller than sizeof(struct ext2fs_dinode).

Since EXT2F_ROCOMPAT_EXTRA_ISIZE isn't used anywhere else in the ext2fs module, I've made a patch that deletes that entire section, and it gets the small filesystems to mount and work.
Comment 1 Pedro F. Giffuni freebsd_committer 2016-01-11 19:41:35 UTC
This is wrong:

Look at struct ext2fs_dinode (ext2_dinode.h). If the inode size is 128, the extra timestamps really don't fit. Any attempt to read beyond the 128 would be a buffer overflow.

I recall the big block sizes were used for handling (non standard) extended attributes and the extra_isize only started getting used with ext4.
I think this might be a bug in the GNU ext2fsprogs: technically you should disable the extra_isize with tune2fs before mounting such filesystems.
Comment 2 Pedro F. Giffuni freebsd_committer 2016-01-14 01:58:04 UTC
As explained, I think we are doing the right thing here.