summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-06-20 12:38:29 +0200
committerCarl Hetherington <cth@carlh.net>2022-06-20 12:38:29 +0200
commitee865fa65f05e348cd4e0bce0552a2725ad5663a (patch)
treee913f8e39078da05cd8d3da4b5d763771c7ae6e8 /src
parent20f87c446b671c6a3fbb9387669041d8c5870c5b (diff)
Fix free block count in last block group.
This calculation is done when making the group bitmaps but wasn't being done here, so e2fsck would give an error with certain partition sizes.
Diffstat (limited to 'src')
-rw-r--r--src/ext4_mkfs.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ext4_mkfs.c b/src/ext4_mkfs.c
index 4ff2f75..4765926 100644
--- a/src/ext4_mkfs.c
+++ b/src/ext4_mkfs.c
@@ -322,8 +322,14 @@ static int write_bgroups(struct ext4_fs *fs, struct ext4_blockdev *bd, struct fs
uint32_t blk_off = 0;
struct ext4_bgroup* bg_desc = (struct ext4_bgroup *) (((char *) all_bg_desc) + i * dsc_size);
- bg_free_blk = info->blocks_per_group -
- aux_info->inode_table_blocks;
+
+ uint32_t blocks_in_group = info->blocks_per_group;
+ if (i == aux_info->groups - 1) {
+ blocks_in_group = (uint32_t)
+ (ext4_sb_get_blocks_cnt(aux_info->sb) - ext4_get32(aux_info->sb, first_data_block) - info->blocks_per_group * (ext4_block_group_cnt(aux_info->sb) - 1));
+ }
+
+ bg_free_blk = blocks_in_group - aux_info->inode_table_blocks;
bg_free_blk -= 2;
blk_off += aux_info->bg_desc_blocks;