2 * Copyright (c) 2016 Jeff Mahoney <jeffm@suse.com>
3 * Copyright (c) 2016-2018 The strace developers.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifdef HAVE_LINUX_BTRFS_H
33 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_dev_replace_args)
34 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_send_args)
35 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_received_subvol_args)
36 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_vol_args_v2)
38 # include <linux/btrfs.h>
40 typedef struct btrfs_ioctl_dev_replace_args
41 struct_btrfs_ioctl_dev_replace_args;
42 typedef struct btrfs_ioctl_send_args
43 struct_btrfs_ioctl_send_args;
44 typedef struct btrfs_ioctl_received_subvol_args
45 struct_btrfs_ioctl_received_subvol_args;
46 typedef struct btrfs_ioctl_vol_args_v2
47 struct_btrfs_ioctl_vol_args_v2;
49 #endif /* HAVE_LINUX_BTRFS_H */
53 #ifdef HAVE_LINUX_BTRFS_H
55 #include "print_fields.h"
59 * Prior to Linux 3.12, the BTRFS_IOC_DEFAULT_SUBVOL used u64 in
60 * its definition, which isn't exported by the kernel.
64 #ifndef HAVE_STRUCT_BTRFS_IOCTL_FEATURE_FLAGS_COMPAT_FLAGS
65 struct btrfs_ioctl_feature_flags {
66 uint64_t compat_flags;
67 uint64_t compat_ro_flags;
68 uint64_t incompat_flags;
72 #ifndef HAVE_STRUCT_BTRFS_IOCTL_DEFRAG_RANGE_ARGS_START
73 struct btrfs_ioctl_defrag_range_args {
77 uint32_t extent_thresh;
78 uint32_t compress_type;
83 #ifndef BTRFS_LABEL_SIZE
84 # define BTRFS_LABEL_SIZE 256
87 #ifndef BTRFS_FIRST_FREE_OBJECTID
88 # define BTRFS_FIRST_FREE_OBJECTID 256ULL
91 #ifndef BTRFS_IOC_QUOTA_RESCAN
92 struct btrfs_ioctl_quota_rescan_args {
93 uint64_t flags, progress, reserved[6];
95 # define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
96 struct btrfs_ioctl_quota_rescan_args)
97 # define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
98 struct btrfs_ioctl_quota_rescan_args)
101 #ifndef BTRFS_IOC_QUOTA_RESCAN_WAIT
102 # define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
105 #ifndef BTRFS_IOC_GET_FEATURES
106 # define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
107 struct btrfs_ioctl_feature_flags)
108 # define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
109 struct btrfs_ioctl_feature_flags[2])
110 # define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
111 struct btrfs_ioctl_feature_flags[3])
114 #ifndef BTRFS_IOC_TREE_SEARCH_V2
115 # define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
116 struct btrfs_ioctl_search_args_v2)
117 struct btrfs_ioctl_search_args_v2 {
118 struct btrfs_ioctl_search_key key; /* in/out - search parameters */
119 uint64_t buf_size; /* in - size of buffer
120 * out - on EOVERFLOW: needed size
122 uint64_t buf[0]; /* out - found items */
126 #include "xlat/btrfs_balance_args.h"
127 #include "xlat/btrfs_balance_ctl_cmds.h"
128 #include "xlat/btrfs_balance_flags.h"
129 #include "xlat/btrfs_balance_state.h"
130 #include "xlat/btrfs_compress_types.h"
131 #include "xlat/btrfs_cont_reading_from_srcdev_mode.h"
132 #include "xlat/btrfs_defrag_flags.h"
133 #include "xlat/btrfs_dev_replace_cmds.h"
134 #include "xlat/btrfs_dev_replace_results.h"
135 #include "xlat/btrfs_dev_replace_state.h"
136 #include "xlat/btrfs_dev_stats_flags.h"
137 #include "xlat/btrfs_dev_stats_values.h"
138 #include "xlat/btrfs_features_compat.h"
139 #include "xlat/btrfs_features_compat_ro.h"
140 #include "xlat/btrfs_features_incompat.h"
141 #include "xlat/btrfs_key_types.h"
142 #include "xlat/btrfs_logical_ino_args_flags.h"
143 #include "xlat/btrfs_qgroup_ctl_cmds.h"
144 #include "xlat/btrfs_qgroup_inherit_flags.h"
145 #include "xlat/btrfs_qgroup_limit_flags.h"
146 #include "xlat/btrfs_qgroup_status_flags.h"
147 #include "xlat/btrfs_scrub_flags.h"
148 #include "xlat/btrfs_send_flags.h"
149 #include "xlat/btrfs_snap_flags_v2.h"
150 #include "xlat/btrfs_space_info_flags.h"
151 #include "xlat/btrfs_tree_objectids.h"
157 return 'a' + (v - 10);
161 /* 8-4-4-4-12 = 36 characters */
162 #define UUID_STRING_SIZE 36
164 /* Formats uuid, returns 0 if it's all zeroes */
166 btrfs_unparse_uuid(unsigned char *uuid, char *out)
170 for (i = 0; i < BTRFS_UUID_SIZE; i++) {
171 if (i == 4 || i == 6 || i == 8 || i == 10)
173 *out++ = prnibble(uuid[i] >> 4);
174 *out++ = prnibble(uuid[i] & 0xf);
183 btrfs_print_balance_args(const char *name, const struct btrfs_balance_args *bba)
185 tprintf(", %s=", name);
186 PRINT_FIELD_FLAGS("{", *bba, profiles, btrfs_space_info_flags,
187 "BTRFS_BLOCK_GROUP_???");
188 PRINT_FIELD_U64(", ", *bba, usage);
189 PRINT_FIELD_DEV(", ", *bba, devid);
190 PRINT_FIELD_U64(", ", *bba, pstart);
191 PRINT_FIELD_U64(", ", *bba, pend);
192 PRINT_FIELD_U64(", ", *bba, vstart);
193 PRINT_FIELD_U64(", ", *bba, vend);
194 PRINT_FIELD_U64(", ", *bba, target);
195 PRINT_FIELD_FLAGS(", ", *bba, flags, btrfs_balance_args,
196 "BTRFS_BALANCE_ARGS_???");
201 btrfs_print_balance(struct tcb *const tcp, const kernel_ulong_t arg, bool out)
203 struct btrfs_ioctl_balance_args balance_args;
205 if (umove_or_printaddr(tcp, arg, &balance_args))
208 PRINT_FIELD_FLAGS("{", balance_args, flags, btrfs_balance_flags,
209 "BTRFS_BALANCE_???");
211 PRINT_FIELD_FLAGS(", ", balance_args, state,
213 "BTRFS_BALANCE_STATE_???");
215 if (balance_args.flags & BTRFS_BALANCE_DATA)
216 btrfs_print_balance_args("data", &balance_args.data);
217 if (balance_args.flags & BTRFS_BALANCE_METADATA)
218 btrfs_print_balance_args("meta", &balance_args.meta);
219 if (balance_args.flags & BTRFS_BALANCE_SYSTEM)
220 btrfs_print_balance_args("sys", &balance_args.sys);
225 btrfs_print_features(const struct btrfs_ioctl_feature_flags *flags)
227 PRINT_FIELD_FLAGS("{", *flags, compat_flags, btrfs_features_compat,
228 "BTRFS_FEATURE_COMPAT_???");
229 PRINT_FIELD_FLAGS(", ", *flags, compat_ro_flags,
230 btrfs_features_compat_ro,
231 "BTRFS_FEATURE_COMPAT_RO_???");
232 PRINT_FIELD_FLAGS(", ", *flags, incompat_flags, btrfs_features_incompat,
233 "BTRFS_FEATURE_INCOMPAT_???");
238 btrfs_print_qgroup_limit(const struct btrfs_qgroup_limit *lim)
240 PRINT_FIELD_FLAGS(", lim={", *lim, flags, btrfs_qgroup_limit_flags,
241 "BTRFS_QGROUP_LIMIT_???");
242 PRINT_FIELD_U(", ", *lim, max_rfer);
243 PRINT_FIELD_U(", ", *lim, max_excl);
244 PRINT_FIELD_U(", ", *lim, rsv_rfer);
245 PRINT_FIELD_U(", ", *lim, rsv_excl);
249 #define btrfs_print_key_type(prefix_, where_, field_) \
250 PRINT_FIELD_XVAL_U((prefix_), (where_), field_, btrfs_key_types, NULL)
251 #define btrfs_print_objectid(prefix_, where_, field_) \
252 PRINT_FIELD_XVAL_U((prefix_), (where_), field_, btrfs_tree_objectids, \
256 btrfs_print_data_container_header(const struct btrfs_data_container *container)
258 PRINT_FIELD_U("{", *container, bytes_left);
259 PRINT_FIELD_U(", ", *container, bytes_missing);
260 PRINT_FIELD_U(", ", *container, elem_cnt);
261 PRINT_FIELD_U(", ", *container, elem_missed);
265 btrfs_print_data_container_footer(void)
271 print_btrfs_data_container_logical_ino(struct tcb *tcp, void *elem_buf,
272 size_t elem_size, void *data)
278 } *const record = elem_buf;
280 PRINT_FIELD_U("{", *record, inum);
281 PRINT_FIELD_U(", ", *record, offset);
282 PRINT_FIELD_U(", ", *record, root);
289 btrfs_print_logical_ino_container(struct tcb *tcp,
290 const uint64_t inodes_addr)
292 struct btrfs_data_container container;
294 if (umove_or_printaddr(tcp, inodes_addr, &container))
297 btrfs_print_data_container_header(&container);
302 const uint64_t val_addr =
303 inodes_addr + offsetof(typeof(container), val);
306 print_array(tcp, val_addr, container.elem_cnt / 3,
307 record, sizeof(record),
309 print_btrfs_data_container_logical_ino, 0);
312 btrfs_print_data_container_footer();
316 print_btrfs_data_container_ino_path(struct tcb *tcp, void *elem_buf,
317 size_t elem_size, void *data)
319 const uint64_t *const offset = elem_buf;
320 const uint64_t *const val_addr = data;
322 printpath(tcp, *val_addr + *offset);
328 btrfs_print_ino_path_container(struct tcb *tcp,
329 const uint64_t fspath_addr)
331 struct btrfs_data_container container;
333 if (umove_or_printaddr(tcp, fspath_addr, &container))
336 btrfs_print_data_container_header(&container);
342 fspath_addr + offsetof(typeof(container), val);
345 print_array(tcp, val_addr, container.elem_cnt,
346 &offset, sizeof(offset),
348 print_btrfs_data_container_ino_path, &val_addr);
351 btrfs_print_data_container_footer();
355 btrfs_print_qgroup_inherit(struct tcb *const tcp, const kernel_ulong_t qgi_addr)
357 struct btrfs_qgroup_inherit inherit;
359 if (umove_or_printaddr(tcp, qgi_addr, &inherit))
362 PRINT_FIELD_FLAGS("{", inherit, flags, btrfs_qgroup_inherit_flags,
363 "BTRFS_QGROUP_INHERIT_???");
364 PRINT_FIELD_U(", ", inherit, num_qgroups);
365 PRINT_FIELD_U(", ", inherit, num_ref_copies);
366 PRINT_FIELD_U(", ", inherit, num_excl_copies);
368 btrfs_print_qgroup_limit(&inherit.lim);
374 tprints(", qgroups=");
375 print_array(tcp, qgi_addr + offsetof(typeof(inherit), qgroups),
376 inherit.num_qgroups, &record, sizeof(record),
377 umoven_or_printaddr, print_uint64_array_member, 0);
383 btrfs_print_tree_search(struct tcb *tcp, struct btrfs_ioctl_search_key *key,
384 uint64_t buf_addr, uint64_t buf_size, bool print_size)
387 btrfs_print_objectid("{key={", *key, tree_id);
389 if (key->min_objectid != BTRFS_FIRST_FREE_OBJECTID ||
391 btrfs_print_objectid(", ", *key, min_objectid);
393 if (key->max_objectid != BTRFS_LAST_FREE_OBJECTID ||
395 btrfs_print_objectid(", ", *key, max_objectid);
397 PRINT_FIELD_U64(", ", *key, min_offset);
398 PRINT_FIELD_U64(", ", *key, max_offset);
399 PRINT_FIELD_U64(", ", *key, min_transid);
400 PRINT_FIELD_U64(", ", *key, max_transid);
402 btrfs_print_key_type(", ", *key, min_type);
403 btrfs_print_key_type(", ", *key, max_type);
404 PRINT_FIELD_U(", ", *key, nr_items);
407 tprintf(", buf_size=%" PRIu64, buf_size);
410 PRINT_FIELD_U("{key={", *key, nr_items);
413 tprintf(", buf_size=%" PRIu64, buf_size);
420 for (i = 0; i < key->nr_items; i++) {
421 struct btrfs_ioctl_search_header sh;
422 uint64_t addr = buf_addr + off;
425 if (i > max_strlen ||
426 umove(tcp, addr, &sh)) {
430 PRINT_FIELD_U("{", sh, transid);
431 btrfs_print_objectid(", ", sh, objectid);
432 PRINT_FIELD_U(", ", sh, offset);
433 btrfs_print_key_type(", ", sh, type);
434 PRINT_FIELD_U(", ", sh, len);
436 off += sizeof(sh) + sh.len;
446 print_objectid_callback(struct tcb *tcp, void *elem_buf,
447 size_t elem_size, void *data)
449 printxvals_ex(*(uint64_t *) elem_buf, NULL, XLAT_STYLE_FMT_U,
450 btrfs_tree_objectids, NULL);
456 print_btrfs_ioctl_space_info(struct tcb *tcp, void *elem_buf,
457 size_t elem_size, void *data)
459 const struct btrfs_ioctl_space_info *info = elem_buf;
461 PRINT_FIELD_FLAGS("{", *info, flags, btrfs_space_info_flags,
462 "BTRFS_SPACE_INFO_???");
463 PRINT_FIELD_U(", ", *info, total_bytes);
464 PRINT_FIELD_U(", ", *info, used_bytes);
471 print_btrfs_timespec(const char *prefix, uint64_t sec, uint32_t nsec)
473 tprintf("%s{sec=%" PRIu64 ", nsec=%u}", prefix, sec, nsec);
474 tprints_comment(sprinttime_nsec(sec, nsec));
477 MPERS_PRINTER_DECL(int, btrfs_ioctl,
478 struct tcb *const tcp, const unsigned int code,
479 const kernel_ulong_t arg)
482 /* Take no arguments; command only. */
483 case BTRFS_IOC_TRANS_START:
484 case BTRFS_IOC_TRANS_END:
486 case BTRFS_IOC_SCRUB_CANCEL:
487 case BTRFS_IOC_QUOTA_RESCAN_WAIT:
489 * The codes for these ioctls are based on each accepting a
490 * vol_args but none of them actually consume an argument.
492 case BTRFS_IOC_DEFRAG:
493 case BTRFS_IOC_BALANCE:
496 /* takes a signed int */
497 case BTRFS_IOC_BALANCE_CTL:
499 printxval(btrfs_balance_ctl_cmds, arg, "BTRFS_BALANCE_CTL_???");
503 case BTRFS_IOC_START_SYNC: /* R */
506 ATTRIBUTE_FALLTHROUGH;
508 case BTRFS_IOC_DEFAULT_SUBVOL: /* W */
509 case BTRFS_IOC_WAIT_SYNC: /* W */
511 printnum_int64(tcp, arg, "%" PRIu64);
514 /* u64 but describe a flags bitfield; we can make that symbolic */
515 case BTRFS_IOC_SUBVOL_GETFLAGS: { /* R */
523 if (umove_or_printaddr(tcp, arg, &flags))
526 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
530 case BTRFS_IOC_SUBVOL_SETFLAGS: { /* W */
535 if (umove_or_printaddr(tcp, arg, &flags))
538 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
542 /* More complex types */
543 case BTRFS_IOC_BALANCE_V2: /* RW */
546 btrfs_print_balance(tcp, arg, false);
554 btrfs_print_balance(tcp, arg, true);
556 case BTRFS_IOC_BALANCE_PROGRESS: /* R */
561 btrfs_print_balance(tcp, arg, true);
564 case BTRFS_IOC_DEFRAG_RANGE: { /* W */
565 struct btrfs_ioctl_defrag_range_args args;
569 if (umove_or_printaddr(tcp, arg, &args))
572 PRINT_FIELD_U("{", args, start);
573 PRINT_FIELD_U64(", ", args, len);
575 PRINT_FIELD_FLAGS(", ", args, flags, btrfs_defrag_flags,
576 "BTRFS_DEFRAG_RANGE_???");
577 PRINT_FIELD_U(", ", args, extent_thresh);
578 PRINT_FIELD_XVAL(", ", args, compress_type,
579 btrfs_compress_types, "BTRFS_COMPRESS_???");
584 case BTRFS_IOC_DEV_INFO: { /* RW */
585 struct btrfs_ioctl_dev_info_args args;
586 char uuid[UUID_STRING_SIZE+1];
591 else if (syserror(tcp))
595 if (umove_or_printaddr(tcp, arg, &args))
598 valid = btrfs_unparse_uuid(args.uuid, uuid);
600 PRINT_FIELD_DEV("{", args, devid);
602 tprintf(", uuid=%s", uuid);
609 tprintf("uuid=%s, ", uuid);
611 PRINT_FIELD_U("", args, bytes_used);
612 PRINT_FIELD_U(", ", args, total_bytes);
613 PRINT_FIELD_CSTRING(", ", args, path);
619 case BTRFS_IOC_DEV_REPLACE: { /* RW */
620 struct_btrfs_ioctl_dev_replace_args args;
624 else if (syserror(tcp))
629 if (umove_or_printaddr(tcp, arg, &args))
633 PRINT_FIELD_XVAL("{", args, cmd, btrfs_dev_replace_cmds,
634 "BTRFS_IOCTL_DEV_REPLACE_CMD_???");
635 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_START) {
636 PRINT_FIELD_DEV(", start={", args.start,
638 PRINT_FIELD_XVAL(", ", args.start,
639 cont_reading_from_srcdev_mode,
640 btrfs_cont_reading_from_srcdev_mode,
641 "BTRFS_IOCTL_DEV_REPLACE_CONT_READING"
642 "_FROM_SRCDEV_MODE_???");
643 PRINT_FIELD_CSTRING(", ", args.start,
645 PRINT_FIELD_CSTRING(", ", args.start,
654 PRINT_FIELD_XVAL("{", args, result, btrfs_dev_replace_results,
655 "BTRFS_IOCTL_DEV_REPLACE_RESULT_???");
656 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS) {
657 PRINT_FIELD_XVAL(", status={", args.status,
658 replace_state, btrfs_dev_replace_state,
659 "BTRFS_IOCTL_DEV_REPLACE_STATE_???");
661 PRINT_FIELD_U(", ", args.status, progress_1000);
662 if (args.status.progress_1000 <= 1000)
663 tprintf_comment("%u.%u%%",
664 (unsigned) args.status.progress_1000 / 10,
665 (unsigned) args.status.progress_1000 % 10);
667 PRINT_FIELD_U(", ", args.status, time_started);
668 tprints_comment(sprinttime(args.status.time_started));
670 PRINT_FIELD_U(", ", args.status, time_stopped);
671 tprints_comment(sprinttime(args.status.time_stopped));
673 PRINT_FIELD_U(", ", args.status, num_write_errors);
674 PRINT_FIELD_U(", ", args.status,
675 num_uncorrectable_read_errors);
681 case BTRFS_IOC_GET_FEATURES: { /* R */
682 struct btrfs_ioctl_feature_flags flags;
688 if (umove_or_printaddr(tcp, arg, &flags))
691 btrfs_print_features(&flags);
695 case BTRFS_IOC_SET_FEATURES: { /* W */
696 struct btrfs_ioctl_feature_flags flarg[2];
700 if (umove_or_printaddr(tcp, arg, &flarg))
704 btrfs_print_features(&flarg[0]);
706 btrfs_print_features(&flarg[1]);
711 case BTRFS_IOC_GET_SUPPORTED_FEATURES: { /* R */
712 struct btrfs_ioctl_feature_flags flarg[3];
718 if (umove_or_printaddr(tcp, arg, &flarg))
722 btrfs_print_features(&flarg[0]);
723 tprints_comment("supported");
726 btrfs_print_features(&flarg[1]);
727 tprints_comment("safe to set");
730 btrfs_print_features(&flarg[2]);
731 tprints_comment("safe to clear");
737 case BTRFS_IOC_FS_INFO: { /* R */
738 struct btrfs_ioctl_fs_info_args args;
739 char uuid[UUID_STRING_SIZE+1];
740 uint32_t nodesize, sectorsize, clone_alignment;
741 #ifndef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
742 uint32_t *reserved32;
749 if (umove_or_printaddr(tcp, arg, &args))
752 #ifdef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
753 nodesize = args.nodesize,
754 sectorsize = args.sectorsize,
755 clone_alignment = args.clone_alignment;
757 reserved32 = (void *) args.reserved;
758 nodesize = reserved32[0];
759 sectorsize = reserved32[1];
760 clone_alignment = reserved32[2];
762 btrfs_unparse_uuid(args.fsid, uuid);
764 PRINT_FIELD_U("{", args, max_id);
765 PRINT_FIELD_U(", ", args, num_devices);
766 tprintf(", fsid=%s, nodesize=%u, sectorsize=%u"
767 ", clone_alignment=%u",
768 uuid, nodesize, sectorsize, clone_alignment);
773 case BTRFS_IOC_GET_DEV_STATS: { /* RW */
774 struct btrfs_ioctl_get_dev_stats args;
779 else if (syserror(tcp))
783 if (umove_or_printaddr(tcp, arg, &args))
789 PRINT_FIELD_DEV("", args, devid);
793 PRINT_FIELD_U("", args, nr_items);
794 PRINT_FIELD_FLAGS(", ", args, flags, btrfs_dev_stats_flags,
795 "BTRFS_DEV_STATS_???");
803 * The structure has a 1k limit; Let's make sure we don't
804 * go off into the middle of nowhere with a bad nr_items
808 for (i = 0; i < args.nr_items; i++) {
811 if (i >= ARRAY_SIZE(args.values)) {
817 printxval_u(btrfs_dev_stats_values, i, NULL);
818 tprintf("] = %" PRI__u64, args.values[i]);
824 case BTRFS_IOC_INO_LOOKUP: { /* RW */
825 struct btrfs_ioctl_ino_lookup_args args;
829 else if (syserror(tcp))
834 if (umove_or_printaddr(tcp, arg, &args))
838 /* Use subvolume id of the containing root */
839 if (args.treeid == 0)
840 set_tcb_priv_ulong(tcp, 1);
842 btrfs_print_objectid("{", args, treeid);
843 btrfs_print_objectid(", ", args, objectid);
849 if (get_tcb_priv_ulong(tcp)) {
850 btrfs_print_objectid("", args, treeid);
854 PRINT_FIELD_CSTRING("", args, name);
859 case BTRFS_IOC_INO_PATHS: { /* RW */
860 struct btrfs_ioctl_ino_path_args args;
864 else if (syserror(tcp))
869 if (umove_or_printaddr(tcp, arg, &args))
873 PRINT_FIELD_U("{", args, inum);
874 PRINT_FIELD_U(", ", args, size);
875 PRINT_FIELD_ADDR64(", ", args, fspath);
881 btrfs_print_ino_path_container(tcp, args.fspath);
887 case BTRFS_IOC_LOGICAL_INO: { /* RW */
888 struct btrfs_ioctl_logical_ino_args args;
892 else if (syserror(tcp))
897 if (umove_or_printaddr(tcp, arg, &args))
901 PRINT_FIELD_U("{", args, logical);
902 PRINT_FIELD_U(", ", args, size);
904 if (!IS_ARRAY_ZERO(args.reserved)) {
905 tprints(", reserved=[");
906 for (size_t i = 0; i < 3; ++i)
907 tprintf("%s%#" PRI__x64,
914 printflags64(btrfs_logical_ino_args_flags,
915 #ifdef HAVE_STRUCT_BTRFS_IOCTL_LOGICAL_INO_ARGS_FLAGS
920 , "BTRFS_LOGICAL_INO_ARGS_???");
921 PRINT_FIELD_ADDR64(", ", args, inodes);
927 btrfs_print_logical_ino_container(tcp, args.inodes);
933 case BTRFS_IOC_QGROUP_ASSIGN: { /* W */
934 struct btrfs_ioctl_qgroup_assign_args args;
937 if (umove_or_printaddr(tcp, arg, &args))
940 PRINT_FIELD_U("{", args, assign);
941 PRINT_FIELD_U(", ", args, src);
942 PRINT_FIELD_U(", ", args, dst);
947 case BTRFS_IOC_QGROUP_CREATE: { /* W */
948 struct btrfs_ioctl_qgroup_create_args args;
951 if (umove_or_printaddr(tcp, arg, &args))
954 PRINT_FIELD_U("{", args, create);
955 PRINT_FIELD_U(", ", args, qgroupid);
960 case BTRFS_IOC_QGROUP_LIMIT: { /* R */
961 struct btrfs_ioctl_qgroup_limit_args args;
967 if (umove_or_printaddr(tcp, arg, &args))
970 PRINT_FIELD_U("{", args, qgroupid);
971 btrfs_print_qgroup_limit(&args.lim);
976 case BTRFS_IOC_QUOTA_CTL: { /* W */
977 struct btrfs_ioctl_quota_ctl_args args;
980 if (umove_or_printaddr(tcp, arg, &args))
983 PRINT_FIELD_XVAL("{", args, cmd, btrfs_qgroup_ctl_cmds,
984 "BTRFS_QUOTA_CTL_???");
990 case BTRFS_IOC_QUOTA_RESCAN: { /* W */
991 struct btrfs_ioctl_quota_rescan_args args;
994 if (umove_or_printaddr(tcp, arg, &args))
997 PRINT_FIELD_U("{", args, flags);
1002 case BTRFS_IOC_QUOTA_RESCAN_STATUS: { /* R */
1003 struct btrfs_ioctl_quota_rescan_args args;
1009 if (umove_or_printaddr(tcp, arg, &args))
1012 PRINT_FIELD_U("{", args, flags);
1013 btrfs_print_objectid(", ", args, progress);
1018 case BTRFS_IOC_SET_RECEIVED_SUBVOL: { /* RW */
1019 struct_btrfs_ioctl_received_subvol_args args;
1020 char uuid[UUID_STRING_SIZE+1];
1024 else if (syserror(tcp))
1029 if (umove_or_printaddr(tcp, arg, &args))
1032 if (entering(tcp)) {
1033 btrfs_unparse_uuid((unsigned char *)args.uuid, uuid);
1034 tprintf("{uuid=%s", uuid);
1035 PRINT_FIELD_U(", ", args, stransid);
1036 print_btrfs_timespec(", stime=",
1037 args.stime.sec, args.stime.nsec);
1038 PRINT_FIELD_U(", ", args, flags);
1042 PRINT_FIELD_U("{", args, rtransid);
1043 print_btrfs_timespec(", rtime=",
1044 args.rtime.sec, args.rtime.nsec);
1049 case BTRFS_IOC_SCRUB: /* RW */
1050 case BTRFS_IOC_SCRUB_PROGRESS: { /* RW */
1051 struct btrfs_ioctl_scrub_args args;
1055 else if (syserror(tcp))
1060 if (umove_or_printaddr(tcp, arg, &args))
1063 if (entering(tcp)) {
1064 PRINT_FIELD_DEV("{", args, devid);
1065 if (code == BTRFS_IOC_SCRUB) {
1066 PRINT_FIELD_U(", ", args, start);
1067 PRINT_FIELD_U64(", ", args, end);
1068 PRINT_FIELD_FLAGS(", ", args, flags,
1075 PRINT_FIELD_U("{progress={", args.progress,
1076 data_extents_scrubbed);
1077 PRINT_FIELD_U(", ", args.progress, tree_extents_scrubbed);
1078 PRINT_FIELD_U(", ", args.progress, data_bytes_scrubbed);
1079 PRINT_FIELD_U(", ", args.progress, tree_bytes_scrubbed);
1080 PRINT_FIELD_U(", ", args.progress, read_errors);
1081 PRINT_FIELD_U(", ", args.progress, csum_errors);
1082 PRINT_FIELD_U(", ", args.progress, verify_errors);
1083 PRINT_FIELD_U(", ", args.progress, no_csum);
1084 PRINT_FIELD_U(", ", args.progress, csum_discards);
1085 PRINT_FIELD_U(", ", args.progress, super_errors);
1086 PRINT_FIELD_U(", ", args.progress, malloc_errors);
1087 PRINT_FIELD_U(", ", args.progress, uncorrectable_errors);
1088 PRINT_FIELD_U(", ", args.progress, corrected_errors);
1089 PRINT_FIELD_U(", ", args.progress, last_physical);
1090 PRINT_FIELD_U(", ", args.progress, unverified_errors);
1095 case BTRFS_IOC_TREE_SEARCH: { /* RW */
1096 struct btrfs_ioctl_search_args args;
1097 uint64_t buf_offset;
1101 else if (syserror(tcp))
1106 if (umove_or_printaddr(tcp, arg, &args))
1109 buf_offset = offsetof(struct btrfs_ioctl_search_args, buf);
1110 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1111 sizeof(args.buf), false);
1117 case BTRFS_IOC_TREE_SEARCH_V2: { /* RW */
1118 struct btrfs_ioctl_search_args_v2 args;
1119 uint64_t buf_offset;
1123 else if (syserror(tcp)) {
1124 if (tcp->u_error == EOVERFLOW) {
1126 if (!umove_or_printaddr_ignore_syserror(tcp,
1128 PRINT_FIELD_U("{", args, buf_size);
1135 if (umove_or_printaddr(tcp, arg, &args))
1138 buf_offset = offsetof(struct btrfs_ioctl_search_args_v2, buf);
1139 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1140 args.buf_size, true);
1146 case BTRFS_IOC_SEND: { /* W */
1147 struct_btrfs_ioctl_send_args args;
1150 if (umove_or_printaddr(tcp, arg, &args))
1153 PRINT_FIELD_FD("{", args, send_fd, tcp);
1154 PRINT_FIELD_U(", ", args, clone_sources_count);
1156 tprints(", clone_sources=");
1158 printaddr((uintptr_t) args.clone_sources);
1161 print_array(tcp, ptr_to_kulong(args.clone_sources),
1162 args.clone_sources_count,
1163 &record, sizeof(record),
1164 umoven_or_printaddr,
1165 print_objectid_callback, 0);
1167 btrfs_print_objectid(", ", args, parent_root);
1168 PRINT_FIELD_FLAGS(", ", args, flags, btrfs_send_flags,
1169 "BTRFS_SEND_FLAGS_???");
1174 case BTRFS_IOC_SPACE_INFO: { /* RW */
1175 struct btrfs_ioctl_space_args args;
1179 else if (syserror(tcp))
1184 if (umove_or_printaddr(tcp, arg, &args))
1187 if (entering(tcp)) {
1188 PRINT_FIELD_U("{", args, space_slots);
1193 PRINT_FIELD_U("{", args, total_spaces);
1195 if (args.space_slots == 0 && args.total_spaces) {
1203 struct btrfs_ioctl_space_info info;
1204 tprints(", spaces=");
1205 print_array(tcp, arg + offsetof(typeof(args), spaces),
1207 &info, sizeof(info), umoven_or_printaddr,
1208 print_btrfs_ioctl_space_info, 0);
1214 case BTRFS_IOC_SNAP_CREATE:
1215 case BTRFS_IOC_RESIZE:
1216 case BTRFS_IOC_SCAN_DEV:
1217 case BTRFS_IOC_ADD_DEV:
1218 case BTRFS_IOC_RM_DEV:
1219 case BTRFS_IOC_SUBVOL_CREATE:
1220 case BTRFS_IOC_SNAP_DESTROY:
1221 case BTRFS_IOC_DEVICES_READY: { /* W */
1222 struct btrfs_ioctl_vol_args args;
1225 if (umove_or_printaddr(tcp, arg, &args))
1228 PRINT_FIELD_FD("{", args, fd, tcp);
1229 PRINT_FIELD_CSTRING(", ", args, name);
1234 case BTRFS_IOC_SNAP_CREATE_V2:
1235 case BTRFS_IOC_SUBVOL_CREATE_V2: { /* code is W, but is actually RW */
1236 struct_btrfs_ioctl_vol_args_v2 args;
1240 else if (syserror(tcp))
1245 if (umove_or_printaddr(tcp, arg, &args))
1248 if (entering(tcp)) {
1249 PRINT_FIELD_FD("{", args, fd, tcp);
1250 PRINT_FIELD_FLAGS(", ", args, flags,
1251 btrfs_snap_flags_v2,
1252 "BTRFS_SUBVOL_???");
1253 if (args.flags & BTRFS_SUBVOL_QGROUP_INHERIT) {
1254 PRINT_FIELD_U(", ", args, size);
1255 tprints(", qgroup_inherit=");
1256 btrfs_print_qgroup_inherit(tcp,
1257 ptr_to_kulong(args.qgroup_inherit));
1259 PRINT_FIELD_CSTRING(", ", args, name);
1263 PRINT_FIELD_U("{", args, transid);
1268 case BTRFS_IOC_GET_FSLABEL: /* R */
1271 ATTRIBUTE_FALLTHROUGH;
1272 case BTRFS_IOC_SET_FSLABEL: { /* W */
1273 char label[BTRFS_LABEL_SIZE];
1276 if (umove_or_printaddr(tcp, arg, &label))
1278 print_quoted_cstring(label, sizeof(label));
1282 case BTRFS_IOC_CLONE: /* FICLONE */
1283 case BTRFS_IOC_CLONE_RANGE: /* FICLONERANGE */
1284 #ifdef BTRFS_IOC_FILE_EXTENT_SAME
1285 case BTRFS_IOC_FILE_EXTENT_SAME: /* FIDEDUPERANGE */
1288 * FICLONE, FICLONERANGE, and FIDEDUPERANGE started out as
1289 * btrfs ioctls and the code was kept for the generic
1290 * implementations. We use the BTRFS_* names here because
1291 * they will be available on older systems.
1293 return file_ioctl(tcp, code, arg);
1296 return RVAL_DECODED;
1298 return RVAL_IOCTL_DECODED;
1300 #endif /* HAVE_LINUX_BTRFS_H */