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