From: Darrick J. Wong Date: Wed, 15 Feb 2012 20:11:46 +0000 (-0500) Subject: libext2fs: when truncating file, punch out blocks at end X-Git-Tag: v1.42.1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e89dbbd462b389b6406eb9f02eb63ca997b0e8a;p=thirdparty%2Fe2fsprogs.git libext2fs: when truncating file, punch out blocks at end Currently, ext2fs_file_set_size2 punches out data blocks between the end of the file and infinity when truncate_block <= old_truncate (i.e. when you've made the file longer). This is not a useful behavior, particularly since it *fails* to punch out the data blocks when the file is shortened (i.e. truncate_block < old_truncate). This seems to be the result of the test being backwards, so fix the code to punch only when the file is getting shorter. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c index d56f5b506..8751635b5 100644 --- a/lib/ext2fs/fileio.c +++ b/lib/ext2fs/fileio.c @@ -389,7 +389,7 @@ errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size) return retval; } - if (truncate_block <= old_truncate) + if (truncate_block >= old_truncate) return 0; return ext2fs_punch(file->fs, file->ino, &file->inode, 0,