BTRFS_IOC_INO_LOOKUP ioctl fixes
cover BTRFS_IOC_INO_LOOKUP ioctl fixes
This set of patches fixes 2 issues with the BTRFS_IOC_INO_LOOKUP ioctl:
1) missing error code return when path is too long;
2) ocassional ENOENT error even when the desired inode ref items exist.
Filipe David Borba Manana (2):
Btrfs: add missing error code to BTRFS_IOC_INO_LOOKUP handler
Btrfs: don't miss inode ref items in BTRFS_IOC_INO_LOOKUP
fs/btrfs/ioctl.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/2 Btrfs: add missing error code to BTRFS_IOC_INO_LOOKUP handler
If the path doesn't fit in the input buffer, return ENAMETOOLONG instead of returning with a success code (0) and a partially filled and right justified buffer.
Also removed useless buffer pointer check outside the while loop.
--- fs/btrfs/ioctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +3 -3
@@ -2015,8 +2015,10 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, len =btrfs_inode_ref_name_len (l, iref); ptr -= len +1 ; total_len += len +1 ; -if (ptr < name) +if (ptr < name) { + ret = -ENAMETOOLONG ; goto out; + } *(ptr + len) ='/' ;read_extent_buffer (l, ptr,(unsigned long )(iref +1 ), len);
@@ -2029,8 +2031,6 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, key.offset = (u64)-1 ; dirid = key.objectid; } -if (ptr < name) - goto out;memmove (name, ptr, total_len); name[total_len]='\0' ; ret =0 ;
Signature · 1 line
1.7.9.5
PATCH 2/2 Btrfs: don't miss inode ref items in BTRFS_IOC_INO_LOOKUP
In reply to Filipe David Borba MananaIf the inode ref key was not found and the current leaf slot was 0 (first item in the leaf) the code would always return -ENOENT. This was not correct because the desired inode ref item might be the last item in the previous leaf.
--- fs/btrfs/ioctl.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
fs/btrfs/ioctl.c +10 -8
@@ -1998,19 +1998,21 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 );if (ret <0 ) goto out; +else if (ret >0 ) { + ret =btrfs_previous_item (root, path, dirid, +BTRFS_INODE_REF_KEY ); +if (ret <0 ) + goto out; +else if (ret >0 ) { + ret = -ENOENT ; + goto out; + } + } l = path->nodes[0 ]; slot = path->slots[0 ]; -if (ret >0 && slot >0 ) - slot--;btrfs_item_key_to_cpu (l, &key, slot); -if (ret >0 && (key.objectid != dirid || - key.type !=BTRFS_INODE_REF_KEY )) { - ret = -ENOENT ; - goto out; - } - iref = btrfs_item_ptr(l, slot, struct btrfs_inode_ref); len =btrfs_inode_ref_name_len (l, iref); ptr -= len +1 ;
Signature · 1 line
1.7.9.5