Add unprivileged ioctl BTRFS_IOC_GET_SUBVOL_ROOTREF which returns ROOT_REF information of the subvolume containing this inode except the subvolume name (this is because to prevent potential name leak). The subvolume name will be gained by user version of ino_lookup ioctl (BTRFS_IOC_INO_LOOKUP_USER) which also performs permission check. The min id of root ref's subvolume to be searched is specified by @min_id in struct btrfs_ioctl_get_subvol_rootref_args. After the search ends, @min_id is set to the last searched root ref's subvolid + 1. Also, if there are more root refs than BTRFS_MAX_ROOTREF_BUFFER_NUM, -EOVERFLOW is returned. Therefore the caller can just call this ioctl again without changing the argument to continue search.
Showing the changes to include/uapi/linux (1 of 2 files). Show all
Unified · Split
| @@ -785,6 +785,22 @@ struct btrfs_ioctl_get_subvol_info_args { · 784 unmodified lines | ||
| 785 | 785 | __u64 reserved[8]; |
| 786 | 786 | }; |
| 787 | 787 | |
| 788 | +#define BTRFS_MAX_ROOTREF_BUFFER_NUM 255 | |
| 789 | +struct btrfs_ioctl_get_subvol_rootref_args { | |
| 790 | + /* in/out, minimum id of rootref's treeid to be searched */ | |
| 791 | + __u64 min_treeid; | |
| 792 | + | |
| 793 | + /* out */ | |
| 794 | + struct { | |
| 795 | + __u64 treeid; | |
| 796 | + __u64 dirid; | |
| 797 | + } rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM]; | |
| 798 | + | |
| 799 | + /* out, number of found items */ | |
| 800 | + __u8 num_items; | |
| 801 | + __u8 align[7]; | |
| 802 | +}; | |
| 803 | + | |
| 788 | 804 | /* Error codes as returned by the kernel */ |
| 789 | 805 | enum btrfs_err_code { |
| 790 | 806 | BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, |
| @@ -905,5 +921,7 @@ enum btrfs_err_code { · 114 unmodified lines | ||
| 905 | 921 | struct btrfs_ioctl_logical_ino_args) |
| 906 | 922 | #define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \ |
| 907 | 923 | struct btrfs_ioctl_get_subvol_info_args) |
| 924 | +#define BTRFS_IOC_GET_SUBVOL_ROOTREF _IOWR(BTRFS_IOCTL_MAGIC, 61, \ | |
| 925 | + struct btrfs_ioctl_get_subvol_rootref_args) | |
| 908 | 926 | |
| 909 | 927 | #endif /* _UAPI_LINUX_BTRFS_H */ |