blob: 8f91a6c1f69480c3a33badb9f8a8aaaa0c343afe [file] [log] [blame]
Dmitry V. Levin22129182016-05-24 01:32:09 +00001#include "tests.h"
2
3#ifdef HAVE_LINUX_BTRFS_H
4
Jeff Mahoney35866792016-05-18 18:09:42 -04005#include <errno.h>
Jeff Mahoney35866792016-05-18 18:09:42 -04006#include <fcntl.h>
Dmitry V. Levin28a5f662016-05-24 01:32:41 +00007#include <inttypes.h>
8#include <limits.h>
9#include <stdbool.h>
10#include <stdint.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <unistd.h>
15#include <sys/fcntl.h>
16#include <sys/ioctl.h>
17#include <sys/stat.h>
18#include <sys/vfs.h>
Jeff Mahoney35866792016-05-18 18:09:42 -040019#include <linux/fs.h>
20#include <linux/btrfs.h>
21#include <linux/magic.h>
Jeff Mahoney35866792016-05-18 18:09:42 -040022#include "xlat.h"
23
24#include "xlat/btrfs_balance_args.h"
25#include "xlat/btrfs_balance_flags.h"
26#include "xlat/btrfs_balance_state.h"
27#include "xlat/btrfs_compress_types.h"
28#include "xlat/btrfs_defrag_flags.h"
29#include "xlat/btrfs_dev_stats_values.h"
30#include "xlat/btrfs_dev_stats_flags.h"
31#include "xlat/btrfs_qgroup_inherit_flags.h"
32#include "xlat/btrfs_qgroup_limit_flags.h"
33#include "xlat/btrfs_scrub_flags.h"
34#include "xlat/btrfs_send_flags.h"
35#include "xlat/btrfs_space_info_flags.h"
36#include "xlat/btrfs_snap_flags_v2.h"
37#include "xlat/btrfs_tree_objectids.h"
38#include "xlat/btrfs_features_compat.h"
39#include "xlat/btrfs_features_compat_ro.h"
40#include "xlat/btrfs_features_incompat.h"
41#include "xlat/btrfs_key_types.h"
42
Dmitry V. Levin22129182016-05-24 01:32:09 +000043#ifdef HAVE_LINUX_FIEMAP_H
44# include <linux/fiemap.h>
45# include "xlat/fiemap_flags.h"
46# include "xlat/fiemap_extent_flags.h"
47#endif
Jeff Mahoney35866792016-05-18 18:09:42 -040048
49#ifndef BTRFS_LABEL_SIZE
Dmitry V. Levin2447de42016-05-24 01:32:55 +000050# define BTRFS_LABEL_SIZE 256
Jeff Mahoney35866792016-05-18 18:09:42 -040051#endif
52
53#ifndef BTRFS_NAME_LEN
Dmitry V. Levin2447de42016-05-24 01:32:55 +000054# define BTRFS_NAME_LEN 255
Jeff Mahoney35866792016-05-18 18:09:42 -040055#endif
56
Dmitry V. Levin6697d152016-05-24 02:56:39 +000057/*
58 * Prior to Linux 3.12, the BTRFS_IOC_DEFAULT_SUBVOL used u64 in
59 * its definition, which isn't exported by the kernel.
60 */
61typedef __u64 u64;
62
Jeff Mahoney35866792016-05-18 18:09:42 -040063static const char *btrfs_test_root;
64static int btrfs_test_dir_fd;
65static bool verbose = false;
66static bool write_ok = false;
67
68const unsigned char uuid_reference[BTRFS_UUID_SIZE] = {
69 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
70 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
71};
72
73const char uuid_reference_string[] = "01234567-89ab-cdef-fedc-ba9876543210";
74
Dmitry V. Levinfe7a4512016-06-17 03:02:46 +030075#ifndef BTRFS_IOC_QUOTA_RESCAN
76struct btrfs_ioctl_quota_rescan_args {
77 uint64_t flags, progress, reserved[6];
78};
79# define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
80 struct btrfs_ioctl_quota_rescan_args)
81# define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
82 struct btrfs_ioctl_quota_rescan_args)
83#endif
84
85#ifndef BTRFS_IOC_QUOTA_RESCAN_WAIT
86# define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
87#endif
88
Jeff Mahoney35866792016-05-18 18:09:42 -040089#ifndef BTRFS_IOC_GET_FEATURES
Dmitry V. Levin2447de42016-05-24 01:32:55 +000090# define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
Jeff Mahoney35866792016-05-18 18:09:42 -040091 struct btrfs_ioctl_feature_flags)
Dmitry V. Levin2447de42016-05-24 01:32:55 +000092# define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
Jeff Mahoney35866792016-05-18 18:09:42 -040093 struct btrfs_ioctl_feature_flags[2])
Dmitry V. Levin2447de42016-05-24 01:32:55 +000094# define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
Jeff Mahoney35866792016-05-18 18:09:42 -040095 struct btrfs_ioctl_feature_flags[3])
96#endif
97
98#ifndef HAVE_STRUCT_BTRFS_IOCTL_FEATURE_FLAGS_COMPAT_FLAGS
99struct btrfs_ioctl_feature_flags {
100 uint64_t compat_flags;
101 uint64_t compat_ro_flags;
102 uint64_t incompat_flags;
103};
104#endif
105
106#ifndef HAVE_STRUCT_BTRFS_IOCTL_DEFRAG_RANGE_ARGS_START
107struct btrfs_ioctl_defrag_range_args {
108 uint64_t start;
109 uint64_t len;
110 uint64_t flags;
111 uint32_t extent_thresh;
112 uint32_t compress_type;
113 uint32_t unused[4];
114};
115#endif
116
117#ifndef FIDEDUPERANGE
Dmitry V. Levin2447de42016-05-24 01:32:55 +0000118# define FIDEDUPERANGE _IOWR(0x94, 54, struct file_dedupe_range)
Jeff Mahoney35866792016-05-18 18:09:42 -0400119struct file_dedupe_range_info {
120 int64_t dest_fd; /* in - destination file */
121 uint64_t dest_offset; /* in - start of extent in destination */
122 uint64_t bytes_deduped; /* out - total # of bytes we were able
123 * to dedupe from this file. */
124 /* status of this dedupe operation:
125 * < 0 for error
126 * == FILE_DEDUPE_RANGE_SAME if dedupe succeeds
127 * == FILE_DEDUPE_RANGE_DIFFERS if data differs
128 */
129 int32_t status; /* out - see above description */
130 uint32_t reserved; /* must be zero */
131};
132
133struct file_dedupe_range {
134 uint64_t src_offset; /* in - start of extent in source */
135 uint64_t src_length; /* in - length of extent */
136 uint16_t dest_count; /* in - total elements in info array */
137 uint16_t reserved1; /* must be zero */
138 uint32_t reserved2; /* must be zero */
139 struct file_dedupe_range_info info[0];
140};
141#endif
142
143#ifndef BTRFS_IOC_TREE_SEARCH_V2
Dmitry V. Levin2447de42016-05-24 01:32:55 +0000144# define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
Jeff Mahoney35866792016-05-18 18:09:42 -0400145 struct btrfs_ioctl_search_args_v2)
146struct btrfs_ioctl_search_args_v2 {
147 struct btrfs_ioctl_search_key key; /* in/out - search parameters */
148 uint64_t buf_size; /* in - size of buffer
149 * out - on EOVERFLOW: needed size
150 * to store item */
151 uint64_t buf[0]; /* out - found items */
152};
153#endif
154
155
Dmitry V. Levin2447de42016-05-24 01:32:55 +0000156static const char *
157maybe_print_uint64max(uint64_t val)
Jeff Mahoney35866792016-05-18 18:09:42 -0400158{
159 if (val == UINT64_MAX)
160 return " /* UINT64_MAX */";
161 return "";
162}
163
164/* takes highest valid flag bit */
Dmitry V. Levin2447de42016-05-24 01:32:55 +0000165static uint64_t
166max_flags_plus_one(int bit)
Jeff Mahoney35866792016-05-18 18:09:42 -0400167{
168 int i;
169 uint64_t val = 0;
170 if (bit == -1)
171 return 1;
172 for (i = 0; i <= bit + 1 && i < 64; i++)
173 val |= (1ULL << i);
174 return val;
175}
176
177/*
178 * Consumes no arguments, returns nothing:
179 *
180 * - BTRFS_IOC_TRANS_START
181 * - BTRFS_IOC_TRANS_END
182 */
183static void
184btrfs_test_trans_ioctls(void)
185{
186 ioctl(-1, BTRFS_IOC_TRANS_START, NULL);
187 printf("ioctl(-1, BTRFS_IOC_TRANS_START) = -1 EBADF (%m)\n");
188
189 ioctl(-1, BTRFS_IOC_TRANS_END, NULL);
190 printf("ioctl(-1, BTRFS_IOC_TRANS_END) = -1 EBADF (%m)\n");
191}
192
193/*
194 * Consumes no arguments, returns nothing:
195 * - BTRFS_IOC_SYNC
196 *
197 * Consumes argument, returns nothing
198 * - BTRFS_IOC_WAIT_SYNC
199 */
200static void
201btrfs_test_sync_ioctls(void)
202{
Dmitry V. Levin57888fa2016-05-24 02:07:47 +0000203 uint64_t u64val = 0xdeadbeefbadc0ded;
Jeff Mahoney35866792016-05-18 18:09:42 -0400204
205 ioctl(-1, BTRFS_IOC_SYNC, NULL);
206 printf("ioctl(-1, BTRFS_IOC_SYNC) = -1 EBADF (%m)\n");
207
208 ioctl(-1, BTRFS_IOC_WAIT_SYNC, NULL);
209 printf("ioctl(-1, BTRFS_IOC_WAIT_SYNC, NULL) = -1 EBADF (%m)\n");
210
211 ioctl(-1, BTRFS_IOC_WAIT_SYNC, &u64val);
212 printf("ioctl(-1, BTRFS_IOC_WAIT_SYNC, [%" PRIu64
213 "]) = -1 EBADF (%m)\n", u64val);
214
215 /*
216 * The live test of BTRFS_IOC_SYNC happens as a part of the test
217 * for BTRFS_IOC_LOGICAL_INO
218 */
219}
220
221static void
222btrfs_print_qgroup_inherit(struct btrfs_qgroup_inherit *inherit)
223{
224 printf("{flags=");
225 printflags(btrfs_qgroup_inherit_flags, inherit->flags,
226 "BTRFS_QGROUP_INHERIT_???");
227 printf(", num_qgroups=%" PRI__u64
228 ", num_ref_copies=%" PRI__u64
229 ", num_excl_copies=%" PRI__u64", lim={flags=",
230 inherit->num_qgroups, inherit->num_ref_copies,
231 inherit->num_excl_copies);
232 printflags(btrfs_qgroup_limit_flags,
233 inherit->lim.flags,
234 "BTRFS_QGROUP_LIMIT_???");
235 printf(", max_rfer=%" PRI__u64 ", max_excl=%" PRI__u64
236 ", rsv_rfer=%" PRI__u64 ", rsv_excl=%" PRI__u64
237 "}, qgroups=",
238 inherit->lim.max_rfer, inherit->lim.max_excl,
239 inherit->lim.rsv_rfer, inherit->lim.rsv_excl);
240 if (verbose) {
241 unsigned int i;
242 printf("[");
243 for (i = 0; i < inherit->num_qgroups; i++) {
244 if (i > 0)
245 printf(", ");
246 printf("%" PRI__u64, inherit->qgroups[i]);
247 }
248 printf("]");
249 } else
250 printf("...");
251 printf("}");
252}
253
254
255static void
256btrfs_print_vol_args_v2(struct btrfs_ioctl_vol_args_v2 *args, int print_qgroups)
257{
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000258 printf("{fd=%d, flags=", (int) args->fd);
Jeff Mahoney35866792016-05-18 18:09:42 -0400259 printflags(btrfs_snap_flags_v2, args->flags, "BTRFS_SUBVOL_???");
260
261 if (args->flags & BTRFS_SUBVOL_QGROUP_INHERIT) {
262 printf(", size=%" PRI__u64 ", qgroup_inherit=", args->size);
263 if (args->qgroup_inherit && print_qgroups)
264 btrfs_print_qgroup_inherit(args->qgroup_inherit);
265 else if (args->qgroup_inherit)
266 printf("%p", args->qgroup_inherit);
267 else
268 printf("NULL");
269 }
270 printf(", name=\"%s\"}", args->name);
271}
272
273/*
274 * Consumes argument, returns nothing:
275 * - BTRFS_IOC_SNAP_CREATE
276 * - BTRFS_IOC_SUBVOL_CREATE
277 * - BTRFS_IOC_SNAP_DESTROY
278 * - BTRFS_IOC_DEFAULT_SUBVOL
279 *
280 * Consumes argument, returns u64:
281 * - BTRFS_IOC_SNAP_CREATE_V2
282 * - BTRFS_IOC_SUBVOL_CREATE_V2
283 */
284
285static void
286btrfs_test_subvol_ioctls(void)
287{
288 const char *subvol_name = "subvol-name";
289 char *long_subvol_name;
Dmitry V. Levin57888fa2016-05-24 02:07:47 +0000290 void *bad_pointer = (void *) (unsigned long) 0xdeadbeeffffffeed;
291 uint64_t u64val = 0xdeadbeefbadc0ded;
Jeff Mahoney35866792016-05-18 18:09:42 -0400292 struct btrfs_ioctl_vol_args vol_args = {};
293 struct btrfs_ioctl_vol_args_v2 vol_args_v2 = {
294 .fd = 2,
295 .flags = max_flags_plus_one(2),
296 };
Jeff Mahoney35866792016-05-18 18:09:42 -0400297
298 long_subvol_name = malloc(BTRFS_PATH_NAME_MAX);
299 if (!long_subvol_name)
300 perror_msg_and_fail("malloc failed");
301 memset(long_subvol_name, 'f', BTRFS_PATH_NAME_MAX);
302 long_subvol_name[BTRFS_PATH_NAME_MAX - 1] = '\0';
303
304 strcpy(vol_args.name, subvol_name);
305
306 ioctl(-1, BTRFS_IOC_SNAP_CREATE, NULL);
307 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE, NULL) = -1 EBADF (%m)\n");
308
309 ioctl(-1, BTRFS_IOC_SNAP_CREATE, &vol_args);
310 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE, "
311 "{fd=0, name=\"%s\"}) = -1 EBADF (%m)\n", vol_args.name);
312
313 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE, &vol_args);
314 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE, "
315 "{fd=0, name=\"%s\"}) = -1 EBADF (%m)\n", vol_args.name);
316
317 ioctl(-1, BTRFS_IOC_SNAP_DESTROY, &vol_args);
318 printf("ioctl(-1, BTRFS_IOC_SNAP_DESTROY,"
319 " {fd=0, name=\"%s\"}) = -1 EBADF (%m)\n", vol_args.name);
320
321 strncpy(vol_args.name, long_subvol_name, BTRFS_PATH_NAME_MAX);
322 ioctl(-1, BTRFS_IOC_SNAP_CREATE, &vol_args);
323 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE,"
324 " {fd=0, name=\"%s\"}) = -1 EBADF (%m)\n", vol_args.name);
325
326 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE, &vol_args);
327 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE,"
328 " {fd=0, name=\"%s\"}) = -1 EBADF (%m)\n", vol_args.name);
329
330 ioctl(-1, BTRFS_IOC_SNAP_DESTROY, &vol_args);
331 printf("ioctl(-1, BTRFS_IOC_SNAP_DESTROY,"
332 " {fd=0, name=\"%s\"}) = -1 EBADF (%m)\n", vol_args.name);
333
334 long_subvol_name = realloc(long_subvol_name, BTRFS_SUBVOL_NAME_MAX);
335 if (!long_subvol_name)
336 perror_msg_and_fail("realloc failed");
337
338 ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, NULL);
339 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, NULL) = -1 EBADF (%m)\n");
340
341 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, NULL);
342 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, NULL) = -1 EBADF (%m)\n");
343
344 strcpy(vol_args_v2.name, subvol_name);
345 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, ");
346 btrfs_print_vol_args_v2(&vol_args_v2, 1);
347 ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, &vol_args_v2);
348 printf(") = -1 EBADF (%m)\n");
349
350 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, ");
351 btrfs_print_vol_args_v2(&vol_args_v2, 1);
352 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, &vol_args_v2);
353 printf(") = -1 EBADF (%m)\n");
354
355 strncpy(vol_args_v2.name, long_subvol_name, BTRFS_SUBVOL_NAME_MAX);
356 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, ");
357 btrfs_print_vol_args_v2(&vol_args_v2, 1);
358 ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, &vol_args_v2);
359 printf(") = -1 EBADF (%m)\n");
360
Jeff Mahoney35866792016-05-18 18:09:42 -0400361 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, ");
362 btrfs_print_vol_args_v2(&vol_args_v2, 1);
363 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, &vol_args_v2);
364 printf(") = -1 EBADF (%m)\n");
365
366 strcpy(vol_args_v2.name, subvol_name);
Dmitry V. Levin45fcc0c2016-05-24 01:32:27 +0000367 vol_args_v2.qgroup_inherit = bad_pointer;
Jeff Mahoney35866792016-05-18 18:09:42 -0400368
Jeff Mahoney35866792016-05-18 18:09:42 -0400369 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, ");
370 btrfs_print_vol_args_v2(&vol_args_v2, 0);
371 ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, &vol_args_v2);
372 printf(") = -1 EBADF (%m)\n");
373
Jeff Mahoney35866792016-05-18 18:09:42 -0400374 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, ");
375 btrfs_print_vol_args_v2(&vol_args_v2, 0);
376 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, &vol_args_v2);
377 printf(") = -1 EBADF (%m)\n");
378
Dmitry V. Levin45fcc0c2016-05-24 01:32:27 +0000379 const unsigned int n_qgroups = 8;
380 unsigned int i;
381 struct btrfs_qgroup_inherit *inherit;
382 vol_args_v2.size =
383 sizeof(*inherit) + n_qgroups * sizeof(inherit->qgroups[0]);
384 inherit = tail_alloc(vol_args_v2.size);
Jeff Mahoney35866792016-05-18 18:09:42 -0400385
Dmitry V. Levin45fcc0c2016-05-24 01:32:27 +0000386 inherit->flags = 0x3;
387 inherit->num_ref_copies = 0;
388 inherit->num_excl_copies = 0;
389 inherit->num_qgroups = n_qgroups;
390 for (i = 0; i < n_qgroups; i++)
391 inherit->qgroups[i] = 1ULL << i;
392 inherit->lim.flags = 0x7f;
393 inherit->lim.max_rfer = u64val;
394 inherit->lim.max_excl = u64val;
395 inherit->lim.rsv_rfer = u64val;
396 inherit->lim.rsv_excl = u64val;
397 vol_args_v2.qgroup_inherit = inherit;
Jeff Mahoney35866792016-05-18 18:09:42 -0400398
Dmitry V. Levin45fcc0c2016-05-24 01:32:27 +0000399 printf("ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, ");
400 btrfs_print_vol_args_v2(&vol_args_v2, 1);
401 ioctl(-1, BTRFS_IOC_SNAP_CREATE_V2, &vol_args_v2);
402 printf(") = -1 EBADF (%m)\n");
Jeff Mahoney35866792016-05-18 18:09:42 -0400403
Dmitry V. Levin45fcc0c2016-05-24 01:32:27 +0000404 printf("ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, ");
405 btrfs_print_vol_args_v2(&vol_args_v2, 1);
406 ioctl(-1, BTRFS_IOC_SUBVOL_CREATE_V2, &vol_args_v2);
407 printf(") = -1 EBADF (%m)\n");
Jeff Mahoney35866792016-05-18 18:09:42 -0400408
409 ioctl(-1, BTRFS_IOC_DEFAULT_SUBVOL, NULL);
410 printf("ioctl(-1, BTRFS_IOC_DEFAULT_SUBVOL, NULL) = -1 EBADF (%m)\n");
411
412 ioctl(-1, BTRFS_IOC_DEFAULT_SUBVOL, &u64val);
413 printf("ioctl(-1, BTRFS_IOC_DEFAULT_SUBVOL, [%"
414 PRIu64 "]) = -1 EBADF (%m)\n", u64val);
415
416 printf("ioctl(-1, BTRFS_IOC_SUBVOL_SETFLAGS, ");
417 printflags(btrfs_snap_flags_v2, vol_args_v2.flags,
418 "BTRFS_SUBVOL_???");
419 ioctl(-1, BTRFS_IOC_SUBVOL_SETFLAGS, &vol_args_v2.flags);
420 printf(") = -1 EBADF (%m)\n");
421
422 if (write_ok) {
423 struct btrfs_ioctl_vol_args_v2 args_passed;
424 /*
425 * Returns transid if flags & BTRFS_SUBVOL_CREATE_ASYNC
426 * - BTRFS_IOC_SNAP_CREATE_V2
427 * - BTRFS_IOC_SUBVOL_CREATE_V2
428 */
429 int subvolfd;
430
431 strncpy(vol_args_v2.name, subvol_name,
432 sizeof(vol_args_v2.name));
433 vol_args_v2.flags = BTRFS_SUBVOL_CREATE_ASYNC;
434 vol_args_v2.size = 0;
435 vol_args_v2.qgroup_inherit = NULL;
436 args_passed = vol_args_v2;
437 printf("ioctl(%d, BTRFS_IOC_SUBVOL_CREATE_V2, ",
438 btrfs_test_dir_fd);
439 btrfs_print_vol_args_v2(&vol_args_v2, 1);
440 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SUBVOL_CREATE_V2,
441 &args_passed);
442 printf(" => {transid=%" PRI__u64"}) = 0\n",
443 args_passed.transid);
444
445 subvolfd = openat(btrfs_test_dir_fd, subvol_name,
446 O_RDONLY|O_DIRECTORY);
447 if (subvolfd < 0)
448 perror_msg_and_fail("openat(%s) failed", subvol_name);
449
450 strncpy(vol_args_v2.name, long_subvol_name, BTRFS_NAME_LEN);
451 vol_args_v2.fd = subvolfd;
452 args_passed = vol_args_v2;
453 printf("ioctl(%d, BTRFS_IOC_SNAP_CREATE_V2, ",
454 btrfs_test_dir_fd);
455 btrfs_print_vol_args_v2(&args_passed, 1);
456 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SNAP_CREATE_V2,
457 &args_passed);
458 printf(" => {transid=%" PRI__u64"}) = 0\n",
459 args_passed.transid);
460
461 /* This only works when mounted w/ -ouser_subvol_rm_allowed */
462 strncpy(vol_args.name, long_subvol_name, 255);
463 vol_args.name[255] = 0;
464 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SNAP_DESTROY, &vol_args);
465 printf("ioctl(%d, BTRFS_IOC_SNAP_DESTROY, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000466 "{fd=%d, name=\"%.*s\"}) = 0\n",
467 btrfs_test_dir_fd, (int) vol_args.fd, 255, long_subvol_name);
Jeff Mahoney35866792016-05-18 18:09:42 -0400468
469 strcpy(vol_args.name, subvol_name);
470 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SNAP_DESTROY, &vol_args);
471 printf("ioctl(%d, BTRFS_IOC_SNAP_DESTROY, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000472 "{fd=%d, name=\"%s\"}) = 0\n",
473 btrfs_test_dir_fd, (int) vol_args.fd, subvol_name);
Jeff Mahoney35866792016-05-18 18:09:42 -0400474
475 close(subvolfd);
476 }
477 free(long_subvol_name);
478}
479
480static void
481btrfs_print_balance_args(struct btrfs_balance_args *args)
482{
483 printf("{profiles=");
484 printflags(btrfs_space_info_flags, args->profiles,
485 "BTRFS_BLOCK_GROUP_???");
486 printf(", usage=%"PRI__u64 "%s, devid=%"PRI__u64 "%s, pstart=%"PRI__u64
487 "%s, pend=%"PRI__u64 "%s, vstart=%"PRI__u64 "%s, vend=%"PRI__u64
488 "%s, target=%"PRI__u64 "%s, flags=",
489 args->usage, maybe_print_uint64max(args->usage),
490 args->devid, maybe_print_uint64max(args->devid),
491 args->pstart, maybe_print_uint64max(args->pstart),
492 args->pend, maybe_print_uint64max(args->pend),
493 args->vstart, maybe_print_uint64max(args->vstart),
494 args->vend, maybe_print_uint64max(args->vend),
495 args->target, maybe_print_uint64max(args->target));
496 printflags(btrfs_balance_args, args->flags, "BTRFS_BALANCE_ARGS_???");
497 printf("}");
498}
499
500/*
501 * Accepts argument, returns nothing
502 * - BTRFS_IOC_BALANCE
503 * - BTRFS_IOC_BALANCE_CTL
504 *
505 * Accepts argument, returns argument
506 * - BTRFS_IOC_BALANCE_V2
507 */
508static void
509btrfs_test_balance_ioctls(void)
510{
511 struct btrfs_ioctl_balance_args args = {
512 .flags = 0x3f,
513 .data = {
514 .profiles = 0x7,
515 .flags = 0x7,
516 .devid = 1,
517 .pend = -1ULL,
518 .vend = -1ULL,
519 },
520
521 .meta = {
522 .profiles = 0x38,
523 .flags = 0x38,
524 .devid = 1,
525 },
526
527 .sys = {
528 .profiles = 0x1c0 | (1ULL << 48),
529 .flags = 0x4c0,
530 .devid = 1,
531 },
532 };
533 struct btrfs_ioctl_vol_args vol_args = {};
534
535 ioctl(-1, BTRFS_IOC_BALANCE_CTL, 1);
536 printf("ioctl(-1, BTRFS_IOC_BALANCE_CTL, "
537 "BTRFS_BALANCE_CTL_PAUSE) = -1 EBADF (%m)\n");
538
539 ioctl(-1, BTRFS_IOC_BALANCE_CTL, 2);
540 printf("ioctl(-1, BTRFS_IOC_BALANCE_CTL, "
541 "BTRFS_BALANCE_CTL_CANCEL) = -1 EBADF (%m)\n");
542
543 ioctl(-1, BTRFS_IOC_BALANCE, NULL);
544 printf("ioctl(-1, BTRFS_IOC_BALANCE) = -1 EBADF (%m)\n");
545
546 ioctl(-1, BTRFS_IOC_BALANCE, &vol_args);
547 printf("ioctl(-1, BTRFS_IOC_BALANCE) = -1 EBADF (%m)\n");
548
549 /* struct btrfs_ioctl_balance_args */
550 ioctl(-1, BTRFS_IOC_BALANCE_V2, NULL);
551 printf("ioctl(-1, BTRFS_IOC_BALANCE_V2, NULL) = -1 EBADF (%m)\n");
552
553 printf("ioctl(-1, BTRFS_IOC_BALANCE_V2, {flags=");
554 printflags(btrfs_balance_flags, args.flags, "BTRFS_BALANCE_???");
555 printf(", data=");
556 btrfs_print_balance_args(&args.data);
557 printf(", meta=");
558 btrfs_print_balance_args(&args.meta);
559 printf(", sys=");
560 btrfs_print_balance_args(&args.sys);
561 ioctl(-1, BTRFS_IOC_BALANCE_V2, &args);
562 printf("}) = -1 EBADF (%m)\n");
563
564 if (write_ok) {
565 args.flags = BTRFS_BALANCE_DATA | BTRFS_BALANCE_METADATA |
566 BTRFS_BALANCE_SYSTEM;
567 args.data.flags = 0;
568 args.data.profiles = 0;
569 args.meta.flags = 0;
570 args.meta.profiles = 0;
571 args.sys.flags = 0;
572 args.sys.profiles = 0;
573 printf("ioctl(%d, BTRFS_IOC_BALANCE_V2, {flags=",
574 btrfs_test_dir_fd);
575
576 printflags(btrfs_balance_flags, args.flags,
577 "BTRFS_BALANCE_???");
578 printf(", data=");
579 btrfs_print_balance_args(&args.data);
580 printf(", meta=");
581 btrfs_print_balance_args(&args.meta);
582 printf(", sys=");
583 btrfs_print_balance_args(&args.sys);
584 ioctl(btrfs_test_dir_fd, BTRFS_IOC_BALANCE_V2, &args);
585 printf("} => {flags=");
586 printflags(btrfs_balance_flags, args.flags,
587 "BTRFS_BALANCE_???");
588 printf(", state=");
589 printflags(btrfs_balance_state, args.state,
590 "BTRFS_BALANCE_STATE_???");
591 printf(", data=");
592 btrfs_print_balance_args(&args.data);
593 printf(", meta=");
594 btrfs_print_balance_args(&args.meta);
595 printf(", sys=");
596 btrfs_print_balance_args(&args.sys);
597 printf("}) = 0\n");
598 }
599}
600
601/*
602 * Consumes argument, returns nothing:
603 * - BTRFS_IOC_RESIZE
604 *
605 * Requires /dev/btrfs-control, consumes argument, returns nothing:
606 * - BTRFS_IOC_SCAN_DEV
607 * - BTRFS_IOC_DEVICES_READY
608 *
609 */
610static void
611btrfs_test_device_ioctls(void)
612{
613 const char *devid = "1";
614 const char *devname = "/dev/sda1";
615 struct btrfs_ioctl_vol_args args = {
616 .fd = 2,
617 };
618
619 ioctl(-1, BTRFS_IOC_RESIZE, NULL);
620 printf("ioctl(-1, BTRFS_IOC_RESIZE, NULL) = -1 EBADF (%m)\n");
621
622 strcpy(args.name, devid);
623 ioctl(-1, BTRFS_IOC_RESIZE, &args);
624 printf("ioctl(-1, BTRFS_IOC_RESIZE, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000625 "{fd=%d, name=\"%s\"}) = -1 EBADF (%m)\n",
626 (int) args.fd, args.name);
Jeff Mahoney35866792016-05-18 18:09:42 -0400627
628 ioctl(-1, BTRFS_IOC_SCAN_DEV, NULL);
629 printf("ioctl(-1, BTRFS_IOC_SCAN_DEV, NULL) = -1 EBADF (%m)\n");
630
631 strcpy(args.name, devname);
632 ioctl(-1, BTRFS_IOC_SCAN_DEV, &args);
633 printf("ioctl(-1, BTRFS_IOC_SCAN_DEV, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000634 "{fd=%d, name=\"%s\"}) = -1 EBADF (%m)\n",
635 (int) args.fd, args.name);
Jeff Mahoney35866792016-05-18 18:09:42 -0400636
637 ioctl(-1, BTRFS_IOC_ADD_DEV, NULL);
638 printf("ioctl(-1, BTRFS_IOC_ADD_DEV, NULL) = -1 EBADF (%m)\n");
639
640 ioctl(-1, BTRFS_IOC_ADD_DEV, &args);
641 printf("ioctl(-1, BTRFS_IOC_ADD_DEV, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000642 "{fd=%d, name=\"%s\"}) = -1 EBADF (%m)\n",
643 (int) args.fd, args.name);
Jeff Mahoney35866792016-05-18 18:09:42 -0400644
645 ioctl(-1, BTRFS_IOC_RM_DEV, NULL);
646 printf("ioctl(-1, BTRFS_IOC_RM_DEV, NULL) = -1 EBADF (%m)\n");
647
648 ioctl(-1, BTRFS_IOC_RM_DEV, &args);
649 printf("ioctl(-1, BTRFS_IOC_RM_DEV, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000650 "{fd=%d, name=\"%s\"}) = -1 EBADF (%m)\n",
651 (int) args.fd, args.name);
Jeff Mahoney35866792016-05-18 18:09:42 -0400652
653}
654
655/*
656 * Consumes argument, returns nothing:
657 * - BTRFS_IOC_CLONE
658 * - BTRFS_IOC_CLONE_RANGE
659 */
660static void
661btrfs_test_clone_ioctls(void)
662{
663 int clone_fd = 4;
664 struct btrfs_ioctl_clone_range_args args = {
665 .src_fd = clone_fd,
666 .src_offset = 4096,
667 .src_length = 16384,
668 .dest_offset = 128 * 1024,
669 };
670
671 ioctl(-1, BTRFS_IOC_CLONE, clone_fd);
672 printf("ioctl(-1, BTRFS_IOC_CLONE or FICLONE, %x) = -1 EBADF (%m)\n",
673 clone_fd);
674
675 ioctl(-1, BTRFS_IOC_CLONE_RANGE, NULL);
676 printf("ioctl(-1, BTRFS_IOC_CLONE_RANGE or FICLONERANGE, "
677 "NULL) = -1 EBADF (%m)\n");
678
679 ioctl(-1, BTRFS_IOC_CLONE_RANGE, &args);
680 printf("ioctl(-1, BTRFS_IOC_CLONE_RANGE or FICLONERANGE, "
Dmitry V. Levin3f366112016-05-24 02:17:49 +0000681 "{src_fd=%d, src_offset=%" PRI__u64 ", src_length=%" PRI__u64
682 ", dest_offset=%" PRI__u64 "}) = -1 EBADF (%m)\n",
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +0000683 (int) args.src_fd, args.src_offset, args.src_length,
Jeff Mahoney35866792016-05-18 18:09:42 -0400684 args.dest_offset);
685}
686
687#define BTRFS_COMPRESS_TYPES 2
688#define BTRFS_INVALID_COMPRESS (BTRFS_COMPRESS_TYPES + 1)
689
690static void
691btrfs_print_defrag_range_args(struct btrfs_ioctl_defrag_range_args *args)
692{
693 printf("{start=%" PRIu64", len=%" PRIu64 "%s, flags=",
Dmitry V. Levind4bdff62016-06-17 00:44:44 +0000694 (uint64_t) args->start, (uint64_t) args->len,
695 maybe_print_uint64max(args->len));
Jeff Mahoney35866792016-05-18 18:09:42 -0400696
697 printflags(btrfs_defrag_flags, args->flags, "BTRFS_DEFRAG_RANGE_???");
698 printf(", extent_thresh=%u, compress_type=", args->extent_thresh);
699 printxval(btrfs_compress_types, args->compress_type,
700 "BTRFS_COMPRESS_???");
701 printf("}");
702}
703
704/*
705 * Consumes argument, returns nothing:
706 * - BTRFS_IOC_DEFRAG
707 * - BTRFS_DEFRAG_RANGE
708 */
709static void
710btrfs_test_defrag_ioctls(void)
711{
712 struct btrfs_ioctl_vol_args vol_args = {};
713 struct btrfs_ioctl_defrag_range_args args = {
714 .start = 0,
715 .len = -1ULL,
716 .flags = max_flags_plus_one(1),
717 .extent_thresh = 128 * 1024,
718 .compress_type = 2, /* BTRFS_COMPRESS_LZO */
719 };
720
721 /*
722 * These are documented as using vol_args but don't
723 * actually consume it.
724 */
725 ioctl(-1, BTRFS_IOC_DEFRAG, NULL);
726 printf("ioctl(-1, BTRFS_IOC_DEFRAG) = -1 EBADF (%m)\n");
727
728 ioctl(-1, BTRFS_IOC_DEFRAG, &vol_args);
729 printf("ioctl(-1, BTRFS_IOC_DEFRAG) = -1 EBADF (%m)\n");
730
731 /* struct btrfs_ioctl_defrag_range_args */
732 ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, NULL);
733 printf("ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, NULL) = -1 EBADF (%m)\n");
734
735 printf("ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, ");
736 btrfs_print_defrag_range_args(&args);
737 ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, &args);
738 printf(") = -1 EBADF (%m)\n");
739
740 args.compress_type = BTRFS_INVALID_COMPRESS;
741 printf("ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, ");
742 btrfs_print_defrag_range_args(&args);
743 ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, &args);
744 printf(") = -1 EBADF (%m)\n");
745
746 args.len--;
747 printf("ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, ");
748 btrfs_print_defrag_range_args(&args);
749 ioctl(-1, BTRFS_IOC_DEFRAG_RANGE, &args);
750 printf(") = -1 EBADF (%m)\n");
751}
752
753static const char *
754xlookup(const struct xlat *xlat, const uint64_t val)
755{
756 for (; xlat->str != NULL; xlat++)
757 if (xlat->val == val)
758 return xlat->str;
759 return NULL;
760}
761
762static void
763btrfs_print_objectid(uint64_t objectid)
764{
765 const char *str = xlookup(btrfs_tree_objectids, objectid);
766 printf("%" PRIu64, objectid);
767 if (str)
768 printf(" /* %s */", str);
769}
770
771static void
772btrfs_print_key_type(uint32_t type)
773{
774 const char *str = xlookup(btrfs_key_types, type);
775 printf("%u", type);
776 if (str)
777 printf(" /* %s */", str);
778}
779
780static void
781btrfs_print_search_key(struct btrfs_ioctl_search_key *key)
782{
783 printf("key={tree_id=");
784 btrfs_print_objectid(key->tree_id);
785 if (verbose || key->min_objectid != 256) {
786 printf(", min_objectid=");
787 btrfs_print_objectid(key->min_objectid);
788 }
789 if (verbose || key->max_objectid != -256ULL) {
790 printf(", max_objectid=");
791 btrfs_print_objectid(key->max_objectid);
792 }
793 if (key->min_offset)
794 printf(", min_offset=%" PRI__u64 "%s",
795 key->min_offset, maybe_print_uint64max(key->min_offset));
796 if (key->max_offset)
797 printf(", max_offset=%" PRI__u64 "%s",
798 key->max_offset, maybe_print_uint64max(key->max_offset));
799 if (key->min_transid)
800 printf(", min_transid=%" PRI__u64"%s", key->min_transid,
801 maybe_print_uint64max(key->min_transid));
802 if (key->max_transid)
803 printf(", max_transid=%" PRI__u64"%s", key->max_transid,
804 maybe_print_uint64max(key->max_transid));
805 printf(", min_type=");
806 btrfs_print_key_type(key->min_type);
807 printf(", max_type=");
808 btrfs_print_key_type(key->max_type);
809 printf(", nr_items=%u}", key->nr_items);
810}
811
812static void
813btrfs_print_tree_search_buf(struct btrfs_ioctl_search_key *key,
814 void *buf, uint64_t buf_size)
815{
816 if (verbose) {
817 uint64_t i;
818 uint64_t off = 0;
819 printf("[");
820 for (i = 0; i < key->nr_items; i++) {
821 struct btrfs_ioctl_search_header *sh;
822 sh = (typeof(sh))(buf + off);
823 if (i)
824 printf(", ");
825 printf("{transid=%" PRI__u64 ", objectid=",
826 sh->transid);
827 btrfs_print_objectid(sh->objectid);
828 printf(", offset=%" PRI__u64 ", type=", sh->offset);
829 btrfs_print_key_type(sh->type);
830 printf(", len=%u}", sh->len);
831 off += sizeof(*sh) + sh->len;
832 }
833 printf("]");
834 } else
835 printf("...");
836}
837
838/*
839 * Consumes argument, returns argument:
840 * - BTRFS_IOC_TREE_SEARCH
841 * - BTRFS_IOC_TREE_SEARCH_V2
842 */
843static void
844btrfs_test_search_ioctls(void)
845{
846 struct btrfs_ioctl_search_key key_reference = {
847 .tree_id = 5,
848 .min_objectid = 256,
849 .max_objectid = -1ULL,
850 .min_offset = 0,
851 .max_offset = -1ULL,
852 .min_transid = 0,
853 .max_transid = -1ULL,
854 .min_type = 0,
855 .max_type = -1U,
856 .nr_items = 10,
857 };
858 struct btrfs_ioctl_search_args search_args;
859 struct btrfs_ioctl_search_args_v2 search_args_v2 = {
860 .buf_size = 4096,
861 };
862
863 ioctl(-1, BTRFS_IOC_TREE_SEARCH, NULL);
864 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH, NULL) = -1 EBADF (%m)\n");
865
866 ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, NULL);
867 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, NULL) = -1 EBADF (%m)\n");
868
Jeff Mahoney563a7582016-05-26 16:09:28 -0400869 search_args.key = key_reference;
Jeff Mahoney35866792016-05-18 18:09:42 -0400870 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH, {");
871 btrfs_print_search_key(&search_args.key);
872 ioctl(-1, BTRFS_IOC_TREE_SEARCH, &search_args);
873 printf("}) = -1 EBADF (%m)\n");
874
875 search_args_v2.key = key_reference;
876 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, {");
877 btrfs_print_search_key(&search_args_v2.key);
878 ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, &search_args_v2);
879 printf(", buf_size=%" PRIu64 "}) = -1 EBADF (%m)\n",
880 (uint64_t)search_args_v2.buf_size);
881
882 key_reference.min_objectid = 6;
883 key_reference.max_objectid = 7;
Jeff Mahoney563a7582016-05-26 16:09:28 -0400884 search_args.key = key_reference;
Jeff Mahoney35866792016-05-18 18:09:42 -0400885 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH, {");
886 btrfs_print_search_key(&search_args.key);
887 ioctl(-1, BTRFS_IOC_TREE_SEARCH, &search_args);
888 printf("}) = -1 EBADF (%m)\n");
889
890 search_args_v2.key = key_reference;
891 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, {");
892 btrfs_print_search_key(&search_args_v2.key);
893 ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, &search_args_v2);
894 printf(", buf_size=%" PRIu64 "}) = -1 EBADF (%m)\n",
895 (uint64_t)search_args_v2.buf_size);
896
897 key_reference.min_offset++;
898 key_reference.max_offset--;
Jeff Mahoney563a7582016-05-26 16:09:28 -0400899 search_args.key = key_reference;
Jeff Mahoney35866792016-05-18 18:09:42 -0400900 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH, {");
901 btrfs_print_search_key(&search_args.key);
902 ioctl(-1, BTRFS_IOC_TREE_SEARCH, &search_args);
903 printf("}) = -1 EBADF (%m)\n");
904
905 search_args_v2.key = key_reference;
906 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, {");
907 btrfs_print_search_key(&search_args_v2.key);
908 ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, &search_args_v2);
909 printf(", buf_size=%" PRIu64 "}) = -1 EBADF (%m)\n",
910 (uint64_t)search_args_v2.buf_size);
911
912 key_reference.min_transid++;
913 key_reference.max_transid--;
Jeff Mahoney563a7582016-05-26 16:09:28 -0400914 search_args.key = key_reference;
Jeff Mahoney35866792016-05-18 18:09:42 -0400915 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH, {");
916 btrfs_print_search_key(&search_args.key);
917 ioctl(-1, BTRFS_IOC_TREE_SEARCH, &search_args);
918 printf("}) = -1 EBADF (%m)\n");
919
920 search_args_v2.key = key_reference;
921 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, {");
922 btrfs_print_search_key(&search_args_v2.key);
923 ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, &search_args_v2);
924 printf(", buf_size=%" PRIu64 "}) = -1 EBADF (%m)\n",
925 (uint64_t)search_args_v2.buf_size);
926
927 key_reference.min_type = 1;
928 key_reference.max_type = 12;
Jeff Mahoney563a7582016-05-26 16:09:28 -0400929 search_args.key = key_reference;
Jeff Mahoney35866792016-05-18 18:09:42 -0400930 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH, {");
931 btrfs_print_search_key(&search_args.key);
932 ioctl(-1, BTRFS_IOC_TREE_SEARCH, &search_args);
933 printf("}) = -1 EBADF (%m)\n");
934
935 search_args_v2.key = key_reference;
936 printf("ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, {");
937 btrfs_print_search_key(&search_args_v2.key);
938 ioctl(-1, BTRFS_IOC_TREE_SEARCH_V2, &search_args_v2);
939 printf(", buf_size=%" PRIu64 "}) = -1 EBADF (%m)\n",
940 (uint64_t)search_args_v2.buf_size);
941
942 if (btrfs_test_root) {
943 struct btrfs_ioctl_search_args_v2 *args;
944 int bufsize = 4096;
945
946 key_reference.tree_id = 5;
947 key_reference.min_type = 1;
948 key_reference.max_type = 1;
949 key_reference.min_objectid = 256;
950 key_reference.max_objectid = 357;
951 key_reference.min_offset = 0;
952 key_reference.max_offset = -1ULL;
953
954 search_args.key = key_reference;
955 printf("ioctl(%d, BTRFS_IOC_TREE_SEARCH, {",
956 btrfs_test_dir_fd);
957 btrfs_print_search_key(&search_args.key);
958 ioctl(btrfs_test_dir_fd, BTRFS_IOC_TREE_SEARCH, &search_args);
Jeff Mahoneyfd70b502016-05-26 23:33:05 -0400959 printf("} => {key={nr_items=%u}, buf=",
Jeff Mahoney35866792016-05-18 18:09:42 -0400960 search_args.key.nr_items);
Jeff Mahoneyfd70b502016-05-26 23:33:05 -0400961 btrfs_print_tree_search_buf(&search_args.key, search_args.buf,
962 sizeof(search_args.buf));
963 printf("}) = 0\n");
Jeff Mahoney35866792016-05-18 18:09:42 -0400964
965 args = malloc(sizeof(*args) + bufsize);
966 if (!args)
967 perror_msg_and_fail("malloc failed");
968
969 args->key = key_reference;
970 args->buf_size = bufsize;
971 printf("ioctl(%d, BTRFS_IOC_TREE_SEARCH_V2, {",
972 btrfs_test_dir_fd);
973 btrfs_print_search_key(&key_reference);
974 printf(", buf_size=%" PRIu64 "}", (uint64_t) args->buf_size);
975 ioctl(btrfs_test_dir_fd, BTRFS_IOC_TREE_SEARCH_V2, args);
976 printf(" => {key={nr_items=%u}, buf_size=%" PRIu64 ", buf=",
977 args->key.nr_items, (uint64_t)args->buf_size);
978 btrfs_print_tree_search_buf(&args->key, args->buf,
979 args->buf_size);
980 printf("}) = 0\n");
981
982 args->key = key_reference;
983 args->buf_size = sizeof(struct btrfs_ioctl_search_header);
984 printf("ioctl(%d, BTRFS_IOC_TREE_SEARCH_V2, {",
985 btrfs_test_dir_fd);
986 btrfs_print_search_key(&args->key);
987 printf(", buf_size=%" PRIu64 "}", (uint64_t)args->buf_size);
988 ioctl(btrfs_test_dir_fd, BTRFS_IOC_TREE_SEARCH_V2, args);
Jeff Mahoneyfd70b502016-05-26 23:33:05 -0400989 printf(" => {buf_size=%" PRIu64 "}) = -1 EOVERFLOW (%m)\n",
Jeff Mahoney35866792016-05-18 18:09:42 -0400990 (uint64_t)args->buf_size);
991 free(args);
992 }
993}
994
995/*
996 * Consumes argument, returns argument:
997 * - BTRFS_IOC_INO_LOOKUP
998 */
999static void
1000btrfs_test_ino_lookup_ioctl(void)
1001{
1002 struct btrfs_ioctl_ino_lookup_args args = {
1003 .treeid = 5,
1004 .objectid = 256,
1005 };
1006
1007 ioctl(-1, BTRFS_IOC_INO_LOOKUP, NULL);
1008 printf("ioctl(-1, BTRFS_IOC_INO_LOOKUP, NULL) = -1 EBADF (%m)\n");
1009
1010 printf("ioctl(-1, BTRFS_IOC_INO_LOOKUP, {treeid=");
1011 btrfs_print_objectid(args.treeid);
1012 printf(", objectid=");
1013 btrfs_print_objectid(args.objectid);
1014 ioctl(-1, BTRFS_IOC_INO_LOOKUP, &args);
1015 printf("}) = -1 EBADF (%m)\n");
1016
1017 if (btrfs_test_root) {
1018 printf("ioctl(%d, BTRFS_IOC_INO_LOOKUP, {treeid=",
1019 btrfs_test_dir_fd);
1020 btrfs_print_objectid(args.treeid);
1021 printf(", objectid=");
1022 btrfs_print_objectid(args.objectid);
1023 ioctl(btrfs_test_dir_fd, BTRFS_IOC_INO_LOOKUP, &args);
1024 printf("} => {name=\"%s\"}) = 0\n", args.name);
1025 }
1026}
1027
1028/*
1029 * Consumes argument, returns argument:
1030 * - BTRFS_IOC_SPACE_INFO
1031 */
1032static void
1033btrfs_test_space_info_ioctl(void)
1034{
1035 struct btrfs_ioctl_space_args args = {};
1036
1037 ioctl(-1, BTRFS_IOC_SPACE_INFO, NULL);
1038 printf("ioctl(-1, BTRFS_IOC_SPACE_INFO, NULL) = -1 EBADF (%m)\n");
1039
1040 ioctl(-1, BTRFS_IOC_SPACE_INFO, &args);
1041 printf("ioctl(-1, BTRFS_IOC_SPACE_INFO, "
1042 "{space_slots=%" PRI__u64 "}) = -1 EBADF (%m)\n",
1043 args.space_slots);
1044
1045 if (btrfs_test_root) {
1046 struct btrfs_ioctl_space_args args_passed;
1047 struct btrfs_ioctl_space_args *argsp;
1048 args_passed = args;
1049 printf("ioctl(%d, BTRFS_IOC_SPACE_INFO, "
1050 "{space_slots=%" PRI__u64 "}",
1051 btrfs_test_dir_fd, args_passed.space_slots);
1052 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SPACE_INFO, &args_passed);
1053 printf(" => {total_spaces=%" PRI__u64 "}) = 0\n",
1054 args_passed.total_spaces);
1055
1056 argsp = malloc(sizeof(args) +
1057 args_passed.total_spaces * sizeof(args.spaces[0]));
1058 if (!argsp)
1059 perror_msg_and_fail("malloc failed");
1060
1061 *argsp = args;
1062 argsp->space_slots = args_passed.total_spaces;
1063 printf("ioctl(%d, BTRFS_IOC_SPACE_INFO, "
1064 "{space_slots=%" PRI__u64 "}",
1065 btrfs_test_dir_fd, argsp->space_slots);
1066 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SPACE_INFO, argsp);
1067 printf(" => {total_spaces=%" PRI__u64 ", spaces=",
1068 argsp->total_spaces);
1069 if (verbose) {
1070 unsigned int i;
1071 printf("[");
1072 for (i = 0; i < argsp->total_spaces; i++) {
1073 struct btrfs_ioctl_space_info *info;
1074 info = &argsp->spaces[i];
1075 if (i)
1076 printf(", ");
1077 printf("{flags=");
1078 printflags(btrfs_space_info_flags, info->flags,
1079 "BTRFS_SPACE_INFO_???");
1080 printf(", total_bytes=%" PRI__u64
1081 ", used_bytes=%" PRI__u64 "}",
1082 info->total_bytes, info->used_bytes);
1083 }
1084
1085 printf("]");
1086 } else
1087 printf("...");
1088 printf("}) = 0\n");
1089 free(argsp);
1090 }
1091}
1092
1093/*
1094 * Consumes no arguments, returns nothing:
1095 * - BTRFS_IOC_SCRUB_CANCEL
1096 * Consumes argument, returns argument:
1097 - * BTRFS_IOC_SCRUB
1098 - * BTRFS_IOC_SCRUB_PROGRESS
1099 */
1100static void
1101btrfs_test_scrub_ioctls(void)
1102{
1103 struct btrfs_ioctl_scrub_args args = {
1104 .devid = 1,
1105 .start = 0,
1106 .end = -1ULL,
1107 .flags = max_flags_plus_one(0),
1108 };
1109
1110 ioctl(-1, BTRFS_IOC_SCRUB, NULL);
1111 printf("ioctl(-1, BTRFS_IOC_SCRUB, NULL) = -1 EBADF (%m)\n");
1112
1113 ioctl(-1, BTRFS_IOC_SCRUB_CANCEL, NULL);
1114 printf("ioctl(-1, BTRFS_IOC_SCRUB_CANCEL) = -1 EBADF (%m)\n");
1115
1116 printf("ioctl(-1, BTRFS_IOC_SCRUB, {devid=%" PRI__u64 ", start=%"
1117 PRI__u64 "%s, end=%" PRI__u64"%s, flags=",
1118 args.devid, args.start, maybe_print_uint64max(args.start),
1119 args.end, maybe_print_uint64max(args.end));
1120 printflags(btrfs_scrub_flags, args.flags, "BTRFS_SCRUB_???");
1121 ioctl(-1, BTRFS_IOC_SCRUB, &args);
1122 printf("}) = -1 EBADF (%m)\n");
1123
1124 ioctl(-1, BTRFS_IOC_SCRUB_PROGRESS, NULL);
1125 printf("ioctl(-1, BTRFS_IOC_SCRUB_PROGRESS, NULL) = -1 EBADF (%m)\n");
1126
1127 ioctl(-1, BTRFS_IOC_SCRUB_PROGRESS, &args);
1128 printf("ioctl(-1, BTRFS_IOC_SCRUB_PROGRESS, "
1129 "{devid=%" PRI__u64 "}) = -1 EBADF (%m)\n", args.devid);
1130}
1131
1132/*
1133 * Consumes argument, returns argument:
1134 * - BTRFS_IOC_DEV_INFO
1135 */
1136static void
1137btrfs_test_dev_info_ioctl(void)
1138{
1139 struct btrfs_ioctl_dev_info_args args = {
1140 .devid = 1,
1141 };
1142 memcpy(&args.uuid, uuid_reference, BTRFS_UUID_SIZE);
1143
1144 ioctl(-1, BTRFS_IOC_DEV_INFO, NULL);
1145 printf("ioctl(-1, BTRFS_IOC_DEV_INFO, NULL) = -1 EBADF (%m)\n");
1146
1147 ioctl(-1, BTRFS_IOC_DEV_INFO, &args);
1148 printf("ioctl(-1, BTRFS_IOC_DEV_INFO, "
1149 "{devid=%" PRI__u64", uuid=%s}) = -1 EBADF (%m)\n",
1150 args.devid, uuid_reference_string);
1151}
1152
1153/*
1154 * Consumes argument, returns argument:
1155 * - BTRFS_IOC_INO_PATHS
1156 * - BTRFS_IOC_LOGICAL_INO
1157 */
1158static void
1159btrfs_test_ino_path_ioctls(void)
1160{
1161 char buf[16384];
1162 struct btrfs_ioctl_ino_path_args args = {
1163 .inum = 256,
1164 .size = sizeof(buf),
1165 .fspath = (unsigned long)buf,
1166 };
1167
1168 ioctl(-1, BTRFS_IOC_INO_PATHS, NULL);
1169 printf("ioctl(-1, BTRFS_IOC_INO_PATHS, NULL) = -1 EBADF (%m)\n");
1170
1171 ioctl(-1, BTRFS_IOC_LOGICAL_INO, NULL);
1172 printf("ioctl(-1, BTRFS_IOC_LOGICAL_INO, NULL) = -1 EBADF (%m)\n");
1173
1174 ioctl(-1, BTRFS_IOC_INO_PATHS, &args);
1175 printf("ioctl(-1, BTRFS_IOC_INO_PATHS, "
1176 "{inum=%" PRI__u64", size=%" PRI__u64
1177 ", fspath=0x%" PRI__x64 "}) = -1 EBADF (%m)\n",
1178 args.inum, args.size, args.fspath);
1179
1180 ioctl(-1, BTRFS_IOC_LOGICAL_INO, &args);
1181 printf("ioctl(-1, BTRFS_IOC_LOGICAL_INO, {logical=%" PRI__u64
1182 ", size=%" PRI__u64", inodes=0x%" PRI__x64
1183 "}) = -1 EBADF (%m)\n", args.inum, args.size, args.fspath);
1184
Dmitry V. Levin22129182016-05-24 01:32:09 +00001185#ifdef HAVE_LINUX_FIEMAP_H
Jeff Mahoney35866792016-05-18 18:09:42 -04001186 if (btrfs_test_root) {
1187 int size;
1188 struct stat si;
1189 int ret;
1190 struct btrfs_data_container *data = (void *)buf;
1191 struct fiemap *fiemap;
1192 int fd;
1193
1194 ret = fstat(btrfs_test_dir_fd, &si);
1195 if (ret)
1196 perror_msg_and_fail("fstat failed");
1197
1198 args.inum = si.st_ino;
1199 printf("ioctl(%d, BTRFS_IOC_INO_PATHS, "
1200 "{inum=%" PRI__u64", size=%" PRI__u64
1201 ", fspath=0x%" PRI__x64"}",
1202 btrfs_test_dir_fd, args.inum, args.size,
1203 args.fspath);
1204 ioctl(btrfs_test_dir_fd, BTRFS_IOC_INO_PATHS, &args);
1205 printf(" => {fspath={bytes_left=%u, bytes_missing=%u, elem_cnt=%u, elem_missed=%u, val=",
1206 data->bytes_left, data->bytes_missing, data->elem_cnt,
1207 data->elem_missed);
1208 if (verbose) {
1209 printf("[\"strace-test\"]");
1210 } else
1211 printf("...");
1212 printf("}}) = 0\n");
1213
1214 fd = openat(btrfs_test_dir_fd, "file1", O_RDWR|O_CREAT, 0600);
1215 if (fd < 0)
1216 perror_msg_and_fail("openat(file1) failed");
1217
1218 ret = fstat(fd, &si);
1219 if (ret)
1220 perror_msg_and_fail("fstat failed");
1221
1222 if (write(fd, buf, sizeof(buf)) < 0)
1223 perror_msg_and_fail("write: fd");
1224
1225 /*
1226 * Force delalloc so we can actually
1227 * search for the extent.
1228 */
1229 fsync(fd);
1230 ioctl(fd, BTRFS_IOC_SYNC, NULL);
1231 printf("ioctl(%d, BTRFS_IOC_SYNC) = 0\n", fd);
1232
1233 size = sizeof(*fiemap) + 2 * sizeof(fiemap->fm_extents[0]);
1234 fiemap = malloc(size);
1235 if (!fiemap)
1236 perror_msg_and_fail("malloc failed");
1237 memset(fiemap, 0, size);
1238
1239 fiemap->fm_length = sizeof(buf);
1240 fiemap->fm_extent_count = 2;
1241
1242 /* This is also a live test for FIEMAP */
1243 printf("ioctl(%d, FS_IOC_FIEMAP, {fm_start=%" PRI__u64
1244 ", fm_length=%" PRI__u64", fm_flags=",
1245 fd, fiemap->fm_start, fiemap->fm_length);
1246 printflags(fiemap_flags, fiemap->fm_flags, "FIEMAP_FLAG_???");
1247 printf(", fm_extent_count=%u}", fiemap->fm_extent_count);
1248 ioctl(fd, FS_IOC_FIEMAP, fiemap);
1249 printf(" => {fm_flags=");
1250 printflags(fiemap_flags, fiemap->fm_flags, "FIEMAP_FLAG_???");
1251 printf(", fm_mapped_extents=%u, fm_extents=",
1252 fiemap->fm_mapped_extents);
1253 if (verbose) {
1254 printf("[");
1255 unsigned int i;
1256 for (i = 0; i < fiemap->fm_mapped_extents; i++) {
1257 struct fiemap_extent *fe;
1258 fe = &fiemap->fm_extents[i];
1259 if (i)
1260 printf(", ");
1261 printf("{fe_logical=%" PRI__u64
1262 ", fe_physical=%" PRI__u64
1263 ", fe_length=%" PRI__u64
1264 ", ",
1265 fe->fe_logical, fe->fe_physical,
1266 fe->fe_length);
1267 printflags(fiemap_extent_flags, fe->fe_flags,
1268 "FIEMAP_EXTENT_???");
1269 printf("}");
1270 }
1271 printf("]");
1272 } else
1273 printf("...");
1274 printf("}) = 0\n");
1275
1276 args.inum = fiemap->fm_extents[0].fe_physical;
1277 printf("ioctl(%d, BTRFS_IOC_LOGICAL_INO, {logical=%" PRI__u64
1278 ", size=%" PRI__u64", inodes=0x%" PRI__x64"}",
1279 fd, args.inum, args.size, args.fspath);
1280 ioctl(fd, BTRFS_IOC_LOGICAL_INO, &args);
1281 printf(" => {inodes={bytes_left=%u, bytes_missing=%u, elem_cnt=%u, elem_missed=%u, val=",
1282 data->bytes_left, data->bytes_missing, data->elem_cnt,
1283 data->elem_missed);
1284 if (verbose) {
Gleb Fotengauer-Malinovskiye79f0382016-05-24 18:09:46 +03001285 printf("[{inum=%llu, offset=0, root=5}]",
1286 (unsigned long long) si.st_ino);
Jeff Mahoney35866792016-05-18 18:09:42 -04001287 } else
1288 printf("...");
1289 printf("}}) = 0\n");
1290 close(fd);
1291 free(fiemap);
1292 }
Dmitry V. Levin22129182016-05-24 01:32:09 +00001293#endif /* HAVE_LINUX_FIEMAP_H */
Jeff Mahoney35866792016-05-18 18:09:42 -04001294}
1295
1296/*
1297 * Consumes argument, returns argument:
1298 * - BTRFS_IOC_SET_RECEIVED_SUBVOL
1299 */
1300static void
1301btrfs_test_set_received_subvol_ioctl(void)
1302{
1303 struct btrfs_ioctl_received_subvol_args args = {
1304 .stransid = 0x12345,
1305 .stime = {
1306 .sec = 1463193386,
1307 .nsec = 12345,
1308 },
1309 };
1310 memcpy(&args.uuid, uuid_reference, BTRFS_UUID_SIZE);
1311
1312 ioctl(-1, BTRFS_IOC_SET_RECEIVED_SUBVOL, NULL);
1313 printf("ioctl(-1, BTRFS_IOC_SET_RECEIVED_SUBVOL, "
1314 "NULL) = -1 EBADF (%m)\n");
1315
1316 ioctl(-1, BTRFS_IOC_SET_RECEIVED_SUBVOL, &args);
1317 printf("ioctl(-1, BTRFS_IOC_SET_RECEIVED_SUBVOL, "
1318 "{uuid=%s, stransid=%" PRI__u64", stime=%" PRI__u64
1319 ".%u, flags=0}) = -1 EBADF (%m)\n",
1320 uuid_reference_string, args.stransid, args.stime.sec,
1321 args.stime.nsec);
1322}
1323
1324/*
1325 * Consumes argument, returns nothing (output is via send_fd)
1326 * - BTRFS_IOC_SEND
1327 */
1328static void
1329btrfs_test_send_ioctl(void)
1330{
1331 uint64_t u64_array[2] = { 256, 257 };
1332 struct btrfs_ioctl_send_args args = {
1333 .send_fd = 4,
1334 .parent_root = 257,
1335 .flags = max_flags_plus_one(2),
1336 };
1337
1338 ioctl(-1, BTRFS_IOC_SEND, NULL);
1339 printf("ioctl(-1, BTRFS_IOC_SEND, NULL) = -1 EBADF (%m)\n");
1340
1341 printf("ioctl(-1, BTRFS_IOC_SEND, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +00001342 "{send_fd=%d, clone_sources_count=%" PRI__u64
1343 ", clone_sources=",
1344 (int) args.send_fd, args.clone_sources_count);
Jeff Mahoney35866792016-05-18 18:09:42 -04001345 if (verbose)
1346 printf("NULL");
1347 else
1348 printf("...");
1349 printf(", parent_root=");
1350 btrfs_print_objectid(args.parent_root);
1351 printf(", flags=");
1352 printflags(btrfs_send_flags, args.flags, "BTRFS_SEND_FLAGS_???");
1353 ioctl(-1, BTRFS_IOC_SEND, &args);
1354 printf("}) = -1 EBADF (%m)\n");
1355
1356 args.clone_sources_count = 2;
1357 args.clone_sources = (__u64 *)u64_array;
1358
1359 printf("ioctl(-1, BTRFS_IOC_SEND, "
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +00001360 "{send_fd=%d, clone_sources_count=%" PRI__u64
1361 ", clone_sources=",
1362 (int) args.send_fd, args.clone_sources_count);
Jeff Mahoney35866792016-05-18 18:09:42 -04001363 if (verbose) {
1364 printf("[");
1365 btrfs_print_objectid(u64_array[0]);
1366 printf(", ");
1367 btrfs_print_objectid(u64_array[1]);
1368 printf("]");
1369 } else
1370 printf("...");
1371 printf(", parent_root=");
1372 btrfs_print_objectid(args.parent_root);
1373 printf(", flags=");
1374 printflags(btrfs_send_flags, args.flags, "BTRFS_SEND_FLAGS_???");
1375 ioctl(-1, BTRFS_IOC_SEND, &args);
1376 printf("}) = -1 EBADF (%m)\n");
1377}
1378
1379/*
1380 * Consumes argument, returns nothing:
1381 * - BTRFS_IOC_QUOTA_CTL
1382 */
1383static void
1384btrfs_test_quota_ctl_ioctl(void)
1385{
1386 struct btrfs_ioctl_quota_ctl_args args = {
1387 .cmd = 1,
1388 };
1389
1390 ioctl(-1, BTRFS_IOC_QUOTA_CTL, NULL);
1391 printf("ioctl(-1, BTRFS_IOC_QUOTA_CTL, NULL) = -1 EBADF (%m)\n");
1392
1393 ioctl(-1, BTRFS_IOC_QUOTA_CTL, &args);
1394 printf("ioctl(-1, BTRFS_IOC_QUOTA_CTL, "
1395 "BTRFS_QUOTA_CTL_ENABLE}) = -1 EBADF (%m)\n");
1396
1397 args.cmd = 2;
1398 ioctl(-1, BTRFS_IOC_QUOTA_CTL, &args);
1399 printf("ioctl(-1, BTRFS_IOC_QUOTA_CTL, "
1400 "BTRFS_QUOTA_CTL_DISABLE}) = -1 EBADF (%m)\n");
1401
1402 args.cmd = 3;
1403 ioctl(-1, BTRFS_IOC_QUOTA_CTL, &args);
1404 printf("ioctl(-1, BTRFS_IOC_QUOTA_CTL, "
1405 "BTRFS_QUOTA_CTL_RESCAN__NOTUSED}) = -1 EBADF (%m)\n");
1406
1407 args.cmd = 4;
1408 ioctl(-1, BTRFS_IOC_QUOTA_CTL, &args);
1409 printf("ioctl(-1, BTRFS_IOC_QUOTA_CTL, "
1410 "0x4 /* BTRFS_QUOTA_CTL_??? */}) = -1 EBADF (%m)\n");
1411}
1412
1413/*
1414 * Consumes argument, returns nothing:
1415 * - BTRFS_IOC_QGROUP_ASSIGN
1416 */
1417static void
1418btrfs_test_qgroup_assign_ioctl(void)
1419{
1420 struct btrfs_ioctl_qgroup_assign_args args = {
1421 .assign = 1,
1422 .src = 257,
1423 .dst = 258,
1424 };
1425
1426 ioctl(-1, BTRFS_IOC_QGROUP_ASSIGN, NULL);
1427 printf("ioctl(-1, BTRFS_IOC_QGROUP_ASSIGN, NULL) = -1 EBADF (%m)\n");
1428
1429 ioctl(-1, BTRFS_IOC_QGROUP_ASSIGN, &args);
1430 printf("ioctl(-1, BTRFS_IOC_QGROUP_ASSIGN, "
1431 "{assign=%" PRI__u64", src=%" PRI__u64", dst=%" PRI__u64
1432 "}) = -1 EBADF (%m)\n", args.assign, args.src, args.dst);
1433}
1434
1435/*
1436 * Consumes argument, returns nothing:
1437 * - BTRFS_IOC_QGROUP_CREATE
1438 */
1439static void
1440btrfs_test_qgroup_create_ioctl(void)
1441{
1442 struct btrfs_ioctl_qgroup_create_args args = {
1443 .create = 1,
1444 .qgroupid = 257,
1445 };
1446
1447 ioctl(-1, BTRFS_IOC_QGROUP_CREATE, NULL);
1448 printf("ioctl(-1, BTRFS_IOC_QGROUP_CREATE, NULL) = -1 EBADF (%m)\n");
1449
1450 ioctl(-1, BTRFS_IOC_QGROUP_CREATE, &args);
1451 printf("ioctl(-1, BTRFS_IOC_QGROUP_CREATE, "
1452 "{create=%" PRI__u64", qgroupid=%" PRI__u64
1453 "}) = -1 EBADF (%m)\n", args.create, args.qgroupid);
1454}
1455
1456/*
1457 * Consumes nothing, returns nothing:
1458 * - BTRFS_IOC_QUOTA_RESCAN_WAIT
1459 * Consumes argument, returns nothing:
1460 * - BTRFS_IOC_QUOTA_RESCAN
1461 */
1462static void
1463btrfs_test_quota_rescan_ioctl(void)
1464{
1465 struct btrfs_ioctl_quota_rescan_args args = {
1466 .progress = 1,
1467 };
1468
1469 ioctl(-1, BTRFS_IOC_QUOTA_RESCAN, NULL);
1470 printf("ioctl(-1, BTRFS_IOC_QUOTA_RESCAN, NULL) = -1 EBADF (%m)\n");
1471
1472 ioctl(-1, BTRFS_IOC_QUOTA_RESCAN, &args);
1473 printf("ioctl(-1, BTRFS_IOC_QUOTA_RESCAN, "
1474 "{flags=0}) = -1 EBADF (%m)\n");
1475 ioctl(-1, BTRFS_IOC_QUOTA_RESCAN_WAIT, NULL);
1476 printf("ioctl(-1, BTRFS_IOC_QUOTA_RESCAN_WAIT) = -1 EBADF (%m)\n");
1477
1478}
1479
1480/*
1481 * Consumes argument, returns nothing:
1482 * - BTRFS_IOC_SET_FSLABEL
1483 *
1484 * Consumes no argument, returns argument:
1485 * - BTRFS_IOC_GET_FS_LABEL
1486 */
1487static void
1488btrfs_test_label_ioctls(void)
1489{
1490 char label[BTRFS_LABEL_SIZE] = "btrfs-label";
1491
1492 ioctl(-1, BTRFS_IOC_SET_FSLABEL, NULL);
1493 printf("ioctl(-1, BTRFS_IOC_SET_FSLABEL, NULL) = -1 EBADF (%m)\n");
1494
1495 ioctl(-1, BTRFS_IOC_SET_FSLABEL, label);
1496 printf("ioctl(-1, BTRFS_IOC_SET_FSLABEL, \"%s\") = -1 EBADF (%m)\n",
1497 label);
1498
1499 if (write_ok) {
1500 ioctl(btrfs_test_dir_fd, BTRFS_IOC_SET_FSLABEL, label);
1501 printf("ioctl(%d, BTRFS_IOC_SET_FSLABEL, \"%s\") = 0\n",
1502 btrfs_test_dir_fd, label);
1503
1504 ioctl(btrfs_test_dir_fd, BTRFS_IOC_GET_FSLABEL, label);
1505 printf("ioctl(%d, BTRFS_IOC_GET_FSLABEL, \"%s\") = 0\n",
1506 btrfs_test_dir_fd, label);
1507 }
1508}
1509
1510/*
1511 * Consumes argument, returns argument:
1512 * - BTRFS_IOC_GET_DEV_STATS
1513 */
1514static void
1515btrfs_test_get_dev_stats_ioctl(void)
1516{
1517 struct btrfs_ioctl_get_dev_stats args = {
1518 .devid = 1,
1519 .nr_items = 5,
1520 .flags = max_flags_plus_one(0),
1521 };
1522
1523 ioctl(-1, BTRFS_IOC_GET_DEV_STATS, NULL);
1524 printf("ioctl(-1, BTRFS_IOC_GET_DEV_STATS, NULL) = -1 EBADF (%m)\n");
1525
1526 printf("ioctl(-1, BTRFS_IOC_GET_DEV_STATS, {devid=%" PRI__u64
1527 ", nr_items=%" PRI__u64", flags=",
1528 args.devid, args.nr_items);
1529 printflags(btrfs_dev_stats_flags, args.flags,
1530 "BTRFS_DEV_STATS_???");
1531 ioctl(-1, BTRFS_IOC_GET_DEV_STATS, &args);
1532 printf("}) = -1 EBADF (%m)\n");
1533
1534 if (write_ok) {
1535 unsigned int i;
1536 args.flags = BTRFS_DEV_STATS_RESET;
1537 printf("ioctl(%d, BTRFS_IOC_GET_DEV_STATS, {devid=%" PRI__u64
1538 ", nr_items=%" PRI__u64", flags=",
1539 btrfs_test_dir_fd, args.devid, args.nr_items);
1540 printflags(btrfs_dev_stats_flags, args.flags,
1541 "BTRFS_DEV_STATS_???");
1542 ioctl(btrfs_test_dir_fd, BTRFS_IOC_GET_DEV_STATS, &args);
1543 printf("} => {nr_items=%" PRI__u64 ", flags=",
1544 args.nr_items);
1545 printflags(btrfs_dev_stats_flags, args.flags,
1546 "BTRFS_DEV_STATS_???");
1547 printf(", [");
1548 for (i = 0; i < args.nr_items; i++) {
1549 const char *name = xlookup(btrfs_dev_stats_values, i);
1550 if (i)
1551 printf(", ");
1552 if (name)
1553 printf("/* %s */ ", name);
1554 printf("%" PRI__u64, args.values[i]);
1555 }
1556 printf("]}) = 0\n");
1557 }
1558}
1559
1560/*
1561 * Consumes argument, returns argument:
1562 * - BTRFS_IOC_DEV_REPLACE
1563 *
1564 * Test environment for this is more difficult; It's better to do it by hand.
1565 */
1566static void
1567btrfs_test_dev_replace_ioctl(void)
1568{
1569 struct btrfs_ioctl_dev_replace_args args = {
1570 .cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_START,
1571 .start = {
1572 .srcdevid = 1,
1573 },
1574 };
1575 strcpy((char *)args.start.srcdev_name, "/dev/sda1");
1576 strcpy((char *)args.start.tgtdev_name, "/dev/sdb1");
1577
1578 /* struct btrfs_ioctl_dev_replace_args */
1579 ioctl(-1, BTRFS_IOC_DEV_REPLACE, NULL);
1580 printf("ioctl(-1, BTRFS_IOC_DEV_REPLACE, NULL) = -1 EBADF (%m)\n");
1581
1582 ioctl(-1, BTRFS_IOC_DEV_REPLACE, &args);
1583 printf("ioctl(-1, BTRFS_IOC_DEV_REPLACE, "
1584 "{cmd=BTRFS_IOCTL_DEV_REPLACE_CMD_START, start={srcdevid=%"
1585 PRI__u64", cont_reading_from_srcdev_mode=%" PRI__u64
1586 ", srcdev_name=\"%s\", tgtdev_name=\"%s\"}}) = -1 EBADF (%m)\n",
1587 args.start.srcdevid,
1588 args.start.cont_reading_from_srcdev_mode,
1589 (char *)args.start.srcdev_name,
1590 (char *)args.start.tgtdev_name);
1591
1592 args.cmd = 1;
1593 ioctl(-1, BTRFS_IOC_DEV_REPLACE, &args);
1594 printf("ioctl(-1, BTRFS_IOC_DEV_REPLACE, "
1595 "{cmd=BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS}) = -1 EBADF (%m)\n");
1596}
1597
1598static void
1599btrfs_test_extent_same_ioctl(void)
1600{
Dmitry V. Levinea516df2016-05-24 02:40:13 +00001601#ifdef BTRFS_IOC_FILE_EXTENT_SAME
Jeff Mahoney35866792016-05-18 18:09:42 -04001602 struct file_dedupe_range args = {
1603 .src_offset = 1024,
1604 .src_length = 10240,
1605 };
1606 struct file_dedupe_range *argsp;
1607
1608 ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME, NULL);
1609 printf("ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
1610 "NULL) = -1 EBADF (%m)\n");
1611
1612 printf("ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
1613 "{src_offset=%" PRIu64
1614 ", src_length=%" PRIu64
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001615 ", dest_count=%hu, info=[]",
Jeff Mahoney35866792016-05-18 18:09:42 -04001616 (uint64_t)args.src_offset,
1617 (uint64_t)args.src_length, args.dest_count);
Jeff Mahoney35866792016-05-18 18:09:42 -04001618 ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME, &args);
1619 printf("}) = -1 EBADF (%m)\n");
1620
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001621 argsp = malloc(sizeof(*argsp) + sizeof(argsp->info[0]) * 3);
Jeff Mahoney35866792016-05-18 18:09:42 -04001622 if (!argsp)
1623 perror_msg_and_fail("malloc failed");
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001624 memset(argsp, 0, sizeof(*argsp) + sizeof(argsp->info[0]) * 3);
Jeff Mahoney35866792016-05-18 18:09:42 -04001625
1626 *argsp = args;
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001627 argsp->dest_count = 3;
Jeff Mahoney35866792016-05-18 18:09:42 -04001628 argsp->info[0].dest_fd = 2;
1629 argsp->info[0].dest_offset = 0;
1630 argsp->info[1].dest_fd = 2;
1631 argsp->info[1].dest_offset = 10240;
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001632 argsp->info[2].dest_fd = 2;
1633 argsp->info[2].dest_offset = 20480;
Jeff Mahoney35866792016-05-18 18:09:42 -04001634
1635 printf("ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
1636 "{src_offset=%" PRIu64
1637 ", src_length=%" PRIu64
1638 ", dest_count=%hu, info=",
1639 (int64_t)argsp->src_offset,
1640 (uint64_t)argsp->src_length, argsp->dest_count);
Jeff Mahoney35866792016-05-18 18:09:42 -04001641 printf("[{dest_fd=%" PRId64 ", dest_offset=%" PRIu64
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001642 "}, {dest_fd=%" PRId64 ", dest_offset=%"PRIu64 "}",
Jeff Mahoney35866792016-05-18 18:09:42 -04001643 (int64_t)argsp->info[0].dest_fd,
1644 (uint64_t)argsp->info[0].dest_offset,
1645 (int64_t)argsp->info[1].dest_fd,
1646 (uint64_t)argsp->info[1].dest_offset);
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001647 if (verbose)
1648 printf(", {dest_fd=%" PRId64 ", dest_offset=%" PRIu64 "}",
1649 (int64_t)argsp->info[2].dest_fd,
1650 (uint64_t)argsp->info[2].dest_offset);
Jeff Mahoney35866792016-05-18 18:09:42 -04001651 else
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001652 printf(", ...");
1653 printf("]");
Jeff Mahoney35866792016-05-18 18:09:42 -04001654 ioctl(-1, BTRFS_IOC_FILE_EXTENT_SAME, argsp);
1655 printf("}) = -1 EBADF (%m)\n");
1656
1657 if (write_ok) {
1658 int fd1, fd2;
1659 char buf[16384];
Jeff Mahoney35866792016-05-18 18:09:42 -04001660
1661 memset(buf, 0, sizeof(buf));
1662
1663 fd1 = openat(btrfs_test_dir_fd, "file1", O_RDWR|O_CREAT, 0600);
1664 if (fd1 < 0)
1665 perror_msg_and_fail("open file1 failed");
1666
1667 fd2 = openat(btrfs_test_dir_fd, "file2", O_RDWR|O_CREAT, 0600);
1668 if (fd2 < 0)
1669 perror_msg_and_fail("open file2 failed");
1670
1671 if (write(fd1, buf, sizeof(buf)) < 0)
1672 perror_msg_and_fail("write: fd1");
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001673 if (write(fd1, buf, sizeof(buf)) < 0)
1674 perror_msg_and_fail("write: fd1");
1675 if (write(fd2, buf, sizeof(buf)) < 0)
1676 perror_msg_and_fail("write: fd2");
Jeff Mahoney35866792016-05-18 18:09:42 -04001677 if (write(fd2, buf, sizeof(buf)) < 0)
1678 perror_msg_and_fail("write: fd2");
1679
1680 close(fd2);
1681 fd2 = openat(btrfs_test_dir_fd, "file2", O_RDONLY);
1682 if (fd2 < 0)
1683 perror_msg_and_fail("open file2 failed");
1684
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001685 memset(argsp, 0, sizeof(*argsp) + sizeof(argsp->info[0]) * 3);
Jeff Mahoney35866792016-05-18 18:09:42 -04001686
1687 argsp->src_offset = 0;
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001688 argsp->src_length = 4096;
1689 argsp->dest_count = 3;
Jeff Mahoney35866792016-05-18 18:09:42 -04001690 argsp->info[0].dest_fd = fd2;
1691 argsp->info[0].dest_offset = 0;
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001692 argsp->info[1].dest_fd = fd2;
1693 argsp->info[1].dest_offset = 10240;
1694 argsp->info[2].dest_fd = fd2;
1695 argsp->info[2].dest_offset = 20480;
Jeff Mahoney35866792016-05-18 18:09:42 -04001696
1697 printf("ioctl(%d, BTRFS_IOC_FILE_EXTENT_SAME or FIDEDUPERANGE, "
1698 "{src_offset=%" PRIu64 ", src_length=%" PRIu64
1699 ", dest_count=%hu, info=", fd1,
1700 (uint64_t)argsp->src_offset,
1701 (uint64_t)argsp->src_length, argsp->dest_count);
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001702 printf("[{dest_fd=%" PRId64 ", dest_offset=%" PRIu64
1703 "}, {dest_fd=%" PRId64 ", dest_offset=%"PRIu64 "}",
1704 (int64_t)argsp->info[0].dest_fd,
1705 (uint64_t)argsp->info[0].dest_offset,
1706 (int64_t)argsp->info[1].dest_fd,
1707 (uint64_t)argsp->info[1].dest_offset);
Jeff Mahoney35866792016-05-18 18:09:42 -04001708 if (verbose)
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001709 printf(", {dest_fd=%" PRId64
1710 ", dest_offset=%" PRIu64 "}",
1711 (int64_t)argsp->info[2].dest_fd,
1712 (uint64_t)argsp->info[2].dest_offset);
Jeff Mahoney35866792016-05-18 18:09:42 -04001713 else
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001714 printf(", ...");
1715
Jeff Mahoney35866792016-05-18 18:09:42 -04001716 ioctl(fd1, BTRFS_IOC_FILE_EXTENT_SAME, argsp);
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001717 printf("]} => {info=");
1718 printf("[{bytes_deduped=%" PRIu64 ", status=%d}, "
1719 "{bytes_deduped=%" PRIu64 ", status=%d}",
1720 (uint64_t)argsp->info[0].bytes_deduped,
1721 argsp->info[0].status,
1722 (uint64_t)argsp->info[1].bytes_deduped,
1723 argsp->info[1].status);
Jeff Mahoney35866792016-05-18 18:09:42 -04001724 if (verbose)
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001725 printf(", {bytes_deduped=%" PRIu64 ", status=%d}",
1726 (uint64_t)argsp->info[2].bytes_deduped,
1727 argsp->info[2].status);
Jeff Mahoney35866792016-05-18 18:09:42 -04001728 else
Jeff Mahoneyeb36e382016-05-27 16:07:22 -04001729 printf(", ...");
1730 printf("]}) = 0\n");
Jeff Mahoney35866792016-05-18 18:09:42 -04001731 close(fd1);
1732 close(fd2);
1733 unlinkat(btrfs_test_dir_fd, "file1", 0);
1734 unlinkat(btrfs_test_dir_fd, "file2", 0);
1735 close(fd1);
1736 close(fd2);
1737 }
1738 free(argsp);
Dmitry V. Levinea516df2016-05-24 02:40:13 +00001739#endif /* BTRFS_IOC_FILE_EXTENT_SAME */
Jeff Mahoney35866792016-05-18 18:09:42 -04001740}
1741
1742static void
1743btrfs_print_features(struct btrfs_ioctl_feature_flags *flags)
1744{
1745 printf("{compat_flags=");
1746 printflags(btrfs_features_compat, flags->compat_flags,
1747 "BTRFS_FEATURE_COMPAT_???");
1748
1749 printf(", compat_ro_flags=");
1750 printflags(btrfs_features_compat_ro, flags->compat_ro_flags,
1751 "BTRFS_FEATURE_COMPAT_RO_???");
1752
1753 printf(", incompat_flags=");
1754 printflags(btrfs_features_incompat, flags->incompat_flags,
1755 "BTRFS_FEATURE_INCOMPAT_???");
1756 printf("}");
1757}
1758
1759/*
1760 * Consumes argument, returns nothing:
1761 * - BTRFS_IOC_SET_FEATURES
1762 *
1763 * Consumes nothing, returns argument:
1764 * - BTRFS_IOC_GET_FEATURES
1765 * - BTRFS_IOC_GET_SUPPORTED_FEATURES
1766 */
1767static void
1768btrfs_test_features_ioctls(void)
1769{
1770 struct btrfs_ioctl_feature_flags args[2] = {
1771 {
1772 .compat_flags = max_flags_plus_one(-1),
1773 .incompat_flags = max_flags_plus_one(9),
1774 .compat_ro_flags = max_flags_plus_one(0),
1775 }, {
1776 .compat_flags = max_flags_plus_one(-1),
1777 .incompat_flags = max_flags_plus_one(9),
1778 .compat_ro_flags = max_flags_plus_one(0),
1779 },
1780 };
1781 struct btrfs_ioctl_feature_flags supported_features[3];
1782
1783 ioctl(-1, BTRFS_IOC_SET_FEATURES, NULL);
1784 printf("ioctl(-1, BTRFS_IOC_SET_FEATURES, NULL) = -1 EBADF (%m)\n");
1785
1786 printf("ioctl(-1, BTRFS_IOC_SET_FEATURES, [");
1787 btrfs_print_features(&args[0]);
1788 printf(", ");
1789 btrfs_print_features(&args[1]);
1790 ioctl(-1, BTRFS_IOC_SET_FEATURES, &args);
1791 printf("]) = -1 EBADF (%m)\n");
1792
1793 if (btrfs_test_root) {
1794 printf("ioctl(%d, BTRFS_IOC_GET_FEATURES, ",
1795 btrfs_test_dir_fd);
1796 ioctl(btrfs_test_dir_fd, BTRFS_IOC_GET_FEATURES,
1797 &supported_features);
1798 btrfs_print_features(&supported_features[0]);
1799 printf(") = 0\n");
1800
1801 ioctl(btrfs_test_dir_fd, BTRFS_IOC_GET_SUPPORTED_FEATURES,
1802 &supported_features);
1803 printf("ioctl(%d, BTRFS_IOC_GET_SUPPORTED_FEATURES, ",
1804 btrfs_test_dir_fd);
1805 printf("[ /* supported */ ");
1806 btrfs_print_features(&supported_features[0]);
1807 printf(", /* safe to set */ ");
1808 btrfs_print_features(&supported_features[1]);
1809 printf(", /* safe to clear */ ");
1810 btrfs_print_features(&supported_features[2]);
1811 printf("]) = 0\n");
1812 }
1813}
1814
Dmitry V. Levinb356ad82016-05-26 14:26:15 +00001815static void
1816btrfs_test_read_ioctls(void)
1817{
1818 static const struct xlat btrfs_read_cmd[] = {
1819 XLAT(BTRFS_IOC_BALANCE_PROGRESS),
1820 XLAT(BTRFS_IOC_FS_INFO),
1821 XLAT(BTRFS_IOC_GET_FEATURES),
1822 XLAT(BTRFS_IOC_GET_FSLABEL),
1823 XLAT(BTRFS_IOC_GET_SUPPORTED_FEATURES),
1824 XLAT(BTRFS_IOC_QGROUP_LIMIT),
1825 XLAT(BTRFS_IOC_QUOTA_RESCAN_STATUS),
1826 XLAT(BTRFS_IOC_START_SYNC),
1827 XLAT(BTRFS_IOC_SUBVOL_GETFLAGS),
1828 };
1829
1830 unsigned int i;
1831 for (i = 0; i < ARRAY_SIZE(btrfs_read_cmd); ++i) {
1832 ioctl(-1, (unsigned long) btrfs_read_cmd[i].val, 0);
1833 printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", btrfs_read_cmd[i].str);
1834 }
1835}
1836
Jeff Mahoney35866792016-05-18 18:09:42 -04001837int
1838main(int argc, char *argv[])
1839{
1840
1841 int opt;
1842 int ret;
1843 const char *path;
1844
1845 while ((opt = getopt(argc, argv, "wv")) != -1) {
1846 switch (opt) {
1847 case 'v':
1848 /*
1849 * These tests are incomplete, especially when
1850 * printing arrays of objects are involved.
1851 */
1852 verbose = true;
1853 break;
1854 case 'w':
1855 write_ok = true;
1856 break;
1857 default:
1858 error_msg_and_fail("usage: btrfs [-v] [-w] [path]");
1859 }
1860 }
1861
1862 /*
1863 * This will enable optional tests that require a valid file descriptor
1864 */
1865 if (optind < argc) {
1866 int rootfd;
1867 struct statfs sfi;
1868 path = argv[optind];
1869
1870 ret = statfs(path, &sfi);
1871 if (ret)
1872 perror_msg_and_fail("statfs(%s) failed", path);
1873
1874 if ((unsigned) sfi.f_type != BTRFS_SUPER_MAGIC)
Dmitry V. Levin9298c662016-05-24 01:33:08 +00001875 error_msg_and_fail("%s is not a btrfs file system",
1876 path);
Jeff Mahoney35866792016-05-18 18:09:42 -04001877
1878 btrfs_test_root = path;
1879 rootfd = open(path, O_RDONLY|O_DIRECTORY);
1880 if (rootfd < 0)
1881 perror_msg_and_fail("open(%s) failed", path);
1882
1883 ret = mkdirat(rootfd, "strace-test", 0755);
1884 if (ret < 0 && errno != EEXIST)
1885 perror_msg_and_fail("mkdirat(strace-test) failed");
1886
1887 btrfs_test_dir_fd = openat(rootfd, "strace-test",
1888 O_RDONLY|O_DIRECTORY);
1889 if (btrfs_test_dir_fd < 0)
1890 perror_msg_and_fail("openat(strace-test) failed");
1891 close(rootfd);
1892 } else
1893 write_ok = false;
1894
1895 if (btrfs_test_root) {
1896 fprintf(stderr, "Testing live ioctls on %s (%s)\n",
1897 btrfs_test_root, write_ok ? "read/write" : "read only");
1898 }
1899
Dmitry V. Levinb356ad82016-05-26 14:26:15 +00001900 btrfs_test_read_ioctls();
Jeff Mahoney35866792016-05-18 18:09:42 -04001901 btrfs_test_trans_ioctls();
1902 btrfs_test_sync_ioctls();
1903 btrfs_test_subvol_ioctls();
1904 btrfs_test_balance_ioctls();
1905 btrfs_test_device_ioctls();
1906 btrfs_test_clone_ioctls();
1907 btrfs_test_defrag_ioctls();
1908 btrfs_test_search_ioctls();
1909 btrfs_test_ino_lookup_ioctl();
1910 btrfs_test_space_info_ioctl();
1911 btrfs_test_scrub_ioctls();
1912 btrfs_test_dev_info_ioctl();
1913 btrfs_test_ino_path_ioctls();
1914 btrfs_test_set_received_subvol_ioctl();
1915 btrfs_test_send_ioctl();
1916 btrfs_test_quota_ctl_ioctl();
1917 btrfs_test_qgroup_assign_ioctl();
1918 btrfs_test_qgroup_create_ioctl();
1919 btrfs_test_quota_rescan_ioctl();
1920 btrfs_test_label_ioctls();
1921 btrfs_test_get_dev_stats_ioctl();
1922 btrfs_test_dev_replace_ioctl();
1923 btrfs_test_extent_same_ioctl();
1924 btrfs_test_features_ioctls();
1925
1926 puts("+++ exited with 0 +++");
1927
1928 return 0;
1929}
Dmitry V. Levin22129182016-05-24 01:32:09 +00001930
1931#else
1932
1933SKIP_MAIN_UNDEFINED("HAVE_LINUX_BTRFS_H")
1934
1935#endif