blob: 6d02cb2c960542f11400c73be1bbba9f36517d2b [file] [log] [blame]
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001/*
2 * Copyright (c) 2016 Jeff Mahoney <jeffm@suse.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
15 *
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.
26 */
27
28#include "defs.h"
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +000029
Jeff Mahoney8cc69622016-05-18 18:09:39 -040030#ifdef HAVE_LINUX_BTRFS_H
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +000031
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)
Dmitry V. Levine7d3d642016-08-25 21:24:33 +000035#include DEF_MPERS_TYPE(struct_btrfs_ioctl_vol_args_v2)
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +000036
37# include <linux/btrfs.h>
38
39typedef struct btrfs_ioctl_dev_replace_args
40 struct_btrfs_ioctl_dev_replace_args;
41typedef struct btrfs_ioctl_send_args
42 struct_btrfs_ioctl_send_args;
43typedef struct btrfs_ioctl_received_subvol_args
44 struct_btrfs_ioctl_received_subvol_args;
Dmitry V. Levine7d3d642016-08-25 21:24:33 +000045typedef struct btrfs_ioctl_vol_args_v2
46 struct_btrfs_ioctl_vol_args_v2;
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +000047
48#endif /* HAVE_LINUX_BTRFS_H */
49
50#include MPERS_DEFS
51
52#ifdef HAVE_LINUX_BTRFS_H
53
54#include <linux/fs.h>
55
Jeff Mahoney8cc69622016-05-18 18:09:39 -040056/*
57 * Prior to Linux 3.12, the BTRFS_IOC_DEFAULT_SUBVOL used u64 in
58 * its definition, which isn't exported by the kernel.
59 */
60typedef __u64 u64;
61
Jeff Mahoney8cc69622016-05-18 18:09:39 -040062#ifndef HAVE_STRUCT_BTRFS_IOCTL_FEATURE_FLAGS_COMPAT_FLAGS
63struct btrfs_ioctl_feature_flags {
64 uint64_t compat_flags;
65 uint64_t compat_ro_flags;
66 uint64_t incompat_flags;
67};
68#endif
69
70#ifndef HAVE_STRUCT_BTRFS_IOCTL_DEFRAG_RANGE_ARGS_START
71struct btrfs_ioctl_defrag_range_args {
72 uint64_t start;
73 uint64_t len;
74 uint64_t flags;
75 uint32_t extent_thresh;
76 uint32_t compress_type;
77 uint32_t unused[4];
78};
79#endif
80
Jeff Mahoney8cc69622016-05-18 18:09:39 -040081#ifndef BTRFS_LABEL_SIZE
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +000082# define BTRFS_LABEL_SIZE 256
Jeff Mahoney8cc69622016-05-18 18:09:39 -040083#endif
84
85#ifndef BTRFS_FIRST_FREE_OBJECTID
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +000086# define BTRFS_FIRST_FREE_OBJECTID 256ULL
Jeff Mahoney8cc69622016-05-18 18:09:39 -040087#endif
88
Dmitry V. Levinfe7a4512016-06-17 03:02:46 +030089#ifndef BTRFS_IOC_QUOTA_RESCAN
90struct btrfs_ioctl_quota_rescan_args {
91 uint64_t flags, progress, reserved[6];
92};
93# define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
94 struct btrfs_ioctl_quota_rescan_args)
95# define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
96 struct btrfs_ioctl_quota_rescan_args)
97#endif
98
99#ifndef BTRFS_IOC_QUOTA_RESCAN_WAIT
100# define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
101#endif
102
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400103#ifndef BTRFS_IOC_GET_FEATURES
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +0000104# define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
105 struct btrfs_ioctl_feature_flags)
106# define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
107 struct btrfs_ioctl_feature_flags[2])
108# define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
109 struct btrfs_ioctl_feature_flags[3])
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400110#endif
111
112#ifndef BTRFS_IOC_TREE_SEARCH_V2
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +0000113# define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
114 struct btrfs_ioctl_search_args_v2)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400115struct btrfs_ioctl_search_args_v2 {
116 struct btrfs_ioctl_search_key key; /* in/out - search parameters */
117 uint64_t buf_size; /* in - size of buffer
118 * out - on EOVERFLOW: needed size
119 * to store item */
120 uint64_t buf[0]; /* out - found items */
121};
122#endif
123
124#include "xlat/btrfs_balance_args.h"
125#include "xlat/btrfs_balance_ctl_cmds.h"
126#include "xlat/btrfs_balance_flags.h"
127#include "xlat/btrfs_balance_state.h"
128#include "xlat/btrfs_compress_types.h"
129#include "xlat/btrfs_defrag_flags.h"
130#include "xlat/btrfs_dev_replace_cmds.h"
131#include "xlat/btrfs_dev_replace_results.h"
132#include "xlat/btrfs_dev_replace_state.h"
133#include "xlat/btrfs_dev_stats_flags.h"
134#include "xlat/btrfs_dev_stats_values.h"
135#include "xlat/btrfs_features_compat.h"
136#include "xlat/btrfs_features_compat_ro.h"
137#include "xlat/btrfs_features_incompat.h"
138#include "xlat/btrfs_key_types.h"
139#include "xlat/btrfs_qgroup_ctl_cmds.h"
140#include "xlat/btrfs_qgroup_inherit_flags.h"
141#include "xlat/btrfs_qgroup_limit_flags.h"
142#include "xlat/btrfs_qgroup_status_flags.h"
143#include "xlat/btrfs_scrub_flags.h"
144#include "xlat/btrfs_send_flags.h"
145#include "xlat/btrfs_snap_flags_v2.h"
146#include "xlat/btrfs_space_info_flags.h"
147#include "xlat/btrfs_tree_objectids.h"
148
149static inline char
150prnibble(char v)
151{
152 if (v >= 10)
153 return 'a' + (v - 10);
154 return '0' + v;
155}
156
157/* 8-4-4-4-12 = 36 characters */
158#define UUID_STRING_SIZE 36
159
160/* Formats uuid, returns 0 if it's all zeroes */
161static int
162btrfs_unparse_uuid(unsigned char *uuid, char *out)
163{
164 int i;
165 int ret = 0;
166 for (i = 0; i < BTRFS_UUID_SIZE; i++) {
167 if (i == 4 || i == 6 || i == 8 || i == 10)
168 *out++ = '-';
169 *out++ = prnibble(uuid[i] >> 4);
170 *out++ = prnibble(uuid[i] & 0xf);
171 if (uuid[i])
172 ret = 1;
173 }
174 *out = '\0';
175 return ret;
176}
177
178static void
179print_u64(const char *name, uint64_t value)
180{
181 tprintf(", %s=%" PRIu64, name, value);
182 if (value == UINT64_MAX)
183 tprints(" /* UINT64_MAX */");
184}
185
186#define print_member_u64(obj, name) print_u64(#name, obj->name)
187
188static void
Dmitry V. Levinb85d09f2016-05-24 00:56:08 +0000189btrfs_print_balance_args(const char *name, const struct btrfs_balance_args *bba)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400190{
191 tprintf(", %s={profiles=", name);
192 printflags64(btrfs_space_info_flags, bba->profiles,
193 "BTRFS_BLOCK_GROUP_???");
194 print_member_u64(bba, usage);
195 print_member_u64(bba, devid);
196 print_member_u64(bba, pstart);
197 print_member_u64(bba, pend);
198 print_member_u64(bba, vstart);
199 print_member_u64(bba, vend);
200 print_member_u64(bba, target);
201 tprints(", flags=");
202 printflags64(btrfs_balance_args, bba->flags, "BTRFS_BALANCE_ARGS_???");
203 tprints("}");
204}
205
206static void
207btrfs_print_balance(struct tcb *tcp, const long arg, bool out)
208{
209 struct btrfs_ioctl_balance_args balance_args;
210
211 if (umove_or_printaddr(tcp, arg, &balance_args))
212 return;
213
214 tprints("{flags=");
215 printflags64(btrfs_balance_flags, balance_args.flags,
216 "BTRFS_BALANCE_???");
217 if (out) {
218 tprints(", state=");
219 printflags64(btrfs_balance_state, balance_args.state,
220 "BTRFS_BALANCE_STATE_???");
221 }
222
223 if (balance_args.flags & BTRFS_BALANCE_DATA)
224 btrfs_print_balance_args("data", &balance_args.data);
225 if (balance_args.flags & BTRFS_BALANCE_METADATA)
226 btrfs_print_balance_args("meta", &balance_args.meta);
227 if (balance_args.flags & BTRFS_BALANCE_SYSTEM)
228 btrfs_print_balance_args("sys", &balance_args.sys);
229 tprints("}");
230}
231
232static void
Dmitry V. Levinb85d09f2016-05-24 00:56:08 +0000233btrfs_print_features(const struct btrfs_ioctl_feature_flags *flags)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400234{
235 tprints("{compat_flags=");
236 printflags64(btrfs_features_compat, flags->compat_flags,
237 "BTRFS_FEATURE_COMPAT_???");
238
239 tprints(", compat_ro_flags=");
240 printflags64(btrfs_features_compat_ro, flags->compat_ro_flags,
241 "BTRFS_FEATURE_COMPAT_RO_???");
242
243 tprints(", incompat_flags=");
244 printflags64(btrfs_features_incompat, flags->incompat_flags,
245 "BTRFS_FEATURE_INCOMPAT_???");
246 tprints("}");
247}
248
249static void
Dmitry V. Levinb85d09f2016-05-24 00:56:08 +0000250btrfs_print_qgroup_limit(const struct btrfs_qgroup_limit *lim)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400251{
252 tprints("{flags=");
253 printflags64(btrfs_qgroup_limit_flags, lim->flags,
254 "BTRFS_QGROUP_LIMIT_???");
255 tprintf(", max_rfer=%" PRI__u64 ", max_excl=%" PRI__u64
256 ", rsv_rfer=%" PRI__u64 ", rsv_excl=%" PRI__u64 "}",
257 lim->max_rfer, lim->max_excl,
258 lim->rsv_rfer, lim->rsv_excl);
259}
260
261static void
262btrfs_print_key_type(uint32_t type)
263{
264 const char *str = xlookup(btrfs_key_types, type);
265 tprintf("%u", type);
266 if (str)
267 tprintf(" /* %s */", str);
268}
269
270static void
271btrfs_print_objectid(uint64_t objectid)
272{
273 const char *str = xlookup(btrfs_tree_objectids, objectid);
274 tprintf("%" PRIu64, objectid);
275 if (str)
276 tprintf(" /* %s */", str);
277}
278
279static void
Dmitry V. Levinb85d09f2016-05-24 00:56:08 +0000280btrfs_print_data_container_header(const struct btrfs_data_container *container)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400281{
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +0000282 tprintf("{bytes_left=%u, bytes_missing=%u"
283 ", elem_cnt=%u, elem_missed=%u, val=",
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400284 container->bytes_left, container->bytes_missing,
285 container->elem_cnt, container->elem_missed);
286}
287
288static void
289btrfs_print_data_container_footer(void)
290{
291 tprints("}");
292}
293
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000294static bool
295print_btrfs_data_container_logical_ino(struct tcb *tcp, void *elem_buf,
296 size_t elem_size, void *data)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400297{
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000298 const uint64_t *const record = elem_buf;
299
300 tprintf("{inum=%" PRIu64 ", offset=%" PRIu64 ", root=%" PRIu64 "}",
301 record[0], record[1], record[2]);
302
303 return true;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400304}
305
306static void
Dmitry V. Levinb85d09f2016-05-24 00:56:08 +0000307btrfs_print_logical_ino_container(struct tcb *tcp,
308 const uint64_t inodes_addr)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400309{
310 struct btrfs_data_container container;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400311
Dmitry V. Levin90ffbc72016-05-24 00:49:50 +0000312 if (umove_or_printaddr(tcp, inodes_addr, &container))
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400313 return;
314
315 btrfs_print_data_container_header(&container);
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000316
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400317 if (abbrev(tcp)) {
318 tprints("...");
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000319 } else {
320 const uint64_t val_addr =
321 inodes_addr + offsetof(typeof(container), val);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400322 uint64_t record[3];
Jeff Mahoney2060d972016-05-26 23:33:03 -0400323 print_array(tcp, val_addr, container.elem_cnt / 3,
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000324 record, sizeof(record),
325 umoven_or_printaddr,
326 print_btrfs_data_container_logical_ino, 0);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400327 }
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000328
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400329 btrfs_print_data_container_footer();
330}
331
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000332static bool
333print_btrfs_data_container_ino_path(struct tcb *tcp, void *elem_buf,
334 size_t elem_size, void *data)
335{
336 const uint64_t *const offset = elem_buf;
337 const uint64_t *const val_addr = data;
338
339 printpath(tcp, *val_addr + *offset);
340
341 return true;
342}
343
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400344static void
Dmitry V. Levinb85d09f2016-05-24 00:56:08 +0000345btrfs_print_ino_path_container(struct tcb *tcp,
346 const uint64_t fspath_addr)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400347{
348 struct btrfs_data_container container;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400349
Dmitry V. Levin90ffbc72016-05-24 00:49:50 +0000350 if (umove_or_printaddr(tcp, fspath_addr, &container))
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400351 return;
352
353 btrfs_print_data_container_header(&container);
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000354
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400355 if (abbrev(tcp)) {
356 tprints("...");
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000357 } else {
358 uint64_t val_addr =
359 fspath_addr + offsetof(typeof(container), val);
360 uint64_t offset;
361 print_array(tcp, val_addr, container.elem_cnt,
362 &offset, sizeof(offset),
363 umoven_or_printaddr,
364 print_btrfs_data_container_ino_path, &val_addr);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400365 }
366
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400367 btrfs_print_data_container_footer();
368}
369
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000370static bool
371print_uint64(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
372{
373 tprintf("%" PRIu64, * (uint64_t *) elem_buf);
374
375 return true;
376}
377
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400378static void
Dmitry V. Levine7d3d642016-08-25 21:24:33 +0000379btrfs_print_qgroup_inherit(struct tcb *tcp, const unsigned long qgi_addr)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400380{
381 struct btrfs_qgroup_inherit inherit;
382
Dmitry V. Levin90ffbc72016-05-24 00:49:50 +0000383 if (umove_or_printaddr(tcp, qgi_addr, &inherit))
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400384 return;
385
386 tprintf("{flags=");
387 printflags64(btrfs_qgroup_inherit_flags, inherit.flags,
388 "BTRFS_QGROUP_INHERIT_???");
389 tprintf(", num_qgroups=%" PRI__u64 ", num_ref_copies=%" PRI__u64
390 ", num_excl_copies=%" PRI__u64 ", lim=",
391 inherit.num_qgroups, inherit.num_ref_copies,
392 inherit.num_excl_copies);
393
394 btrfs_print_qgroup_limit(&inherit.lim);
395
396 tprints(", qgroups=");
397
398 if (abbrev(tcp)) {
399 tprints("...");
400 } else {
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000401 uint64_t record;
402 print_array(tcp, qgi_addr + offsetof(typeof(inherit), qgroups),
403 inherit.num_qgroups, &record, sizeof(record),
404 umoven_or_printaddr, print_uint64, 0);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400405 }
406 tprints("}");
407}
408
409static void
410print_key_value_internal(struct tcb *tcp, const char *name, uint64_t value)
411{
412 if (value) {
413 tprintf(", %s=%" PRIu64, name, value);
414 if (value == UINT64_MAX)
415 tprints(" /* UINT64_MAX */");
416 }
417}
418#define print_key_value(tcp, key, name) \
419 print_key_value_internal((tcp), #name, (key)->name)
420
421static void
422btrfs_print_tree_search(struct tcb *tcp, struct btrfs_ioctl_search_key *key,
423 uint64_t buf_addr, uint64_t buf_size, bool print_size)
424{
425 if (entering(tcp)) {
426 tprintf("{key={tree_id=");
427 btrfs_print_objectid(key->tree_id);
428
429 if (key->min_objectid != BTRFS_FIRST_FREE_OBJECTID ||
430 !abbrev(tcp)) {
431 tprints(", min_objectid=");
432 btrfs_print_objectid(key->min_objectid);
433 }
434
435 if (key->max_objectid != BTRFS_LAST_FREE_OBJECTID ||
436 !abbrev(tcp)) {
437 tprints(", max_objectid=");
438 btrfs_print_objectid(key->max_objectid);
439 }
440
441 print_key_value(tcp, key, min_offset);
442 print_key_value(tcp, key, max_offset);
443 print_key_value(tcp, key, min_transid);
444 print_key_value(tcp, key, max_transid);
445
446 tprints(", min_type=");
447 btrfs_print_key_type(key->min_type);
448 tprints(", max_type=");
449 btrfs_print_key_type(key->max_type);
450 tprintf(", nr_items=%u}", key->nr_items);
451 if (print_size)
452 tprintf(", buf_size=%" PRIu64, buf_size);
453 tprints("}");
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000454 } else {
455 tprintf("{key={nr_items=%u}", key->nr_items);
456 if (print_size)
457 tprintf(", buf_size=%" PRIu64, buf_size);
458 tprints(", buf=");
459 if (abbrev(tcp))
460 tprints("...");
461 else {
Jeff Mahoneyd32d95a2016-05-26 23:33:04 -0400462 uint64_t i;
463 uint64_t off = 0;
464 tprints("[");
465 for (i = 0; i < key->nr_items; i++) {
466 struct btrfs_ioctl_search_header sh;
467 uint64_t addr = buf_addr + off;
468 if (i)
469 tprints(", ");
470 if (i > max_strlen ||
471 umove(tcp, addr, &sh)) {
472 tprints("...");
473 break;
474 }
475 tprintf("{transid=%" PRI__u64 ", objectid=",
476 sh.transid);
477 btrfs_print_objectid(sh.objectid);
478 tprintf(", offset=%" PRI__u64 ", type=", sh.offset);
479 btrfs_print_key_type(sh.type);
480 tprintf(", len=%u}", sh.len);
481 off += sizeof(sh) + sh.len;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400482
Jeff Mahoneyd32d95a2016-05-26 23:33:04 -0400483 }
484 tprints("]");
Dmitry V. Levind57cc262016-05-24 01:15:18 +0000485 }
486 tprints("}");
487 }
488}
489
490static bool
491print_objectid_callback(struct tcb *tcp, void *elem_buf,
492 size_t elem_size, void *data)
493{
494 btrfs_print_objectid(* (uint64_t *) elem_buf);
495
496 return true;
497}
498
499static bool
500print_btrfs_ioctl_space_info(struct tcb *tcp, void *elem_buf,
501 size_t elem_size, void *data)
502{
503 const struct btrfs_ioctl_space_info *info = elem_buf;
504
505 tprints("{flags=");
506 printflags64(btrfs_space_info_flags, info->flags,
507 "BTRFS_SPACE_INFO_???");
508 tprintf(", total_bytes=%" PRI__u64 ", used_bytes=%" PRI__u64 "}",
509 info->total_bytes, info->used_bytes);
510
511 return true;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400512}
513
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000514MPERS_PRINTER_DECL(int, btrfs_ioctl,
515 struct tcb *tcp, const unsigned int code, const long arg)
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400516{
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400517 switch (code) {
Dmitry V. Levin3ce2dfc2016-05-24 00:45:05 +0000518 /* Take no arguments; command only. */
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400519 case BTRFS_IOC_TRANS_START:
520 case BTRFS_IOC_TRANS_END:
521 case BTRFS_IOC_SYNC:
522 case BTRFS_IOC_SCRUB_CANCEL:
523 case BTRFS_IOC_QUOTA_RESCAN_WAIT:
524 /*
525 * The codes for these ioctls are based on each accepting a
526 * vol_args but none of them actually consume an argument.
527 */
528 case BTRFS_IOC_DEFRAG:
529 case BTRFS_IOC_BALANCE:
530 break;
531
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000532 /* takes a signed int */
533 case BTRFS_IOC_BALANCE_CTL:
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400534 tprints(", ");
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000535 printxval(btrfs_balance_ctl_cmds, arg, "BTRFS_BALANCE_CTL_???");
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400536 break;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400537
538 /* returns a 64 */
539 case BTRFS_IOC_START_SYNC: /* R */
540 if (entering(tcp))
541 return 0;
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000542 /* fall through */
543 /* takes a u64 */
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400544 case BTRFS_IOC_DEFAULT_SUBVOL: /* W */
545 case BTRFS_IOC_WAIT_SYNC: /* W */
546 tprints(", ");
547 printnum_int64(tcp, arg, "%" PRIu64);
548 break;
549
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000550 /* u64 but describe a flags bitfield; we can make that symbolic */
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400551 case BTRFS_IOC_SUBVOL_GETFLAGS: { /* R */
552 uint64_t flags;
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000553
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400554 if (entering(tcp))
555 return 0;
556
557 tprints(", ");
558
559 if (umove_or_printaddr(tcp, arg, &flags))
560 break;
561
562 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
563 break;
564 }
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000565
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400566 case BTRFS_IOC_SUBVOL_SETFLAGS: { /* W */
567 uint64_t flags;
568
569 tprints(", ");
570
571 if (umove_or_printaddr(tcp, arg, &flags))
572 break;
573
574 printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???");
575 break;
576 }
577
578 /* More complex types */
579 case BTRFS_IOC_BALANCE_V2: /* RW */
580 if (entering(tcp)) {
581 tprints(", ");
582 btrfs_print_balance(tcp, arg, false);
583 return 0;
584 }
585
586 if (syserror(tcp))
587 break;
588
589 tprints(" => ");
590 btrfs_print_balance(tcp, arg, true);
591 break;
592 case BTRFS_IOC_BALANCE_PROGRESS: /* R */
593 if (entering(tcp))
594 return 0;
595
596 tprints(", ");
597 btrfs_print_balance(tcp, arg, true);
598 break;
599
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000600 case BTRFS_IOC_DEFRAG_RANGE: { /* W */
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400601 struct btrfs_ioctl_defrag_range_args args;
602
603 tprints(", ");
604
605 if (umove_or_printaddr(tcp, arg, &args))
606 break;
607
608 tprintf("{start=%" PRIu64 ", len=", (uint64_t)args.start);
609
Dmitry V. Levind4bdff62016-06-17 00:44:44 +0000610 tprintf("%" PRIu64, (uint64_t) args.len);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400611 if (args.len == UINT64_MAX)
612 tprints(" /* UINT64_MAX */");
613
614 tprints(", flags=");
615 printflags64(btrfs_defrag_flags, args.flags,
616 "BTRFS_DEFRAG_RANGE_???");
617 tprintf(", extent_thresh=%u, compress_type=",
618 args.extent_thresh);
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000619 printxval(btrfs_compress_types, args.compress_type,
620 "BTRFS_COMPRESS_???");
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400621 tprints("}");
622 break;
623 }
624
625 case BTRFS_IOC_DEV_INFO: { /* RW */
626 struct btrfs_ioctl_dev_info_args args;
627 char uuid[UUID_STRING_SIZE+1];
628 int valid;
629
630 if (entering(tcp))
631 tprints(", ");
632 else if (syserror(tcp))
633 break;
634 else
635 tprints(" => ");
636 if (umove_or_printaddr(tcp, arg, &args))
637 break;
638 tprints("{");
639
640 valid = btrfs_unparse_uuid(args.uuid, uuid);
641 if (entering(tcp)) {
642 tprintf("devid=%" PRI__u64, args.devid);
643 if (valid)
644 tprintf(", uuid=%s", uuid);
645 tprints("}");
646 return 0;
647 }
648 if (valid)
649 tprintf("uuid=%s, ", uuid);
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +0000650 tprintf("bytes_used=%" PRI__u64
651 ", total_bytes=%" PRI__u64 ", path=",
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400652 args.bytes_used, args.total_bytes);
653 print_quoted_string((const char *)args.path, sizeof(args.path),
654 QUOTE_0_TERMINATED);
655 tprints("}");
656 break;
657 }
658
659 case BTRFS_IOC_DEV_REPLACE: { /* RW */
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000660 struct_btrfs_ioctl_dev_replace_args args;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400661
662 if (entering(tcp))
663 tprints(", ");
664 else if (syserror(tcp))
665 break;
666 else
667 tprints(" => ");
668
669 if (umove_or_printaddr(tcp, arg, &args))
670 break;
671
672 if (entering(tcp)) {
673 tprints("{cmd=");
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000674 printxval64(btrfs_dev_replace_cmds, args.cmd,
675 "BTRFS_IOCTL_DEV_REPLACE_CMD_???");
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400676 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_START) {
677 const char *str;
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000678 tprintf(", start={srcdevid=%" PRIu64
679 ", cont_reading_from_srcdev_mode=%" PRIu64
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400680 ", srcdev_name=",
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000681 (uint64_t) args.start.srcdevid,
682 (uint64_t) args.start.cont_reading_from_srcdev_mode);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400683
684 str = (const char*) args.start.srcdev_name;
685 print_quoted_string(str,
686 sizeof(args.start.srcdev_name),
687 QUOTE_0_TERMINATED);
688 tprints(", tgtdev_name=");
689 str = (const char*) args.start.tgtdev_name;
690 print_quoted_string(str,
691 sizeof(args.start.tgtdev_name),
692 QUOTE_0_TERMINATED);
693 tprints("}");
694
695 }
696 tprints("}");
697 return 0;
698 }
699
700 tprints("{result=");
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000701 printxval64(btrfs_dev_replace_results, args.result,
702 "BTRFS_IOCTL_DEV_REPLACE_RESULT_???");
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400703 if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS) {
704 char buf[sizeof("HH:MM:SS") + 1];
705 time_t time;
706 tprints(", ");
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000707 printxval64(btrfs_dev_replace_state,
708 args.status.replace_state,
709 "BTRFS_IOCTL_DEV_REPLACE_STATE_???");
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000710 tprintf(", progress_1000=%" PRIu64 " /* ",
711 (uint64_t) args.status.progress_1000);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400712 if (args.status.progress_1000 <= 1000)
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000713 tprintf("%" PRIu64 ".%.2" PRIu64 "%%",
714 (uint64_t) args.status.progress_1000 / 10,
715 (uint64_t) args.status.progress_1000 % 10);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400716 else
717 tprints("???");
718 tprints(" */ ,");
719
720 time = args.status.time_started;
721 strftime(buf, sizeof(buf), "%T",
722 localtime(&time));
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000723 tprintf("time_started=%" PRIu64" /* %s */, ",
724 (uint64_t) args.status.time_started, buf);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400725
726 time = args.status.time_stopped;
727 strftime(buf, sizeof(buf), "%T",
728 localtime(&time));
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000729 tprintf("time_stopped=%" PRIu64" /* %s */, ",
730 (uint64_t) args.status.time_stopped, buf);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400731
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +0000732 tprintf("num_write_errors=%" PRIu64
733 ", num_uncorrectable_read_errors=%" PRIu64,
734 (uint64_t) args.status.num_write_errors,
735 (uint64_t) args.status.num_uncorrectable_read_errors);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400736 }
737 tprints("}");
738 break;
739 }
740
741 case BTRFS_IOC_GET_FEATURES: { /* R */
742 struct btrfs_ioctl_feature_flags flags;
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000743
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400744 if (entering(tcp))
745 return 0;
746
747 tprints(", ");
748 if (umove_or_printaddr(tcp, arg, &flags))
749 break;
750
751 btrfs_print_features(&flags);
752 break;
753 }
Dmitry V. Levin95577cf2016-05-24 00:35:49 +0000754
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400755 case BTRFS_IOC_SET_FEATURES: { /* W */
756 struct btrfs_ioctl_feature_flags flarg[2];
757
758 tprints(", ");
759
760 if (umove_or_printaddr(tcp, arg, &flarg))
761 break;
762
763 tprints("[");
764 btrfs_print_features(&flarg[0]);
765 tprints(", ");
766 btrfs_print_features(&flarg[1]);
767 tprints("]");
768 break;
769 }
770
771 case BTRFS_IOC_GET_SUPPORTED_FEATURES: { /* R */
772 struct btrfs_ioctl_feature_flags flarg[3];
773
774 if (entering(tcp))
775 return 0;
776
777 tprints(", ");
778 if (umove_or_printaddr(tcp, arg, &flarg))
779 break;
780
781 tprints("[ /* supported */ ");
782 btrfs_print_features(&flarg[0]);
783
784 tprints(", /* safe to set */ ");
785 btrfs_print_features(&flarg[1]);
786
787 tprints(", /* safe to clear */ ");
788 btrfs_print_features(&flarg[2]);
789 tprints("]");
790
791 break;
792 }
793
794 case BTRFS_IOC_FS_INFO: { /* R */
795 struct btrfs_ioctl_fs_info_args args;
796 char uuid[UUID_STRING_SIZE+1];
797 uint32_t nodesize, sectorsize, clone_alignment;
798#ifndef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
799 __u32 *reserved32;
800#endif
801
802 if (entering(tcp))
803 return 0;
804
805 tprints(", ");
806 if (umove_or_printaddr(tcp, arg, &args))
807 break;
808
809#ifdef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE
810 nodesize = args.nodesize,
811 sectorsize = args.sectorsize,
812 clone_alignment = args.clone_alignment;
813#else
Dmitry V. Levinde5b0092016-07-26 15:59:28 +0000814 reserved32 = (__u32 *) (void *) args.reserved;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400815 nodesize = reserved32[0];
816 sectorsize = reserved32[1];
817 clone_alignment = reserved32[2];
818#endif
819 btrfs_unparse_uuid(args.fsid, uuid);
820
821 tprints("{");
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +0000822 tprintf("max_id=%" PRI__u64 ", num_devices=%" PRI__u64
823 ", fsid=%s, nodesize=%u, sectorsize=%u"
824 ", clone_alignment=%u",
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400825 args.max_id, args.num_devices, uuid,
826 nodesize, sectorsize, clone_alignment);
827 tprints("}");
828 break;
829 }
830
831 case BTRFS_IOC_GET_DEV_STATS: { /* RW */
832 struct btrfs_ioctl_get_dev_stats args;
Dmitry V. Levin92b90622016-05-24 01:04:56 +0000833 uint64_t i;
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400834
835 if (entering(tcp))
836 tprints(", ");
837 else if (syserror(tcp))
838 break;
839 else
840 tprints(" => ");
841 if (umove_or_printaddr(tcp, arg, &args))
842 break;
843
844 tprints("{");
845
846 if (entering(tcp))
847 tprintf("devid=%" PRI__u64 ", ", args.devid);
848
849 tprintf("nr_items=%" PRI__u64 ", flags=", args.nr_items);
850 printflags64(btrfs_dev_stats_flags, args.flags,
851 "BTRFS_DEV_STATS_???");
852
853 if (entering(tcp)) {
854 tprints("}");
855 return 0;
856 }
857
858 /*
859 * The structure has a 1k limit; Let's make sure we don't
860 * go off into the middle of nowhere with a bad nr_items
861 * value.
862 */
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400863 tprints(", [");
864 for (i = 0; i < args.nr_items; i++) {
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400865 if (i)
866 tprints(", ");
Dmitry V. Levin92b90622016-05-24 01:04:56 +0000867 if (i >= ARRAY_SIZE(args.values)) {
868 tprints("...");
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400869 break;
870 }
Dmitry V. Levin92b90622016-05-24 01:04:56 +0000871 const char *name = xlookup(btrfs_dev_stats_values, i);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400872 if (name)
873 tprintf("/* %s */ ", name);
874 tprintf("%" PRI__u64, args.values[i]);
875 }
876 tprints("]}");
877 break;
878 }
879
880 case BTRFS_IOC_INO_LOOKUP: { /* RW */
881 struct btrfs_ioctl_ino_lookup_args args;
882
883 if (entering(tcp))
884 tprints(", ");
885 else if (syserror(tcp))
886 break;
887 else
888 tprints(" => ");
889
890 if (umove_or_printaddr(tcp, arg, &args))
891 break;
892
893 if (entering(tcp)) {
894 /* Use subvolume id of the containing root */
895 if (args.treeid == 0)
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000896 set_tcb_priv_ulong(tcp, 1);
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400897
898 tprints("{treeid=");
899 btrfs_print_objectid(args.treeid);
900 tprints(", objectid=");
901 btrfs_print_objectid(args.objectid);
902 tprints("}");
903 return 0;
904 }
905
906 tprints("{");
Dmitry V. Levinb759d272016-07-15 16:08:19 +0000907 if (get_tcb_priv_ulong(tcp)) {
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400908 tprints("treeid=");
909 btrfs_print_objectid(args.treeid);
910 tprints(", ");
911 }
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400912
913 tprints("name=");
914 print_quoted_string(args.name, sizeof(args.name),
915 QUOTE_0_TERMINATED);
916 tprints("}");
917 break;
918 }
919
920 case BTRFS_IOC_INO_PATHS: { /* RW */
921 struct btrfs_ioctl_ino_path_args args;
922
923 if (entering(tcp))
924 tprints(", ");
925 else if (syserror(tcp))
926 break;
927 else
928 tprints(" => ");
929
930 if (umove_or_printaddr(tcp, arg, &args))
931 break;
932
933 tprints("{");
934
935 if (entering(tcp)) {
936 tprintf("inum=%" PRI__u64 ", size=%" PRI__u64,
937 args.inum, args.size);
938 tprintf(", fspath=0x%" PRI__x64 "}", args.fspath);
939 return 0;
940 }
941
942 tprints("fspath=");
943 btrfs_print_ino_path_container(tcp, args.fspath);
944
945 tprints("}");
946 break;
947 }
948
949 case BTRFS_IOC_LOGICAL_INO: { /* RW */
950 struct btrfs_ioctl_logical_ino_args args;
951
952 if (entering(tcp))
953 tprints(", ");
954 else if (syserror(tcp))
955 break;
956 else
957 tprints(" => ");
958
959 if (umove_or_printaddr(tcp, arg, &args))
960 break;
961
962 tprints("{");
963
964 if (entering(tcp)) {
965 tprintf("logical=%" PRI__u64 ", size=%" PRI__u64,
966 args.logical, args.size);
967 tprintf(", inodes=0x%" PRI__x64 "}", args.inodes);
968 return 0;
969 }
970
971 tprints("inodes=");
972 btrfs_print_logical_ino_container(tcp, args.inodes);
973
974 tprints("}");
975 break;
976 }
977
978 case BTRFS_IOC_QGROUP_ASSIGN: { /* W */
979 struct btrfs_ioctl_qgroup_assign_args args;
980
981 tprints(", ");
982 if (umove_or_printaddr(tcp, arg, &args))
983 break;
984
985 tprintf("{assign=%" PRI__u64 ", src=%" PRI__u64
986 ", dst=%" PRI__u64 "}",
987 args.assign, args.src, args.dst);
988 break;
989 }
990
991 case BTRFS_IOC_QGROUP_CREATE: { /* W */
992 struct btrfs_ioctl_qgroup_create_args args;
993
994 tprints(", ");
995 if (umove_or_printaddr(tcp, arg, &args))
996 break;
997
998 tprintf("{create=%" PRI__u64 ", qgroupid=%" PRI__u64 "}",
999 args.create, args.qgroupid);
1000 break;
1001 }
1002
1003 case BTRFS_IOC_QGROUP_LIMIT: { /* R */
1004 struct btrfs_ioctl_qgroup_limit_args args;
1005
1006 if (entering(tcp))
1007 return 0;
1008
1009 tprints(", ");
1010 if (umove_or_printaddr(tcp, arg, &args))
1011 break;
1012
1013 tprintf("{qgroupid=%" PRI__u64 ", lim=", args.qgroupid);
1014 btrfs_print_qgroup_limit(&args.lim);
1015 tprints("}");
1016 break;
1017 }
1018
1019 case BTRFS_IOC_QUOTA_CTL: { /* W */
1020 struct btrfs_ioctl_quota_ctl_args args;
1021
1022 tprints(", ");
1023 if (umove_or_printaddr(tcp, arg, &args))
1024 break;
1025
Dmitry V. Levin95577cf2016-05-24 00:35:49 +00001026 printxval64(btrfs_qgroup_ctl_cmds, args.cmd,
1027 "BTRFS_QUOTA_CTL_???");
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001028 tprints("}");
1029
1030 break;
1031 }
Dmitry V. Levin95577cf2016-05-24 00:35:49 +00001032
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001033 case BTRFS_IOC_QUOTA_RESCAN: { /* W */
1034 struct btrfs_ioctl_quota_rescan_args args;
1035
1036 tprints(", ");
1037 if (umove_or_printaddr(tcp, arg, &args))
1038 break;
1039
Dmitry V. Levinfe7a4512016-06-17 03:02:46 +03001040 tprintf("{flags=%" PRIu64 "}", (uint64_t) args.flags);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001041 break;
1042 }
Dmitry V. Levin95577cf2016-05-24 00:35:49 +00001043
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001044 case BTRFS_IOC_QUOTA_RESCAN_STATUS: { /* R */
1045 struct btrfs_ioctl_quota_rescan_args args;
1046
1047 if (entering(tcp))
1048 return 0;
1049
1050 tprints(", ");
1051 if (umove_or_printaddr(tcp, arg, &args))
1052 break;
1053
Dmitry V. Levinfe7a4512016-06-17 03:02:46 +03001054 tprintf("{flags=%" PRIu64 ", progress=", (uint64_t) args.flags);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001055 btrfs_print_objectid(args.progress);
1056 tprints("}");
1057 break;
1058 }
Dmitry V. Levin95577cf2016-05-24 00:35:49 +00001059
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001060 case BTRFS_IOC_SET_RECEIVED_SUBVOL: { /* RW */
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +00001061 struct_btrfs_ioctl_received_subvol_args args;
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001062 char uuid[UUID_STRING_SIZE+1];
1063
1064 if (entering(tcp))
1065 tprints(", ");
1066 else if (syserror(tcp))
1067 break;
1068 else
1069 tprints(" => ");
1070
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001071 if (umove_or_printaddr(tcp, arg, &args))
1072 break;
1073
1074 if (entering(tcp)) {
1075 btrfs_unparse_uuid((unsigned char *)args.uuid, uuid);
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +00001076 tprintf("{uuid=%s, stransid=%" PRIu64
1077 ", stime=%" PRIu64 ".%u, flags=%" PRIu64
1078 "}", uuid, (uint64_t) args.stransid,
1079 (uint64_t) args.stime.sec, args.stime.nsec,
1080 (uint64_t) args.flags);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001081 return 0;
1082 }
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +00001083 tprintf("{rtransid=%" PRIu64 ", rtime=%" PRIu64 ".%u}",
1084 (uint64_t) args.rtransid, (uint64_t) args.rtime.sec,
1085 args.rtime.nsec);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001086 break;
1087 }
Dmitry V. Levin95577cf2016-05-24 00:35:49 +00001088
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001089 case BTRFS_IOC_SCRUB: /* RW */
1090 case BTRFS_IOC_SCRUB_PROGRESS: { /* RW */
1091 struct btrfs_ioctl_scrub_args args;
1092
1093 if (entering(tcp))
1094 tprints(", ");
1095 else if (syserror(tcp))
1096 break;
1097 else
1098 tprints(" => ");
1099
1100 if (umove_or_printaddr(tcp, arg, &args))
1101 break;
1102
1103 if (entering(tcp)) {
1104 tprintf("{devid=%" PRI__u64, args.devid);
1105 if (code == BTRFS_IOC_SCRUB) {
1106 tprintf(", start=%" PRI__u64 ", end=",
1107 args.start);
1108 tprintf("%" PRI__u64, args.end);
1109 if (args.end == UINT64_MAX)
1110 tprints(" /* UINT64_MAX */");
1111 tprints(", flags=");
1112 printflags64(btrfs_scrub_flags, args.flags,
1113 "BTRFS_SCRUB_???");
1114 }
1115 tprints("}");
1116 return 0;
1117 }
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +00001118 tprintf("{data_extents_scrubbed=%" PRI__u64
1119 ", tree_extents_scrubbed=%" PRI__u64
1120 ", data_bytes_scrubbed=%" PRI__u64
1121 ", tree_bytes_scrubbed=%" PRI__u64
1122 ", read_errors=%" PRI__u64
1123 ", csum_errors=%" PRI__u64
1124 ", verify_errors=%" PRI__u64
1125 ", no_csum=%" PRI__u64
1126 ", csum_discards=%" PRI__u64
1127 ", super_errors=%" PRI__u64
1128 ", malloc_errors=%" PRI__u64
1129 ", uncorrectable_errors=%" PRI__u64
1130 ", corrected_errors=%" PRI__u64
1131 ", last_physical=%" PRI__u64
1132 ", unverified_errors=%" PRI__u64 "}",
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001133 args.progress.data_extents_scrubbed,
1134 args.progress.tree_extents_scrubbed,
1135 args.progress.data_bytes_scrubbed,
1136 args.progress.tree_bytes_scrubbed,
1137 args.progress.read_errors,
1138 args.progress.csum_errors,
1139 args.progress.verify_errors,
1140 args.progress.no_csum,
1141 args.progress.csum_discards,
1142 args.progress.super_errors,
1143 args.progress.malloc_errors,
1144 args.progress.uncorrectable_errors,
1145 args.progress.corrected_errors,
1146 args.progress.last_physical,
1147 args.progress.unverified_errors);
1148 break;
1149 }
1150
1151 case BTRFS_IOC_TREE_SEARCH: { /* RW */
1152 struct btrfs_ioctl_search_args args;
1153 uint64_t buf_offset;
1154
1155 if (entering(tcp))
1156 tprints(", ");
1157 else if (syserror(tcp))
1158 break;
1159 else
1160 tprints(" => ");
1161
1162 if (umove_or_printaddr(tcp, arg, &args))
1163 break;
1164
1165 buf_offset = offsetof(struct btrfs_ioctl_search_args, buf);
1166 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1167 sizeof(args.buf), false);
1168 if (entering(tcp))
1169 return 0;
1170 break;
1171 }
1172
1173 case BTRFS_IOC_TREE_SEARCH_V2: { /* RW */
1174 struct btrfs_ioctl_search_args_v2 args;
1175 uint64_t buf_offset;
1176
1177 if (entering(tcp))
1178 tprints(", ");
1179 else if (syserror(tcp)) {
1180 if (tcp->u_error == EOVERFLOW) {
Dmitry V. Levind67b2172016-05-24 01:10:53 +00001181 tprints(" => ");
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001182 tcp->u_error = 0;
1183 if (!umove_or_printaddr(tcp, arg, &args))
Dmitry V. Levind67b2172016-05-24 01:10:53 +00001184 tprintf("{buf_size=%" PRIu64 "}",
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001185 (uint64_t)args.buf_size);
1186 tcp->u_error = EOVERFLOW;
1187 }
1188 break;
1189 } else
1190 tprints(" => ");
1191
1192 if (umove_or_printaddr(tcp, arg, &args))
1193 break;
1194
1195 buf_offset = offsetof(struct btrfs_ioctl_search_args_v2, buf);
1196 btrfs_print_tree_search(tcp, &args.key, arg + buf_offset,
1197 args.buf_size, true);
1198 if (entering(tcp))
1199 return 0;
1200 break;
1201 }
1202
1203 case BTRFS_IOC_SEND: { /* W */
Dmitry V. Levinfb0c6092016-05-24 01:28:26 +00001204 struct_btrfs_ioctl_send_args args;
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001205
1206 tprints(", ");
1207 if (umove_or_printaddr(tcp, arg, &args))
1208 break;
1209
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +00001210 tprints("{send_fd=");
1211 printfd(tcp, args.send_fd);
1212 tprintf(", clone_sources_count=%" PRIu64 ", clone_sources=",
1213 (uint64_t) args.clone_sources_count);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001214
Dmitry V. Levind57cc262016-05-24 01:15:18 +00001215 if (abbrev(tcp))
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001216 tprints("...");
Dmitry V. Levind57cc262016-05-24 01:15:18 +00001217 else {
1218 uint64_t record;
1219 print_array(tcp, (unsigned long) args.clone_sources,
1220 args.clone_sources_count,
1221 &record, sizeof(record),
1222 umoven_or_printaddr,
1223 print_objectid_callback, 0);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001224 }
1225 tprints(", parent_root=");
1226 btrfs_print_objectid(args.parent_root);
1227 tprints(", flags=");
1228 printflags64(btrfs_send_flags, args.flags,
1229 "BTRFS_SEND_FLAGS_???");
1230 tprints("}");
1231 break;
1232 }
1233
1234 case BTRFS_IOC_SPACE_INFO: { /* RW */
1235 struct btrfs_ioctl_space_args args;
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001236
1237 if (entering(tcp))
1238 tprints(", ");
1239 else if (syserror(tcp))
1240 break;
1241 else
1242 tprints(" => ");
1243
1244 if (umove_or_printaddr(tcp, arg, &args))
1245 break;
1246
1247 tprints("{");
1248 if (entering(tcp)) {
Dmitry V. Levin2be39ec2016-05-24 00:23:31 +00001249 tprintf("space_slots=%" PRI__u64 "}", args.space_slots);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001250 return 0;
1251 }
1252
1253 tprintf("total_spaces=%" PRI__u64, args.total_spaces);
1254
1255 if (args.space_slots == 0 && args.total_spaces) {
1256 tprints("}");
1257 break;
1258 }
1259
1260 tprints(", spaces=");
1261
Dmitry V. Levind57cc262016-05-24 01:15:18 +00001262 if (abbrev(tcp))
1263 tprints("...");
1264 else {
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001265 struct btrfs_ioctl_space_info info;
Dmitry V. Levind57cc262016-05-24 01:15:18 +00001266 print_array(tcp, arg + offsetof(typeof(args), spaces),
1267 args.total_spaces,
1268 &info, sizeof(info), umoven_or_printaddr,
1269 print_btrfs_ioctl_space_info, 0);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001270 }
Dmitry V. Levind57cc262016-05-24 01:15:18 +00001271 tprints("}");
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001272 break;
1273 }
1274
1275 case BTRFS_IOC_SNAP_CREATE:
1276 case BTRFS_IOC_RESIZE:
1277 case BTRFS_IOC_SCAN_DEV:
1278 case BTRFS_IOC_ADD_DEV:
1279 case BTRFS_IOC_RM_DEV:
1280 case BTRFS_IOC_SUBVOL_CREATE:
1281 case BTRFS_IOC_SNAP_DESTROY:
1282 case BTRFS_IOC_DEVICES_READY: { /* W */
1283 struct btrfs_ioctl_vol_args args;
1284
1285 tprints(", ");
1286 if (umove_or_printaddr(tcp, arg, &args))
1287 break;
1288
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +00001289 tprints("{fd=");
1290 printfd(tcp, args.fd);
1291 tprints(", name=");
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001292 print_quoted_string(args.name, sizeof(args.name),
1293 QUOTE_0_TERMINATED);
1294 tprints("}");
1295 break;
1296 }
1297
1298 case BTRFS_IOC_SNAP_CREATE_V2:
1299 case BTRFS_IOC_SUBVOL_CREATE_V2: { /* code is W, but is actually RW */
Dmitry V. Levine7d3d642016-08-25 21:24:33 +00001300 struct_btrfs_ioctl_vol_args_v2 args;
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001301
1302 if (entering(tcp))
1303 tprints(", ");
1304 else if (syserror(tcp))
1305 break;
1306 else
1307 tprints(" => ");
1308
1309 if (umove_or_printaddr(tcp, arg, &args))
1310 break;
1311
1312 if (entering(tcp)) {
Dmitry V. Levin6ce6d3b2016-05-24 01:53:02 +00001313 tprints("{fd=");
1314 printfd(tcp, args.fd);
1315 tprints(", flags=");
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001316 printflags64(btrfs_snap_flags_v2, args.flags,
1317 "BTRFS_SUBVOL_???");
1318 if (args.flags & BTRFS_SUBVOL_QGROUP_INHERIT) {
Dmitry V. Levine7d3d642016-08-25 21:24:33 +00001319 tprintf(", size=%llu, qgroup_inherit=",
1320 (unsigned long long) args.size);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001321
1322 btrfs_print_qgroup_inherit(tcp,
Dmitry V. Levine7d3d642016-08-25 21:24:33 +00001323 (unsigned long) args.qgroup_inherit);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001324 }
1325 tprintf(", name=");
Dmitry V. Levin0cd7ea02016-05-24 00:59:40 +00001326 print_quoted_string(args.name, sizeof(args.name),
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001327 QUOTE_0_TERMINATED);
1328 tprints("}");
1329 return 0;
1330 }
Dmitry V. Levine7d3d642016-08-25 21:24:33 +00001331 tprintf("{transid=%llu}", (unsigned long long) args.transid);
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001332 break;
1333 }
Dmitry V. Levin82b9e342016-05-24 01:12:41 +00001334
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001335 case BTRFS_IOC_GET_FSLABEL: /* R */
Dmitry V. Levin82b9e342016-05-24 01:12:41 +00001336 if (entering(tcp))
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001337 return 0;
Dmitry V. Levin82b9e342016-05-24 01:12:41 +00001338 /* fall through */
1339 case BTRFS_IOC_SET_FSLABEL: { /* W */
1340 char label[BTRFS_LABEL_SIZE];
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001341
1342 tprints(", ");
Dmitry V. Levin90ffbc72016-05-24 00:49:50 +00001343 if (umove_or_printaddr(tcp, arg, &label))
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001344 break;
1345 print_quoted_string(label, sizeof(label), QUOTE_0_TERMINATED);
1346 break;
1347 }
1348
1349 case BTRFS_IOC_CLONE: /* FICLONE */
1350 case BTRFS_IOC_CLONE_RANGE: /* FICLONERANGE */
Dmitry V. Levinea516df2016-05-24 02:40:13 +00001351#ifdef BTRFS_IOC_FILE_EXTENT_SAME
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001352 case BTRFS_IOC_FILE_EXTENT_SAME: /* FIDEDUPERANGE */
Dmitry V. Levinea516df2016-05-24 02:40:13 +00001353#endif
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001354 /*
1355 * FICLONE, FICLONERANGE, and FIDEDUPERANGE started out as
1356 * btrfs ioctls and the code was kept for the generic
1357 * implementations. We use the BTRFS_* names here because
1358 * they will be available on older systems.
1359 */
1360 return file_ioctl(tcp, code, arg);
1361
1362 default:
1363 return RVAL_DECODED;
1364 };
Dmitry V. Levin3ce2dfc2016-05-24 00:45:05 +00001365 return RVAL_DECODED | 1;
Jeff Mahoney8cc69622016-05-18 18:09:39 -04001366}
1367#endif /* HAVE_LINUX_BTRFS_H */