ext4_utils: mark uninitialized inode tables in block groups
Block groups that have no used inodes have their inode table left
uninitialized, unless -t is specified, in which case they are
explicitly zeroed. When they are uninitialized, writing a sparse
ext4 image over existing data can cause e2fsck to confuse the
uninitialized data for lost inodes.
Set the EXT4_BG_INODE_UNINIT flags on block groups that have no
used inodes. This flag requires the block group checksum feature
to be enabled, so also enable the checksum feature in the superblock
and compute the checksum for the block group.
Since zeroing the inode tables is now useless, remove the code for
it and deprecate the -t command line option.
Change-Id: I4927c1d866d051547cf0dadc8c8703ded0163925
diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c
index 43b4480..4b87c6e 100644
--- a/ext4_utils/ext4_utils.c
+++ b/ext4_utils/ext4_utils.c
@@ -25,6 +25,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <stddef.h>
#include <string.h>
#ifdef USE_MINGW
@@ -362,11 +363,12 @@
block group */
void ext4_update_free()
{
- unsigned int i;
+ u32 i;
for (i = 0; i < aux_info.groups; i++) {
u32 bg_free_blocks = get_free_blocks(i);
u32 bg_free_inodes = get_free_inodes(i);
+ u16 crc;
aux_info.bg_desc[i].bg_free_blocks_count = bg_free_blocks;
aux_info.sb->s_free_blocks_count_lo += bg_free_blocks;
@@ -375,6 +377,13 @@
aux_info.sb->s_free_inodes_count += bg_free_inodes;
aux_info.bg_desc[i].bg_used_dirs_count += get_directories(i);
+
+ aux_info.bg_desc[i].bg_flags = get_bg_flags(i);
+
+ crc = ext4_crc16(~0, aux_info.sb->s_uuid, sizeof(aux_info.sb->s_uuid));
+ crc = ext4_crc16(crc, &i, sizeof(i));
+ crc = ext4_crc16(crc, &aux_info.bg_desc[i], offsetof(struct ext2_group_desc, bg_checksum));
+ aux_info.bg_desc[i].bg_checksum = crc;
}
}