]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/ext4/extents.c
ext4: fix the length returned by fiemap for an unallocated extent
[net-next-2.6.git] / fs / ext4 / extents.c
index 5f7295287de1d443218118ac8f010f56e6612432..4fec6b7463823244cb186ce0c4082b7b1dfc2eaa 100644 (file)
@@ -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);