aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2016-05-17 20:21:48 -0400
committerDavid Sterba <dsterba@suse.com>2016-05-25 13:53:54 -0400
commit2d324f59f343967a03eeb2690f0ff178304d0687 (patch)
treefa0bf2fb3cb07b89b049542e70ad523d6cad67f5
parent1c8b5b6e8b570a8038fa42cf9e7c23782bd4882c (diff)
Btrfs: fix unexpected return value of fiemap
btrfs's fiemap is supposed to return 0 on success and return < 0 on error. however, ret becomes 1 after looking up the last file extent: btrfs_lookup_file_extent -> btrfs_search_slot(..., ins_len=0, cow=0) and if the offset is beyond EOF, we'll get 'path' pointed to the place of potentail insertion, and ret == 1. This may confuse applications using ioctl(FIEL_IOC_FIEMAP). Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/extent_io.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 2f83448d34fe..f661688c2102 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4389,8 +4389,12 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4389 if (ret < 0) { 4389 if (ret < 0) {
4390 btrfs_free_path(path); 4390 btrfs_free_path(path);
4391 return ret; 4391 return ret;
4392 } else {
4393 WARN_ON(!ret);
4394 if (ret == 1)
4395 ret = 0;
4392 } 4396 }
4393 WARN_ON(!ret); 4397
4394 path->slots[0]--; 4398 path->slots[0]--;
4395 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]); 4399 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
4396 found_type = found_key.type; 4400 found_type = found_key.type;