2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
21 #include <asm/types.h>
22 #include <linux/ioctl.h>
25 #define BTRFS_IOCTL_MAGIC 0x94
26 #define BTRFS_VOL_NAME_MAX 255
28 /* this should be 4k */
29 #define BTRFS_PATH_NAME_MAX 4087
30 struct btrfs_ioctl_vol_args {
32 char name[BTRFS_PATH_NAME_MAX + 1];
35 #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
36 #define BTRFS_SUBVOL_NAME_MAX 4039
38 struct btrfs_ioctl_vol_args_v2 {
43 char name[BTRFS_SUBVOL_NAME_MAX + 1];
46 #define BTRFS_FSID_SIZE 16
47 #define BTRFS_UUID_SIZE 16
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;
61 __u64 uncorrectable_errors;
62 __u64 corrected_errors;
64 __u64 unverified_errors;
67 #define BTRFS_SCRUB_READONLY 1
68 struct btrfs_ioctl_scrub_args {
73 struct btrfs_scrub_progress progress; /* out */
75 __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
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 */
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 */
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
101 * this is packed, because it should be exactly the same as its disk
102 * byte order counterpart (struct btrfs_disk_balance_args)
104 struct btrfs_balance_args {
118 } __attribute__ ((__packed__));
120 struct btrfs_balance_progress {
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)
130 struct btrfs_ioctl_balance_args {
131 __u64 flags; /* in/out */
132 __u64 state; /* out */
134 struct btrfs_balance_args data; /* in/out */
135 struct btrfs_balance_args meta; /* in/out */
136 struct btrfs_balance_args sys; /* in/out */
138 struct btrfs_balance_progress stat; /* out */
140 __u64 unused[72]; /* pad to 1k */
143 struct btrfs_ioctl_search_key {
144 /* which root are we searching. 0 is the tree of tree roots */
147 /* keys returned will be >= min and <= max */
151 /* keys returned will be >= min and <= max */
155 /* max and min transids to search for */
159 /* keys returned will be >= min and <= max */
164 * how many items did userland ask for, and how many are we
169 /* align to 64 bits */
172 /* some extra for later */
179 struct btrfs_ioctl_search_header {
185 } __attribute__((may_alias));
187 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
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
193 struct btrfs_ioctl_search_args {
194 struct btrfs_ioctl_search_key key;
195 char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
198 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
199 struct btrfs_ioctl_ino_lookup_args {
202 char name[BTRFS_INO_LOOKUP_PATH_MAX];
205 /* flags for the defrag range ioctl */
206 #define BTRFS_DEFRAG_RANGE_COMPRESS 1
207 #define BTRFS_DEFRAG_RANGE_START_IO 2
209 struct btrfs_ioctl_defrag_range_args {
210 /* start of the defrag operation */
213 /* number of bytes to defrag, use (u64)-1 to say all */
217 * flags for the operation, which can include turning
218 * on compression for this one defrag
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
230 * which compression method to use if turning on compression
231 * for this defrag operation. If unspecified, zlib will
236 /* spare for later */
240 struct btrfs_ioctl_space_info {
246 struct btrfs_ioctl_space_args {
249 struct btrfs_ioctl_space_info spaces[0];
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 */
260 struct btrfs_ioctl_ino_path_args {
264 /* struct btrfs_data_container *fspath; out */
265 __u64 fspath; /* out */
268 struct btrfs_ioctl_logical_ino_args {
269 __u64 logical; /* in */
272 /* struct btrfs_data_container *inodes; out */
276 struct btrfs_ioctl_timespec {
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 */
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)
301 struct btrfs_ioctl_clone_range_args {
303 __u64 src_offset, src_length;
307 /* trans start and trans end are dangerous, and only for
308 * use by applications that know how to avoid the
309 * resulting deadlocks
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)
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)
360 #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
361 struct btrfs_ioctl_received_subvol_args)