Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1 | /* |
| 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" |
| 29 | #include <linux/fs.h> |
| 30 | #ifdef HAVE_LINUX_BTRFS_H |
| 31 | /* |
| 32 | * Prior to Linux 3.12, the BTRFS_IOC_DEFAULT_SUBVOL used u64 in |
| 33 | * its definition, which isn't exported by the kernel. |
| 34 | */ |
| 35 | typedef __u64 u64; |
| 36 | |
| 37 | #include <linux/btrfs.h> |
| 38 | |
| 39 | #ifndef HAVE_STRUCT_BTRFS_IOCTL_FEATURE_FLAGS_COMPAT_FLAGS |
| 40 | struct btrfs_ioctl_feature_flags { |
| 41 | uint64_t compat_flags; |
| 42 | uint64_t compat_ro_flags; |
| 43 | uint64_t incompat_flags; |
| 44 | }; |
| 45 | #endif |
| 46 | |
| 47 | #ifndef HAVE_STRUCT_BTRFS_IOCTL_DEFRAG_RANGE_ARGS_START |
| 48 | struct btrfs_ioctl_defrag_range_args { |
| 49 | uint64_t start; |
| 50 | uint64_t len; |
| 51 | uint64_t flags; |
| 52 | uint32_t extent_thresh; |
| 53 | uint32_t compress_type; |
| 54 | uint32_t unused[4]; |
| 55 | }; |
| 56 | #endif |
| 57 | |
| 58 | #ifndef BTRFS_SUBVOL_NAME_MAX |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 59 | # define BTRFS_SUBVOL_NAME_MAX 4039 |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | #ifndef BTRFS_LABEL_SIZE |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 63 | # define BTRFS_LABEL_SIZE 256 |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | #ifndef BTRFS_FIRST_FREE_OBJECTID |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 67 | # define BTRFS_FIRST_FREE_OBJECTID 256ULL |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | #ifndef BTRFS_IOC_GET_FEATURES |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 71 | # define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ |
| 72 | struct btrfs_ioctl_feature_flags) |
| 73 | # define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \ |
| 74 | struct btrfs_ioctl_feature_flags[2]) |
| 75 | # define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ |
| 76 | struct btrfs_ioctl_feature_flags[3]) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 77 | #endif |
| 78 | |
| 79 | #ifndef BTRFS_IOC_TREE_SEARCH_V2 |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 80 | # define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \ |
| 81 | struct btrfs_ioctl_search_args_v2) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 82 | struct btrfs_ioctl_search_args_v2 { |
| 83 | struct btrfs_ioctl_search_key key; /* in/out - search parameters */ |
| 84 | uint64_t buf_size; /* in - size of buffer |
| 85 | * out - on EOVERFLOW: needed size |
| 86 | * to store item */ |
| 87 | uint64_t buf[0]; /* out - found items */ |
| 88 | }; |
| 89 | #endif |
| 90 | |
| 91 | #include "xlat/btrfs_balance_args.h" |
| 92 | #include "xlat/btrfs_balance_ctl_cmds.h" |
| 93 | #include "xlat/btrfs_balance_flags.h" |
| 94 | #include "xlat/btrfs_balance_state.h" |
| 95 | #include "xlat/btrfs_compress_types.h" |
| 96 | #include "xlat/btrfs_defrag_flags.h" |
| 97 | #include "xlat/btrfs_dev_replace_cmds.h" |
| 98 | #include "xlat/btrfs_dev_replace_results.h" |
| 99 | #include "xlat/btrfs_dev_replace_state.h" |
| 100 | #include "xlat/btrfs_dev_stats_flags.h" |
| 101 | #include "xlat/btrfs_dev_stats_values.h" |
| 102 | #include "xlat/btrfs_features_compat.h" |
| 103 | #include "xlat/btrfs_features_compat_ro.h" |
| 104 | #include "xlat/btrfs_features_incompat.h" |
| 105 | #include "xlat/btrfs_key_types.h" |
| 106 | #include "xlat/btrfs_qgroup_ctl_cmds.h" |
| 107 | #include "xlat/btrfs_qgroup_inherit_flags.h" |
| 108 | #include "xlat/btrfs_qgroup_limit_flags.h" |
| 109 | #include "xlat/btrfs_qgroup_status_flags.h" |
| 110 | #include "xlat/btrfs_scrub_flags.h" |
| 111 | #include "xlat/btrfs_send_flags.h" |
| 112 | #include "xlat/btrfs_snap_flags_v2.h" |
| 113 | #include "xlat/btrfs_space_info_flags.h" |
| 114 | #include "xlat/btrfs_tree_objectids.h" |
| 115 | |
| 116 | static inline char |
| 117 | prnibble(char v) |
| 118 | { |
| 119 | if (v >= 10) |
| 120 | return 'a' + (v - 10); |
| 121 | return '0' + v; |
| 122 | } |
| 123 | |
| 124 | /* 8-4-4-4-12 = 36 characters */ |
| 125 | #define UUID_STRING_SIZE 36 |
| 126 | |
| 127 | /* Formats uuid, returns 0 if it's all zeroes */ |
| 128 | static int |
| 129 | btrfs_unparse_uuid(unsigned char *uuid, char *out) |
| 130 | { |
| 131 | int i; |
| 132 | int ret = 0; |
| 133 | for (i = 0; i < BTRFS_UUID_SIZE; i++) { |
| 134 | if (i == 4 || i == 6 || i == 8 || i == 10) |
| 135 | *out++ = '-'; |
| 136 | *out++ = prnibble(uuid[i] >> 4); |
| 137 | *out++ = prnibble(uuid[i] & 0xf); |
| 138 | if (uuid[i]) |
| 139 | ret = 1; |
| 140 | } |
| 141 | *out = '\0'; |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | static void |
| 146 | print_u64(const char *name, uint64_t value) |
| 147 | { |
| 148 | tprintf(", %s=%" PRIu64, name, value); |
| 149 | if (value == UINT64_MAX) |
| 150 | tprints(" /* UINT64_MAX */"); |
| 151 | } |
| 152 | |
| 153 | #define print_member_u64(obj, name) print_u64(#name, obj->name) |
| 154 | |
| 155 | static void |
| 156 | btrfs_print_balance_args(const char *name, struct btrfs_balance_args *bba) |
| 157 | { |
| 158 | tprintf(", %s={profiles=", name); |
| 159 | printflags64(btrfs_space_info_flags, bba->profiles, |
| 160 | "BTRFS_BLOCK_GROUP_???"); |
| 161 | print_member_u64(bba, usage); |
| 162 | print_member_u64(bba, devid); |
| 163 | print_member_u64(bba, pstart); |
| 164 | print_member_u64(bba, pend); |
| 165 | print_member_u64(bba, vstart); |
| 166 | print_member_u64(bba, vend); |
| 167 | print_member_u64(bba, target); |
| 168 | tprints(", flags="); |
| 169 | printflags64(btrfs_balance_args, bba->flags, "BTRFS_BALANCE_ARGS_???"); |
| 170 | tprints("}"); |
| 171 | } |
| 172 | |
| 173 | static void |
| 174 | btrfs_print_balance(struct tcb *tcp, const long arg, bool out) |
| 175 | { |
| 176 | struct btrfs_ioctl_balance_args balance_args; |
| 177 | |
| 178 | if (umove_or_printaddr(tcp, arg, &balance_args)) |
| 179 | return; |
| 180 | |
| 181 | tprints("{flags="); |
| 182 | printflags64(btrfs_balance_flags, balance_args.flags, |
| 183 | "BTRFS_BALANCE_???"); |
| 184 | if (out) { |
| 185 | tprints(", state="); |
| 186 | printflags64(btrfs_balance_state, balance_args.state, |
| 187 | "BTRFS_BALANCE_STATE_???"); |
| 188 | } |
| 189 | |
| 190 | if (balance_args.flags & BTRFS_BALANCE_DATA) |
| 191 | btrfs_print_balance_args("data", &balance_args.data); |
| 192 | if (balance_args.flags & BTRFS_BALANCE_METADATA) |
| 193 | btrfs_print_balance_args("meta", &balance_args.meta); |
| 194 | if (balance_args.flags & BTRFS_BALANCE_SYSTEM) |
| 195 | btrfs_print_balance_args("sys", &balance_args.sys); |
| 196 | tprints("}"); |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | btrfs_print_features(struct btrfs_ioctl_feature_flags *flags) |
| 201 | { |
| 202 | tprints("{compat_flags="); |
| 203 | printflags64(btrfs_features_compat, flags->compat_flags, |
| 204 | "BTRFS_FEATURE_COMPAT_???"); |
| 205 | |
| 206 | tprints(", compat_ro_flags="); |
| 207 | printflags64(btrfs_features_compat_ro, flags->compat_ro_flags, |
| 208 | "BTRFS_FEATURE_COMPAT_RO_???"); |
| 209 | |
| 210 | tprints(", incompat_flags="); |
| 211 | printflags64(btrfs_features_incompat, flags->incompat_flags, |
| 212 | "BTRFS_FEATURE_INCOMPAT_???"); |
| 213 | tprints("}"); |
| 214 | } |
| 215 | |
| 216 | static void |
| 217 | btrfs_print_qgroup_limit(struct btrfs_qgroup_limit *lim) |
| 218 | { |
| 219 | tprints("{flags="); |
| 220 | printflags64(btrfs_qgroup_limit_flags, lim->flags, |
| 221 | "BTRFS_QGROUP_LIMIT_???"); |
| 222 | tprintf(", max_rfer=%" PRI__u64 ", max_excl=%" PRI__u64 |
| 223 | ", rsv_rfer=%" PRI__u64 ", rsv_excl=%" PRI__u64 "}", |
| 224 | lim->max_rfer, lim->max_excl, |
| 225 | lim->rsv_rfer, lim->rsv_excl); |
| 226 | } |
| 227 | |
| 228 | static void |
| 229 | btrfs_print_key_type(uint32_t type) |
| 230 | { |
| 231 | const char *str = xlookup(btrfs_key_types, type); |
| 232 | tprintf("%u", type); |
| 233 | if (str) |
| 234 | tprintf(" /* %s */", str); |
| 235 | } |
| 236 | |
| 237 | static void |
| 238 | btrfs_print_objectid(uint64_t objectid) |
| 239 | { |
| 240 | const char *str = xlookup(btrfs_tree_objectids, objectid); |
| 241 | tprintf("%" PRIu64, objectid); |
| 242 | if (str) |
| 243 | tprintf(" /* %s */", str); |
| 244 | } |
| 245 | |
| 246 | static void |
| 247 | btrfs_print_data_container_header(struct btrfs_data_container *container) |
| 248 | { |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 249 | tprintf("{bytes_left=%u, bytes_missing=%u" |
| 250 | ", elem_cnt=%u, elem_missed=%u, val=", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 251 | container->bytes_left, container->bytes_missing, |
| 252 | container->elem_cnt, container->elem_missed); |
| 253 | } |
| 254 | |
| 255 | static void |
| 256 | btrfs_print_data_container_footer(void) |
| 257 | { |
| 258 | tprints("}"); |
| 259 | } |
| 260 | |
| 261 | static uint64_t |
| 262 | data_container_record_offset(unsigned int index) |
| 263 | { |
| 264 | return offsetof(struct btrfs_data_container, val[index]); |
| 265 | } |
| 266 | |
| 267 | static void |
| 268 | btrfs_print_logical_ino_container(struct tcb *tcp, uint64_t inodes_addr) |
| 269 | { |
| 270 | struct btrfs_data_container container; |
| 271 | uint32_t i; |
| 272 | uint32_t printed = 0; |
| 273 | |
| 274 | if (umoven_or_printaddr(tcp, inodes_addr, |
| 275 | sizeof(container), &container)) |
| 276 | return; |
| 277 | |
| 278 | btrfs_print_data_container_header(&container); |
| 279 | if (abbrev(tcp)) { |
| 280 | tprints("..."); |
| 281 | btrfs_print_data_container_footer(); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | tprints("["); |
| 286 | |
| 287 | for (i = 0; i < container.elem_cnt; i += 3, printed++) { |
| 288 | uint64_t offset = data_container_record_offset(i); |
| 289 | uint64_t record[3]; |
| 290 | |
| 291 | if (i) |
| 292 | tprints(", "); |
| 293 | |
| 294 | if (printed > max_strlen || |
| 295 | umoven(tcp, inodes_addr + offset, sizeof(record), record)) { |
| 296 | tprints("..."); |
| 297 | break; |
| 298 | } |
| 299 | tprintf("{inum=%" PRIu64 ", offset=%" PRIu64 |
| 300 | ", root=%" PRIu64 "}", record[0], record[1], record[2]); |
| 301 | } |
| 302 | tprints("]"); |
| 303 | btrfs_print_data_container_footer(); |
| 304 | } |
| 305 | |
| 306 | static void |
| 307 | btrfs_print_ino_path_container(struct tcb *tcp, uint64_t fspath_addr) |
| 308 | { |
| 309 | struct btrfs_data_container container; |
| 310 | uint32_t i; |
| 311 | |
| 312 | if (umoven_or_printaddr(tcp, fspath_addr, |
| 313 | sizeof(container), &container)) |
| 314 | return; |
| 315 | |
| 316 | btrfs_print_data_container_header(&container); |
| 317 | if (abbrev(tcp)) { |
| 318 | tprints("..."); |
| 319 | btrfs_print_data_container_footer(); |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | tprints("["); |
| 324 | |
| 325 | for (i = 0; i < container.elem_cnt; i++) { |
| 326 | uint64_t offset = data_container_record_offset(i); |
| 327 | uint64_t ptr; |
| 328 | |
| 329 | if (i) |
| 330 | tprints(", "); |
| 331 | |
| 332 | if (i > max_strlen || |
| 333 | umoven(tcp, fspath_addr + offset, sizeof(ptr), &ptr)) { |
| 334 | tprints("..."); |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | printpath(tcp, |
| 339 | fspath_addr + data_container_record_offset(0) + ptr); |
| 340 | } |
| 341 | tprints("]"); |
| 342 | btrfs_print_data_container_footer(); |
| 343 | } |
| 344 | |
| 345 | static void |
| 346 | btrfs_print_qgroup_inherit(struct tcb *tcp, uint64_t qgi_addr) |
| 347 | { |
| 348 | struct btrfs_qgroup_inherit inherit; |
| 349 | |
| 350 | if (umoven_or_printaddr(tcp, qgi_addr, sizeof(inherit), &inherit) < 0) |
| 351 | return; |
| 352 | |
| 353 | tprintf("{flags="); |
| 354 | printflags64(btrfs_qgroup_inherit_flags, inherit.flags, |
| 355 | "BTRFS_QGROUP_INHERIT_???"); |
| 356 | tprintf(", num_qgroups=%" PRI__u64 ", num_ref_copies=%" PRI__u64 |
| 357 | ", num_excl_copies=%" PRI__u64 ", lim=", |
| 358 | inherit.num_qgroups, inherit.num_ref_copies, |
| 359 | inherit.num_excl_copies); |
| 360 | |
| 361 | btrfs_print_qgroup_limit(&inherit.lim); |
| 362 | |
| 363 | tprints(", qgroups="); |
| 364 | |
| 365 | if (abbrev(tcp)) { |
| 366 | tprints("..."); |
| 367 | } else { |
| 368 | uint32_t i; |
| 369 | |
| 370 | tprints("["); |
| 371 | for (i = 0; i < inherit.num_qgroups; i++) { |
| 372 | uint64_t offset = offsetof(typeof(inherit), qgroups[i]); |
| 373 | uint64_t record; |
| 374 | if (i) |
| 375 | tprints(", "); |
| 376 | if (i > max_strlen || |
| 377 | umoven(tcp, qgi_addr + offset, |
| 378 | sizeof(record), &record)) { |
| 379 | tprints("..."); |
| 380 | break; |
| 381 | } |
| 382 | |
| 383 | tprintf("%" PRIu64, record); |
| 384 | } |
| 385 | tprints("]"); |
| 386 | } |
| 387 | tprints("}"); |
| 388 | } |
| 389 | |
| 390 | static void |
| 391 | print_key_value_internal(struct tcb *tcp, const char *name, uint64_t value) |
| 392 | { |
| 393 | if (value) { |
| 394 | tprintf(", %s=%" PRIu64, name, value); |
| 395 | if (value == UINT64_MAX) |
| 396 | tprints(" /* UINT64_MAX */"); |
| 397 | } |
| 398 | } |
| 399 | #define print_key_value(tcp, key, name) \ |
| 400 | print_key_value_internal((tcp), #name, (key)->name) |
| 401 | |
| 402 | static void |
| 403 | btrfs_print_tree_search(struct tcb *tcp, struct btrfs_ioctl_search_key *key, |
| 404 | uint64_t buf_addr, uint64_t buf_size, bool print_size) |
| 405 | { |
| 406 | if (entering(tcp)) { |
| 407 | tprintf("{key={tree_id="); |
| 408 | btrfs_print_objectid(key->tree_id); |
| 409 | |
| 410 | if (key->min_objectid != BTRFS_FIRST_FREE_OBJECTID || |
| 411 | !abbrev(tcp)) { |
| 412 | tprints(", min_objectid="); |
| 413 | btrfs_print_objectid(key->min_objectid); |
| 414 | } |
| 415 | |
| 416 | if (key->max_objectid != BTRFS_LAST_FREE_OBJECTID || |
| 417 | !abbrev(tcp)) { |
| 418 | tprints(", max_objectid="); |
| 419 | btrfs_print_objectid(key->max_objectid); |
| 420 | } |
| 421 | |
| 422 | print_key_value(tcp, key, min_offset); |
| 423 | print_key_value(tcp, key, max_offset); |
| 424 | print_key_value(tcp, key, min_transid); |
| 425 | print_key_value(tcp, key, max_transid); |
| 426 | |
| 427 | tprints(", min_type="); |
| 428 | btrfs_print_key_type(key->min_type); |
| 429 | tprints(", max_type="); |
| 430 | btrfs_print_key_type(key->max_type); |
| 431 | tprintf(", nr_items=%u}", key->nr_items); |
| 432 | if (print_size) |
| 433 | tprintf(", buf_size=%" PRIu64, buf_size); |
| 434 | tprints("}"); |
| 435 | return; |
| 436 | } |
| 437 | tprintf("{key={nr_items=%u}", key->nr_items); |
| 438 | if (print_size) |
| 439 | tprintf(", buf_size=%" PRIu64, buf_size); |
| 440 | tprints(", buf="); |
| 441 | if (abbrev(tcp)) |
| 442 | tprints("..."); |
| 443 | else { |
| 444 | uint64_t i; |
| 445 | uint64_t off = 0; |
| 446 | tprints("["); |
| 447 | for (i = 0; i < key->nr_items; i++) { |
| 448 | struct btrfs_ioctl_search_header sh; |
| 449 | uint64_t addr = buf_addr + off; |
| 450 | if (i) |
| 451 | tprints(", "); |
| 452 | if (i > max_strlen || |
| 453 | umoven(tcp, addr, sizeof(sh), &sh)) { |
| 454 | tprints("..."); |
| 455 | break; |
| 456 | } |
| 457 | tprintf("{transid=%" PRI__u64 ", objectid=", |
| 458 | sh.transid); |
| 459 | btrfs_print_objectid(sh.objectid); |
| 460 | tprintf(", offset=%" PRI__u64 ", type=", sh.offset); |
| 461 | btrfs_print_key_type(sh.type); |
| 462 | tprintf(", len=%u}", sh.len); |
| 463 | off += sizeof(sh) + sh.len; |
| 464 | } |
| 465 | tprints("]"); |
| 466 | } |
| 467 | |
| 468 | tprints("}"); |
| 469 | } |
| 470 | |
| 471 | int |
| 472 | btrfs_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
| 473 | { |
| 474 | int ret = 0; |
| 475 | |
| 476 | switch (code) { |
| 477 | /* Take no arguments; Command only. */ |
| 478 | case BTRFS_IOC_TRANS_START: |
| 479 | case BTRFS_IOC_TRANS_END: |
| 480 | case BTRFS_IOC_SYNC: |
| 481 | case BTRFS_IOC_SCRUB_CANCEL: |
| 482 | case BTRFS_IOC_QUOTA_RESCAN_WAIT: |
| 483 | /* |
| 484 | * The codes for these ioctls are based on each accepting a |
| 485 | * vol_args but none of them actually consume an argument. |
| 486 | */ |
| 487 | case BTRFS_IOC_DEFRAG: |
| 488 | case BTRFS_IOC_BALANCE: |
| 489 | break; |
| 490 | |
| 491 | /* take a signed int */ |
| 492 | case BTRFS_IOC_BALANCE_CTL: { |
| 493 | tprints(", "); |
| 494 | printxvals(arg, "BTRFS_BALANCE_CTL_???", |
| 495 | btrfs_balance_ctl_cmds, NULL); |
| 496 | break; |
| 497 | } |
| 498 | |
| 499 | /* returns a 64 */ |
| 500 | case BTRFS_IOC_START_SYNC: /* R */ |
| 501 | if (entering(tcp)) |
| 502 | return 0; |
| 503 | /* fallthrough */ |
| 504 | /* take a u64 */ |
| 505 | case BTRFS_IOC_DEFAULT_SUBVOL: /* W */ |
| 506 | case BTRFS_IOC_WAIT_SYNC: /* W */ |
| 507 | tprints(", "); |
| 508 | printnum_int64(tcp, arg, "%" PRIu64); |
| 509 | break; |
| 510 | |
| 511 | /* u64 but describe a flags bitfield; We can make that symbolic */ |
| 512 | case BTRFS_IOC_SUBVOL_GETFLAGS: { /* R */ |
| 513 | uint64_t flags; |
| 514 | if (entering(tcp)) |
| 515 | return 0; |
| 516 | |
| 517 | tprints(", "); |
| 518 | |
| 519 | if (umove_or_printaddr(tcp, arg, &flags)) |
| 520 | break; |
| 521 | |
| 522 | printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???"); |
| 523 | break; |
| 524 | } |
| 525 | case BTRFS_IOC_SUBVOL_SETFLAGS: { /* W */ |
| 526 | uint64_t flags; |
| 527 | |
| 528 | tprints(", "); |
| 529 | |
| 530 | if (umove_or_printaddr(tcp, arg, &flags)) |
| 531 | break; |
| 532 | |
| 533 | printflags64(btrfs_snap_flags_v2, flags, "BTRFS_SUBVOL_???"); |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | /* More complex types */ |
| 538 | case BTRFS_IOC_BALANCE_V2: /* RW */ |
| 539 | if (entering(tcp)) { |
| 540 | tprints(", "); |
| 541 | btrfs_print_balance(tcp, arg, false); |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | if (syserror(tcp)) |
| 546 | break; |
| 547 | |
| 548 | tprints(" => "); |
| 549 | btrfs_print_balance(tcp, arg, true); |
| 550 | break; |
| 551 | case BTRFS_IOC_BALANCE_PROGRESS: /* R */ |
| 552 | if (entering(tcp)) |
| 553 | return 0; |
| 554 | |
| 555 | tprints(", "); |
| 556 | btrfs_print_balance(tcp, arg, true); |
| 557 | break; |
| 558 | |
| 559 | case BTRFS_IOC_DEFRAG_RANGE: {/* W */ |
| 560 | struct btrfs_ioctl_defrag_range_args args; |
| 561 | |
| 562 | tprints(", "); |
| 563 | |
| 564 | if (umove_or_printaddr(tcp, arg, &args)) |
| 565 | break; |
| 566 | |
| 567 | tprintf("{start=%" PRIu64 ", len=", (uint64_t)args.start); |
| 568 | |
| 569 | tprintf("%" PRIu64, args.len); |
| 570 | if (args.len == UINT64_MAX) |
| 571 | tprints(" /* UINT64_MAX */"); |
| 572 | |
| 573 | tprints(", flags="); |
| 574 | printflags64(btrfs_defrag_flags, args.flags, |
| 575 | "BTRFS_DEFRAG_RANGE_???"); |
| 576 | tprintf(", extent_thresh=%u, compress_type=", |
| 577 | args.extent_thresh); |
| 578 | printxvals(args.compress_type, "BTRFS_COMPRESS_???", |
| 579 | btrfs_compress_types, NULL); |
| 580 | tprints("}"); |
| 581 | break; |
| 582 | } |
| 583 | |
| 584 | case BTRFS_IOC_DEV_INFO: { /* RW */ |
| 585 | struct btrfs_ioctl_dev_info_args args; |
| 586 | char uuid[UUID_STRING_SIZE+1]; |
| 587 | int valid; |
| 588 | |
| 589 | if (entering(tcp)) |
| 590 | tprints(", "); |
| 591 | else if (syserror(tcp)) |
| 592 | break; |
| 593 | else |
| 594 | tprints(" => "); |
| 595 | if (umove_or_printaddr(tcp, arg, &args)) |
| 596 | break; |
| 597 | tprints("{"); |
| 598 | |
| 599 | valid = btrfs_unparse_uuid(args.uuid, uuid); |
| 600 | if (entering(tcp)) { |
| 601 | tprintf("devid=%" PRI__u64, args.devid); |
| 602 | if (valid) |
| 603 | tprintf(", uuid=%s", uuid); |
| 604 | tprints("}"); |
| 605 | return 0; |
| 606 | } |
| 607 | if (valid) |
| 608 | tprintf("uuid=%s, ", uuid); |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 609 | tprintf("bytes_used=%" PRI__u64 |
| 610 | ", total_bytes=%" PRI__u64 ", path=", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 611 | args.bytes_used, args.total_bytes); |
| 612 | print_quoted_string((const char *)args.path, sizeof(args.path), |
| 613 | QUOTE_0_TERMINATED); |
| 614 | tprints("}"); |
| 615 | break; |
| 616 | } |
| 617 | |
| 618 | case BTRFS_IOC_DEV_REPLACE: { /* RW */ |
| 619 | struct btrfs_ioctl_dev_replace_args args; |
| 620 | |
| 621 | if (entering(tcp)) |
| 622 | tprints(", "); |
| 623 | else if (syserror(tcp)) |
| 624 | break; |
| 625 | else |
| 626 | tprints(" => "); |
| 627 | |
| 628 | if (umove_or_printaddr(tcp, arg, &args)) |
| 629 | break; |
| 630 | |
| 631 | if (entering(tcp)) { |
| 632 | tprints("{cmd="); |
| 633 | printxvals(args.cmd, "BTRFS_IOCTL_DEV_REPLACE_CMD_???", |
| 634 | btrfs_dev_replace_cmds, NULL); |
| 635 | if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_START) { |
| 636 | const char *str; |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 637 | tprintf(", start={srcdevid=%" PRI__u64 |
| 638 | ", cont_reading_from_srcdev_mode=%" PRI__u64 |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 639 | ", srcdev_name=", |
| 640 | args.start.srcdevid, |
| 641 | args.start.cont_reading_from_srcdev_mode); |
| 642 | |
| 643 | str = (const char*) args.start.srcdev_name; |
| 644 | print_quoted_string(str, |
| 645 | sizeof(args.start.srcdev_name), |
| 646 | QUOTE_0_TERMINATED); |
| 647 | tprints(", tgtdev_name="); |
| 648 | str = (const char*) args.start.tgtdev_name; |
| 649 | print_quoted_string(str, |
| 650 | sizeof(args.start.tgtdev_name), |
| 651 | QUOTE_0_TERMINATED); |
| 652 | tprints("}"); |
| 653 | |
| 654 | } |
| 655 | tprints("}"); |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | tprints("{result="); |
| 660 | printxvals(args.result, "BTRFS_IOCTL_DEV_REPLACE_RESULT_???", |
| 661 | btrfs_dev_replace_results, NULL); |
| 662 | if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS) { |
| 663 | char buf[sizeof("HH:MM:SS") + 1]; |
| 664 | time_t time; |
| 665 | tprints(", "); |
| 666 | printxvals(args.status.replace_state, |
| 667 | "BTRFS_IOCTL_DEV_REPLACE_STATE_???", |
| 668 | btrfs_dev_replace_state, NULL); |
| 669 | tprintf(", progress_1000=%" PRI__u64 " /* ", |
| 670 | args.status.progress_1000); |
| 671 | if (args.status.progress_1000 <= 1000) |
| 672 | tprintf("%" PRI__u64 ".%.2" PRI__u64 "%%", |
| 673 | args.status.progress_1000 / 10, |
| 674 | args.status.progress_1000 % 10); |
| 675 | else |
| 676 | tprints("???"); |
| 677 | tprints(" */ ,"); |
| 678 | |
| 679 | time = args.status.time_started; |
| 680 | strftime(buf, sizeof(buf), "%T", |
| 681 | localtime(&time)); |
| 682 | tprintf("time_started=%" PRI__u64" /* %s */, ", |
| 683 | args.status.time_started, buf); |
| 684 | |
| 685 | time = args.status.time_stopped; |
| 686 | strftime(buf, sizeof(buf), "%T", |
| 687 | localtime(&time)); |
| 688 | tprintf("time_stopped=%" PRI__u64" /* %s */, ", |
| 689 | args.status.time_stopped, buf); |
| 690 | |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 691 | tprintf("num_write_errors=%" PRI__u64 |
| 692 | ", num_uncorrectable_read_errors=%" PRI__u64, |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 693 | args.status.num_write_errors, |
| 694 | args.status.num_uncorrectable_read_errors); |
| 695 | } |
| 696 | tprints("}"); |
| 697 | break; |
| 698 | } |
| 699 | |
| 700 | case BTRFS_IOC_GET_FEATURES: { /* R */ |
| 701 | struct btrfs_ioctl_feature_flags flags; |
| 702 | if (entering(tcp)) |
| 703 | return 0; |
| 704 | |
| 705 | tprints(", "); |
| 706 | if (umove_or_printaddr(tcp, arg, &flags)) |
| 707 | break; |
| 708 | |
| 709 | btrfs_print_features(&flags); |
| 710 | break; |
| 711 | } |
| 712 | case BTRFS_IOC_SET_FEATURES: { /* W */ |
| 713 | struct btrfs_ioctl_feature_flags flarg[2]; |
| 714 | |
| 715 | tprints(", "); |
| 716 | |
| 717 | if (umove_or_printaddr(tcp, arg, &flarg)) |
| 718 | break; |
| 719 | |
| 720 | tprints("["); |
| 721 | btrfs_print_features(&flarg[0]); |
| 722 | tprints(", "); |
| 723 | btrfs_print_features(&flarg[1]); |
| 724 | tprints("]"); |
| 725 | break; |
| 726 | } |
| 727 | |
| 728 | case BTRFS_IOC_GET_SUPPORTED_FEATURES: { /* R */ |
| 729 | struct btrfs_ioctl_feature_flags flarg[3]; |
| 730 | |
| 731 | if (entering(tcp)) |
| 732 | return 0; |
| 733 | |
| 734 | tprints(", "); |
| 735 | if (umove_or_printaddr(tcp, arg, &flarg)) |
| 736 | break; |
| 737 | |
| 738 | tprints("[ /* supported */ "); |
| 739 | btrfs_print_features(&flarg[0]); |
| 740 | |
| 741 | tprints(", /* safe to set */ "); |
| 742 | btrfs_print_features(&flarg[1]); |
| 743 | |
| 744 | tprints(", /* safe to clear */ "); |
| 745 | btrfs_print_features(&flarg[2]); |
| 746 | tprints("]"); |
| 747 | |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | case BTRFS_IOC_FS_INFO: { /* R */ |
| 752 | struct btrfs_ioctl_fs_info_args args; |
| 753 | char uuid[UUID_STRING_SIZE+1]; |
| 754 | uint32_t nodesize, sectorsize, clone_alignment; |
| 755 | #ifndef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE |
| 756 | __u32 *reserved32; |
| 757 | #endif |
| 758 | |
| 759 | if (entering(tcp)) |
| 760 | return 0; |
| 761 | |
| 762 | tprints(", "); |
| 763 | if (umove_or_printaddr(tcp, arg, &args)) |
| 764 | break; |
| 765 | |
| 766 | #ifdef HAVE_STRUCT_BTRFS_IOCTL_FS_INFO_ARGS_NODESIZE |
| 767 | nodesize = args.nodesize, |
| 768 | sectorsize = args.sectorsize, |
| 769 | clone_alignment = args.clone_alignment; |
| 770 | #else |
| 771 | reserved32 = (__u32 *)args.reserved; |
| 772 | nodesize = reserved32[0]; |
| 773 | sectorsize = reserved32[1]; |
| 774 | clone_alignment = reserved32[2]; |
| 775 | #endif |
| 776 | btrfs_unparse_uuid(args.fsid, uuid); |
| 777 | |
| 778 | tprints("{"); |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 779 | tprintf("max_id=%" PRI__u64 ", num_devices=%" PRI__u64 |
| 780 | ", fsid=%s, nodesize=%u, sectorsize=%u" |
| 781 | ", clone_alignment=%u", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 782 | args.max_id, args.num_devices, uuid, |
| 783 | nodesize, sectorsize, clone_alignment); |
| 784 | tprints("}"); |
| 785 | break; |
| 786 | } |
| 787 | |
| 788 | case BTRFS_IOC_GET_DEV_STATS: { /* RW */ |
| 789 | struct btrfs_ioctl_get_dev_stats args; |
| 790 | uint64_t i, max_nr_items; |
| 791 | |
| 792 | if (entering(tcp)) |
| 793 | tprints(", "); |
| 794 | else if (syserror(tcp)) |
| 795 | break; |
| 796 | else |
| 797 | tprints(" => "); |
| 798 | if (umove_or_printaddr(tcp, arg, &args)) |
| 799 | break; |
| 800 | |
| 801 | tprints("{"); |
| 802 | |
| 803 | if (entering(tcp)) |
| 804 | tprintf("devid=%" PRI__u64 ", ", args.devid); |
| 805 | |
| 806 | tprintf("nr_items=%" PRI__u64 ", flags=", args.nr_items); |
| 807 | printflags64(btrfs_dev_stats_flags, args.flags, |
| 808 | "BTRFS_DEV_STATS_???"); |
| 809 | |
| 810 | if (entering(tcp)) { |
| 811 | tprints("}"); |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * The structure has a 1k limit; Let's make sure we don't |
| 817 | * go off into the middle of nowhere with a bad nr_items |
| 818 | * value. |
| 819 | */ |
| 820 | max_nr_items = sizeof(args) - offsetof(typeof(args), values); |
| 821 | |
| 822 | tprints(", ["); |
| 823 | for (i = 0; i < args.nr_items; i++) { |
| 824 | const char *name = xlookup(btrfs_dev_stats_values, i); |
| 825 | if (i) |
| 826 | tprints(", "); |
| 827 | if (i > max_nr_items) { |
| 828 | tprints("/* overflow */"); |
| 829 | break; |
| 830 | } |
| 831 | if (name) |
| 832 | tprintf("/* %s */ ", name); |
| 833 | tprintf("%" PRI__u64, args.values[i]); |
| 834 | } |
| 835 | tprints("]}"); |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | case BTRFS_IOC_INO_LOOKUP: { /* RW */ |
| 840 | struct btrfs_ioctl_ino_lookup_args args; |
| 841 | |
| 842 | if (entering(tcp)) |
| 843 | tprints(", "); |
| 844 | else if (syserror(tcp)) |
| 845 | break; |
| 846 | else |
| 847 | tprints(" => "); |
| 848 | |
| 849 | if (umove_or_printaddr(tcp, arg, &args)) |
| 850 | break; |
| 851 | |
| 852 | if (entering(tcp)) { |
| 853 | /* Use subvolume id of the containing root */ |
| 854 | if (args.treeid == 0) |
| 855 | /* abuse of auxstr to retain state */ |
| 856 | tcp->auxstr = (void *)1; |
| 857 | else |
| 858 | tcp->auxstr = NULL; |
| 859 | |
| 860 | tprints("{treeid="); |
| 861 | btrfs_print_objectid(args.treeid); |
| 862 | tprints(", objectid="); |
| 863 | btrfs_print_objectid(args.objectid); |
| 864 | tprints("}"); |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | tprints("{"); |
| 869 | if (tcp->auxstr) { |
| 870 | tprints("treeid="); |
| 871 | btrfs_print_objectid(args.treeid); |
| 872 | tprints(", "); |
| 873 | } |
| 874 | tcp->auxstr = NULL; |
| 875 | |
| 876 | tprints("name="); |
| 877 | print_quoted_string(args.name, sizeof(args.name), |
| 878 | QUOTE_0_TERMINATED); |
| 879 | tprints("}"); |
| 880 | break; |
| 881 | } |
| 882 | |
| 883 | case BTRFS_IOC_INO_PATHS: { /* RW */ |
| 884 | struct btrfs_ioctl_ino_path_args args; |
| 885 | |
| 886 | if (entering(tcp)) |
| 887 | tprints(", "); |
| 888 | else if (syserror(tcp)) |
| 889 | break; |
| 890 | else |
| 891 | tprints(" => "); |
| 892 | |
| 893 | if (umove_or_printaddr(tcp, arg, &args)) |
| 894 | break; |
| 895 | |
| 896 | tprints("{"); |
| 897 | |
| 898 | if (entering(tcp)) { |
| 899 | tprintf("inum=%" PRI__u64 ", size=%" PRI__u64, |
| 900 | args.inum, args.size); |
| 901 | tprintf(", fspath=0x%" PRI__x64 "}", args.fspath); |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | tprints("fspath="); |
| 906 | btrfs_print_ino_path_container(tcp, args.fspath); |
| 907 | |
| 908 | tprints("}"); |
| 909 | break; |
| 910 | } |
| 911 | |
| 912 | case BTRFS_IOC_LOGICAL_INO: { /* RW */ |
| 913 | struct btrfs_ioctl_logical_ino_args args; |
| 914 | |
| 915 | if (entering(tcp)) |
| 916 | tprints(", "); |
| 917 | else if (syserror(tcp)) |
| 918 | break; |
| 919 | else |
| 920 | tprints(" => "); |
| 921 | |
| 922 | if (umove_or_printaddr(tcp, arg, &args)) |
| 923 | break; |
| 924 | |
| 925 | tprints("{"); |
| 926 | |
| 927 | if (entering(tcp)) { |
| 928 | tprintf("logical=%" PRI__u64 ", size=%" PRI__u64, |
| 929 | args.logical, args.size); |
| 930 | tprintf(", inodes=0x%" PRI__x64 "}", args.inodes); |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | tprints("inodes="); |
| 935 | btrfs_print_logical_ino_container(tcp, args.inodes); |
| 936 | |
| 937 | tprints("}"); |
| 938 | break; |
| 939 | } |
| 940 | |
| 941 | case BTRFS_IOC_QGROUP_ASSIGN: { /* W */ |
| 942 | struct btrfs_ioctl_qgroup_assign_args args; |
| 943 | |
| 944 | tprints(", "); |
| 945 | if (umove_or_printaddr(tcp, arg, &args)) |
| 946 | break; |
| 947 | |
| 948 | tprintf("{assign=%" PRI__u64 ", src=%" PRI__u64 |
| 949 | ", dst=%" PRI__u64 "}", |
| 950 | args.assign, args.src, args.dst); |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | case BTRFS_IOC_QGROUP_CREATE: { /* W */ |
| 955 | struct btrfs_ioctl_qgroup_create_args args; |
| 956 | |
| 957 | tprints(", "); |
| 958 | if (umove_or_printaddr(tcp, arg, &args)) |
| 959 | break; |
| 960 | |
| 961 | tprintf("{create=%" PRI__u64 ", qgroupid=%" PRI__u64 "}", |
| 962 | args.create, args.qgroupid); |
| 963 | break; |
| 964 | } |
| 965 | |
| 966 | case BTRFS_IOC_QGROUP_LIMIT: { /* R */ |
| 967 | struct btrfs_ioctl_qgroup_limit_args args; |
| 968 | |
| 969 | if (entering(tcp)) |
| 970 | return 0; |
| 971 | |
| 972 | tprints(", "); |
| 973 | if (umove_or_printaddr(tcp, arg, &args)) |
| 974 | break; |
| 975 | |
| 976 | tprintf("{qgroupid=%" PRI__u64 ", lim=", args.qgroupid); |
| 977 | btrfs_print_qgroup_limit(&args.lim); |
| 978 | tprints("}"); |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | case BTRFS_IOC_QUOTA_CTL: { /* W */ |
| 983 | struct btrfs_ioctl_quota_ctl_args args; |
| 984 | |
| 985 | tprints(", "); |
| 986 | if (umove_or_printaddr(tcp, arg, &args)) |
| 987 | break; |
| 988 | |
| 989 | printxvals(args.cmd, "BTRFS_QUOTA_CTL_???", |
| 990 | btrfs_qgroup_ctl_cmds, NULL); |
| 991 | tprints("}"); |
| 992 | |
| 993 | break; |
| 994 | } |
| 995 | case BTRFS_IOC_QUOTA_RESCAN: { /* W */ |
| 996 | struct btrfs_ioctl_quota_rescan_args args; |
| 997 | |
| 998 | tprints(", "); |
| 999 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1000 | break; |
| 1001 | |
| 1002 | tprintf("{flags=%" PRI__u64 "}", args.flags); |
| 1003 | break; |
| 1004 | } |
| 1005 | case BTRFS_IOC_QUOTA_RESCAN_STATUS: { /* R */ |
| 1006 | struct btrfs_ioctl_quota_rescan_args args; |
| 1007 | |
| 1008 | if (entering(tcp)) |
| 1009 | return 0; |
| 1010 | |
| 1011 | tprints(", "); |
| 1012 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1013 | break; |
| 1014 | |
| 1015 | tprintf("{flags=%" PRI__u64 ", progress=", args.flags); |
| 1016 | btrfs_print_objectid(args.progress); |
| 1017 | tprints("}"); |
| 1018 | break; |
| 1019 | } |
| 1020 | case BTRFS_IOC_SET_RECEIVED_SUBVOL: { /* RW */ |
| 1021 | #ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32 |
| 1022 | case BTRFS_IOC_SET_RECEIVED_SUBVOL_32: { /* RW */ |
| 1023 | struct btrfs_ioctl_received_subvol_args_32 args32; |
| 1024 | #endif |
| 1025 | struct btrfs_ioctl_received_subvol_args args; |
| 1026 | char uuid[UUID_STRING_SIZE+1]; |
| 1027 | |
| 1028 | if (entering(tcp)) |
| 1029 | tprints(", "); |
| 1030 | else if (syserror(tcp)) |
| 1031 | break; |
| 1032 | else |
| 1033 | tprints(" => "); |
| 1034 | |
| 1035 | #ifdef BTRFS_IOC_SET_RECEIVED_SUBVOL_32 |
| 1036 | /* |
| 1037 | * This is a compat ioctl for 32 bit tools on |
| 1038 | * 64 bit systems. |
| 1039 | */ |
| 1040 | if (code == BTRFS_IOC_SET_RECEIVED_SUBVOL_32) { |
| 1041 | if (umove_or_printaddr(tcp, arg, &args32)) |
| 1042 | break; |
| 1043 | memcpy(args.uuid, args32.uuid, sizeof(uuid)); |
| 1044 | args.stransid = args32.stransid; |
| 1045 | args.rtransid = args32.rtransid; |
| 1046 | args.stime.sec = args32.stime.sec; |
| 1047 | args.stime.nsec = args32.stime.nsec; |
| 1048 | args.rtime.sec = args32.rtime.sec; |
| 1049 | args.rtime.nsec = args32.rtime.nsec; |
| 1050 | args.flags = args32.flags; |
| 1051 | } else |
| 1052 | #endif |
| 1053 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1054 | break; |
| 1055 | |
| 1056 | if (entering(tcp)) { |
| 1057 | btrfs_unparse_uuid((unsigned char *)args.uuid, uuid); |
| 1058 | tprintf("{uuid=%s, stransid=%" PRI__u64 |
| 1059 | ", stime=%" PRI__u64 ".%u, flags=%" PRI__u64 |
| 1060 | "}", uuid, args.stransid, args.stime.sec, |
| 1061 | args.stime.nsec, args.flags); |
| 1062 | return 0; |
| 1063 | } |
| 1064 | tprintf("{rtransid=%" PRI__u64 ", rtime=%" PRI__u64 ".%u}", |
| 1065 | args.rtransid, args.rtime.sec, args.rtime.nsec); |
| 1066 | break; |
| 1067 | } |
| 1068 | case BTRFS_IOC_SCRUB: /* RW */ |
| 1069 | case BTRFS_IOC_SCRUB_PROGRESS: { /* RW */ |
| 1070 | struct btrfs_ioctl_scrub_args args; |
| 1071 | |
| 1072 | if (entering(tcp)) |
| 1073 | tprints(", "); |
| 1074 | else if (syserror(tcp)) |
| 1075 | break; |
| 1076 | else |
| 1077 | tprints(" => "); |
| 1078 | |
| 1079 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1080 | break; |
| 1081 | |
| 1082 | if (entering(tcp)) { |
| 1083 | tprintf("{devid=%" PRI__u64, args.devid); |
| 1084 | if (code == BTRFS_IOC_SCRUB) { |
| 1085 | tprintf(", start=%" PRI__u64 ", end=", |
| 1086 | args.start); |
| 1087 | tprintf("%" PRI__u64, args.end); |
| 1088 | if (args.end == UINT64_MAX) |
| 1089 | tprints(" /* UINT64_MAX */"); |
| 1090 | tprints(", flags="); |
| 1091 | printflags64(btrfs_scrub_flags, args.flags, |
| 1092 | "BTRFS_SCRUB_???"); |
| 1093 | } |
| 1094 | tprints("}"); |
| 1095 | return 0; |
| 1096 | } |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 1097 | tprintf("{data_extents_scrubbed=%" PRI__u64 |
| 1098 | ", tree_extents_scrubbed=%" PRI__u64 |
| 1099 | ", data_bytes_scrubbed=%" PRI__u64 |
| 1100 | ", tree_bytes_scrubbed=%" PRI__u64 |
| 1101 | ", read_errors=%" PRI__u64 |
| 1102 | ", csum_errors=%" PRI__u64 |
| 1103 | ", verify_errors=%" PRI__u64 |
| 1104 | ", no_csum=%" PRI__u64 |
| 1105 | ", csum_discards=%" PRI__u64 |
| 1106 | ", super_errors=%" PRI__u64 |
| 1107 | ", malloc_errors=%" PRI__u64 |
| 1108 | ", uncorrectable_errors=%" PRI__u64 |
| 1109 | ", corrected_errors=%" PRI__u64 |
| 1110 | ", last_physical=%" PRI__u64 |
| 1111 | ", unverified_errors=%" PRI__u64 "}", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1112 | args.progress.data_extents_scrubbed, |
| 1113 | args.progress.tree_extents_scrubbed, |
| 1114 | args.progress.data_bytes_scrubbed, |
| 1115 | args.progress.tree_bytes_scrubbed, |
| 1116 | args.progress.read_errors, |
| 1117 | args.progress.csum_errors, |
| 1118 | args.progress.verify_errors, |
| 1119 | args.progress.no_csum, |
| 1120 | args.progress.csum_discards, |
| 1121 | args.progress.super_errors, |
| 1122 | args.progress.malloc_errors, |
| 1123 | args.progress.uncorrectable_errors, |
| 1124 | args.progress.corrected_errors, |
| 1125 | args.progress.last_physical, |
| 1126 | args.progress.unverified_errors); |
| 1127 | break; |
| 1128 | } |
| 1129 | |
| 1130 | case BTRFS_IOC_TREE_SEARCH: { /* RW */ |
| 1131 | struct btrfs_ioctl_search_args args; |
| 1132 | uint64_t buf_offset; |
| 1133 | |
| 1134 | if (entering(tcp)) |
| 1135 | tprints(", "); |
| 1136 | else if (syserror(tcp)) |
| 1137 | break; |
| 1138 | else |
| 1139 | tprints(" => "); |
| 1140 | |
| 1141 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1142 | break; |
| 1143 | |
| 1144 | buf_offset = offsetof(struct btrfs_ioctl_search_args, buf); |
| 1145 | btrfs_print_tree_search(tcp, &args.key, arg + buf_offset, |
| 1146 | sizeof(args.buf), false); |
| 1147 | if (entering(tcp)) |
| 1148 | return 0; |
| 1149 | break; |
| 1150 | } |
| 1151 | |
| 1152 | case BTRFS_IOC_TREE_SEARCH_V2: { /* RW */ |
| 1153 | struct btrfs_ioctl_search_args_v2 args; |
| 1154 | uint64_t buf_offset; |
| 1155 | |
| 1156 | if (entering(tcp)) |
| 1157 | tprints(", "); |
| 1158 | else if (syserror(tcp)) { |
| 1159 | if (tcp->u_error == EOVERFLOW) { |
| 1160 | tcp->u_error = 0; |
| 1161 | if (!umove_or_printaddr(tcp, arg, &args)) |
| 1162 | tprintf(" => {buf_size=%" PRIu64 "}", |
| 1163 | (uint64_t)args.buf_size); |
| 1164 | tcp->u_error = EOVERFLOW; |
| 1165 | } |
| 1166 | break; |
| 1167 | } else |
| 1168 | tprints(" => "); |
| 1169 | |
| 1170 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1171 | break; |
| 1172 | |
| 1173 | buf_offset = offsetof(struct btrfs_ioctl_search_args_v2, buf); |
| 1174 | btrfs_print_tree_search(tcp, &args.key, arg + buf_offset, |
| 1175 | args.buf_size, true); |
| 1176 | if (entering(tcp)) |
| 1177 | return 0; |
| 1178 | break; |
| 1179 | } |
| 1180 | |
| 1181 | case BTRFS_IOC_SEND: { /* W */ |
| 1182 | struct btrfs_ioctl_send_args args; |
| 1183 | uint64_t base_addr; |
| 1184 | uint64_t i; |
| 1185 | |
| 1186 | tprints(", "); |
| 1187 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1188 | break; |
| 1189 | |
| 1190 | tprintf("{send_fd=%" PRI__d64 ", clone_sources_count=%" PRI__u64 |
| 1191 | ", clone_sources=", args.send_fd, |
| 1192 | args.clone_sources_count); |
| 1193 | |
| 1194 | if (abbrev(tcp)) { |
| 1195 | tprints("..."); |
| 1196 | } else { |
| 1197 | tprints("["); |
| 1198 | base_addr = (unsigned long)args.clone_sources; |
| 1199 | for (i = 0; i < args.clone_sources_count; i++) { |
| 1200 | uint64_t offset = sizeof(uint64_t) * i; |
| 1201 | uint64_t record; |
| 1202 | if (i) |
| 1203 | tprints(", "); |
| 1204 | if (i > max_strlen || |
| 1205 | umoven(tcp, base_addr + offset, |
| 1206 | sizeof(record), &record)) { |
| 1207 | tprints("..."); |
| 1208 | break; |
| 1209 | } |
| 1210 | btrfs_print_objectid(record); |
| 1211 | } |
| 1212 | tprints("]"); |
| 1213 | } |
| 1214 | tprints(", parent_root="); |
| 1215 | btrfs_print_objectid(args.parent_root); |
| 1216 | tprints(", flags="); |
| 1217 | printflags64(btrfs_send_flags, args.flags, |
| 1218 | "BTRFS_SEND_FLAGS_???"); |
| 1219 | tprints("}"); |
| 1220 | break; |
| 1221 | } |
| 1222 | |
| 1223 | case BTRFS_IOC_SPACE_INFO: { /* RW */ |
| 1224 | struct btrfs_ioctl_space_args args; |
| 1225 | uint64_t i; |
| 1226 | |
| 1227 | if (entering(tcp)) |
| 1228 | tprints(", "); |
| 1229 | else if (syserror(tcp)) |
| 1230 | break; |
| 1231 | else |
| 1232 | tprints(" => "); |
| 1233 | |
| 1234 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1235 | break; |
| 1236 | |
| 1237 | tprints("{"); |
| 1238 | if (entering(tcp)) { |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame^] | 1239 | tprintf("space_slots=%" PRI__u64 "}", args.space_slots); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | tprintf("total_spaces=%" PRI__u64, args.total_spaces); |
| 1244 | |
| 1245 | if (args.space_slots == 0 && args.total_spaces) { |
| 1246 | tprints("}"); |
| 1247 | break; |
| 1248 | } |
| 1249 | |
| 1250 | tprints(", spaces="); |
| 1251 | |
| 1252 | if (abbrev(tcp)) { |
| 1253 | tprints("...}"); |
| 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | tprints("["); |
| 1258 | |
| 1259 | for (i = 0; i < args.total_spaces; i++) { |
| 1260 | struct btrfs_ioctl_space_info info; |
| 1261 | uint64_t off = offsetof(typeof(args), spaces[i]); |
| 1262 | if (i) |
| 1263 | tprints(", "); |
| 1264 | |
| 1265 | if (i > max_strlen || |
| 1266 | umoven(tcp, arg + off, sizeof(info), &info)) { |
| 1267 | tprints("..."); |
| 1268 | break; |
| 1269 | } |
| 1270 | |
| 1271 | tprints("{flags="); |
| 1272 | printflags64(btrfs_space_info_flags, info.flags, |
| 1273 | "BTRFS_SPACE_INFO_???"); |
| 1274 | tprintf(", total_bytes=%" PRI__u64 |
| 1275 | ", used_bytes=%" PRI__u64 "}", |
| 1276 | info.total_bytes, info.used_bytes); |
| 1277 | } |
| 1278 | tprints("]}"); |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | case BTRFS_IOC_SNAP_CREATE: |
| 1283 | case BTRFS_IOC_RESIZE: |
| 1284 | case BTRFS_IOC_SCAN_DEV: |
| 1285 | case BTRFS_IOC_ADD_DEV: |
| 1286 | case BTRFS_IOC_RM_DEV: |
| 1287 | case BTRFS_IOC_SUBVOL_CREATE: |
| 1288 | case BTRFS_IOC_SNAP_DESTROY: |
| 1289 | case BTRFS_IOC_DEVICES_READY: { /* W */ |
| 1290 | struct btrfs_ioctl_vol_args args; |
| 1291 | |
| 1292 | tprints(", "); |
| 1293 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1294 | break; |
| 1295 | |
| 1296 | tprintf("{fd=%" PRI__d64 ", name=", args.fd); |
| 1297 | print_quoted_string(args.name, sizeof(args.name), |
| 1298 | QUOTE_0_TERMINATED); |
| 1299 | tprints("}"); |
| 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | case BTRFS_IOC_SNAP_CREATE_V2: |
| 1304 | case BTRFS_IOC_SUBVOL_CREATE_V2: { /* code is W, but is actually RW */ |
| 1305 | struct btrfs_ioctl_vol_args_v2 args; |
| 1306 | |
| 1307 | if (entering(tcp)) |
| 1308 | tprints(", "); |
| 1309 | else if (syserror(tcp)) |
| 1310 | break; |
| 1311 | else |
| 1312 | tprints(" => "); |
| 1313 | |
| 1314 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1315 | break; |
| 1316 | |
| 1317 | if (entering(tcp)) { |
| 1318 | tprintf("{fd=%" PRI__d64 ", flags=", args.fd); |
| 1319 | printflags64(btrfs_snap_flags_v2, args.flags, |
| 1320 | "BTRFS_SUBVOL_???"); |
| 1321 | if (args.flags & BTRFS_SUBVOL_QGROUP_INHERIT) { |
| 1322 | tprintf(", size=%" PRI__u64 ", qgroup_inherit=", |
| 1323 | args.size); |
| 1324 | |
| 1325 | btrfs_print_qgroup_inherit(tcp, |
| 1326 | (unsigned long)args.qgroup_inherit); |
| 1327 | |
| 1328 | } |
| 1329 | tprintf(", name="); |
| 1330 | print_quoted_string(args.name, |
| 1331 | BTRFS_SUBVOL_NAME_MAX + 1, |
| 1332 | QUOTE_0_TERMINATED); |
| 1333 | tprints("}"); |
| 1334 | return 0; |
| 1335 | } |
| 1336 | tprintf("{transid=%" PRI__u64 "}", args.transid); |
| 1337 | break; |
| 1338 | } |
| 1339 | case BTRFS_IOC_GET_FSLABEL: /* R */ |
| 1340 | case BTRFS_IOC_SET_FSLABEL: {/* W */ |
| 1341 | char label[BTRFS_LABEL_SIZE]; |
| 1342 | if (code == BTRFS_IOC_GET_FSLABEL && entering(tcp)) |
| 1343 | return 0; |
| 1344 | |
| 1345 | tprints(", "); |
| 1346 | if (umoven_or_printaddr(tcp, arg, sizeof(label), label)) |
| 1347 | break; |
| 1348 | print_quoted_string(label, sizeof(label), QUOTE_0_TERMINATED); |
| 1349 | break; |
| 1350 | } |
| 1351 | |
| 1352 | case BTRFS_IOC_CLONE: /* FICLONE */ |
| 1353 | case BTRFS_IOC_CLONE_RANGE: /* FICLONERANGE */ |
| 1354 | case BTRFS_IOC_FILE_EXTENT_SAME: /* FIDEDUPERANGE */ |
| 1355 | /* |
| 1356 | * FICLONE, FICLONERANGE, and FIDEDUPERANGE started out as |
| 1357 | * btrfs ioctls and the code was kept for the generic |
| 1358 | * implementations. We use the BTRFS_* names here because |
| 1359 | * they will be available on older systems. |
| 1360 | */ |
| 1361 | return file_ioctl(tcp, code, arg); |
| 1362 | |
| 1363 | default: |
| 1364 | return RVAL_DECODED; |
| 1365 | }; |
| 1366 | return ret | RVAL_DECODED | 1; |
| 1367 | } |
| 1368 | #endif /* HAVE_LINUX_BTRFS_H */ |