summaryrefslogtreecommitdiff
path: root/ext4_utils/ext4_utils.c
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2013-02-04 00:44:55 -0800
committerColin Cross <ccross@android.com>2013-02-04 15:33:50 -0800
commit56497f28bd20001dd5f931208e8d948cf2f81b2f (patch)
tree00a35e7640dd9b44d6a63fc86633ae7eb8d05cec /ext4_utils/ext4_utils.c
parent682a27cbce4935a6598c42a248855eb5878c1115 (diff)
downloadextras-56497f28bd20001dd5f931208e8d948cf2f81b2f.tar.gz
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
Diffstat (limited to 'ext4_utils/ext4_utils.c')
-rw-r--r--ext4_utils/ext4_utils.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c
index 43b44806..4b87c6e4 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 @@ void ext4_create_journal_inode()
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 @@ void ext4_update_free()
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;
}
}