Skip to contentSkip to conversation

ext2fs: make sure we have at least EXT2_FIRST_INO + 1 inodes

PATCH Applied Li Dongyang 3 participants 3 messages Jul 20, 2023 – Feb 8, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 Ib885735641dfa0ed9c6f6a4a1f9afec291673126
---
 lib/ext2fs/initialize.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
lib/ext2fs/initialize.c +9 -7
index edd692bb9..e96f3cabd 100644
@@ -307,13 +307,6 @@ retry:
 	else
 		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
@@ -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;
 
 	/*
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Li Dongyang

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

Quoted 5 lines

Increase s_inodes_per_group with a step of 8 to make sure we have at least EXT2_FIRST_INO + 1 inodes.

Change-Id Ib885735641dfa0ed9c6f6a4a1f9afec291673126

Cheers, Andreas

#2 lore raw
In reply to Li Dongyang
Quoted 9 lines · Li Dongyang

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

[...]

Applied, thanks!

[1/1] ext2fs: make sure we have at least EXT2_FIRST_INO + 1 inodes

      commit: 196cd1224ccaf5ca76540fc0a6238695d4476ca9

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>