2 * Copyright (c) 2016 Jeff Mahoney <jeffm@suse.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifdef HAVE_LINUX_BTRFS_H
32 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_dev_replace_args)
33 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_send_args)
34 #include DEF_MPERS_TYPE(struct_btrfs_ioctl_received_subvol_args)
36 # include <linux/btrfs.h>
38 typedef struct btrfs_ioctl_dev_replace_args
39 struct_btrfs_ioctl_dev_replace_args;
40 typedef struct btrfs_ioctl_send_args
41 struct_btrfs_ioctl_send_args;
42 typedef struct btrfs_ioctl_received_subvol_args
43 struct_btrfs_ioctl_received_subvol_args;
45 #endif /* HAVE_LINUX_BTRFS_H */
49 #ifdef HAVE_LINUX_BTRFS_H
54 * Prior to Linux 3.12, the BTRFS_IOC_DEFAULT_SUBVOL used u64 in
55 * its definition, which isn't exported by the kernel.
59 #ifndef HAVE_STRUCT_BTRFS_IOCTL_FEATURE_FLAGS_COMPAT_FLAGS
60 struct btrfs_ioctl_feature_flags {
61 uint64_t compat_flags;
62 uint64_t compat_ro_flags;
63 uint64_t incompat_flags;
67 #ifndef HAVE_STRUCT_BTRFS_IOCTL_DEFRAG_RANGE_ARGS_START
68 struct btrfs_ioctl_defrag_range_args {
72 uint32_t extent_thresh;
73 uint32_t compress_type;
78 #ifndef BTRFS_LABEL_SIZE
79 # define BTRFS_LABEL_SIZE 256
82 #ifndef BTRFS_FIRST_FREE_OBJECTID
83 # define BTRFS_FIRST_FREE_OBJECTID 256ULL
86 #ifndef BTRFS_IOC_QUOTA_RESCAN
87 struct btrfs_ioctl_quota_rescan_args {
88 uint64_t flags, progress, reserved[6];
90 # define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
91 struct btrfs_ioctl_quota_rescan_args)
92 # define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
93 struct btrfs_ioctl_quota_rescan_args)
96 #ifndef BTRFS_IOC_QUOTA_RESCAN_WAIT
97 # define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
100 #ifndef BTRFS_IOC_GET_FEATURES
101 # define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
102 struct btrfs_ioctl_feature_flags)
103 # define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
104 struct btrfs_ioctl_feature_flags[2])
105 # define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
106 struct btrfs_ioctl_feature_flags[3])
109 #ifndef BTRFS_IOC_TREE_SEARCH_V2
110 # define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
111 struct btrfs_ioctl_search_args_v2)
112 struct btrfs_ioctl_search_args_v2 {
113 struct btrfs_ioctl_search_key key; /* in/out - search parameters */
114 uint64_t buf_size; /* in - size of buffer
115 * out - on EOVERFLOW: needed size
117 uint64_t buf[0]; /* out - found items */
121 #include "xlat/btrfs_balance_args.h"
122 #include "xlat/btrfs_balance_ctl_cmds.h"
123 #include "xlat/btrfs_balance_flags.h"
124 #include "xlat/btrfs_balance_state.h"
125 #include "xlat/btrfs_compress_types.h"
126 #include "xlat/btrfs_defrag_flags.h"
127 #include "xlat/btrfs_dev_replace_cmds.h"
128 #include "xlat/btrfs_dev_replace_results.h"
129 #include "xlat/btrfs_dev_replace_state.h"
130 #include "xlat/btrfs_dev_stats_flags.h"
131 #include "xlat/btrfs_dev_stats_values.h"
132 #include "xlat/btrfs_features_compat.h"
133 #include "xlat/btrfs_features_compat_ro.h"
134 #include "xlat/btrfs_features_incompat.h"
135 #include "xlat/btrfs_key_types.h"
136 #include "xlat/btrfs_qgroup_ctl_cmds.h"
137 #include "xlat/btrfs_qgroup_inherit_flags.h"
138 #include "xlat/btrfs_qgroup_limit_flags.h"
139 #include "xlat/btrfs_qgroup_status_flags.h"
140 #include "xlat/btrfs_scrub_flags.h"
141 #include "xlat/btrfs_send_flags.h"
142 #include "xlat/btrfs_snap_flags_v2.h"
143 #include "xlat/btrfs_space_info_flags.h"
144 #include "xlat/btrfs_tree_objectids.h"
150 return 'a' + (v - 10);
154 /* 8-4-4-4-12 = 36 characters */
155 #define UUID_STRING_SIZE 36
157 /* Formats uuid, returns 0 if it's all zeroes */
159 btrfs_unparse_uuid(unsigned char *uuid, char *out)
163 for (i = 0; i < BTRFS_UUID_SIZE; i++) {
164 if (i == 4 || i == 6 || i == 8 || i == 10)
166 *out++ = prnibble(uuid[i] >> 4);
167 *out++ = prnibble(uuid[i] & 0xf);
176 print_u64(const char *name, uint64_t value)
178 tprintf(", %s=%" PRIu64, name, value);
179 if (value == UINT64_MAX)
180 tprints(" /* UINT64_MAX */");
183 #define print_member_u64(obj, name) print_u64(#name, obj->name)
186 btrfs_print_balance_args(const char *name, const struct btrfs_balance_args *bba)
188 tprintf(", %s={profiles=", name);
189 printflags64(btrfs_space_info_flags, bba->profiles,
190 "BTRFS_BLOCK_GROUP_???");
191 print_member_u64(bba, usage);
192 print_member_u64(bba, devid);
193 print_member_u64(bba, pstart);
194 print_member_u64(bba, pend);
195 print_member_u64(bba, vstart);
196 print_member_u64(bba, vend);
197 print_member_u64(bba, target);
199 printflags64(btrfs_balance_args, bba->flags, "BTRFS_BALANCE_ARGS_???");
204 btrfs_print_balance(struct tcb *tcp, const long arg, bool out)
206 struct btrfs_ioctl_balance_args balance_args;
208 if (umove_or_printaddr(tcp, arg, &balance_args))
212 printflags64(btrfs_balance_flags, balance_args.flags,
213 "BTRFS_BALANCE_???");
216 printflags64(btrfs_balance_state, balance_args.state,
217 "BTRFS_BALANCE_STATE_???");
220 if (balance_args.flags & BTRFS_BALANCE_DATA)
221 btrfs_print_balance_args("data", &balance_args.data);
222 if (balance_args.flags & BTRFS_BALANCE_METADATA)
223 btrfs_print_balance_args("meta", &balance_args.meta);
224 if (balance_args.flags & BTRFS_BALANCE_SYSTEM)
225 btrfs_print_balance_args("sys", &balance_args.sys);
230 btrfs_print_features(const struct btrfs_ioctl_feature_flags *flags)
232 tprints("{compat_flags=");
233 printflags64(btrfs_features_compat, flags->compat_flags,
234 "BTRFS_FEATURE_COMPAT_???");
236 tprints(", compat_ro_flags=");
237 printflags64(btrfs_features_compat_ro, flags->compat_ro_flags,
238 "BTRFS_FEATURE_COMPAT_RO_???");
240 tprints(", incompat_flags=");
241 printflags64(btrfs_features_incompat, flags->incompat_flags,
242 "BTRFS_FEATURE_INCOMPAT_???");
247 btrfs_print_qgroup_limit(const struct btrfs_qgroup_limit *lim)
250 printflags64(btrfs_qgroup_limit_flags, lim->flags,
251 "BTRFS_QGROUP_LIMIT_???");
252 tprintf(", max_rfer=%" PRI__u64 ", max_excl=%" PRI__u64
253 ", rsv_rfer=%" PRI__u64 ", rsv_excl=%" PRI__u64 "}",
254 lim->max_rfer, lim->max_excl,
255 lim->rsv_rfer, lim->rsv_excl);
259 btrfs_print_key_type(uint32_t type)
261 const char *str = xlookup(btrfs_key_types, type);
264 tprintf(" /* %s */", str);
268 btrfs_print_objectid(uint64_t objectid)
270 const char *str = xlookup(btrfs_tree_objectids, objectid);
271 tprintf("%" PRIu64, objectid);
273 tprintf(" /* %s */", str);
277 btrfs_print_data_container_header(const struct btrfs_data_container *container)
279 tprintf("{bytes_left=%u, bytes_missing=%u"
280 ", elem_cnt=%u, elem_missed=%u, val=",
281 container->bytes_left, container->bytes_missing,
282 container->elem_cnt, container->elem_missed);
286 btrfs_print_data_container_footer(void)
292 print_btrfs_data_container_logical_ino(struct tcb *tcp, void *elem_buf,
293 size_t elem_size, void *data)
295 const uint64_t *const record = elem_buf;
297 tprintf("{inum=%" PRIu64 ", offset=%" PRIu64 ", root=%" PRIu64 "}",
298 record[0], record[1], record[2]);
304 btrfs_print_logical_ino_container(struct tcb *tcp,
305 const uint64_t inodes_addr)
307 struct btrfs_data_container container;
309 if (umove_or_printaddr(tcp, inodes_addr, &container))
312 btrfs_print_data_container_header(&container);
317 const uint64_t val_addr =
318 inodes_addr + offsetof(typeof(container), val);
320 print_array(tcp, val_addr, container.elem_cnt / 3,
321 record, sizeof(record),
323 print_btrfs_data_container_logical_ino, 0);
326 btrfs_print_data_container_footer();
330 print_btrfs_data_container_ino_path(struct tcb *tcp, void *elem_buf,
331 size_t elem_size, void *data)
333 const uint64_t *const offset = elem_buf;
334 const uint64_t *const val_addr = data;
336 printpath(tcp, *val_addr + *offset);
342 btrfs_print_ino_path_container(struct tcb *tcp,
343 const uint64_t fspath_addr)
345 struct btrfs_data_container container;
347 if (umove_or_printaddr(tcp, fspath_addr, &container))
350 btrfs_print_data_container_header(&container);
356 fspath_addr + offsetof(typeof(container), val);
358 print_array(tcp, val_addr, container.elem_cnt,
359 &offset, sizeof(offset),
361 print_btrfs_data_container_ino_path, &val_addr);
364 btrfs_print_data_container_footer();
368 print_uint64(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
370 tprintf("%" PRIu64, * (uint64_t *) elem_buf);
376 btrfs_print_qgroup_inherit(struct tcb *tcp, const uint64_t qgi_addr)
378 struct btrfs_qgroup_inherit inherit;
380 if (umove_or_printaddr(tcp, qgi_addr, &inherit))
384 printflags64(btrfs_qgroup_inherit_flags, inherit.flags,
385 "BTRFS_QGROUP_INHERIT_???");
386 tprintf(", num_qgroups=%" PRI__u64 ", num_ref_copies=%" PRI__u64
387 ", num_excl_copies=%" PRI__u64 ", lim=",
388 inherit.num_qgroups, inherit.num_ref_copies,
389 inherit.num_excl_copies);
391 btrfs_print_qgroup_limit(&inherit.lim);
393 tprints(", qgroups=");
399 print_array(tcp, qgi_addr + offsetof(typeof(inherit), qgroups),
400 inherit.num_qgroups, &record, sizeof(record),
401 umoven_or_printaddr, print_uint64, 0);
407 print_key_value_internal(struct tcb *tcp, const char *name, uint64_t value)
410 tprintf(", %s=%" PRIu64, name, value);
411 if (value == UINT64_MAX)
412 tprints(" /* UINT64_MAX */");
415 #define print_key_value(tcp, key, name) \
416 print_key_value_internal((tcp), #name, (key)->name)
419 btrfs_print_tree_search(struct tcb *tcp, struct btrfs_ioctl_search_key *key,
420 uint64_t buf_addr, uint64_t buf_size, bool print_size)
423 tprintf("{key={tree_id=");
424 btrfs_print_objectid(key->tree_id);
426 if (key->min_objectid != BTRFS_FIRST_FREE_OBJECTID ||
428 tprints(", min_objectid=");
429 btrfs_print_objectid(key->min_objectid);
432 if (key->max_objectid != BTRFS_LAST_FREE_OBJECTID ||
434 tprints(", max_objectid=");
435 btrfs_print_objectid(key->max_objectid);
438 print_key_value(tcp, key, min_offset);
439 print_key_value(tcp, key, max_offset);
440 print_key_value(tcp, key, min_transid);
441 print_key_value(tcp, key, max_transid);
443 tprints(", min_type=");
444 btrfs_print_key_type(key->min_type);
445 tprints(", max_type=");
446 btrfs_print_key_type(key->max_type);
447 tprintf(", nr_items=%u}", key->nr_items);
449 tprintf(", buf_size=%" PRIu64, buf_size);
452 tprintf("{key={nr_items=%u}", key->nr_items);
454 tprintf(", buf_size=%" PRIu64, buf_size);
462 for (i = 0; i < key->nr_items; i++) {
463 struct btrfs_ioctl_search_header sh;
464 uint64_t addr = buf_addr + off;
467 if (i > max_strlen ||
468 umove(tcp, addr, &sh)) {
472 tprintf("{transid=%" PRI__u64 ", objectid=",
474 btrfs_print_objectid(sh.objectid);
475 tprintf(", offset=%" PRI__u64 ", type=", sh.offset);
476 btrfs_print_key_type(sh.type);
477 tprintf(", len=%u}", sh.len);
478 off += sizeof(sh) + sh.len;
488 print_objectid_callback(struct tcb *tcp, void *elem_buf,
489 size_t elem_size, void *data)
491 btrfs_print_objectid(* (uint64_t *) elem_buf);
497 print_btrfs_ioctl_space_info(struct tcb *tcp, void *elem_buf,
498 size_t elem_size, void *data)
500 const struct btrfs_ioctl_space_info *info = elem_buf;
503 printflags64(btrfs_space_info_flags, info->flags,
504 "BTRFS_SPACE_INFO_???");
505 tprintf(", total_bytes=%" PRI__u64 ", used_bytes=%" PRI__u64 "}",
506 info->total_bytes, info->used_bytes);
511 MPERS_PRINTER_DECL(int, btrfs_ioctl,
512 struct tcb *tcp, const unsigned int code, const long arg)
515 /* Take no arguments; command only. */
516 case BTRFS_IOC_TRANS_START:
517 case BTRFS_IOC_TRANS_END:
519 case BTRFS_IOC_SCRUB_CANCEL:
520 case BTRFS_IOC_QUOTA_RESCAN_WAIT:
522 * The codes for these ioctls are based on each accepting a
523 * vol_args but none of them actually consume an argument.
525 case BTRFS_IOC_DEFRAG:
526 case BTRFS_IOC_BALANCE:
529 /* takes a signed int */
530 case BTRFS_IOC_BALANCE_CTL:
532 printxval(btrfs_balance_ctl_cmds, arg, "BTRFS_BALANCE_CTL_???");
536 case BTRFS_IOC_START_SYNC: /* R */
541 case BTRFS_IOC_DEFAULT_SUBVOL: /* W */
542 case BTRFS_IOC_WAIT_SYNC: /* W */
544 printnum_int64(tcp, arg, "%" PRIu64);
547 /* u64 but describe a flags bitfield; we can make that symbolic */
548 case BTRFS_IOC_SUBVOL_GETFLAGS: { /* R */
556 if (umove_or_printaddr(tcp, arg, &flags))
559 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
563 case BTRFS_IOC_SUBVOL_SETFLAGS: { /* W */
568 if (umove_or_printaddr(tcp, arg, &flags))
571 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
575 /* More complex types */
576 case BTRFS_IOC_BALANCE_V2: /* RW */
579 btrfs_print_balance(tcp, arg, false);
587 btrfs_print_balance(tcp, arg, true);
589 case BTRFS_IOC_BALANCE_PROGRESS: /* R */
594 btrfs_print_balance(tcp, arg, true);
597 case BTRFS_IOC_DEFRAG_RANGE: { /* W */
598 struct btrfs_ioctl_defrag_range_args args;
602 if (umove_or_printaddr(tcp, arg, &args))
605 tprintf("{start=%" PRIu64 ", len=", (uint64_t)args.start);
607 tprintf("%" PRIu64, (uint64_t) args.len);
608 if (args.len == UINT64_MAX)
609 tprints(" /* UINT64_MAX */");
612 printflags64(btrfs_defrag_flags, args.flags,
613 "BTRFS_DEFRAG_RANGE_???");
614 tprintf(", extent_thresh=%u, compress_type=",
616 printxval(btrfs_compress_types, args.compress_type,
617 "BTRFS_COMPRESS_???");
622 case BTRFS_IOC_DEV_INFO: { /* RW */
623 struct btrfs_ioctl_dev_info_args args;
624 char uuid[UUID_STRING_SIZE+1];
629 else if (syserror(tcp))
633 if (umove_or_printaddr(tcp, arg, &args))
637 valid = btrfs_unparse_uuid(args.uuid, uuid);
639 tprintf("devid=%" PRI__u64, args.devid);
641 tprintf(", uuid=%s", uuid);
646 tprintf("uuid=%s, ", uuid);
647 tprintf("bytes_used=%" PRI__u64
648 ", total_bytes=%" PRI__u64 ", path=",
649 args.bytes_used, args.total_bytes);
650 print_quoted_string((const char *)args.path, sizeof(args.path),
656 case BTRFS_IOC_DEV_REPLACE: { /* RW */
657 struct_btrfs_ioctl_dev_replace_args args;
661 else if (syserror(tcp))
666 if (umove_or_printaddr(tcp, arg, &args))
671 printxval64(btrfs_dev_replace_cmds, args.cmd,
672 "BTRFS_IOCTL_DEV_REPLACE_CMD_???");
673 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_START) {
675 tprintf(", start={srcdevid=%" PRIu64
676 ", cont_reading_from_srcdev_mode=%" PRIu64
678 (uint64_t) args.start.srcdevid,
679 (uint64_t) args.start.cont_reading_from_srcdev_mode);
681 str = (const char*) args.start.srcdev_name;
682 print_quoted_string(str,
683 sizeof(args.start.srcdev_name),
685 tprints(", tgtdev_name=");
686 str = (const char*) args.start.tgtdev_name;
687 print_quoted_string(str,
688 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) {
701 char buf[sizeof("HH:MM:SS") + 1];
704 printxval64(btrfs_dev_replace_state,
705 args.status.replace_state,
706 "BTRFS_IOCTL_DEV_REPLACE_STATE_???");
707 tprintf(", progress_1000=%" PRIu64 " /* ",
708 (uint64_t) args.status.progress_1000);
709 if (args.status.progress_1000 <= 1000)
710 tprintf("%" PRIu64 ".%.2" PRIu64 "%%",
711 (uint64_t) args.status.progress_1000 / 10,
712 (uint64_t) args.status.progress_1000 % 10);
717 time = args.status.time_started;
718 strftime(buf, sizeof(buf), "%T",
720 tprintf("time_started=%" PRIu64" /* %s */, ",
721 (uint64_t) args.status.time_started, buf);
723 time = args.status.time_stopped;
724 strftime(buf, sizeof(buf), "%T",
726 tprintf("time_stopped=%" PRIu64" /* %s */, ",
727 (uint64_t) args.status.time_stopped, buf);
729 tprintf("num_write_errors=%" PRIu64
730 ", num_uncorrectable_read_errors=%" PRIu64,
731 (uint64_t) args.status.num_write_errors,
732 (uint64_t) args.status.num_uncorrectable_read_errors);
738 case BTRFS_IOC_GET_FEATURES: { /* R */
739 struct btrfs_ioctl_feature_flags flags;
745 if (umove_or_printaddr(tcp, arg, &flags))
748 btrfs_print_features(&flags);
752 case BTRFS_IOC_SET_FEATURES: { /* W */
753 struct btrfs_ioctl_feature_flags flarg[2];
757 if (umove_or_printaddr(tcp, arg, &flarg))
761 btrfs_print_features(&flarg[0]);
763 btrfs_print_features(&flarg[1]);
768 case BTRFS_IOC_GET_SUPPORTED_FEATURES: { /* R */
769 struct btrfs_ioctl_feature_flags flarg[3];
775 if (umove_or_printaddr(tcp, arg, &flarg))
778 tprints("[ /* supported */ ");
779 btrfs_print_features(&flarg[0]);
781 tprints(", /* safe to set */ ");
782 btrfs_print_features(&flarg[1]);
784 tprints(", /* safe to clear */ ");
785 btrfs_print_features(&flarg[2]);
791 case BTRFS_IOC_FS_INFO: { /* R */
792 struct btrfs_ioctl_fs_info_args args;
793 char uuid[UUID_STRING_SIZE+1];
794 uint32_t nodesize, sectorsize, clone_alignment;
795 #ifndef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
803 if (umove_or_printaddr(tcp, arg, &args))
806 #ifdef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
807 nodesize = args.nodesize,
808 sectorsize = args.sectorsize,
809 clone_alignment = args.clone_alignment;
811 reserved32 = (__u32 *)args.reserved;
812 nodesize = reserved32[0];
813 sectorsize = reserved32[1];
814 clone_alignment = reserved32[2];
816 btrfs_unparse_uuid(args.fsid, uuid);
819 tprintf("max_id=%" PRI__u64 ", num_devices=%" PRI__u64
820 ", fsid=%s, nodesize=%u, sectorsize=%u"
821 ", clone_alignment=%u",
822 args.max_id, args.num_devices, uuid,
823 nodesize, sectorsize, clone_alignment);
828 case BTRFS_IOC_GET_DEV_STATS: { /* RW */
829 struct btrfs_ioctl_get_dev_stats args;
834 else if (syserror(tcp))
838 if (umove_or_printaddr(tcp, arg, &args))
844 tprintf("devid=%" PRI__u64 ", ", args.devid);
846 tprintf("nr_items=%" PRI__u64 ", flags=", args.nr_items);
847 printflags64(btrfs_dev_stats_flags, args.flags,
848 "BTRFS_DEV_STATS_???");
856 * The structure has a 1k limit; Let's make sure we don't
857 * go off into the middle of nowhere with a bad nr_items
861 for (i = 0; i < args.nr_items; i++) {
864 if (i >= ARRAY_SIZE(args.values)) {
868 const char *name = xlookup(btrfs_dev_stats_values, i);
870 tprintf("/* %s */ ", name);
871 tprintf("%" PRI__u64, args.values[i]);
877 case BTRFS_IOC_INO_LOOKUP: { /* RW */
878 struct btrfs_ioctl_ino_lookup_args args;
882 else if (syserror(tcp))
887 if (umove_or_printaddr(tcp, arg, &args))
891 /* Use subvolume id of the containing root */
892 if (args.treeid == 0)
893 set_tcb_priv_ulong(tcp, 1);
896 btrfs_print_objectid(args.treeid);
897 tprints(", objectid=");
898 btrfs_print_objectid(args.objectid);
904 if (get_tcb_priv_ulong(tcp)) {
906 btrfs_print_objectid(args.treeid);
911 print_quoted_string(args.name, sizeof(args.name),
917 case BTRFS_IOC_INO_PATHS: { /* RW */
918 struct btrfs_ioctl_ino_path_args args;
922 else if (syserror(tcp))
927 if (umove_or_printaddr(tcp, arg, &args))
933 tprintf("inum=%" PRI__u64 ", size=%" PRI__u64,
934 args.inum, args.size);
935 tprintf(", fspath=0x%" PRI__x64 "}", args.fspath);
940 btrfs_print_ino_path_container(tcp, args.fspath);
946 case BTRFS_IOC_LOGICAL_INO: { /* RW */
947 struct btrfs_ioctl_logical_ino_args args;
951 else if (syserror(tcp))
956 if (umove_or_printaddr(tcp, arg, &args))
962 tprintf("logical=%" PRI__u64 ", size=%" PRI__u64,
963 args.logical, args.size);
964 tprintf(", inodes=0x%" PRI__x64 "}", args.inodes);
969 btrfs_print_logical_ino_container(tcp, args.inodes);
975 case BTRFS_IOC_QGROUP_ASSIGN: { /* W */
976 struct btrfs_ioctl_qgroup_assign_args args;
979 if (umove_or_printaddr(tcp, arg, &args))
982 tprintf("{assign=%" PRI__u64 ", src=%" PRI__u64
983 ", dst=%" PRI__u64 "}",
984 args.assign, args.src, args.dst);
988 case BTRFS_IOC_QGROUP_CREATE: { /* W */
989 struct btrfs_ioctl_qgroup_create_args args;
992 if (umove_or_printaddr(tcp, arg, &args))
995 tprintf("{create=%" PRI__u64 ", qgroupid=%" PRI__u64 "}",
996 args.create, args.qgroupid);
1000 case BTRFS_IOC_QGROUP_LIMIT: { /* R */
1001 struct btrfs_ioctl_qgroup_limit_args args;
1007 if (umove_or_printaddr(tcp, arg, &args))
1010 tprintf("{qgroupid=%" PRI__u64 ", lim=", args.qgroupid);
1011 btrfs_print_qgroup_limit(&args.lim);
1016 case BTRFS_IOC_QUOTA_CTL: { /* W */
1017 struct btrfs_ioctl_quota_ctl_args args;
1020 if (umove_or_printaddr(tcp, arg, &args))
1023 printxval64(btrfs_qgroup_ctl_cmds, args.cmd,
1024 "BTRFS_QUOTA_CTL_???");
1030 case BTRFS_IOC_QUOTA_RESCAN: { /* W */
1031 struct btrfs_ioctl_quota_rescan_args args;
1034 if (umove_or_printaddr(tcp, arg, &args))
1037 tprintf("{flags=%" PRIu64 "}", (uint64_t) args.flags);
1041 case BTRFS_IOC_QUOTA_RESCAN_STATUS: { /* R */
1042 struct btrfs_ioctl_quota_rescan_args args;
1048 if (umove_or_printaddr(tcp, arg, &args))
1051 tprintf("{flags=%" PRIu64 ", progress=", (uint64_t) args.flags);
1052 btrfs_print_objectid(args.progress);
1057 case BTRFS_IOC_SET_RECEIVED_SUBVOL: { /* RW */
1058 struct_btrfs_ioctl_received_subvol_args args;
1059 char uuid[UUID_STRING_SIZE+1];
1063 else if (syserror(tcp))
1068 if (umove_or_printaddr(tcp, arg, &args))
1071 if (entering(tcp)) {
1072 btrfs_unparse_uuid((unsigned char *)args.uuid, uuid);
1073 tprintf("{uuid=%s, stransid=%" PRIu64
1074 ", stime=%" PRIu64 ".%u, flags=%" PRIu64
1075 "}", uuid, (uint64_t) args.stransid,
1076 (uint64_t) args.stime.sec, args.stime.nsec,
1077 (uint64_t) args.flags);
1080 tprintf("{rtransid=%" PRIu64 ", rtime=%" PRIu64 ".%u}",
1081 (uint64_t) args.rtransid, (uint64_t) args.rtime.sec,
1086 case BTRFS_IOC_SCRUB: /* RW */
1087 case BTRFS_IOC_SCRUB_PROGRESS: { /* RW */
1088 struct btrfs_ioctl_scrub_args args;
1092 else if (syserror(tcp))
1097 if (umove_or_printaddr(tcp, arg, &args))
1100 if (entering(tcp)) {
1101 tprintf("{devid=%" PRI__u64, args.devid);
1102 if (code == BTRFS_IOC_SCRUB) {
1103 tprintf(", start=%" PRI__u64 ", end=",
1105 tprintf("%" PRI__u64, args.end);
1106 if (args.end == UINT64_MAX)
1107 tprints(" /* UINT64_MAX */");
1108 tprints(", flags=");
1109 printflags64(btrfs_scrub_flags, args.flags,
1115 tprintf("{data_extents_scrubbed=%" PRI__u64
1116 ", tree_extents_scrubbed=%" PRI__u64
1117 ", data_bytes_scrubbed=%" PRI__u64
1118 ", tree_bytes_scrubbed=%" PRI__u64
1119 ", read_errors=%" PRI__u64
1120 ", csum_errors=%" PRI__u64
1121 ", verify_errors=%" PRI__u64
1122 ", no_csum=%" PRI__u64
1123 ", csum_discards=%" PRI__u64
1124 ", super_errors=%" PRI__u64
1125 ", malloc_errors=%" PRI__u64
1126 ", uncorrectable_errors=%" PRI__u64
1127 ", corrected_errors=%" PRI__u64
1128 ", last_physical=%" PRI__u64
1129 ", unverified_errors=%" PRI__u64 "}",
1130 args.progress.data_extents_scrubbed,
1131 args.progress.tree_extents_scrubbed,
1132 args.progress.data_bytes_scrubbed,
1133 args.progress.tree_bytes_scrubbed,
1134 args.progress.read_errors,
1135 args.progress.csum_errors,
1136 args.progress.verify_errors,
1137 args.progress.no_csum,
1138 args.progress.csum_discards,
1139 args.progress.super_errors,
1140 args.progress.malloc_errors,
1141 args.progress.uncorrectable_errors,
1142 args.progress.corrected_errors,
1143 args.progress.last_physical,
1144 args.progress.unverified_errors);
1148 case BTRFS_IOC_TREE_SEARCH: { /* RW */
1149 struct btrfs_ioctl_search_args args;
1150 uint64_t buf_offset;
1154 else if (syserror(tcp))
1159 if (umove_or_printaddr(tcp, arg, &args))
1162 buf_offset = offsetof(struct btrfs_ioctl_search_args, buf);
1163 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1164 sizeof(args.buf), false);
1170 case BTRFS_IOC_TREE_SEARCH_V2: { /* RW */
1171 struct btrfs_ioctl_search_args_v2 args;
1172 uint64_t buf_offset;
1176 else if (syserror(tcp)) {
1177 if (tcp->u_error == EOVERFLOW) {
1180 if (!umove_or_printaddr(tcp, arg, &args))
1181 tprintf("{buf_size=%" PRIu64 "}",
1182 (uint64_t)args.buf_size);
1183 tcp->u_error = EOVERFLOW;
1189 if (umove_or_printaddr(tcp, arg, &args))
1192 buf_offset = offsetof(struct btrfs_ioctl_search_args_v2, buf);
1193 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1194 args.buf_size, true);
1200 case BTRFS_IOC_SEND: { /* W */
1201 struct_btrfs_ioctl_send_args args;
1204 if (umove_or_printaddr(tcp, arg, &args))
1207 tprints("{send_fd=");
1208 printfd(tcp, args.send_fd);
1209 tprintf(", clone_sources_count=%" PRIu64 ", clone_sources=",
1210 (uint64_t) args.clone_sources_count);
1216 print_array(tcp, (unsigned long) args.clone_sources,
1217 args.clone_sources_count,
1218 &record, sizeof(record),
1219 umoven_or_printaddr,
1220 print_objectid_callback, 0);
1222 tprints(", parent_root=");
1223 btrfs_print_objectid(args.parent_root);
1224 tprints(", flags=");
1225 printflags64(btrfs_send_flags, args.flags,
1226 "BTRFS_SEND_FLAGS_???");
1231 case BTRFS_IOC_SPACE_INFO: { /* RW */
1232 struct btrfs_ioctl_space_args args;
1236 else if (syserror(tcp))
1241 if (umove_or_printaddr(tcp, arg, &args))
1245 if (entering(tcp)) {
1246 tprintf("space_slots=%" PRI__u64 "}", args.space_slots);
1250 tprintf("total_spaces=%" PRI__u64, args.total_spaces);
1252 if (args.space_slots == 0 && args.total_spaces) {
1257 tprints(", spaces=");
1262 struct btrfs_ioctl_space_info info;
1263 print_array(tcp, arg + offsetof(typeof(args), spaces),
1265 &info, sizeof(info), umoven_or_printaddr,
1266 print_btrfs_ioctl_space_info, 0);
1272 case BTRFS_IOC_SNAP_CREATE:
1273 case BTRFS_IOC_RESIZE:
1274 case BTRFS_IOC_SCAN_DEV:
1275 case BTRFS_IOC_ADD_DEV:
1276 case BTRFS_IOC_RM_DEV:
1277 case BTRFS_IOC_SUBVOL_CREATE:
1278 case BTRFS_IOC_SNAP_DESTROY:
1279 case BTRFS_IOC_DEVICES_READY: { /* W */
1280 struct btrfs_ioctl_vol_args args;
1283 if (umove_or_printaddr(tcp, arg, &args))
1287 printfd(tcp, args.fd);
1289 print_quoted_string(args.name, sizeof(args.name),
1290 QUOTE_0_TERMINATED);
1295 case BTRFS_IOC_SNAP_CREATE_V2:
1296 case BTRFS_IOC_SUBVOL_CREATE_V2: { /* code is W, but is actually RW */
1297 struct btrfs_ioctl_vol_args_v2 args;
1301 else if (syserror(tcp))
1306 if (umove_or_printaddr(tcp, arg, &args))
1309 if (entering(tcp)) {
1311 printfd(tcp, args.fd);
1312 tprints(", flags=");
1313 printflags64(btrfs_snap_flags_v2, args.flags,
1314 "BTRFS_SUBVOL_???");
1315 if (args.flags & BTRFS_SUBVOL_QGROUP_INHERIT) {
1316 tprintf(", size=%" PRI__u64 ", qgroup_inherit=",
1319 btrfs_print_qgroup_inherit(tcp,
1320 (unsigned long)args.qgroup_inherit);
1323 print_quoted_string(args.name, sizeof(args.name),
1324 QUOTE_0_TERMINATED);
1328 tprintf("{transid=%" PRI__u64 "}", args.transid);
1332 case BTRFS_IOC_GET_FSLABEL: /* R */
1336 case BTRFS_IOC_SET_FSLABEL: { /* W */
1337 char label[BTRFS_LABEL_SIZE];
1340 if (umove_or_printaddr(tcp, arg, &label))
1342 print_quoted_string(label, sizeof(label), QUOTE_0_TERMINATED);
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_DECODED | 1;
1364 #endif /* HAVE_LINUX_BTRFS_H */