]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: when truncating file, punch out blocks at end
authorDarrick J. Wong <djwong@us.ibm.com>
Wed, 15 Feb 2012 20:11:46 +0000 (15:11 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 17 Feb 2012 19:32:10 +0000 (14:32 -0500)
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 <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/fileio.c

index d56f5b506402b29e3f29c1a6881eaab73b5a9932..8751635b5c9aa70c746cd8d0eb4e01cc83f80ce8 100644 (file)
@@ -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,