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" |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 29 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 30 | #ifdef HAVE_LINUX_BTRFS_H |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 31 | |
| 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. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 35 | #include DEF_MPERS_TYPE(struct_btrfs_ioctl_vol_args_v2) |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 36 | |
| 37 | # include <linux/btrfs.h> |
| 38 | |
| 39 | typedef struct btrfs_ioctl_dev_replace_args |
| 40 | struct_btrfs_ioctl_dev_replace_args; |
| 41 | typedef struct btrfs_ioctl_send_args |
| 42 | struct_btrfs_ioctl_send_args; |
| 43 | typedef struct btrfs_ioctl_received_subvol_args |
| 44 | struct_btrfs_ioctl_received_subvol_args; |
Dmitry V. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 45 | typedef struct btrfs_ioctl_vol_args_v2 |
| 46 | struct_btrfs_ioctl_vol_args_v2; |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 47 | |
| 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 56 | /* |
| 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 | */ |
| 60 | typedef __u64 u64; |
| 61 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 62 | #ifndef HAVE_STRUCT_BTRFS_IOCTL_FEATURE_FLAGS_COMPAT_FLAGS |
| 63 | struct 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 |
| 71 | struct 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 81 | #ifndef BTRFS_LABEL_SIZE |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 82 | # define BTRFS_LABEL_SIZE 256 |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | #ifndef BTRFS_FIRST_FREE_OBJECTID |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 86 | # define BTRFS_FIRST_FREE_OBJECTID 256ULL |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 87 | #endif |
| 88 | |
Dmitry V. Levin | fe7a451 | 2016-06-17 03:02:46 +0300 | [diff] [blame] | 89 | #ifndef BTRFS_IOC_QUOTA_RESCAN |
| 90 | struct 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 103 | #ifndef BTRFS_IOC_GET_FEATURES |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 104 | # 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 110 | #endif |
| 111 | |
| 112 | #ifndef BTRFS_IOC_TREE_SEARCH_V2 |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 113 | # define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \ |
| 114 | struct btrfs_ioctl_search_args_v2) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 115 | struct 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 | |
| 149 | static inline char |
| 150 | prnibble(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 */ |
| 161 | static int |
| 162 | btrfs_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 | |
| 178 | static void |
| 179 | print_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 | |
| 188 | static void |
Dmitry V. Levin | b85d09f | 2016-05-24 00:56:08 +0000 | [diff] [blame] | 189 | btrfs_print_balance_args(const char *name, const struct btrfs_balance_args *bba) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 190 | { |
| 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 | |
| 206 | static void |
| 207 | btrfs_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 | |
| 232 | static void |
Dmitry V. Levin | b85d09f | 2016-05-24 00:56:08 +0000 | [diff] [blame] | 233 | btrfs_print_features(const struct btrfs_ioctl_feature_flags *flags) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 234 | { |
| 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 | |
| 249 | static void |
Dmitry V. Levin | b85d09f | 2016-05-24 00:56:08 +0000 | [diff] [blame] | 250 | btrfs_print_qgroup_limit(const struct btrfs_qgroup_limit *lim) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 251 | { |
| 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 | |
| 261 | static void |
| 262 | btrfs_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 | |
| 270 | static void |
| 271 | btrfs_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 | |
| 279 | static void |
Dmitry V. Levin | b85d09f | 2016-05-24 00:56:08 +0000 | [diff] [blame] | 280 | btrfs_print_data_container_header(const struct btrfs_data_container *container) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 281 | { |
Dmitry V. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 282 | tprintf("{bytes_left=%u, bytes_missing=%u" |
| 283 | ", elem_cnt=%u, elem_missed=%u, val=", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 284 | container->bytes_left, container->bytes_missing, |
| 285 | container->elem_cnt, container->elem_missed); |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | btrfs_print_data_container_footer(void) |
| 290 | { |
| 291 | tprints("}"); |
| 292 | } |
| 293 | |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 294 | static bool |
| 295 | print_btrfs_data_container_logical_ino(struct tcb *tcp, void *elem_buf, |
| 296 | size_t elem_size, void *data) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 297 | { |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 298 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static void |
Dmitry V. Levin | b85d09f | 2016-05-24 00:56:08 +0000 | [diff] [blame] | 307 | btrfs_print_logical_ino_container(struct tcb *tcp, |
| 308 | const uint64_t inodes_addr) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 309 | { |
| 310 | struct btrfs_data_container container; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 311 | |
Dmitry V. Levin | 90ffbc7 | 2016-05-24 00:49:50 +0000 | [diff] [blame] | 312 | if (umove_or_printaddr(tcp, inodes_addr, &container)) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 313 | return; |
| 314 | |
| 315 | btrfs_print_data_container_header(&container); |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 316 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 317 | if (abbrev(tcp)) { |
| 318 | tprints("..."); |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 319 | } else { |
| 320 | const uint64_t val_addr = |
| 321 | inodes_addr + offsetof(typeof(container), val); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 322 | uint64_t record[3]; |
Jeff Mahoney | 2060d97 | 2016-05-26 23:33:03 -0400 | [diff] [blame] | 323 | print_array(tcp, val_addr, container.elem_cnt / 3, |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 324 | record, sizeof(record), |
| 325 | umoven_or_printaddr, |
| 326 | print_btrfs_data_container_logical_ino, 0); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 327 | } |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 328 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 329 | btrfs_print_data_container_footer(); |
| 330 | } |
| 331 | |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 332 | static bool |
| 333 | print_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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 344 | static void |
Dmitry V. Levin | b85d09f | 2016-05-24 00:56:08 +0000 | [diff] [blame] | 345 | btrfs_print_ino_path_container(struct tcb *tcp, |
| 346 | const uint64_t fspath_addr) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 347 | { |
| 348 | struct btrfs_data_container container; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 349 | |
Dmitry V. Levin | 90ffbc7 | 2016-05-24 00:49:50 +0000 | [diff] [blame] | 350 | if (umove_or_printaddr(tcp, fspath_addr, &container)) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 351 | return; |
| 352 | |
| 353 | btrfs_print_data_container_header(&container); |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 354 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 355 | if (abbrev(tcp)) { |
| 356 | tprints("..."); |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 357 | } 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 367 | btrfs_print_data_container_footer(); |
| 368 | } |
| 369 | |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 370 | static bool |
| 371 | print_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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 378 | static void |
Dmitry V. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 379 | btrfs_print_qgroup_inherit(struct tcb *tcp, const unsigned long qgi_addr) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 380 | { |
| 381 | struct btrfs_qgroup_inherit inherit; |
| 382 | |
Dmitry V. Levin | 90ffbc7 | 2016-05-24 00:49:50 +0000 | [diff] [blame] | 383 | if (umove_or_printaddr(tcp, qgi_addr, &inherit)) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 384 | 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. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 401 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 405 | } |
| 406 | tprints("}"); |
| 407 | } |
| 408 | |
| 409 | static void |
| 410 | print_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 | |
| 421 | static void |
| 422 | btrfs_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. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 454 | } 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 Mahoney | d32d95a | 2016-05-26 23:33:04 -0400 | [diff] [blame] | 462 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 482 | |
Jeff Mahoney | d32d95a | 2016-05-26 23:33:04 -0400 | [diff] [blame] | 483 | } |
| 484 | tprints("]"); |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 485 | } |
| 486 | tprints("}"); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | static bool |
| 491 | print_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 | |
| 499 | static bool |
| 500 | print_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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 514 | MPERS_PRINTER_DECL(int, btrfs_ioctl, |
| 515 | struct tcb *tcp, const unsigned int code, const long arg) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 516 | { |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 517 | switch (code) { |
Dmitry V. Levin | 3ce2dfc | 2016-05-24 00:45:05 +0000 | [diff] [blame] | 518 | /* Take no arguments; command only. */ |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 519 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 532 | /* takes a signed int */ |
| 533 | case BTRFS_IOC_BALANCE_CTL: |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 534 | tprints(", "); |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 535 | printxval(btrfs_balance_ctl_cmds, arg, "BTRFS_BALANCE_CTL_???"); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 536 | break; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 537 | |
| 538 | /* returns a 64 */ |
| 539 | case BTRFS_IOC_START_SYNC: /* R */ |
| 540 | if (entering(tcp)) |
| 541 | return 0; |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 542 | /* fall through */ |
| 543 | /* takes a u64 */ |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 544 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 550 | /* u64 but describe a flags bitfield; we can make that symbolic */ |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 551 | case BTRFS_IOC_SUBVOL_GETFLAGS: { /* R */ |
| 552 | uint64_t flags; |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 553 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 554 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 565 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 566 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 600 | case BTRFS_IOC_DEFRAG_RANGE: { /* W */ |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 601 | 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. Levin | d4bdff6 | 2016-06-17 00:44:44 +0000 | [diff] [blame] | 610 | tprintf("%" PRIu64, (uint64_t) args.len); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 611 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 619 | printxval(btrfs_compress_types, args.compress_type, |
| 620 | "BTRFS_COMPRESS_???"); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 621 | 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. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 650 | tprintf("bytes_used=%" PRI__u64 |
| 651 | ", total_bytes=%" PRI__u64 ", path=", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 652 | 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. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 660 | struct_btrfs_ioctl_dev_replace_args args; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 661 | |
| 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 674 | printxval64(btrfs_dev_replace_cmds, args.cmd, |
| 675 | "BTRFS_IOCTL_DEV_REPLACE_CMD_???"); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 676 | if (args.cmd == BTRFS_IOCTL_DEV_REPLACE_CMD_START) { |
| 677 | const char *str; |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 678 | tprintf(", start={srcdevid=%" PRIu64 |
| 679 | ", cont_reading_from_srcdev_mode=%" PRIu64 |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 680 | ", srcdev_name=", |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 681 | (uint64_t) args.start.srcdevid, |
| 682 | (uint64_t) args.start.cont_reading_from_srcdev_mode); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 683 | |
| 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 701 | printxval64(btrfs_dev_replace_results, args.result, |
| 702 | "BTRFS_IOCTL_DEV_REPLACE_RESULT_???"); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 703 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 707 | printxval64(btrfs_dev_replace_state, |
| 708 | args.status.replace_state, |
| 709 | "BTRFS_IOCTL_DEV_REPLACE_STATE_???"); |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 710 | tprintf(", progress_1000=%" PRIu64 " /* ", |
| 711 | (uint64_t) args.status.progress_1000); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 712 | if (args.status.progress_1000 <= 1000) |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 713 | tprintf("%" PRIu64 ".%.2" PRIu64 "%%", |
| 714 | (uint64_t) args.status.progress_1000 / 10, |
| 715 | (uint64_t) args.status.progress_1000 % 10); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 716 | else |
| 717 | tprints("???"); |
| 718 | tprints(" */ ,"); |
| 719 | |
| 720 | time = args.status.time_started; |
| 721 | strftime(buf, sizeof(buf), "%T", |
| 722 | localtime(&time)); |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 723 | tprintf("time_started=%" PRIu64" /* %s */, ", |
| 724 | (uint64_t) args.status.time_started, buf); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 725 | |
| 726 | time = args.status.time_stopped; |
| 727 | strftime(buf, sizeof(buf), "%T", |
| 728 | localtime(&time)); |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 729 | tprintf("time_stopped=%" PRIu64" /* %s */, ", |
| 730 | (uint64_t) args.status.time_stopped, buf); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 731 | |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 732 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 736 | } |
| 737 | tprints("}"); |
| 738 | break; |
| 739 | } |
| 740 | |
| 741 | case BTRFS_IOC_GET_FEATURES: { /* R */ |
| 742 | struct btrfs_ioctl_feature_flags flags; |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 743 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 744 | 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 754 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 755 | 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. Levin | de5b009 | 2016-07-26 15:59:28 +0000 | [diff] [blame] | 814 | reserved32 = (__u32 *) (void *) args.reserved; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 815 | 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. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 822 | tprintf("max_id=%" PRI__u64 ", num_devices=%" PRI__u64 |
| 823 | ", fsid=%s, nodesize=%u, sectorsize=%u" |
| 824 | ", clone_alignment=%u", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 825 | 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. Levin | 92b9062 | 2016-05-24 01:04:56 +0000 | [diff] [blame] | 833 | uint64_t i; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 834 | |
| 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 863 | tprints(", ["); |
| 864 | for (i = 0; i < args.nr_items; i++) { |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 865 | if (i) |
| 866 | tprints(", "); |
Dmitry V. Levin | 92b9062 | 2016-05-24 01:04:56 +0000 | [diff] [blame] | 867 | if (i >= ARRAY_SIZE(args.values)) { |
| 868 | tprints("..."); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 869 | break; |
| 870 | } |
Dmitry V. Levin | 92b9062 | 2016-05-24 01:04:56 +0000 | [diff] [blame] | 871 | const char *name = xlookup(btrfs_dev_stats_values, i); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 872 | 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. Levin | b759d27 | 2016-07-15 16:08:19 +0000 | [diff] [blame] | 896 | set_tcb_priv_ulong(tcp, 1); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 897 | |
| 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. Levin | b759d27 | 2016-07-15 16:08:19 +0000 | [diff] [blame] | 907 | if (get_tcb_priv_ulong(tcp)) { |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 908 | tprints("treeid="); |
| 909 | btrfs_print_objectid(args.treeid); |
| 910 | tprints(", "); |
| 911 | } |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 912 | |
| 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. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 1026 | printxval64(btrfs_qgroup_ctl_cmds, args.cmd, |
| 1027 | "BTRFS_QUOTA_CTL_???"); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1028 | tprints("}"); |
| 1029 | |
| 1030 | break; |
| 1031 | } |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 1032 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1033 | 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. Levin | fe7a451 | 2016-06-17 03:02:46 +0300 | [diff] [blame] | 1040 | tprintf("{flags=%" PRIu64 "}", (uint64_t) args.flags); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1041 | break; |
| 1042 | } |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 1043 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1044 | 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. Levin | fe7a451 | 2016-06-17 03:02:46 +0300 | [diff] [blame] | 1054 | tprintf("{flags=%" PRIu64 ", progress=", (uint64_t) args.flags); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1055 | btrfs_print_objectid(args.progress); |
| 1056 | tprints("}"); |
| 1057 | break; |
| 1058 | } |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 1059 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1060 | case BTRFS_IOC_SET_RECEIVED_SUBVOL: { /* RW */ |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 1061 | struct_btrfs_ioctl_received_subvol_args args; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1062 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1071 | 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. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 1076 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1081 | return 0; |
| 1082 | } |
Dmitry V. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 1083 | tprintf("{rtransid=%" PRIu64 ", rtime=%" PRIu64 ".%u}", |
| 1084 | (uint64_t) args.rtransid, (uint64_t) args.rtime.sec, |
| 1085 | args.rtime.nsec); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1086 | break; |
| 1087 | } |
Dmitry V. Levin | 95577cf | 2016-05-24 00:35:49 +0000 | [diff] [blame] | 1088 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1089 | 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. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 1118 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1133 | 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. Levin | d67b217 | 2016-05-24 01:10:53 +0000 | [diff] [blame] | 1181 | tprints(" => "); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1182 | tcp->u_error = 0; |
| 1183 | if (!umove_or_printaddr(tcp, arg, &args)) |
Dmitry V. Levin | d67b217 | 2016-05-24 01:10:53 +0000 | [diff] [blame] | 1184 | tprintf("{buf_size=%" PRIu64 "}", |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1185 | (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. Levin | fb0c609 | 2016-05-24 01:28:26 +0000 | [diff] [blame] | 1204 | struct_btrfs_ioctl_send_args args; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1205 | |
| 1206 | tprints(", "); |
| 1207 | if (umove_or_printaddr(tcp, arg, &args)) |
| 1208 | break; |
| 1209 | |
Dmitry V. Levin | 6ce6d3b | 2016-05-24 01:53:02 +0000 | [diff] [blame] | 1210 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1214 | |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 1215 | if (abbrev(tcp)) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1216 | tprints("..."); |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 1217 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1224 | } |
| 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1236 | |
| 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. Levin | 2be39ec | 2016-05-24 00:23:31 +0000 | [diff] [blame] | 1249 | tprintf("space_slots=%" PRI__u64 "}", args.space_slots); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1250 | 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. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 1262 | if (abbrev(tcp)) |
| 1263 | tprints("..."); |
| 1264 | else { |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1265 | struct btrfs_ioctl_space_info info; |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 1266 | 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 Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1270 | } |
Dmitry V. Levin | d57cc26 | 2016-05-24 01:15:18 +0000 | [diff] [blame] | 1271 | tprints("}"); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1272 | 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. Levin | 6ce6d3b | 2016-05-24 01:53:02 +0000 | [diff] [blame] | 1289 | tprints("{fd="); |
| 1290 | printfd(tcp, args.fd); |
| 1291 | tprints(", name="); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1292 | 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. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 1300 | struct_btrfs_ioctl_vol_args_v2 args; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1301 | |
| 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. Levin | 6ce6d3b | 2016-05-24 01:53:02 +0000 | [diff] [blame] | 1313 | tprints("{fd="); |
| 1314 | printfd(tcp, args.fd); |
| 1315 | tprints(", flags="); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1316 | printflags64(btrfs_snap_flags_v2, args.flags, |
| 1317 | "BTRFS_SUBVOL_???"); |
| 1318 | if (args.flags & BTRFS_SUBVOL_QGROUP_INHERIT) { |
Dmitry V. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 1319 | tprintf(", size=%llu, qgroup_inherit=", |
| 1320 | (unsigned long long) args.size); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1321 | |
| 1322 | btrfs_print_qgroup_inherit(tcp, |
Dmitry V. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 1323 | (unsigned long) args.qgroup_inherit); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1324 | } |
| 1325 | tprintf(", name="); |
Dmitry V. Levin | 0cd7ea0 | 2016-05-24 00:59:40 +0000 | [diff] [blame] | 1326 | print_quoted_string(args.name, sizeof(args.name), |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1327 | QUOTE_0_TERMINATED); |
| 1328 | tprints("}"); |
| 1329 | return 0; |
| 1330 | } |
Dmitry V. Levin | e7d3d64 | 2016-08-25 21:24:33 +0000 | [diff] [blame] | 1331 | tprintf("{transid=%llu}", (unsigned long long) args.transid); |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1332 | break; |
| 1333 | } |
Dmitry V. Levin | 82b9e34 | 2016-05-24 01:12:41 +0000 | [diff] [blame] | 1334 | |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1335 | case BTRFS_IOC_GET_FSLABEL: /* R */ |
Dmitry V. Levin | 82b9e34 | 2016-05-24 01:12:41 +0000 | [diff] [blame] | 1336 | if (entering(tcp)) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1337 | return 0; |
Dmitry V. Levin | 82b9e34 | 2016-05-24 01:12:41 +0000 | [diff] [blame] | 1338 | /* fall through */ |
| 1339 | case BTRFS_IOC_SET_FSLABEL: { /* W */ |
| 1340 | char label[BTRFS_LABEL_SIZE]; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1341 | |
| 1342 | tprints(", "); |
Dmitry V. Levin | 90ffbc7 | 2016-05-24 00:49:50 +0000 | [diff] [blame] | 1343 | if (umove_or_printaddr(tcp, arg, &label)) |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1344 | 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. Levin | ea516df | 2016-05-24 02:40:13 +0000 | [diff] [blame] | 1351 | #ifdef BTRFS_IOC_FILE_EXTENT_SAME |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1352 | case BTRFS_IOC_FILE_EXTENT_SAME: /* FIDEDUPERANGE */ |
Dmitry V. Levin | ea516df | 2016-05-24 02:40:13 +0000 | [diff] [blame] | 1353 | #endif |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1354 | /* |
| 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. Levin | 3ce2dfc | 2016-05-24 00:45:05 +0000 | [diff] [blame] | 1365 | return RVAL_DECODED | 1; |
Jeff Mahoney | 8cc6962 | 2016-05-18 18:09:39 -0400 | [diff] [blame] | 1366 | } |
| 1367 | #endif /* HAVE_LINUX_BTRFS_H */ |