xref: /linux-6.15/include/uapi/linux/btrfs.h (revision 9376ff9b)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Copyright (C) 2007 Oracle.  All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License v2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 021110-1307, USA.
18  */
19 
20 #ifndef _UAPI_LINUX_BTRFS_H
21 #define _UAPI_LINUX_BTRFS_H
22 #include <linux/types.h>
23 #include <linux/ioctl.h>
24 
25 #define BTRFS_IOCTL_MAGIC 0x94
26 #define BTRFS_VOL_NAME_MAX 255
27 #define BTRFS_LABEL_SIZE 256
28 
29 /* this should be 4k */
30 #define BTRFS_PATH_NAME_MAX 4087
31 struct btrfs_ioctl_vol_args {
32 	__s64 fd;
33 	char name[BTRFS_PATH_NAME_MAX + 1];
34 };
35 
36 #define BTRFS_DEVICE_PATH_NAME_MAX	1024
37 #define BTRFS_SUBVOL_NAME_MAX 		4039
38 
39 #define BTRFS_SUBVOL_CREATE_ASYNC	(1ULL << 0)
40 #define BTRFS_SUBVOL_RDONLY		(1ULL << 1)
41 #define BTRFS_SUBVOL_QGROUP_INHERIT	(1ULL << 2)
42 
43 #define BTRFS_DEVICE_SPEC_BY_ID		(1ULL << 3)
44 
45 #define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED		\
46 			(BTRFS_SUBVOL_CREATE_ASYNC |	\
47 			BTRFS_SUBVOL_RDONLY |		\
48 			BTRFS_SUBVOL_QGROUP_INHERIT |	\
49 			BTRFS_DEVICE_SPEC_BY_ID)
50 
51 #define BTRFS_FSID_SIZE 16
52 #define BTRFS_UUID_SIZE 16
53 #define BTRFS_UUID_UNPARSED_SIZE	37
54 
55 /*
56  * flags definition for qgroup limits
57  *
58  * Used by:
59  * struct btrfs_qgroup_limit.flags
60  * struct btrfs_qgroup_limit_item.flags
61  */
62 #define BTRFS_QGROUP_LIMIT_MAX_RFER	(1ULL << 0)
63 #define BTRFS_QGROUP_LIMIT_MAX_EXCL	(1ULL << 1)
64 #define BTRFS_QGROUP_LIMIT_RSV_RFER	(1ULL << 2)
65 #define BTRFS_QGROUP_LIMIT_RSV_EXCL	(1ULL << 3)
66 #define BTRFS_QGROUP_LIMIT_RFER_CMPR	(1ULL << 4)
67 #define BTRFS_QGROUP_LIMIT_EXCL_CMPR	(1ULL << 5)
68 
69 struct btrfs_qgroup_limit {
70 	__u64	flags;
71 	__u64	max_rfer;
72 	__u64	max_excl;
73 	__u64	rsv_rfer;
74 	__u64	rsv_excl;
75 };
76 
77 /*
78  * flags definition for qgroup inheritance
79  *
80  * Used by:
81  * struct btrfs_qgroup_inherit.flags
82  */
83 #define BTRFS_QGROUP_INHERIT_SET_LIMITS	(1ULL << 0)
84 
85 struct btrfs_qgroup_inherit {
86 	__u64	flags;
87 	__u64	num_qgroups;
88 	__u64	num_ref_copies;
89 	__u64	num_excl_copies;
90 	struct btrfs_qgroup_limit lim;
91 	__u64	qgroups[0];
92 };
93 
94 struct btrfs_ioctl_qgroup_limit_args {
95 	__u64	qgroupid;
96 	struct btrfs_qgroup_limit lim;
97 };
98 
99 /*
100  * flags for subvolumes
101  *
102  * Used by:
103  * struct btrfs_ioctl_vol_args_v2.flags
104  *
105  * BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls:
106  * - BTRFS_IOC_SUBVOL_GETFLAGS
107  * - BTRFS_IOC_SUBVOL_SETFLAGS
108  */
109 
110 struct btrfs_ioctl_vol_args_v2 {
111 	__s64 fd;
112 	__u64 transid;
113 	__u64 flags;
114 	union {
115 		struct {
116 			__u64 size;
117 			struct btrfs_qgroup_inherit __user *qgroup_inherit;
118 		};
119 		__u64 unused[4];
120 	};
121 	union {
122 		char name[BTRFS_SUBVOL_NAME_MAX + 1];
123 		__u64 devid;
124 	};
125 };
126 
127 /*
128  * structure to report errors and progress to userspace, either as a
129  * result of a finished scrub, a canceled scrub or a progress inquiry
130  */
131 struct btrfs_scrub_progress {
132 	__u64 data_extents_scrubbed;	/* # of data extents scrubbed */
133 	__u64 tree_extents_scrubbed;	/* # of tree extents scrubbed */
134 	__u64 data_bytes_scrubbed;	/* # of data bytes scrubbed */
135 	__u64 tree_bytes_scrubbed;	/* # of tree bytes scrubbed */
136 	__u64 read_errors;		/* # of read errors encountered (EIO) */
137 	__u64 csum_errors;		/* # of failed csum checks */
138 	__u64 verify_errors;		/* # of occurences, where the metadata
139 					 * of a tree block did not match the
140 					 * expected values, like generation or
141 					 * logical */
142 	__u64 no_csum;			/* # of 4k data block for which no csum
143 					 * is present, probably the result of
144 					 * data written with nodatasum */
145 	__u64 csum_discards;		/* # of csum for which no data was found
146 					 * in the extent tree. */
147 	__u64 super_errors;		/* # of bad super blocks encountered */
148 	__u64 malloc_errors;		/* # of internal kmalloc errors. These
149 					 * will likely cause an incomplete
150 					 * scrub */
151 	__u64 uncorrectable_errors;	/* # of errors where either no intact
152 					 * copy was found or the writeback
153 					 * failed */
154 	__u64 corrected_errors;		/* # of errors corrected */
155 	__u64 last_physical;		/* last physical address scrubbed. In
156 					 * case a scrub was aborted, this can
157 					 * be used to restart the scrub */
158 	__u64 unverified_errors;	/* # of occurences where a read for a
159 					 * full (64k) bio failed, but the re-
160 					 * check succeeded for each 4k piece.
161 					 * Intermittent error. */
162 };
163 
164 #define BTRFS_SCRUB_READONLY	1
165 struct btrfs_ioctl_scrub_args {
166 	__u64 devid;				/* in */
167 	__u64 start;				/* in */
168 	__u64 end;				/* in */
169 	__u64 flags;				/* in */
170 	struct btrfs_scrub_progress progress;	/* out */
171 	/* pad to 1k */
172 	__u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
173 };
174 
175 #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS	0
176 #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID	1
177 struct btrfs_ioctl_dev_replace_start_params {
178 	__u64 srcdevid;	/* in, if 0, use srcdev_name instead */
179 	__u64 cont_reading_from_srcdev_mode;	/* in, see #define
180 						 * above */
181 	__u8 srcdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1];	/* in */
182 	__u8 tgtdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1];	/* in */
183 };
184 
185 #define BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED	0
186 #define BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED		1
187 #define BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED		2
188 #define BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED		3
189 #define BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED		4
190 struct btrfs_ioctl_dev_replace_status_params {
191 	__u64 replace_state;	/* out, see #define above */
192 	__u64 progress_1000;	/* out, 0 <= x <= 1000 */
193 	__u64 time_started;	/* out, seconds since 1-Jan-1970 */
194 	__u64 time_stopped;	/* out, seconds since 1-Jan-1970 */
195 	__u64 num_write_errors;	/* out */
196 	__u64 num_uncorrectable_read_errors;	/* out */
197 };
198 
199 #define BTRFS_IOCTL_DEV_REPLACE_CMD_START			0
200 #define BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS			1
201 #define BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL			2
202 #define BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR			0
203 #define BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED		1
204 #define BTRFS_IOCTL_DEV_REPLACE_RESULT_ALREADY_STARTED		2
205 #define BTRFS_IOCTL_DEV_REPLACE_RESULT_SCRUB_INPROGRESS		3
206 struct btrfs_ioctl_dev_replace_args {
207 	__u64 cmd;	/* in */
208 	__u64 result;	/* out */
209 
210 	union {
211 		struct btrfs_ioctl_dev_replace_start_params start;
212 		struct btrfs_ioctl_dev_replace_status_params status;
213 	};	/* in/out */
214 
215 	__u64 spare[64];
216 };
217 
218 struct btrfs_ioctl_dev_info_args {
219 	__u64 devid;				/* in/out */
220 	__u8 uuid[BTRFS_UUID_SIZE];		/* in/out */
221 	__u64 bytes_used;			/* out */
222 	__u64 total_bytes;			/* out */
223 	__u64 unused[379];			/* pad to 4k */
224 	__u8 path[BTRFS_DEVICE_PATH_NAME_MAX];	/* out */
225 };
226 
227 struct btrfs_ioctl_fs_info_args {
228 	__u64 max_id;				/* out */
229 	__u64 num_devices;			/* out */
230 	__u8 fsid[BTRFS_FSID_SIZE];		/* out */
231 	__u32 nodesize;				/* out */
232 	__u32 sectorsize;			/* out */
233 	__u32 clone_alignment;			/* out */
234 	__u32 reserved32;
235 	__u64 reserved[122];			/* pad to 1k */
236 };
237 
238 /*
239  * feature flags
240  *
241  * Used by:
242  * struct btrfs_ioctl_feature_flags
243  */
244 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE		(1ULL << 0)
245 /*
246  * Older kernels (< 4.9) on big-endian systems produced broken free space tree
247  * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
248  * < 4.7.3).  If this bit is clear, then the free space tree cannot be trusted.
249  * btrfs-progs can also intentionally clear this bit to ask the kernel to
250  * rebuild the free space tree, however this might not work on older kernels
251  * that do not know about this bit. If not sure, clear the cache manually on
252  * first mount when booting older kernel versions.
253  */
254 #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID	(1ULL << 1)
255 
256 #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF	(1ULL << 0)
257 #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL	(1ULL << 1)
258 #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS	(1ULL << 2)
259 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO	(1ULL << 3)
260 #define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD	(1ULL << 4)
261 
262 /*
263  * older kernels tried to do bigger metadata blocks, but the
264  * code was pretty buggy.  Lets not let them try anymore.
265  */
266 #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA	(1ULL << 5)
267 
268 #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF	(1ULL << 6)
269 #define BTRFS_FEATURE_INCOMPAT_RAID56		(1ULL << 7)
270 #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA	(1ULL << 8)
271 #define BTRFS_FEATURE_INCOMPAT_NO_HOLES		(1ULL << 9)
272 
273 struct btrfs_ioctl_feature_flags {
274 	__u64 compat_flags;
275 	__u64 compat_ro_flags;
276 	__u64 incompat_flags;
277 };
278 
279 /* balance control ioctl modes */
280 #define BTRFS_BALANCE_CTL_PAUSE		1
281 #define BTRFS_BALANCE_CTL_CANCEL	2
282 
283 /*
284  * this is packed, because it should be exactly the same as its disk
285  * byte order counterpart (struct btrfs_disk_balance_args)
286  */
287 struct btrfs_balance_args {
288 	__u64 profiles;
289 	union {
290 		__u64 usage;
291 		struct {
292 			__u32 usage_min;
293 			__u32 usage_max;
294 		};
295 	};
296 	__u64 devid;
297 	__u64 pstart;
298 	__u64 pend;
299 	__u64 vstart;
300 	__u64 vend;
301 
302 	__u64 target;
303 
304 	__u64 flags;
305 
306 	/*
307 	 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
308 	 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
309 	 * and maximum
310 	 */
311 	union {
312 		__u64 limit;		/* limit number of processed chunks */
313 		struct {
314 			__u32 limit_min;
315 			__u32 limit_max;
316 		};
317 	};
318 
319 	/*
320 	 * Process chunks that cross stripes_min..stripes_max devices,
321 	 * BTRFS_BALANCE_ARGS_STRIPES_RANGE
322 	 */
323 	__u32 stripes_min;
324 	__u32 stripes_max;
325 
326 	__u64 unused[6];
327 } __attribute__ ((__packed__));
328 
329 /* report balance progress to userspace */
330 struct btrfs_balance_progress {
331 	__u64 expected;		/* estimated # of chunks that will be
332 				 * relocated to fulfill the request */
333 	__u64 considered;	/* # of chunks we have considered so far */
334 	__u64 completed;	/* # of chunks relocated so far */
335 };
336 
337 /*
338  * flags definition for balance
339  *
340  * Restriper's general type filter
341  *
342  * Used by:
343  * btrfs_ioctl_balance_args.flags
344  * btrfs_balance_control.flags (internal)
345  */
346 #define BTRFS_BALANCE_DATA		(1ULL << 0)
347 #define BTRFS_BALANCE_SYSTEM		(1ULL << 1)
348 #define BTRFS_BALANCE_METADATA		(1ULL << 2)
349 
350 #define BTRFS_BALANCE_TYPE_MASK		(BTRFS_BALANCE_DATA |	    \
351 					 BTRFS_BALANCE_SYSTEM |	    \
352 					 BTRFS_BALANCE_METADATA)
353 
354 #define BTRFS_BALANCE_FORCE		(1ULL << 3)
355 #define BTRFS_BALANCE_RESUME		(1ULL << 4)
356 
357 /*
358  * flags definitions for per-type balance args
359  *
360  * Balance filters
361  *
362  * Used by:
363  * struct btrfs_balance_args
364  */
365 #define BTRFS_BALANCE_ARGS_PROFILES	(1ULL << 0)
366 #define BTRFS_BALANCE_ARGS_USAGE	(1ULL << 1)
367 #define BTRFS_BALANCE_ARGS_DEVID	(1ULL << 2)
368 #define BTRFS_BALANCE_ARGS_DRANGE	(1ULL << 3)
369 #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
370 #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
371 #define BTRFS_BALANCE_ARGS_LIMIT_RANGE	(1ULL << 6)
372 #define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
373 #define BTRFS_BALANCE_ARGS_USAGE_RANGE	(1ULL << 10)
374 
375 #define BTRFS_BALANCE_ARGS_MASK			\
376 	(BTRFS_BALANCE_ARGS_PROFILES |		\
377 	 BTRFS_BALANCE_ARGS_USAGE |		\
378 	 BTRFS_BALANCE_ARGS_DEVID | 		\
379 	 BTRFS_BALANCE_ARGS_DRANGE |		\
380 	 BTRFS_BALANCE_ARGS_VRANGE |		\
381 	 BTRFS_BALANCE_ARGS_LIMIT |		\
382 	 BTRFS_BALANCE_ARGS_LIMIT_RANGE |	\
383 	 BTRFS_BALANCE_ARGS_STRIPES_RANGE |	\
384 	 BTRFS_BALANCE_ARGS_USAGE_RANGE)
385 
386 /*
387  * Profile changing flags.  When SOFT is set we won't relocate chunk if
388  * it already has the target profile (even though it may be
389  * half-filled).
390  */
391 #define BTRFS_BALANCE_ARGS_CONVERT	(1ULL << 8)
392 #define BTRFS_BALANCE_ARGS_SOFT		(1ULL << 9)
393 
394 
395 /*
396  * flags definition for balance state
397  *
398  * Used by:
399  * struct btrfs_ioctl_balance_args.state
400  */
401 #define BTRFS_BALANCE_STATE_RUNNING	(1ULL << 0)
402 #define BTRFS_BALANCE_STATE_PAUSE_REQ	(1ULL << 1)
403 #define BTRFS_BALANCE_STATE_CANCEL_REQ	(1ULL << 2)
404 
405 struct btrfs_ioctl_balance_args {
406 	__u64 flags;				/* in/out */
407 	__u64 state;				/* out */
408 
409 	struct btrfs_balance_args data;		/* in/out */
410 	struct btrfs_balance_args meta;		/* in/out */
411 	struct btrfs_balance_args sys;		/* in/out */
412 
413 	struct btrfs_balance_progress stat;	/* out */
414 
415 	__u64 unused[72];			/* pad to 1k */
416 };
417 
418 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
419 struct btrfs_ioctl_ino_lookup_args {
420 	__u64 treeid;
421 	__u64 objectid;
422 	char name[BTRFS_INO_LOOKUP_PATH_MAX];
423 };
424 
425 /* Search criteria for the btrfs SEARCH ioctl family. */
426 struct btrfs_ioctl_search_key {
427 	/*
428 	 * The tree we're searching in. 1 is the tree of tree roots, 2 is the
429 	 * extent tree, etc...
430 	 *
431 	 * A special tree_id value of 0 will cause a search in the subvolume
432 	 * tree that the inode which is passed to the ioctl is part of.
433 	 */
434 	__u64 tree_id;		/* in */
435 
436 	/*
437 	 * When doing a tree search, we're actually taking a slice from a
438 	 * linear search space of 136-bit keys.
439 	 *
440 	 * A full 136-bit tree key is composed as:
441 	 *   (objectid << 72) + (type << 64) + offset
442 	 *
443 	 * The individual min and max values for objectid, type and offset
444 	 * define the min_key and max_key values for the search range. All
445 	 * metadata items with a key in the interval [min_key, max_key] will be
446 	 * returned.
447 	 *
448 	 * Additionally, we can filter the items returned on transaction id of
449 	 * the metadata block they're stored in by specifying a transid range.
450 	 * Be aware that this transaction id only denotes when the metadata
451 	 * page that currently contains the item got written the last time as
452 	 * result of a COW operation.  The number does not have any meaning
453 	 * related to the transaction in which an individual item that is being
454 	 * returned was created or changed.
455 	 */
456 	__u64 min_objectid;	/* in */
457 	__u64 max_objectid;	/* in */
458 	__u64 min_offset;	/* in */
459 	__u64 max_offset;	/* in */
460 	__u64 min_transid;	/* in */
461 	__u64 max_transid;	/* in */
462 	__u32 min_type;		/* in */
463 	__u32 max_type;		/* in */
464 
465 	/*
466 	 * input: The maximum amount of results desired.
467 	 * output: The actual amount of items returned, restricted by any of:
468 	 *  - reaching the upper bound of the search range
469 	 *  - reaching the input nr_items amount of items
470 	 *  - completely filling the supplied memory buffer
471 	 */
472 	__u32 nr_items;		/* in/out */
473 
474 	/* align to 64 bits */
475 	__u32 unused;
476 
477 	/* some extra for later */
478 	__u64 unused1;
479 	__u64 unused2;
480 	__u64 unused3;
481 	__u64 unused4;
482 };
483 
484 struct btrfs_ioctl_search_header {
485 	__u64 transid;
486 	__u64 objectid;
487 	__u64 offset;
488 	__u32 type;
489 	__u32 len;
490 };
491 
492 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
493 /*
494  * the buf is an array of search headers where
495  * each header is followed by the actual item
496  * the type field is expanded to 32 bits for alignment
497  */
498 struct btrfs_ioctl_search_args {
499 	struct btrfs_ioctl_search_key key;
500 	char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
501 };
502 
503 struct btrfs_ioctl_search_args_v2 {
504 	struct btrfs_ioctl_search_key key; /* in/out - search parameters */
505 	__u64 buf_size;		   /* in - size of buffer
506 					    * out - on EOVERFLOW: needed size
507 					    *       to store item */
508 	__u64 buf[0];                       /* out - found items */
509 };
510 
511 struct btrfs_ioctl_clone_range_args {
512   __s64 src_fd;
513   __u64 src_offset, src_length;
514   __u64 dest_offset;
515 };
516 
517 /*
518  * flags definition for the defrag range ioctl
519  *
520  * Used by:
521  * struct btrfs_ioctl_defrag_range_args.flags
522  */
523 #define BTRFS_DEFRAG_RANGE_COMPRESS 1
524 #define BTRFS_DEFRAG_RANGE_START_IO 2
525 struct btrfs_ioctl_defrag_range_args {
526 	/* start of the defrag operation */
527 	__u64 start;
528 
529 	/* number of bytes to defrag, use (u64)-1 to say all */
530 	__u64 len;
531 
532 	/*
533 	 * flags for the operation, which can include turning
534 	 * on compression for this one defrag
535 	 */
536 	__u64 flags;
537 
538 	/*
539 	 * any extent bigger than this will be considered
540 	 * already defragged.  Use 0 to take the kernel default
541 	 * Use 1 to say every single extent must be rewritten
542 	 */
543 	__u32 extent_thresh;
544 
545 	/*
546 	 * which compression method to use if turning on compression
547 	 * for this defrag operation.  If unspecified, zlib will
548 	 * be used
549 	 */
550 	__u32 compress_type;
551 
552 	/* spare for later */
553 	__u32 unused[4];
554 };
555 
556 
557 #define BTRFS_SAME_DATA_DIFFERS	1
558 /* For extent-same ioctl */
559 struct btrfs_ioctl_same_extent_info {
560 	__s64 fd;		/* in - destination file */
561 	__u64 logical_offset;	/* in - start of extent in destination */
562 	__u64 bytes_deduped;	/* out - total # of bytes we were able
563 				 * to dedupe from this file */
564 	/* status of this dedupe operation:
565 	 * 0 if dedup succeeds
566 	 * < 0 for error
567 	 * == BTRFS_SAME_DATA_DIFFERS if data differs
568 	 */
569 	__s32 status;		/* out - see above description */
570 	__u32 reserved;
571 };
572 
573 struct btrfs_ioctl_same_args {
574 	__u64 logical_offset;	/* in - start of extent in source */
575 	__u64 length;		/* in - length of extent */
576 	__u16 dest_count;	/* in - total elements in info array */
577 	__u16 reserved1;
578 	__u32 reserved2;
579 	struct btrfs_ioctl_same_extent_info info[0];
580 };
581 
582 struct btrfs_ioctl_space_info {
583 	__u64 flags;
584 	__u64 total_bytes;
585 	__u64 used_bytes;
586 };
587 
588 struct btrfs_ioctl_space_args {
589 	__u64 space_slots;
590 	__u64 total_spaces;
591 	struct btrfs_ioctl_space_info spaces[0];
592 };
593 
594 struct btrfs_data_container {
595 	__u32	bytes_left;	/* out -- bytes not needed to deliver output */
596 	__u32	bytes_missing;	/* out -- additional bytes needed for result */
597 	__u32	elem_cnt;	/* out */
598 	__u32	elem_missed;	/* out */
599 	__u64	val[0];		/* out */
600 };
601 
602 struct btrfs_ioctl_ino_path_args {
603 	__u64				inum;		/* in */
604 	__u64				size;		/* in */
605 	__u64				reserved[4];
606 	/* struct btrfs_data_container	*fspath;	   out */
607 	__u64				fspath;		/* out */
608 };
609 
610 struct btrfs_ioctl_logical_ino_args {
611 	__u64				logical;	/* in */
612 	__u64				size;		/* in */
613 	__u64				reserved[3];	/* must be 0 for now */
614 	__u64				flags;		/* in, v2 only */
615 	/* struct btrfs_data_container	*inodes;	out   */
616 	__u64				inodes;
617 };
618 /* Return every ref to the extent, not just those containing logical block.
619  * Requires logical == extent bytenr. */
620 #define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET	(1ULL << 0)
621 
622 enum btrfs_dev_stat_values {
623 	/* disk I/O failure stats */
624 	BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
625 	BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
626 	BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
627 
628 	/* stats for indirect indications for I/O failures */
629 	BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
630 					 * contents is illegal: this is an
631 					 * indication that the block was damaged
632 					 * during read or write, or written to
633 					 * wrong location or read from wrong
634 					 * location */
635 	BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
636 					 * been written */
637 
638 	BTRFS_DEV_STAT_VALUES_MAX
639 };
640 
641 /* Reset statistics after reading; needs SYS_ADMIN capability */
642 #define	BTRFS_DEV_STATS_RESET		(1ULL << 0)
643 
644 struct btrfs_ioctl_get_dev_stats {
645 	__u64 devid;				/* in */
646 	__u64 nr_items;				/* in/out */
647 	__u64 flags;				/* in/out */
648 
649 	/* out values: */
650 	__u64 values[BTRFS_DEV_STAT_VALUES_MAX];
651 
652 	__u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
653 };
654 
655 #define BTRFS_QUOTA_CTL_ENABLE	1
656 #define BTRFS_QUOTA_CTL_DISABLE	2
657 #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED	3
658 struct btrfs_ioctl_quota_ctl_args {
659 	__u64 cmd;
660 	__u64 status;
661 };
662 
663 struct btrfs_ioctl_quota_rescan_args {
664 	__u64	flags;
665 	__u64   progress;
666 	__u64   reserved[6];
667 };
668 
669 struct btrfs_ioctl_qgroup_assign_args {
670 	__u64 assign;
671 	__u64 src;
672 	__u64 dst;
673 };
674 
675 struct btrfs_ioctl_qgroup_create_args {
676 	__u64 create;
677 	__u64 qgroupid;
678 };
679 struct btrfs_ioctl_timespec {
680 	__u64 sec;
681 	__u32 nsec;
682 };
683 
684 struct btrfs_ioctl_received_subvol_args {
685 	char	uuid[BTRFS_UUID_SIZE];	/* in */
686 	__u64	stransid;		/* in */
687 	__u64	rtransid;		/* out */
688 	struct btrfs_ioctl_timespec stime; /* in */
689 	struct btrfs_ioctl_timespec rtime; /* out */
690 	__u64	flags;			/* in */
691 	__u64	reserved[16];		/* in */
692 };
693 
694 /*
695  * Caller doesn't want file data in the send stream, even if the
696  * search of clone sources doesn't find an extent. UPDATE_EXTENT
697  * commands will be sent instead of WRITE commands.
698  */
699 #define BTRFS_SEND_FLAG_NO_FILE_DATA		0x1
700 
701 /*
702  * Do not add the leading stream header. Used when multiple snapshots
703  * are sent back to back.
704  */
705 #define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER	0x2
706 
707 /*
708  * Omit the command at the end of the stream that indicated the end
709  * of the stream. This option is used when multiple snapshots are
710  * sent back to back.
711  */
712 #define BTRFS_SEND_FLAG_OMIT_END_CMD		0x4
713 
714 #define BTRFS_SEND_FLAG_MASK \
715 	(BTRFS_SEND_FLAG_NO_FILE_DATA | \
716 	 BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \
717 	 BTRFS_SEND_FLAG_OMIT_END_CMD)
718 
719 struct btrfs_ioctl_send_args {
720 	__s64 send_fd;			/* in */
721 	__u64 clone_sources_count;	/* in */
722 	__u64 __user *clone_sources;	/* in */
723 	__u64 parent_root;		/* in */
724 	__u64 flags;			/* in */
725 	__u64 reserved[4];		/* in */
726 };
727 
728 /* Error codes as returned by the kernel */
729 enum btrfs_err_code {
730 	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
731 	BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
732 	BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
733 	BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
734 	BTRFS_ERROR_DEV_TGT_REPLACE,
735 	BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
736 	BTRFS_ERROR_DEV_ONLY_WRITABLE,
737 	BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
738 };
739 
740 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
741 				   struct btrfs_ioctl_vol_args)
742 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
743 				   struct btrfs_ioctl_vol_args)
744 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
745 				   struct btrfs_ioctl_vol_args)
746 #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
747 				   struct btrfs_ioctl_vol_args)
748 /* trans start and trans end are dangerous, and only for
749  * use by applications that know how to avoid the
750  * resulting deadlocks
751  */
752 #define BTRFS_IOC_TRANS_START  _IO(BTRFS_IOCTL_MAGIC, 6)
753 #define BTRFS_IOC_TRANS_END    _IO(BTRFS_IOCTL_MAGIC, 7)
754 #define BTRFS_IOC_SYNC         _IO(BTRFS_IOCTL_MAGIC, 8)
755 
756 #define BTRFS_IOC_CLONE        _IOW(BTRFS_IOCTL_MAGIC, 9, int)
757 #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
758 				   struct btrfs_ioctl_vol_args)
759 #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
760 				   struct btrfs_ioctl_vol_args)
761 #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
762 				   struct btrfs_ioctl_vol_args)
763 
764 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
765 				  struct btrfs_ioctl_clone_range_args)
766 
767 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
768 				   struct btrfs_ioctl_vol_args)
769 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
770 				struct btrfs_ioctl_vol_args)
771 #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
772 				struct btrfs_ioctl_defrag_range_args)
773 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
774 				   struct btrfs_ioctl_search_args)
775 #define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
776 					   struct btrfs_ioctl_search_args_v2)
777 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
778 				   struct btrfs_ioctl_ino_lookup_args)
779 #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
780 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
781 				    struct btrfs_ioctl_space_args)
782 #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
783 #define BTRFS_IOC_WAIT_SYNC  _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
784 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
785 				   struct btrfs_ioctl_vol_args_v2)
786 #define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \
787 				   struct btrfs_ioctl_vol_args_v2)
788 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
789 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
790 #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
791 			      struct btrfs_ioctl_scrub_args)
792 #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
793 #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
794 				       struct btrfs_ioctl_scrub_args)
795 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
796 				 struct btrfs_ioctl_dev_info_args)
797 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
798 			       struct btrfs_ioctl_fs_info_args)
799 #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
800 				   struct btrfs_ioctl_balance_args)
801 #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
802 #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
803 					struct btrfs_ioctl_balance_args)
804 #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
805 					struct btrfs_ioctl_ino_path_args)
806 #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
807 					struct btrfs_ioctl_logical_ino_args)
808 #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
809 				struct btrfs_ioctl_received_subvol_args)
810 #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
811 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
812 				     struct btrfs_ioctl_vol_args)
813 #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
814 			       struct btrfs_ioctl_quota_ctl_args)
815 #define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \
816 			       struct btrfs_ioctl_qgroup_assign_args)
817 #define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \
818 			       struct btrfs_ioctl_qgroup_create_args)
819 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
820 			       struct btrfs_ioctl_qgroup_limit_args)
821 #define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
822 			       struct btrfs_ioctl_quota_rescan_args)
823 #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
824 			       struct btrfs_ioctl_quota_rescan_args)
825 #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
826 #define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
827 				   char[BTRFS_LABEL_SIZE])
828 #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
829 				   char[BTRFS_LABEL_SIZE])
830 #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
831 				      struct btrfs_ioctl_get_dev_stats)
832 #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
833 				    struct btrfs_ioctl_dev_replace_args)
834 #define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \
835 					 struct btrfs_ioctl_same_args)
836 #define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
837 				   struct btrfs_ioctl_feature_flags)
838 #define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
839 				   struct btrfs_ioctl_feature_flags[2])
840 #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
841 				   struct btrfs_ioctl_feature_flags[3])
842 #define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
843 				   struct btrfs_ioctl_vol_args_v2)
844 #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \
845 					struct btrfs_ioctl_logical_ino_args)
846 
847 #endif /* _UAPI_LINUX_BTRFS_H */
848