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