From 085757fcc22a86168ee6793dfad9a95d88fb09db Mon Sep 17 00:00:00 2001 From: Eric Whitney Date: Mon, 9 Sep 2013 10:53:03 -0400 Subject: [PATCH] e2fsck: don't report uninit extents past EOF invalid Commit d3f32c2db8 introduced a regression that caused e2fsck failures in xfstests generic 013, 070, 083, 091, and 263. Uninitialized extents created by fallocate() at the end of file with the FALLOC_FL_KEEP_SIZE flag were identified as invalid. However, because the file size is not increased when FALLOC_FL_KEEP_SIZE is used, uninitialized extents can correctly contain blocks located past the end of file. Fix this by filtering out possible invalid extents if they are uninitialized and extend past the block containing the end of file. Signed-off-by: Eric Whitney Signed-off-by: "Theodore Ts'o" Signed-off-by: Kir Kolyshkin --- e2fsck/pass1.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff -urN --exclude '*.orig' e2fsprogs-1.41.12-orig/e2fsck/pass1.c e2fsprogs-1.41.12/e2fsck/pass1.c --- e2fsprogs-1.41.12-orig/e2fsck/pass1.c 2013-11-08 23:03:51.000000000 +0400 +++ e2fsprogs-1.41.12/e2fsck/pass1.c 2013-11-08 23:13:31.000000000 +0400 @@ -1674,6 +1674,7 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx, struct process_block_struct *pb, blk64_t start_block, blk64_t end_block, + blk64_t eof_block, ext2_extent_handle_t ehandle) { struct ext2fs_extent extent; @@ -1702,7 +1703,9 @@ problem = PR_1_EXTENT_BAD_START_BLK; else if (extent.e_lblk < start_block) problem = PR_1_OUT_OF_ORDER_EXTENTS; - else if (end_block && last_lblk > end_block) + else if ((end_block && last_lblk > end_block) && + (!(extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT && + last_lblk > eof_block))) problem = PR_1_EXTENT_END_OUT_OF_BOUNDS; else if (is_leaf && (extent.e_pblk + extent.e_len) > @@ -1761,7 +1764,7 @@ ext2fs_extent_fix_parents(ehandle); } scan_extent_node(ctx, pctx, pb, extent.e_lblk, - last_lblk, ehandle); + last_lblk, eof_block, ehandle); if (pctx->errcode) return; pctx->errcode = ext2fs_extent_get(ehandle, @@ -1850,6 +1853,7 @@ ext2_filsys fs = ctx->fs; ext2_ino_t ino = pctx->ino; errcode_t retval; + blk64_t eof_lblk; pctx->errcode = ext2fs_extent_open2(fs, ino, inode, &ehandle); if (pctx->errcode) { @@ -1867,7 +1871,9 @@ ctx->extent_depth_count[info.max_depth]++; } - scan_extent_node(ctx, pctx, pb, 0, 0, ehandle); + eof_lblk = ((EXT2_I_SIZE(inode) + fs->blocksize - 1) >> + EXT2_BLOCK_SIZE_BITS(fs->super)) - 1; + scan_extent_node(ctx, pctx, pb, 0, 0, eof_lblk, ehandle); if (pctx->errcode && fix_problem(ctx, PR_1_EXTENT_ITERATE_FAILURE, pctx)) { pb->num_blocks = 0;