From 598d20cc3c0f71561402e13c07aaf5880b85fa37 Mon Sep 17 00:00:00 2001 From: Tao Ma Date: Mon, 9 May 2011 23:38:42 +0800 Subject: [PATCH] mke2fs: make s_inodes_per_group >= 8 in ext2fs_initialize current mkfs.ext4 fails if we tried with the following parameters: mkfs.ext4 -m 0 -N 16 -O ^has_journal,^resize_inode,^uninit_bg,extent,meta_bg -b 1024 /dev/sdb3 It will cause segfault, but it is caused by another issue. See my patch "mke2fs: Avoid segmentation fault in ext2fs_alloc_generic_bmap". And with that patch, the mkfs.ext4 will fail with the error: /dev/sdb3: Memory allocation failed while setting up superblock The reason is that in ext2fs_initialize, we align s_inodes_per_group to 8, but fails to consider the case that s_inodes_per_group < 8. So make at least 8 inodes for s_inodes_per_group. Signed-off-by: Tao Ma Signed-off-by: Theodore Ts'o --- lib/ext2fs/initialize.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index e1f229b3..4706773a 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -282,6 +282,8 @@ ipg_retry: * multiple of 8. This is needed to simplify the bitmap * splicing code. */ + if (super->s_inodes_per_group < 8) + super->s_inodes_per_group = 8; super->s_inodes_per_group &= ~7; fs->inode_blocks_per_group = (((super->s_inodes_per_group * EXT2_INODE_SIZE(super)) + -- 2.11.0