Btrfs-progs: added ioctls and commands to resolve inodes and logical addrs
[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
24 #define BTRFS_IOCTL_MAGIC 0x94
25 #define BTRFS_VOL_NAME_MAX 255
26
27 /* this should be 4k */
28 #define BTRFS_PATH_NAME_MAX 4087
29 struct btrfs_ioctl_vol_args {
30         __s64 fd;
31         char name[BTRFS_PATH_NAME_MAX + 1];
32 };
33
34 #define BTRFS_SUBVOL_RDONLY             (1ULL << 1)
35 #define BTRFS_SUBVOL_NAME_MAX 4039
36
37 struct btrfs_ioctl_vol_args_v2 {
38         __s64 fd;
39         __u64 transid;
40         __u64 flags;
41         __u64 unused[4];
42         char name[BTRFS_SUBVOL_NAME_MAX + 1];
43 };
44
45 #define BTRFS_FSID_SIZE 16
46 #define BTRFS_UUID_SIZE 16
47
48 struct btrfs_scrub_progress {
49         __u64 data_extents_scrubbed;
50         __u64 tree_extents_scrubbed;
51         __u64 data_bytes_scrubbed;
52         __u64 tree_bytes_scrubbed;
53         __u64 read_errors;
54         __u64 csum_errors;
55         __u64 verify_errors;
56         __u64 no_csum;
57         __u64 csum_discards;
58         __u64 super_errors;
59         __u64 malloc_errors;
60         __u64 uncorrectable_errors;
61         __u64 corrected_errors;
62         __u64 last_physical;
63         __u64 unverified_errors;
64 };
65
66 #define BTRFS_SCRUB_READONLY    1
67 struct btrfs_ioctl_scrub_args {
68         __u64 devid;                            /* in */
69         __u64 start;                            /* in */
70         __u64 end;                              /* in */
71         __u64 flags;                            /* in */
72         struct btrfs_scrub_progress progress;   /* out */
73         /* pad to 1k */
74         __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
75 };
76
77 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
78 struct btrfs_ioctl_dev_info_args {
79         __u64 devid;                            /* in/out */
80         __u8 uuid[BTRFS_UUID_SIZE];             /* in/out */
81         __u64 bytes_used;                       /* out */
82         __u64 total_bytes;                      /* out */
83         __u64 unused[379];                      /* pad to 4k */
84         __u8 path[BTRFS_DEVICE_PATH_NAME_MAX];  /* out */
85 };
86
87 struct btrfs_ioctl_fs_info_args {
88         __u64 max_id;                           /* out */
89         __u64 num_devices;                      /* out */
90         __u8 fsid[BTRFS_FSID_SIZE];             /* out */
91         __u64 reserved[124];                    /* pad to 1k */
92 };
93
94 struct btrfs_ioctl_search_key {
95         /* which root are we searching.  0 is the tree of tree roots */
96         __u64 tree_id;
97
98         /* keys returned will be >= min and <= max */
99         __u64 min_objectid;
100         __u64 max_objectid;
101
102         /* keys returned will be >= min and <= max */
103         __u64 min_offset;
104         __u64 max_offset;
105
106         /* max and min transids to search for */
107         __u64 min_transid;
108         __u64 max_transid;
109
110         /* keys returned will be >= min and <= max */
111         __u32 min_type;
112         __u32 max_type;
113
114         /*
115          * how many items did userland ask for, and how many are we
116          * returning
117          */
118         __u32 nr_items;
119
120         /* align to 64 bits */
121         __u32 unused;
122
123         /* some extra for later */
124         __u64 unused1;
125         __u64 unused2;
126         __u64 unused3;
127         __u64 unused4;
128 };
129
130 struct btrfs_ioctl_search_header {
131         __u64 transid;
132         __u64 objectid;
133         __u64 offset;
134         __u32 type;
135         __u32 len;
136 } __attribute__((may_alias));
137
138 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
139 /*
140  * the buf is an array of search headers where
141  * each header is followed by the actual item
142  * the type field is expanded to 32 bits for alignment
143  */
144 struct btrfs_ioctl_search_args {
145         struct btrfs_ioctl_search_key key;
146         char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
147 };
148
149 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
150 struct btrfs_ioctl_ino_lookup_args {
151         __u64 treeid;
152         __u64 objectid;
153         char name[BTRFS_INO_LOOKUP_PATH_MAX];
154 };
155
156 /* flags for the defrag range ioctl */
157 #define BTRFS_DEFRAG_RANGE_COMPRESS 1
158 #define BTRFS_DEFRAG_RANGE_START_IO 2
159
160 struct btrfs_ioctl_defrag_range_args {
161         /* start of the defrag operation */
162         __u64 start;
163
164         /* number of bytes to defrag, use (u64)-1 to say all */
165         __u64 len;
166
167         /*
168          * flags for the operation, which can include turning
169          * on compression for this one defrag
170          */
171         __u64 flags;
172
173         /*
174          * any extent bigger than this will be considered
175          * already defragged.  Use 0 to take the kernel default
176          * Use 1 to say every single extent must be rewritten
177          */
178         __u32 extent_thresh;
179
180         /*
181          * which compression method to use if turning on compression
182          * for this defrag operation.  If unspecified, zlib will
183          * be used
184          */
185         __u32 compress_type;
186
187         /* spare for later */
188         __u32 unused[4];
189 };
190
191 struct btrfs_ioctl_space_info {
192         __u64 flags;
193         __u64 total_bytes;
194         __u64 used_bytes;
195 };
196
197 struct btrfs_ioctl_space_args {
198         __u64 space_slots;
199         __u64 total_spaces;
200         struct btrfs_ioctl_space_info spaces[0];
201 };
202
203 struct btrfs_data_container {
204         __u32   bytes_left;     /* out -- bytes not needed to deliver output */
205         __u32   bytes_missing;  /* out -- additional bytes needed for result */
206         __u32   elem_cnt;       /* out */
207         __u32   elem_missed;    /* out */
208         __u64   val[0];         /* out */
209 };
210
211 struct btrfs_ioctl_ino_path_args {
212         __u64                           inum;           /* in */
213         __u64                           size;           /* in */
214         __u64                           reserved[4];
215         /* struct btrfs_data_container  *fspath;           out */
216         __u64                           fspath;         /* out */
217 };
218
219 struct btrfs_ioctl_logical_ino_args {
220         __u64                           logical;        /* in */
221         __u64                           size;           /* in */
222         __u64                           reserved[4];
223         /* struct btrfs_data_container  *inodes;        out   */
224         __u64                           inodes;
225 };
226
227 /* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */
228 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
229                                    struct btrfs_ioctl_vol_args)
230 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
231                                    struct btrfs_ioctl_vol_args)
232 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
233                                    struct btrfs_ioctl_vol_args)
234 #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
235                                    struct btrfs_ioctl_vol_args)
236 /* trans start and trans end are dangerous, and only for
237  * use by applications that know how to avoid the
238  * resulting deadlocks
239  */
240 #define BTRFS_IOC_TRANS_START  _IO(BTRFS_IOCTL_MAGIC, 6)
241 #define BTRFS_IOC_TRANS_END    _IO(BTRFS_IOCTL_MAGIC, 7)
242 #define BTRFS_IOC_SYNC         _IO(BTRFS_IOCTL_MAGIC, 8)
243
244 #define BTRFS_IOC_CLONE        _IOW(BTRFS_IOCTL_MAGIC, 9, int)
245 #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
246                                    struct btrfs_ioctl_vol_args)
247 #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
248                                    struct btrfs_ioctl_vol_args)
249 #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
250                                    struct btrfs_ioctl_vol_args)
251 /* 13 is for CLONE_RANGE */
252 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
253                                    struct btrfs_ioctl_vol_args)
254 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
255                                    struct btrfs_ioctl_vol_args)
256 #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
257                                 struct btrfs_ioctl_defrag_range_args)
258 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
259                                    struct btrfs_ioctl_search_args)
260 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
261                                    struct btrfs_ioctl_ino_lookup_args)
262 #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
263 #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
264                                     struct btrfs_ioctl_space_args)
265 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
266                                    struct btrfs_ioctl_vol_args_v2)
267 #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
268                                 struct btrfs_ioctl_scrub_args)
269 #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
270 #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
271                                         struct btrfs_ioctl_scrub_args)
272 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
273                                         struct btrfs_ioctl_dev_info_args)
274 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
275                                  struct btrfs_ioctl_fs_info_args)
276 #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
277                                         struct btrfs_ioctl_ino_path_args)
278 #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
279                                         struct btrfs_ioctl_ino_path_args)
280
281 #endif