Btrfs-progs: update btrfs-progs for subvol uuid+times support
[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 __IOCTL_
20 #define __IOCTL_
21 #include <asm/types.h>
22 #include <linux/ioctl.h>
23 #include <time.h>
24
25 #define BTRFS_IOCTL_MAGIC 0x94
26 #define BTRFS_VOL_NAME_MAX 255
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_SUBVOL_RDONLY             (1ULL << 1)
36 #define BTRFS_SUBVOL_NAME_MAX 4039
37
38 struct btrfs_ioctl_vol_args_v2 {
39         __s64 fd;
40         __u64 transid;
41         __u64 flags;
42         __u64 unused[4];
43         char name[BTRFS_SUBVOL_NAME_MAX + 1];
44 };
45
46 #define BTRFS_FSID_SIZE 16
47 #define BTRFS_UUID_SIZE 16
48
49 struct btrfs_scrub_progress {
50         __u64 data_extents_scrubbed;
51         __u64 tree_extents_scrubbed;
52         __u64 data_bytes_scrubbed;
53         __u64 tree_bytes_scrubbed;
54         __u64 read_errors;
55         __u64 csum_errors;
56         __u64 verify_errors;
57         __u64 no_csum;
58         __u64 csum_discards;
59         __u64 super_errors;
60         __u64 malloc_errors;
61         __u64 uncorrectable_errors;
62         __u64 corrected_errors;
63         __u64 last_physical;
64         __u64 unverified_errors;
65 };
66
67 #define BTRFS_SCRUB_READONLY    1
68 struct btrfs_ioctl_scrub_args {
69         __u64 devid;                            /* in */
70         __u64 start;                            /* in */
71         __u64 end;                              /* in */
72         __u64 flags;                            /* in */
73         struct btrfs_scrub_progress progress;   /* out */
74         /* pad to 1k */
75         __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
76 };
77
78 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
79 struct btrfs_ioctl_dev_info_args {
80         __u64 devid;                            /* in/out */
81         __u8 uuid[BTRFS_UUID_SIZE];             /* in/out */
82         __u64 bytes_used;                       /* out */
83         __u64 total_bytes;                      /* out */
84         __u64 unused[379];                      /* pad to 4k */
85         __u8 path[BTRFS_DEVICE_PATH_NAME_MAX];  /* out */
86 };
87
88 struct btrfs_ioctl_fs_info_args {
89         __u64 max_id;                           /* out */
90         __u64 num_devices;                      /* out */
91         __u8 fsid[BTRFS_FSID_SIZE];             /* out */
92         __u64 reserved[124];                    /* pad to 1k */
93 };
94
95 /* balance control ioctl modes */
96 #define BTRFS_BALANCE_CTL_PAUSE         1
97 #define BTRFS_BALANCE_CTL_CANCEL        2
98 #define BTRFS_BALANCE_CTL_RESUME        3
99
100 /*
101  * this is packed, because it should be exactly the same as its disk
102  * byte order counterpart (struct btrfs_disk_balance_args)
103  */
104 struct btrfs_balance_args {
105         __u64 profiles;
106         __u64 usage;
107         __u64 devid;
108         __u64 pstart;
109         __u64 pend;
110         __u64 vstart;
111         __u64 vend;
112
113         __u64 target;
114
115         __u64 flags;
116
117         __u64 unused[8];
118 } __attribute__ ((__packed__));
119
120 struct btrfs_balance_progress {
121         __u64 expected;
122         __u64 considered;
123         __u64 completed;
124 };
125
126 #define BTRFS_BALANCE_STATE_RUNNING     (1ULL << 0)
127 #define BTRFS_BALANCE_STATE_PAUSE_REQ   (1ULL << 1)
128 #define BTRFS_BALANCE_STATE_CANCEL_REQ  (1ULL << 2)
129
130 struct btrfs_ioctl_balance_args {
131         __u64 flags;                            /* in/out */
132         __u64 state;                            /* out */
133
134         struct btrfs_balance_args data;         /* in/out */
135         struct btrfs_balance_args meta;         /* in/out */
136         struct btrfs_balance_args sys;          /* in/out */
137
138         struct btrfs_balance_progress stat;     /* out */
139
140         __u64 unused[72];                       /* pad to 1k */
141 };
142
143 struct btrfs_ioctl_search_key {
144         /* which root are we searching.  0 is the tree of tree roots */
145         __u64 tree_id;
146
147         /* keys returned will be >= min and <= max */
148         __u64 min_objectid;
149         __u64 max_objectid;
150
151         /* keys returned will be >= min and <= max */
152         __u64 min_offset;
153         __u64 max_offset;
154
155         /* max and min transids to search for */
156         __u64 min_transid;
157         __u64 max_transid;
158
159         /* keys returned will be >= min and <= max */
160         __u32 min_type;
161         __u32 max_type;
162
163         /*
164          * how many items did userland ask for, and how many are we
165          * returning
166          */
167         __u32 nr_items;
168
169         /* align to 64 bits */
170         __u32 unused;
171
172         /* some extra for later */
173         __u64 unused1;
174         __u64 unused2;
175         __u64 unused3;
176         __u64 unused4;
177 };
178
179 struct btrfs_ioctl_search_header {
180         __u64 transid;
181         __u64 objectid;
182         __u64 offset;
183         __u32 type;
184         __u32 len;
185 } __attribute__((may_alias));
186
187 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
188 /*
189  * the buf is an array of search headers where
190  * each header is followed by the actual item
191  * the type field is expanded to 32 bits for alignment
192  */
193 struct btrfs_ioctl_search_args {
194         struct btrfs_ioctl_search_key key;
195         char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
196 };
197
198 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
199 struct btrfs_ioctl_ino_lookup_args {
200         __u64 treeid;
201         __u64 objectid;
202         char name[BTRFS_INO_LOOKUP_PATH_MAX];
203 };
204
205 /* flags for the defrag range ioctl */
206 #define BTRFS_DEFRAG_RANGE_COMPRESS 1
207 #define BTRFS_DEFRAG_RANGE_START_IO 2
208
209 struct btrfs_ioctl_defrag_range_args {
210         /* start of the defrag operation */
211         __u64 start;
212
213         /* number of bytes to defrag, use (u64)-1 to say all */
214         __u64 len;
215
216         /*
217          * flags for the operation, which can include turning
218          * on compression for this one defrag
219          */
220         __u64 flags;
221
222         /*
223          * any extent bigger than this will be considered
224          * already defragged.  Use 0 to take the kernel default
225          * Use 1 to say every single extent must be rewritten
226          */
227         __u32 extent_thresh;
228
229         /*
230          * which compression method to use if turning on compression
231          * for this defrag operation.  If unspecified, zlib will
232          * be used
233          */
234         __u32 compress_type;
235
236         /* spare for later */
237         __u32 unused[4];
238 };
239
240 struct btrfs_ioctl_space_info {
241         __u64 flags;
242         __u64 total_bytes;
243         __u64 used_bytes;
244 };
245
246 struct btrfs_ioctl_space_args {
247         __u64 space_slots;
248         __u64 total_spaces;
249         struct btrfs_ioctl_space_info spaces[0];
250 };
251
252 struct btrfs_data_container {
253         __u32   bytes_left;     /* out -- bytes not needed to deliver output */
254         __u32   bytes_missing;  /* out -- additional bytes needed for result */
255         __u32   elem_cnt;       /* out */
256         __u32   elem_missed;    /* out */
257         __u64   val[0];         /* out */
258 };
259
260 struct btrfs_ioctl_ino_path_args {
261         __u64                           inum;           /* in */
262         __u64                           size;           /* in */
263         __u64                           reserved[4];
264         /* struct btrfs_data_container  *fspath;           out */
265         __u64                           fspath;         /* out */
266 };
267
268 struct btrfs_ioctl_logical_ino_args {
269         __u64                           logical;        /* in */
270         __u64                           size;           /* in */
271         __u64                           reserved[4];
272         /* struct btrfs_data_container  *inodes;        out   */
273         __u64                           inodes;
274 };
275
276 struct btrfs_ioctl_timespec {
277         __u64 sec;
278         __u32 nsec;
279 };
280
281 struct btrfs_ioctl_received_subvol_args {
282         char    uuid[BTRFS_UUID_SIZE];  /* in */
283         __u64   stransid;               /* in */
284         __u64   rtransid;               /* out */
285         struct btrfs_ioctl_timespec stime; /* in */
286         struct btrfs_ioctl_timespec rtime; /* out */
287         __u64   flags;                  /* in */
288         __u64   reserved[16];           /* in */
289 };
290
291 /* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
292 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
293                                    struct btrfs_ioctl_vol_args)
294 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
295                                    struct btrfs_ioctl_vol_args)
296 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
297                                    struct btrfs_ioctl_vol_args)
298 #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
299                                    struct btrfs_ioctl_vol_args)
300
301 struct btrfs_ioctl_clone_range_args {
302         __s64 src_fd;
303         __u64 src_offset, src_length;
304         __u64 dest_offset;
305 };
306
307 /* trans start and trans end are dangerous, and only for
308  * use by applications that know how to avoid the
309  * resulting deadlocks
310  */
311 #define BTRFS_IOC_TRANS_START  _IO(BTRFS_IOCTL_MAGIC, 6)
312 #define BTRFS_IOC_TRANS_END    _IO(BTRFS_IOCTL_MAGIC, 7)
313 #define BTRFS_IOC_SYNC         _IO(BTRFS_IOCTL_MAGIC, 8)
314
315 #define BTRFS_IOC_CLONE        _IOW(BTRFS_IOCTL_MAGIC, 9, int)
316 #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
317                                    struct btrfs_ioctl_vol_args)
318 #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
319                                    struct btrfs_ioctl_vol_args)
320 #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
321                                    struct btrfs_ioctl_vol_args)
322 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
323                                    struct btrfs_ioctl_clone_range_args)
324 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
325                                    struct btrfs_ioctl_vol_args)
326 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
327                                    struct btrfs_ioctl_vol_args)
328 #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
329                                 struct btrfs_ioctl_defrag_range_args)
330 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
331                                    struct btrfs_ioctl_search_args)
332 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
333                                    struct btrfs_ioctl_ino_lookup_args)
334 #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
335 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
336                                     struct btrfs_ioctl_space_args)
337 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
338                                    struct btrfs_ioctl_vol_args_v2)
339 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
340 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
341 #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
342                                 struct btrfs_ioctl_scrub_args)
343 #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
344 #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
345                                         struct btrfs_ioctl_scrub_args)
346 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
347                                         struct btrfs_ioctl_dev_info_args)
348 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
349                                  struct btrfs_ioctl_fs_info_args)
350 #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
351                                    struct btrfs_ioctl_balance_args)
352 #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
353 #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
354                                         struct btrfs_ioctl_balance_args)
355 #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
356                                         struct btrfs_ioctl_ino_path_args)
357 #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
358                                         struct btrfs_ioctl_ino_path_args)
359
360 #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
361                                 struct btrfs_ioctl_received_subvol_args)
362 #endif