Skip to content

Commit 2d324f5

Browse files
Liu Bokdave
authored andcommitted
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 <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1c8b5b6 commit 2d324f5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/btrfs/extent_io.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4389,8 +4389,12 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
43894389
if (ret < 0) {
43904390
btrfs_free_path(path);
43914391
return ret;
4392+
} else {
4393+
WARN_ON(!ret);
4394+
if (ret == 1)
4395+
ret = 0;
43924396
}
4393-
WARN_ON(!ret);
4397+
43944398
path->slots[0]--;
43954399
btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
43964400
found_type = found_key.type;

0 commit comments

Comments
 (0)