1From 79a7b5e1f387caf907ec88460cdb39b8364bfb0b Mon Sep 17 00:00:00 2001 2From: Theodore Ts'o <tytso@mit.edu> 3Date: Thu, 16 Mar 2023 22:57:10 -0400 4Subject: e2fsck: fix bad htree checksums in preen mode 5 6We attempt to fix directories which have a bad/corrupted htree index 7node by completely rebuilding the directory htree nodes. Since this 8is a very safe thing to do and has no risk of losing directory 9entries, we've enabled this for preen mode. Unfortunately, subsequent 10index nodes look like empty directory entries that fill the entire 11block --- without a checksum at the end of the directory. So these 12nodes will be treated as a completely corrupted directory block, and 13this will *not* be fixed while in preen mode. 14 15So add code to treat an empty directory entry which covers the entire 16block as valid if the directory is already on the list of inodes to be 17rebuilt. 18 19Addresses-Gooogle-Bug: 178607853 20Signed-off-by: Theodore Ts'o <tytso@mit.edu> 21--- 22 e2fsck/pass2.c | 16 ++++++++++++++-- 23 1 file changed, 14 insertions(+), 2 deletions(-) 24 25diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c 26index 287360943..2700e3409 100644 27--- a/e2fsck/pass2.c 28+++ b/e2fsck/pass2.c 29@@ -1341,7 +1341,18 @@ skip_checksum: 30 (rec_len < min_dir_len) || 31 ((rec_len % 4) != 0) || 32 ((ext2fs_dir_rec_len(ext2fs_dirent_name_len(dirent), 33- extended)) > rec_len)) { 34+ extended)) > rec_len)) 35+ problem = PR_2_DIR_CORRUPTED; 36+ if (problem) { 37+ if ((offset == 0) && 38+ (rec_len == fs->blocksize) && 39+ (dirent->inode == 0) && 40+ e2fsck_dir_will_be_rehashed(ctx, ino)) { 41+ problem = 0; 42+ max_block_size = fs->blocksize; 43+ } 44+ } 45+ if (problem) { 46 if (fix_problem(ctx, PR_2_DIR_CORRUPTED, 47 &cd->pctx)) { 48 #ifdef WORDS_BIGENDIAN 49@@ -1573,7 +1584,8 @@ skip_checksum: 50 */ 51 if (!(ctx->flags & E2F_FLAG_RESTART_LATER) && 52 !(ext2fs_test_inode_bitmap2(ctx->inode_used_map, 53- dirent->inode))) 54+ dirent->inode)) 55+ ) 56 problem = PR_2_UNUSED_INODE; 57 58 if (problem) { 59-- 60cgit 61