17
17
* Boston, MA 021110-1307, USA.
18
18
*/
19
19
20
- #ifndef _LINUX_BTRFS_H
21
- #define _LINUX_BTRFS_H
20
+ #ifndef _LIBBTRFSUTIL_BTRFS_H_
21
+ #define _LIBBTRFSUTIL_BTRFS_H_
22
+
22
23
#include <linux/types.h>
23
24
#include <linux/ioctl.h>
24
25
@@ -32,11 +33,18 @@ struct btrfs_ioctl_vol_args {
32
33
__s64 fd ;
33
34
char name [BTRFS_PATH_NAME_MAX + 1 ];
34
35
};
36
+ #define BTRFS_DEVICE_PATH_NAME_MAX 1024
37
+ #define BTRFS_SUBVOL_NAME_MAX 4039
35
38
36
- #define BTRFS_DEVICE_PATH_NAME_MAX 1024
37
- #define BTRFS_SUBVOL_NAME_MAX 4039
39
+ /*
40
+ * Obsolete since 5.15, functionality removed in kernel 5.7:
41
+ * BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
42
+ */
43
+ #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
44
+ #define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
38
45
39
46
#define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
47
+
40
48
#define BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4)
41
49
42
50
#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
@@ -78,6 +86,7 @@ struct btrfs_qgroup_limit {
78
86
* struct btrfs_qgroup_inherit.flags
79
87
*/
80
88
#define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
89
+ #define BTRFS_QGROUP_INHERIT_FLAGS_SUPP (BTRFS_QGROUP_INHERIT_SET_LIMITS)
81
90
82
91
struct btrfs_qgroup_inherit {
83
92
__u64 flags ;
@@ -94,21 +103,29 @@ struct btrfs_ioctl_qgroup_limit_args {
94
103
};
95
104
96
105
/*
97
- * flags for subvolumes
106
+ * Arguments for specification of subvolumes or devices, supporting by-name or
107
+ * by-id and flags
98
108
*
99
- * Used by:
100
- * struct btrfs_ioctl_vol_args_v2.flags
109
+ * The set of supported flags depends on the ioctl
101
110
*
102
111
* BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls:
103
112
* - BTRFS_IOC_SUBVOL_GETFLAGS
104
113
* - BTRFS_IOC_SUBVOL_SETFLAGS
105
114
*/
106
- /*
107
- * Obsolete since 5.15, functionality removed in kernel 5.7:
108
- * BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
109
- */
110
- #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
111
- #define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
115
+
116
+ /* Supported flags for BTRFS_IOC_RM_DEV_V2 */
117
+ #define BTRFS_DEVICE_REMOVE_ARGS_MASK \
118
+ (BTRFS_DEVICE_SPEC_BY_ID)
119
+
120
+ /* Supported flags for BTRFS_IOC_SNAP_CREATE_V2 and BTRFS_IOC_SUBVOL_CREATE_V2 */
121
+ #define BTRFS_SUBVOL_CREATE_ARGS_MASK \
122
+ (BTRFS_SUBVOL_RDONLY | \
123
+ BTRFS_SUBVOL_QGROUP_INHERIT)
124
+
125
+ /* Supported flags for BTRFS_IOC_SNAP_DESTROY_V2 */
126
+ #define BTRFS_SUBVOL_DELETE_ARGS_MASK \
127
+ (BTRFS_SUBVOL_SPEC_BY_ID)
128
+
112
129
struct btrfs_ioctl_vol_args_v2 {
113
130
__s64 fd ;
114
131
__u64 transid ;
@@ -227,7 +244,7 @@ struct btrfs_ioctl_dev_info_args {
227
244
* Optional, out.
228
245
*
229
246
* Showing the fsid of the device, allowing user space to check if this
230
- * device is a seed one.
247
+ * device is a seeding one.
231
248
*
232
249
* Introduced in v6.3, thus user space still needs to check if kernel
233
250
* changed this value. Older kernel will not touch the values here.
@@ -322,7 +339,6 @@ struct btrfs_ioctl_feature_flags {
322
339
/* balance control ioctl modes */
323
340
#define BTRFS_BALANCE_CTL_PAUSE 1
324
341
#define BTRFS_BALANCE_CTL_CANCEL 2
325
- #define BTRFS_BALANCE_CTL_RESUME 3
326
342
327
343
/*
328
344
* this is packed, because it should be exactly the same as its disk
@@ -577,6 +593,7 @@ struct btrfs_ioctl_search_args_v2 {
577
593
__u64 buf [0 ]; /* out - found items */
578
594
};
579
595
596
+ /* With a @src_length of zero, the range from @src_offset->EOF is cloned! */
580
597
struct btrfs_ioctl_clone_range_args {
581
598
__s64 src_fd ;
582
599
__u64 src_offset , src_length ;
@@ -591,6 +608,9 @@ struct btrfs_ioctl_clone_range_args {
591
608
*/
592
609
#define BTRFS_DEFRAG_RANGE_COMPRESS 1
593
610
#define BTRFS_DEFRAG_RANGE_START_IO 2
611
+ #define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | \
612
+ BTRFS_DEFRAG_RANGE_START_IO)
613
+
594
614
struct btrfs_ioctl_defrag_range_args {
595
615
/* start of the defrag operation */
596
616
__u64 start ;
@@ -895,6 +915,157 @@ struct btrfs_ioctl_get_subvol_rootref_args {
895
915
__u8 align [7 ];
896
916
};
897
917
918
+ /*
919
+ * Data and metadata for an encoded read or write.
920
+ *
921
+ * Encoded I/O bypasses any encoding automatically done by the filesystem (e.g.,
922
+ * compression). This can be used to read the compressed contents of a file or
923
+ * write pre-compressed data directly to a file.
924
+ *
925
+ * BTRFS_IOC_ENCODED_READ and BTRFS_IOC_ENCODED_WRITE are essentially
926
+ * preadv/pwritev with additional metadata about how the data is encoded and the
927
+ * size of the unencoded data.
928
+ *
929
+ * BTRFS_IOC_ENCODED_READ fills the given iovecs with the encoded data, fills
930
+ * the metadata fields, and returns the size of the encoded data. It reads one
931
+ * extent per call. It can also read data which is not encoded.
932
+ *
933
+ * BTRFS_IOC_ENCODED_WRITE uses the metadata fields, writes the encoded data
934
+ * from the iovecs, and returns the size of the encoded data. Note that the
935
+ * encoded data is not validated when it is written; if it is not valid (e.g.,
936
+ * it cannot be decompressed), then a subsequent read may return an error.
937
+ *
938
+ * Since the filesystem page cache contains decoded data, encoded I/O bypasses
939
+ * the page cache. Encoded I/O requires CAP_SYS_ADMIN.
940
+ */
941
+ struct btrfs_ioctl_encoded_io_args {
942
+ /* Input parameters for both reads and writes. */
943
+
944
+ /*
945
+ * iovecs containing encoded data.
946
+ *
947
+ * For reads, if the size of the encoded data is larger than the sum of
948
+ * iov[n].iov_len for 0 <= n < iovcnt, then the ioctl fails with
949
+ * ENOBUFS.
950
+ *
951
+ * For writes, the size of the encoded data is the sum of iov[n].iov_len
952
+ * for 0 <= n < iovcnt. This must be less than 128 KiB (this limit may
953
+ * increase in the future). This must also be less than or equal to
954
+ * unencoded_len.
955
+ */
956
+ const struct iovec * iov ;
957
+ /* Number of iovecs. */
958
+ unsigned long iovcnt ;
959
+ /*
960
+ * Offset in file.
961
+ *
962
+ * For writes, must be aligned to the sector size of the filesystem.
963
+ */
964
+ __s64 offset ;
965
+ /* Currently must be zero. */
966
+ __u64 flags ;
967
+
968
+ /*
969
+ * For reads, the following members are output parameters that will
970
+ * contain the returned metadata for the encoded data.
971
+ * For writes, the following members must be set to the metadata for the
972
+ * encoded data.
973
+ */
974
+
975
+ /*
976
+ * Length of the data in the file.
977
+ *
978
+ * Must be less than or equal to unencoded_len - unencoded_offset. For
979
+ * writes, must be aligned to the sector size of the filesystem unless
980
+ * the data ends at or beyond the current end of the file.
981
+ */
982
+ __u64 len ;
983
+ /*
984
+ * Length of the unencoded (i.e., decrypted and decompressed) data.
985
+ *
986
+ * For writes, must be no more than 128 KiB (this limit may increase in
987
+ * the future). If the unencoded data is actually longer than
988
+ * unencoded_len, then it is truncated; if it is shorter, then it is
989
+ * extended with zeroes.
990
+ */
991
+ __u64 unencoded_len ;
992
+ /*
993
+ * Offset from the first byte of the unencoded data to the first byte of
994
+ * logical data in the file.
995
+ *
996
+ * Must be less than unencoded_len.
997
+ */
998
+ __u64 unencoded_offset ;
999
+ /*
1000
+ * BTRFS_ENCODED_IO_COMPRESSION_* type.
1001
+ *
1002
+ * For writes, must not be BTRFS_ENCODED_IO_COMPRESSION_NONE.
1003
+ */
1004
+ __u32 compression ;
1005
+ /* Currently always BTRFS_ENCODED_IO_ENCRYPTION_NONE. */
1006
+ __u32 encryption ;
1007
+ /*
1008
+ * Reserved for future expansion.
1009
+ *
1010
+ * For reads, always returned as zero. Users should check for non-zero
1011
+ * bytes. If there are any, then the kernel has a newer version of this
1012
+ * structure with additional information that the user definition is
1013
+ * missing.
1014
+ *
1015
+ * For writes, must be zeroed.
1016
+ */
1017
+ __u8 reserved [64 ];
1018
+ };
1019
+
1020
+ /* Data is not compressed. */
1021
+ #define BTRFS_ENCODED_IO_COMPRESSION_NONE 0
1022
+ /* Data is compressed as a single zlib stream. */
1023
+ #define BTRFS_ENCODED_IO_COMPRESSION_ZLIB 1
1024
+ /*
1025
+ * Data is compressed as a single zstd frame with the windowLog compression
1026
+ * parameter set to no more than 17.
1027
+ */
1028
+ #define BTRFS_ENCODED_IO_COMPRESSION_ZSTD 2
1029
+ /*
1030
+ * Data is compressed sector by sector (using the sector size indicated by the
1031
+ * name of the constant) with LZO1X and wrapped in the format documented in
1032
+ * fs/btrfs/lzo.c. For writes, the compression sector size must match the
1033
+ * filesystem sector size.
1034
+ */
1035
+ #define BTRFS_ENCODED_IO_COMPRESSION_LZO_4K 3
1036
+ #define BTRFS_ENCODED_IO_COMPRESSION_LZO_8K 4
1037
+ #define BTRFS_ENCODED_IO_COMPRESSION_LZO_16K 5
1038
+ #define BTRFS_ENCODED_IO_COMPRESSION_LZO_32K 6
1039
+ #define BTRFS_ENCODED_IO_COMPRESSION_LZO_64K 7
1040
+ #define BTRFS_ENCODED_IO_COMPRESSION_TYPES 8
1041
+
1042
+ /* Data is not encrypted. */
1043
+ #define BTRFS_ENCODED_IO_ENCRYPTION_NONE 0
1044
+ #define BTRFS_ENCODED_IO_ENCRYPTION_TYPES 1
1045
+
1046
+ /*
1047
+ * Wait for subvolume cleaning process. This queries the kernel queue and it
1048
+ * can change between the calls.
1049
+ *
1050
+ * - FOR_ONE - specify the subvolid
1051
+ * - FOR_QUEUED - wait for all currently queued
1052
+ * - COUNT - count number of queued
1053
+ * - PEEK_FIRST - read which is the first in the queue (to be cleaned or being
1054
+ * cleaned already), or 0 if the queue is empty
1055
+ * - PEEK_LAST - read the last subvolid in the queue, or 0 if the queue is empty
1056
+ */
1057
+ struct btrfs_ioctl_subvol_wait {
1058
+ __u64 subvolid ;
1059
+ __u32 mode ;
1060
+ __u32 count ;
1061
+ };
1062
+
1063
+ #define BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE (0)
1064
+ #define BTRFS_SUBVOL_SYNC_WAIT_FOR_QUEUED (1)
1065
+ #define BTRFS_SUBVOL_SYNC_COUNT (2)
1066
+ #define BTRFS_SUBVOL_SYNC_PEEK_FIRST (3)
1067
+ #define BTRFS_SUBVOL_SYNC_PEEK_LAST (4)
1068
+
898
1069
/* Error codes as returned by the kernel */
899
1070
enum btrfs_err_code {
900
1071
BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1 ,
@@ -1025,5 +1196,11 @@ enum btrfs_err_code {
1025
1196
struct btrfs_ioctl_ino_lookup_user_args)
1026
1197
#define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \
1027
1198
struct btrfs_ioctl_vol_args_v2)
1028
-
1029
- #endif /* _LINUX_BTRFS_H */
1199
+ #define BTRFS_IOC_ENCODED_READ _IOR(BTRFS_IOCTL_MAGIC, 64, \
1200
+ struct btrfs_ioctl_encoded_io_args)
1201
+ #define BTRFS_IOC_ENCODED_WRITE _IOW(BTRFS_IOCTL_MAGIC, 64, \
1202
+ struct btrfs_ioctl_encoded_io_args)
1203
+ #define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \
1204
+ struct btrfs_ioctl_subvol_wait)
1205
+
1206
+ #endif /* _LIBBTRFSUTIL_BTRFS_H_ */
0 commit comments