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_defrag_flags.h"
132 #include "xlat/btrfs_dev_replace_cmds.h"
133 #include "xlat/btrfs_dev_replace_results.h"
134 #include "xlat/btrfs_dev_replace_state.h"
135 #include "xlat/btrfs_dev_stats_flags.h"
136 #include "xlat/btrfs_dev_stats_values.h"
137 #include "xlat/btrfs_features_compat.h"
138 #include "xlat/btrfs_features_compat_ro.h"
139 #include "xlat/btrfs_features_incompat.h"
140 #include "xlat/btrfs_key_types.h"
141 #include "xlat/btrfs_logical_ino_args_flags.h"
142 #include "xlat/btrfs_qgroup_ctl_cmds.h"
143 #include "xlat/btrfs_qgroup_inherit_flags.h"
144 #include "xlat/btrfs_qgroup_limit_flags.h"
145 #include "xlat/btrfs_qgroup_status_flags.h"
146 #include "xlat/btrfs_scrub_flags.h"
147 #include "xlat/btrfs_send_flags.h"
148 #include "xlat/btrfs_snap_flags_v2.h"
149 #include "xlat/btrfs_space_info_flags.h"
150 #include "xlat/btrfs_tree_objectids.h"
156 return 'a' + (v - 10);
160 /* 8-4-4-4-12 = 36 characters */
161 #define UUID_STRING_SIZE 36
163 /* Formats uuid, returns 0 if it's all zeroes */
165 btrfs_unparse_uuid(unsigned char *uuid, char *out)
169 for (i = 0; i < BTRFS_UUID_SIZE; i++) {
170 if (i == 4 || i == 6 || i == 8 || i == 10)
172 *out++ = prnibble(uuid[i] >> 4);
173 *out++ = prnibble(uuid[i] & 0xf);
182 print_u64(const char *name, uint64_t value)
184 tprintf(", %s=%" PRIu64, name, value);
185 if (value == UINT64_MAX)
186 tprints_comment("UINT64_MAX");
189 #define print_member_u64(obj, name) print_u64(#name, obj->name)
192 btrfs_print_balance_args(const char *name, const struct btrfs_balance_args *bba)
194 tprintf(", %s={profiles=", name);
195 printflags64(btrfs_space_info_flags, bba->profiles,
196 "BTRFS_BLOCK_GROUP_???");
197 print_member_u64(bba, usage);
198 print_member_u64(bba, devid);
199 print_member_u64(bba, pstart);
200 print_member_u64(bba, pend);
201 print_member_u64(bba, vstart);
202 print_member_u64(bba, vend);
203 print_member_u64(bba, target);
205 printflags64(btrfs_balance_args, bba->flags, "BTRFS_BALANCE_ARGS_???");
210 btrfs_print_balance(struct tcb *const tcp, const kernel_ulong_t arg, bool out)
212 struct btrfs_ioctl_balance_args balance_args;
214 if (umove_or_printaddr(tcp, arg, &balance_args))
218 printflags64(btrfs_balance_flags, balance_args.flags,
219 "BTRFS_BALANCE_???");
222 printflags64(btrfs_balance_state, balance_args.state,
223 "BTRFS_BALANCE_STATE_???");
226 if (balance_args.flags & BTRFS_BALANCE_DATA)
227 btrfs_print_balance_args("data", &balance_args.data);
228 if (balance_args.flags & BTRFS_BALANCE_METADATA)
229 btrfs_print_balance_args("meta", &balance_args.meta);
230 if (balance_args.flags & BTRFS_BALANCE_SYSTEM)
231 btrfs_print_balance_args("sys", &balance_args.sys);
236 btrfs_print_features(const struct btrfs_ioctl_feature_flags *flags)
238 tprints("{compat_flags=");
239 printflags64(btrfs_features_compat, flags->compat_flags,
240 "BTRFS_FEATURE_COMPAT_???");
242 tprints(", compat_ro_flags=");
243 printflags64(btrfs_features_compat_ro, flags->compat_ro_flags,
244 "BTRFS_FEATURE_COMPAT_RO_???");
246 tprints(", incompat_flags=");
247 printflags64(btrfs_features_incompat, flags->incompat_flags,
248 "BTRFS_FEATURE_INCOMPAT_???");
253 btrfs_print_qgroup_limit(const struct btrfs_qgroup_limit *lim)
256 printflags64(btrfs_qgroup_limit_flags, lim->flags,
257 "BTRFS_QGROUP_LIMIT_???");
258 tprintf(", max_rfer=%" PRI__u64 ", max_excl=%" PRI__u64
259 ", rsv_rfer=%" PRI__u64 ", rsv_excl=%" PRI__u64 "}",
260 lim->max_rfer, lim->max_excl,
261 lim->rsv_rfer, lim->rsv_excl);
265 btrfs_print_key_type(uint32_t type)
268 tprints_comment(xlookup(btrfs_key_types, type));
272 btrfs_print_objectid(uint64_t objectid)
274 tprintf("%" PRIu64, objectid);
275 tprints_comment(xlookup(btrfs_tree_objectids, objectid));
279 btrfs_print_data_container_header(const struct btrfs_data_container *container)
281 tprintf("{bytes_left=%u, bytes_missing=%u"
282 ", elem_cnt=%u, elem_missed=%u, val=",
283 container->bytes_left, container->bytes_missing,
284 container->elem_cnt, container->elem_missed);
288 btrfs_print_data_container_footer(void)
294 print_btrfs_data_container_logical_ino(struct tcb *tcp, void *elem_buf,
295 size_t elem_size, void *data)
297 const uint64_t *const record = elem_buf;
299 tprintf("{inum=%" PRIu64 ", offset=%" PRIu64 ", root=%" PRIu64 "}",
300 record[0], record[1], record[2]);
306 btrfs_print_logical_ino_container(struct tcb *tcp,
307 const uint64_t inodes_addr)
309 struct btrfs_data_container container;
311 if (umove_or_printaddr(tcp, inodes_addr, &container))
314 btrfs_print_data_container_header(&container);
319 const uint64_t val_addr =
320 inodes_addr + offsetof(typeof(container), val);
322 print_array(tcp, val_addr, container.elem_cnt / 3,
323 record, sizeof(record),
325 print_btrfs_data_container_logical_ino, 0);
328 btrfs_print_data_container_footer();
332 print_btrfs_data_container_ino_path(struct tcb *tcp, void *elem_buf,
333 size_t elem_size, void *data)
335 const uint64_t *const offset = elem_buf;
336 const uint64_t *const val_addr = data;
338 printpath(tcp, *val_addr + *offset);
344 btrfs_print_ino_path_container(struct tcb *tcp,
345 const uint64_t fspath_addr)
347 struct btrfs_data_container container;
349 if (umove_or_printaddr(tcp, fspath_addr, &container))
352 btrfs_print_data_container_header(&container);
358 fspath_addr + offsetof(typeof(container), val);
360 print_array(tcp, val_addr, container.elem_cnt,
361 &offset, sizeof(offset),
363 print_btrfs_data_container_ino_path, &val_addr);
366 btrfs_print_data_container_footer();
370 print_uint64(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
372 tprintf("%" PRIu64, *(uint64_t *) elem_buf);
378 btrfs_print_qgroup_inherit(struct tcb *const tcp, const kernel_ulong_t qgi_addr)
380 struct btrfs_qgroup_inherit inherit;
382 if (umove_or_printaddr(tcp, qgi_addr, &inherit))
386 printflags64(btrfs_qgroup_inherit_flags, inherit.flags,
387 "BTRFS_QGROUP_INHERIT_???");
388 tprintf(", num_qgroups=%" PRI__u64 ", num_ref_copies=%" PRI__u64
389 ", num_excl_copies=%" PRI__u64 ", lim=",
390 inherit.num_qgroups, inherit.num_ref_copies,
391 inherit.num_excl_copies);
393 btrfs_print_qgroup_limit(&inherit.lim);
395 tprints(", qgroups=");
401 print_array(tcp, qgi_addr + offsetof(typeof(inherit), qgroups),
402 inherit.num_qgroups, &record, sizeof(record),
403 umoven_or_printaddr, print_uint64, 0);
409 print_key_value_internal(struct tcb *tcp, const char *name, uint64_t value)
412 tprintf(", %s=%" PRIu64, name, value);
413 if (value == UINT64_MAX)
414 tprints_comment("UINT64_MAX");
417 #define print_key_value(tcp, key, name) \
418 print_key_value_internal((tcp), #name, (key)->name)
421 btrfs_print_tree_search(struct tcb *tcp, struct btrfs_ioctl_search_key *key,
422 uint64_t buf_addr, uint64_t buf_size, bool print_size)
425 tprints("{key={tree_id=");
426 btrfs_print_objectid(key->tree_id);
428 if (key->min_objectid != BTRFS_FIRST_FREE_OBJECTID ||
430 tprints(", min_objectid=");
431 btrfs_print_objectid(key->min_objectid);
434 if (key->max_objectid != BTRFS_LAST_FREE_OBJECTID ||
436 tprints(", max_objectid=");
437 btrfs_print_objectid(key->max_objectid);
440 print_key_value(tcp, key, min_offset);
441 print_key_value(tcp, key, max_offset);
442 print_key_value(tcp, key, min_transid);
443 print_key_value(tcp, key, max_transid);
445 tprints(", min_type=");
446 btrfs_print_key_type(key->min_type);
447 tprints(", max_type=");
448 btrfs_print_key_type(key->max_type);
449 tprintf(", nr_items=%u}", key->nr_items);
451 tprintf(", buf_size=%" PRIu64, buf_size);
454 tprintf("{key={nr_items=%u}", key->nr_items);
456 tprintf(", buf_size=%" PRIu64, buf_size);
464 for (i = 0; i < key->nr_items; i++) {
465 struct btrfs_ioctl_search_header sh;
466 uint64_t addr = buf_addr + off;
469 if (i > max_strlen ||
470 umove(tcp, addr, &sh)) {
474 tprintf("{transid=%" PRI__u64 ", objectid=",
476 btrfs_print_objectid(sh.objectid);
477 tprintf(", offset=%" PRI__u64 ", type=", sh.offset);
478 btrfs_print_key_type(sh.type);
479 tprintf(", len=%u}", sh.len);
480 off += sizeof(sh) + sh.len;
490 print_objectid_callback(struct tcb *tcp, void *elem_buf,
491 size_t elem_size, void *data)
493 btrfs_print_objectid(*(uint64_t *) elem_buf);
499 print_btrfs_ioctl_space_info(struct tcb *tcp, void *elem_buf,
500 size_t elem_size, void *data)
502 const struct btrfs_ioctl_space_info *info = elem_buf;
505 printflags64(btrfs_space_info_flags, info->flags,
506 "BTRFS_SPACE_INFO_???");
507 tprintf(", total_bytes=%" PRI__u64 ", used_bytes=%" PRI__u64 "}",
508 info->total_bytes, info->used_bytes);
513 MPERS_PRINTER_DECL(int, btrfs_ioctl,
514 struct tcb *const tcp, const unsigned int code,
515 const kernel_ulong_t arg)
518 /* Take no arguments; command only. */
519 case BTRFS_IOC_TRANS_START:
520 case BTRFS_IOC_TRANS_END:
522 case BTRFS_IOC_SCRUB_CANCEL:
523 case BTRFS_IOC_QUOTA_RESCAN_WAIT:
525 * The codes for these ioctls are based on each accepting a
526 * vol_args but none of them actually consume an argument.
528 case BTRFS_IOC_DEFRAG:
529 case BTRFS_IOC_BALANCE:
532 /* takes a signed int */
533 case BTRFS_IOC_BALANCE_CTL:
535 printxval(btrfs_balance_ctl_cmds, arg, "BTRFS_BALANCE_CTL_???");
539 case BTRFS_IOC_START_SYNC: /* R */
542 ATTRIBUTE_FALLTHROUGH;
544 case BTRFS_IOC_DEFAULT_SUBVOL: /* W */
545 case BTRFS_IOC_WAIT_SYNC: /* W */
547 printnum_int64(tcp, arg, "%" PRIu64);
550 /* u64 but describe a flags bitfield; we can make that symbolic */
551 case BTRFS_IOC_SUBVOL_GETFLAGS: { /* R */
559 if (umove_or_printaddr(tcp, arg, &flags))
562 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
566 case BTRFS_IOC_SUBVOL_SETFLAGS: { /* W */
571 if (umove_or_printaddr(tcp, arg, &flags))
574 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
578 /* More complex types */
579 case BTRFS_IOC_BALANCE_V2: /* RW */
582 btrfs_print_balance(tcp, arg, false);
590 btrfs_print_balance(tcp, arg, true);
592 case BTRFS_IOC_BALANCE_PROGRESS: /* R */
597 btrfs_print_balance(tcp, arg, true);
600 case BTRFS_IOC_DEFRAG_RANGE: { /* W */
601 struct btrfs_ioctl_defrag_range_args args;
605 if (umove_or_printaddr(tcp, arg, &args))
608 tprintf("{start=%" PRIu64 ", len=", (uint64_t)args.start);
610 tprintf("%" PRIu64, (uint64_t) args.len);
611 if (args.len == UINT64_MAX)
612 tprints_comment("UINT64_MAX");
615 printflags64(btrfs_defrag_flags, args.flags,
616 "BTRFS_DEFRAG_RANGE_???");
617 tprintf(", extent_thresh=%u, compress_type=",
619 printxval(btrfs_compress_types, args.compress_type,
620 "BTRFS_COMPRESS_???");
625 case BTRFS_IOC_DEV_INFO: { /* RW */
626 struct btrfs_ioctl_dev_info_args args;
627 char uuid[UUID_STRING_SIZE+1];
632 else if (syserror(tcp))
636 if (umove_or_printaddr(tcp, arg, &args))
640 valid = btrfs_unparse_uuid(args.uuid, uuid);
642 tprintf("devid=%" PRI__u64, args.devid);
644 tprintf(", uuid=%s", uuid);
649 tprintf("uuid=%s, ", uuid);
650 tprintf("bytes_used=%" PRI__u64
651 ", total_bytes=%" PRI__u64,
652 args.bytes_used, args.total_bytes);
653 PRINT_FIELD_CSTRING(", ", args, path);
658 case BTRFS_IOC_DEV_REPLACE: { /* RW */
659 struct_btrfs_ioctl_dev_replace_args args;
663 else if (syserror(tcp))
668 if (umove_or_printaddr(tcp, arg, &args))
673 printxval64(btrfs_dev_replace_cmds, args.cmd,
674 "BTRFS_IOCTL_DEV_REPLACE_CMD_???");
675 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_START) {
677 tprintf(", start={srcdevid=%" PRIu64
678 ", cont_reading_from_srcdev_mode=%" PRIu64
680 (uint64_t) args.start.srcdevid,
681 (uint64_t) args.start.cont_reading_from_srcdev_mode);
683 str = (const char *) args.start.srcdev_name;
684 print_quoted_cstring(str,
685 sizeof(args.start.srcdev_name));
686 tprints(", tgtdev_name=");
687 str = (const char *) args.start.tgtdev_name;
688 print_quoted_cstring(str,
689 sizeof(args.start.tgtdev_name));
698 printxval64(btrfs_dev_replace_results, args.result,
699 "BTRFS_IOCTL_DEV_REPLACE_RESULT_???");
700 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS) {
702 printxval64(btrfs_dev_replace_state,
703 args.status.replace_state,
704 "BTRFS_IOCTL_DEV_REPLACE_STATE_???");
705 tprintf(", progress_1000=%" PRIu64,
706 (uint64_t) args.status.progress_1000);
708 if (args.status.progress_1000 <= 1000)
709 tprintf_comment("%u.%u%%",
710 (unsigned) args.status.progress_1000 / 10,
711 (unsigned) args.status.progress_1000 % 10);
713 tprintf(", time_started=%" PRIu64,
714 (uint64_t) args.status.time_started);
715 tprints_comment(sprinttime(args.status.time_started));
717 tprintf(", time_stopped=%" PRIu64,
718 (uint64_t) args.status.time_stopped);
719 tprints_comment(sprinttime(args.status.time_stopped));
721 tprintf(", num_write_errors=%" PRIu64
722 ", num_uncorrectable_read_errors=%" PRIu64,
723 (uint64_t) args.status.num_write_errors,
724 (uint64_t) args.status.num_uncorrectable_read_errors);
730 case BTRFS_IOC_GET_FEATURES: { /* R */
731 struct btrfs_ioctl_feature_flags flags;
737 if (umove_or_printaddr(tcp, arg, &flags))
740 btrfs_print_features(&flags);
744 case BTRFS_IOC_SET_FEATURES: { /* W */
745 struct btrfs_ioctl_feature_flags flarg[2];
749 if (umove_or_printaddr(tcp, arg, &flarg))
753 btrfs_print_features(&flarg[0]);
755 btrfs_print_features(&flarg[1]);
760 case BTRFS_IOC_GET_SUPPORTED_FEATURES: { /* R */
761 struct btrfs_ioctl_feature_flags flarg[3];
767 if (umove_or_printaddr(tcp, arg, &flarg))
771 btrfs_print_features(&flarg[0]);
772 tprints_comment("supported");
775 btrfs_print_features(&flarg[1]);
776 tprints_comment("safe to set");
779 btrfs_print_features(&flarg[2]);
780 tprints_comment("safe to clear");
786 case BTRFS_IOC_FS_INFO: { /* R */
787 struct btrfs_ioctl_fs_info_args args;
788 char uuid[UUID_STRING_SIZE+1];
789 uint32_t nodesize, sectorsize, clone_alignment;
790 #ifndef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
791 uint32_t *reserved32;
798 if (umove_or_printaddr(tcp, arg, &args))
801 #ifdef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
802 nodesize = args.nodesize,
803 sectorsize = args.sectorsize,
804 clone_alignment = args.clone_alignment;
806 reserved32 = (void *) args.reserved;
807 nodesize = reserved32[0];
808 sectorsize = reserved32[1];
809 clone_alignment = reserved32[2];
811 btrfs_unparse_uuid(args.fsid, uuid);
814 tprintf("max_id=%" PRI__u64 ", num_devices=%" PRI__u64
815 ", fsid=%s, nodesize=%u, sectorsize=%u"
816 ", clone_alignment=%u",
817 args.max_id, args.num_devices, uuid,
818 nodesize, sectorsize, clone_alignment);
823 case BTRFS_IOC_GET_DEV_STATS: { /* RW */
824 struct btrfs_ioctl_get_dev_stats args;
829 else if (syserror(tcp))
833 if (umove_or_printaddr(tcp, arg, &args))
839 tprintf("devid=%" PRI__u64 ", ", args.devid);
841 tprintf("nr_items=%" PRI__u64 ", flags=", args.nr_items);
842 printflags64(btrfs_dev_stats_flags, args.flags,
843 "BTRFS_DEV_STATS_???");
851 * The structure has a 1k limit; Let's make sure we don't
852 * go off into the middle of nowhere with a bad nr_items
856 for (i = 0; i < args.nr_items; i++) {
859 if (i >= ARRAY_SIZE(args.values)) {
863 tprintf("%" PRI__u64, args.values[i]);
864 tprints_comment(xlookup(btrfs_dev_stats_values, i));
870 case BTRFS_IOC_INO_LOOKUP: { /* RW */
871 struct btrfs_ioctl_ino_lookup_args args;
875 else if (syserror(tcp))
880 if (umove_or_printaddr(tcp, arg, &args))
884 /* Use subvolume id of the containing root */
885 if (args.treeid == 0)
886 set_tcb_priv_ulong(tcp, 1);
889 btrfs_print_objectid(args.treeid);
890 tprints(", objectid=");
891 btrfs_print_objectid(args.objectid);
897 if (get_tcb_priv_ulong(tcp)) {
899 btrfs_print_objectid(args.treeid);
903 PRINT_FIELD_CSTRING("", args, name);
908 case BTRFS_IOC_INO_PATHS: { /* RW */
909 struct btrfs_ioctl_ino_path_args args;
913 else if (syserror(tcp))
918 if (umove_or_printaddr(tcp, arg, &args))
924 tprintf("inum=%" PRI__u64 ", size=%" PRI__u64,
925 args.inum, args.size);
926 tprints(", fspath=");
927 printaddr64(args.fspath);
933 btrfs_print_ino_path_container(tcp, args.fspath);
939 case BTRFS_IOC_LOGICAL_INO: { /* RW */
940 struct btrfs_ioctl_logical_ino_args args;
944 else if (syserror(tcp))
949 if (umove_or_printaddr(tcp, arg, &args))
955 tprintf("logical=%" PRI__u64 ", size=%" PRI__u64,
956 args.logical, args.size);
959 printflags64(btrfs_logical_ino_args_flags,
960 #ifdef HAVE_STRUCT_BTRFS_IOCTL_LOGICAL_INO_ARGS_FLAGS
965 , "BTRFS_LOGICAL_INO_ARGS_???");
966 tprints(", inodes=");
967 printaddr64(args.inodes);
973 btrfs_print_logical_ino_container(tcp, args.inodes);
979 case BTRFS_IOC_QGROUP_ASSIGN: { /* W */
980 struct btrfs_ioctl_qgroup_assign_args args;
983 if (umove_or_printaddr(tcp, arg, &args))
986 tprintf("{assign=%" PRI__u64 ", src=%" PRI__u64
987 ", dst=%" PRI__u64 "}",
988 args.assign, args.src, args.dst);
992 case BTRFS_IOC_QGROUP_CREATE: { /* W */
993 struct btrfs_ioctl_qgroup_create_args args;
996 if (umove_or_printaddr(tcp, arg, &args))
999 tprintf("{create=%" PRI__u64 ", qgroupid=%" PRI__u64 "}",
1000 args.create, args.qgroupid);
1004 case BTRFS_IOC_QGROUP_LIMIT: { /* R */
1005 struct btrfs_ioctl_qgroup_limit_args args;
1011 if (umove_or_printaddr(tcp, arg, &args))
1014 tprintf("{qgroupid=%" PRI__u64 ", lim=", args.qgroupid);
1015 btrfs_print_qgroup_limit(&args.lim);
1020 case BTRFS_IOC_QUOTA_CTL: { /* W */
1021 struct btrfs_ioctl_quota_ctl_args args;
1024 if (umove_or_printaddr(tcp, arg, &args))
1027 printxval64(btrfs_qgroup_ctl_cmds, args.cmd,
1028 "BTRFS_QUOTA_CTL_???");
1034 case BTRFS_IOC_QUOTA_RESCAN: { /* W */
1035 struct btrfs_ioctl_quota_rescan_args args;
1038 if (umove_or_printaddr(tcp, arg, &args))
1041 tprintf("{flags=%" PRIu64 "}", (uint64_t) args.flags);
1045 case BTRFS_IOC_QUOTA_RESCAN_STATUS: { /* R */
1046 struct btrfs_ioctl_quota_rescan_args args;
1052 if (umove_or_printaddr(tcp, arg, &args))
1055 tprintf("{flags=%" PRIu64 ", progress=", (uint64_t) args.flags);
1056 btrfs_print_objectid(args.progress);
1061 case BTRFS_IOC_SET_RECEIVED_SUBVOL: { /* RW */
1062 struct_btrfs_ioctl_received_subvol_args args;
1063 char uuid[UUID_STRING_SIZE+1];
1067 else if (syserror(tcp))
1072 if (umove_or_printaddr(tcp, arg, &args))
1075 if (entering(tcp)) {
1076 btrfs_unparse_uuid((unsigned char *)args.uuid, uuid);
1077 tprintf("{uuid=%s, stransid=%" PRIu64
1078 ", stime=%" PRIu64 ".%u, flags=%" PRIu64
1079 "}", uuid, (uint64_t) args.stransid,
1080 (uint64_t) args.stime.sec, args.stime.nsec,
1081 (uint64_t) args.flags);
1084 tprintf("{rtransid=%" PRIu64 ", rtime=%" PRIu64 ".%u}",
1085 (uint64_t) args.rtransid, (uint64_t) args.rtime.sec,
1090 case BTRFS_IOC_SCRUB: /* RW */
1091 case BTRFS_IOC_SCRUB_PROGRESS: { /* RW */
1092 struct btrfs_ioctl_scrub_args args;
1096 else if (syserror(tcp))
1101 if (umove_or_printaddr(tcp, arg, &args))
1104 if (entering(tcp)) {
1105 tprintf("{devid=%" PRI__u64, args.devid);
1106 if (code == BTRFS_IOC_SCRUB) {
1107 tprintf(", start=%" PRI__u64 ", end=",
1109 tprintf("%" PRI__u64, args.end);
1110 if (args.end == UINT64_MAX)
1111 tprints_comment("UINT64_MAX");
1112 tprints(", flags=");
1113 printflags64(btrfs_scrub_flags, args.flags,
1119 tprintf("{data_extents_scrubbed=%" PRI__u64
1120 ", tree_extents_scrubbed=%" PRI__u64
1121 ", data_bytes_scrubbed=%" PRI__u64
1122 ", tree_bytes_scrubbed=%" PRI__u64
1123 ", read_errors=%" PRI__u64
1124 ", csum_errors=%" PRI__u64
1125 ", verify_errors=%" PRI__u64
1126 ", no_csum=%" PRI__u64
1127 ", csum_discards=%" PRI__u64
1128 ", super_errors=%" PRI__u64
1129 ", malloc_errors=%" PRI__u64
1130 ", uncorrectable_errors=%" PRI__u64
1131 ", corrected_errors=%" PRI__u64
1132 ", last_physical=%" PRI__u64
1133 ", unverified_errors=%" PRI__u64 "}",
1134 args.progress.data_extents_scrubbed,
1135 args.progress.tree_extents_scrubbed,
1136 args.progress.data_bytes_scrubbed,
1137 args.progress.tree_bytes_scrubbed,
1138 args.progress.read_errors,
1139 args.progress.csum_errors,
1140 args.progress.verify_errors,
1141 args.progress.no_csum,
1142 args.progress.csum_discards,
1143 args.progress.super_errors,
1144 args.progress.malloc_errors,
1145 args.progress.uncorrectable_errors,
1146 args.progress.corrected_errors,
1147 args.progress.last_physical,
1148 args.progress.unverified_errors);
1152 case BTRFS_IOC_TREE_SEARCH: { /* RW */
1153 struct btrfs_ioctl_search_args args;
1154 uint64_t buf_offset;
1158 else if (syserror(tcp))
1163 if (umove_or_printaddr(tcp, arg, &args))
1166 buf_offset = offsetof(struct btrfs_ioctl_search_args, buf);
1167 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1168 sizeof(args.buf), false);
1174 case BTRFS_IOC_TREE_SEARCH_V2: { /* RW */
1175 struct btrfs_ioctl_search_args_v2 args;
1176 uint64_t buf_offset;
1180 else if (syserror(tcp)) {
1181 if (tcp->u_error == EOVERFLOW) {
1184 if (!umove_or_printaddr(tcp, arg, &args))
1185 tprintf("{buf_size=%" PRIu64 "}",
1186 (uint64_t)args.buf_size);
1187 tcp->u_error = EOVERFLOW;
1193 if (umove_or_printaddr(tcp, arg, &args))
1196 buf_offset = offsetof(struct btrfs_ioctl_search_args_v2, buf);
1197 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1198 args.buf_size, true);
1204 case BTRFS_IOC_SEND: { /* W */
1205 struct_btrfs_ioctl_send_args args;
1208 if (umove_or_printaddr(tcp, arg, &args))
1211 tprints("{send_fd=");
1212 printfd(tcp, args.send_fd);
1213 tprintf(", clone_sources_count=%" PRIu64 ", clone_sources=",
1214 (uint64_t) args.clone_sources_count);
1220 print_array(tcp, ptr_to_kulong(args.clone_sources),
1221 args.clone_sources_count,
1222 &record, sizeof(record),
1223 umoven_or_printaddr,
1224 print_objectid_callback, 0);
1226 tprints(", parent_root=");
1227 btrfs_print_objectid(args.parent_root);
1228 tprints(", flags=");
1229 printflags64(btrfs_send_flags, args.flags,
1230 "BTRFS_SEND_FLAGS_???");
1235 case BTRFS_IOC_SPACE_INFO: { /* RW */
1236 struct btrfs_ioctl_space_args args;
1240 else if (syserror(tcp))
1245 if (umove_or_printaddr(tcp, arg, &args))
1249 if (entering(tcp)) {
1250 tprintf("space_slots=%" PRI__u64 "}", args.space_slots);
1254 tprintf("total_spaces=%" PRI__u64, args.total_spaces);
1256 if (args.space_slots == 0 && args.total_spaces) {
1261 tprints(", spaces=");
1266 struct btrfs_ioctl_space_info info;
1267 print_array(tcp, arg + offsetof(typeof(args), spaces),
1269 &info, sizeof(info), umoven_or_printaddr,
1270 print_btrfs_ioctl_space_info, 0);
1276 case BTRFS_IOC_SNAP_CREATE:
1277 case BTRFS_IOC_RESIZE:
1278 case BTRFS_IOC_SCAN_DEV:
1279 case BTRFS_IOC_ADD_DEV:
1280 case BTRFS_IOC_RM_DEV:
1281 case BTRFS_IOC_SUBVOL_CREATE:
1282 case BTRFS_IOC_SNAP_DESTROY:
1283 case BTRFS_IOC_DEVICES_READY: { /* W */
1284 struct btrfs_ioctl_vol_args args;
1287 if (umove_or_printaddr(tcp, arg, &args))
1291 printfd(tcp, args.fd);
1292 PRINT_FIELD_CSTRING(", ", args, name);
1297 case BTRFS_IOC_SNAP_CREATE_V2:
1298 case BTRFS_IOC_SUBVOL_CREATE_V2: { /* code is W, but is actually RW */
1299 struct_btrfs_ioctl_vol_args_v2 args;
1303 else if (syserror(tcp))
1308 if (umove_or_printaddr(tcp, arg, &args))
1311 if (entering(tcp)) {
1313 printfd(tcp, args.fd);
1314 tprints(", flags=");
1315 printflags64(btrfs_snap_flags_v2, args.flags,
1316 "BTRFS_SUBVOL_???");
1317 if (args.flags & BTRFS_SUBVOL_QGROUP_INHERIT) {
1318 tprintf(", size=%" PRIu64 ", qgroup_inherit=",
1319 (uint64_t) args.size);
1321 btrfs_print_qgroup_inherit(tcp,
1322 ptr_to_kulong(args.qgroup_inherit));
1324 PRINT_FIELD_CSTRING(", ", args, name);
1328 tprintf("{transid=%" PRIu64 "}", (uint64_t) args.transid);
1332 case BTRFS_IOC_GET_FSLABEL: /* R */
1335 ATTRIBUTE_FALLTHROUGH;
1336 case BTRFS_IOC_SET_FSLABEL: { /* W */
1337 char label[BTRFS_LABEL_SIZE];
1340 if (umove_or_printaddr(tcp, arg, &label))
1342 print_quoted_cstring(label, sizeof(label));
1346 case BTRFS_IOC_CLONE: /* FICLONE */
1347 case BTRFS_IOC_CLONE_RANGE: /* FICLONERANGE */
1348 #ifdef BTRFS_IOC_FILE_EXTENT_SAME
1349 case BTRFS_IOC_FILE_EXTENT_SAME: /* FIDEDUPERANGE */
1352 * FICLONE, FICLONERANGE, and FIDEDUPERANGE started out as
1353 * btrfs ioctls and the code was kept for the generic
1354 * implementations. We use the BTRFS_* names here because
1355 * they will be available on older systems.
1357 return file_ioctl(tcp, code, arg);
1360 return RVAL_DECODED;
1362 return RVAL_IOCTL_DECODED;
1364 #endif /* HAVE_LINUX_BTRFS_H */