aboutsummaryrefslogtreecommitdiff
path: root/lib/ext2fs/punch.c
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2013-12-12 13:25:40 -0500
committerTheodore Ts'o <tytso@mit.edu>2013-12-12 13:25:42 -0500
commit042a0f52ec79e448fd798df7757c6addeb00aede (patch)
treed4a3d1611e5ac8e6f181807e443d12827cf8a4f3 /lib/ext2fs/punch.c
parentdc9673abcf8e00f2b2e6e346b6312ef3745ac543 (diff)
downloade2fsprogs-042a0f52ec79e448fd798df7757c6addeb00aede.tar.gz
libext2fs: don't error out when punching a totally sparse file
If we're asked to punch a file with no data blocks mapped to it and a non-zero length, we don't need to do any work in ext2fs_punch_extent() and can return success. Unfortunately, the extent_get() function returns "no current node" because it (correctly) failed to find any extents, which is bubbled up to callers. Since no extents being found is not an error in this corner case, fix up ext2fs_punch_extent() to return 0 to callers. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/punch.c')
-rw-r--r--lib/ext2fs/punch.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c
index 9dfba2eb..ff051f73 100644
--- a/lib/ext2fs/punch.c
+++ b/lib/ext2fs/punch.c
@@ -198,10 +198,17 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
* next-lowest extent if 'start' is in a hole, and doesn't set a
* current node if there was a real error reading the extent tree.
* In that case, _get() will error out.
+ *
+ * Note: If _get() returns 'no current node', that simply means that
+ * there aren't any blocks mapped past this point in the file, so we're
+ * done.
*/
ext2fs_extent_goto(handle, start);
retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent);
- if (retval)
+ if (retval == EXT2_ET_NO_CURRENT_NODE) {
+ retval = 0;
+ goto errout;
+ } else if (retval)
goto errout;
while (1) {
op = EXT2_EXTENT_NEXT_LEAF;