From: Theodore Ts'o Date: Sat, 2 May 2009 23:05:37 +0000 (-0400) Subject: ext4: fix the length returned by fiemap for an unallocated extent X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=eefd7f03b86b8a319890e7fac5a6fcc7f8694b76;p=deliverable%2Flinux.git ext4: fix the length returned by fiemap for an unallocated extent If the file's blocks have not yet been allocated because of delayed allocation, the length of the extent returned by fiemap is incorrect. This commit fixes this bug. Signed-off-by: "Theodore Ts'o" --- diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 5f7295287de1..4fec6b746382 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3244,8 +3244,15 @@ static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path, * XXX this might miss a single-block extent at EXT_MAX_BLOCK */ if (ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK || - newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCK) + newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCK) { + loff_t size = i_size_read(inode); + loff_t bs = EXT4_BLOCK_SIZE(inode->i_sb); + flags |= FIEMAP_EXTENT_LAST; + if ((flags & FIEMAP_EXTENT_DELALLOC) && + logical+length > size) + length = (size - logical + bs - 1) & ~(bs-1); + } error = fiemap_fill_next_extent(fieinfo, logical, physical, length, flags);