From: Li Dongyang Date: Thu, 20 Jul 2023 12:43:31 +0000 (+1000) Subject: LU-16971 ext2fs: make sure we have at least EXT2_FIRST_INO + 1 inodes X-Git-Tag: v1.47.0-wc4~2 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F22%2F51722%2F2;p=tools%2Fe2fsprogs.git LU-16971 ext2fs: make sure we have at least EXT2_FIRST_INO + 1 inodes When creating a small fs with 100 1k blocks, mke2fs fails with: Creating filesystem with 100 1k blocks and 8 inodes Allocating group tables: done Writing inode tables: done ext2fs_mkdir: Could not allocate inode in ext2 filesystem while creating /lost+found Increase s_inodes_per_group with a step of 8 to make sure we have at least EXT2_FIRST_INO + 1 inodes. Change-Id: I5ac30bdadf72e17780ebef93b2e81365a8a90641 Signed-off-by: Li Dongyang Reviewed-on: https://review.whamcloud.com/c/tools/e2fsprogs/+/51722 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index edd692b..e96f3ca 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -308,13 +308,6 @@ retry: set_field(s_inodes_count, ext2fs_blocks_count(super) / i); /* - * Make sure we have at least EXT2_FIRST_INO + 1 inodes, so - * that we have enough inodes for the filesystem(!) - */ - if (super->s_inodes_count < EXT2_FIRST_INODE(super)+1) - super->s_inodes_count = EXT2_FIRST_INODE(super)+1; - - /* * There should be at least as many inodes as the user * requested. Figure out how many inodes per group that * should be. But make sure that we don't allocate more than @@ -375,6 +368,15 @@ ipg_retry: } super->s_inodes_count = super->s_inodes_per_group * fs->group_desc_count; + /* + * Make sure we have at least EXT2_FIRST_INO + 1 inodes, so + * that we have enough inodes for the filesystem(!) + */ + if (super->s_inodes_count < EXT2_FIRST_INODE(super)+1) { + ipg += 8; + goto ipg_retry; + } + super->s_free_inodes_count = super->s_inodes_count; /*