]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: fix indexed dir rehash failure with metadata_csum enabled
authorJan Kara <jack@suse.cz>
Thu, 13 Feb 2020 10:15:57 +0000 (11:15 +0100)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 7 Mar 2020 19:16:59 +0000 (14:16 -0500)
E2fsck directory rehashing code can fail with ENOSPC due to a bug in
ext2fs_htree_intnode_maxrecs() which fails to take metadata checksum
into account and thus e.g. e2fsck can decide to create 1 indirect level
of index tree when two are actually needed. Fix the logic to account for
metadata checksum.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2fs.h

index c949983949af6114896f53462fd8866f133503bc..69c8a3ff032a462ede8cdd3f988e8685d49d96c8 100644 (file)
@@ -2047,7 +2047,13 @@ _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
 
 _INLINE_ int ext2fs_htree_intnode_maxrecs(ext2_filsys fs, int blocks)
 {
-       return blocks * ((fs->blocksize - 8) / sizeof(struct ext2_dx_entry));
+       int csum_size = 0;
+
+       if ((EXT2_SB(fs->super)->s_feature_ro_compat &
+            EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) != 0)
+               csum_size = sizeof(struct ext2_dx_tail);
+       return blocks * ((fs->blocksize - (8 + csum_size)) /
+                                               sizeof(struct ext2_dx_entry));
 }
 
 /*