2 * Copyright (c) 2009, 2010 Jeff Mahoney <jeffm@suse.com>
3 * Copyright (c) 2011-2016 Dmitry V. Levin <ldv@altlinux.org>
4 * Copyright (c) 2011-2018 The strace developers.
7 * SPDX-License-Identifier: LGPL-2.1-or-later
12 #include DEF_MPERS_TYPE(struct_blk_user_trace_setup)
13 #include DEF_MPERS_TYPE(struct_blkpg_ioctl_arg)
14 #include DEF_MPERS_TYPE(struct_blkpg_partition)
16 #include <linux/ioctl.h>
24 } struct_blkpg_ioctl_arg;
26 #define BLKPG_DEVNAMELTH 64
27 #define BLKPG_VOLNAMELTH 64
29 int64_t start; /* starting offset in bytes */
30 int64_t length; /* length in bytes */
31 int pno; /* partition number */
32 char devname[BLKPG_DEVNAMELTH]; /* partition name, like sda5 or c0d1p2,
33 to be used in kernel messages */
34 char volname[BLKPG_VOLNAMELTH]; /* volume label */
35 } struct_blkpg_partition;
37 #define BLKTRACE_BDEV_SIZE 32
38 typedef struct blk_user_trace_setup {
39 char name[BLKTRACE_BDEV_SIZE]; /* output */
40 uint16_t act_mask; /* input */
41 uint32_t buf_size; /* input */
42 uint32_t buf_nr; /* input */
46 } struct_blk_user_trace_setup;
48 /* Provide fall-back definitions for BLK* ioctls */
49 #define XLAT_MACROS_ONLY
50 #include "xlat/block_ioctl_cmds.h"
51 #undef XLAT_MACROS_ONLY
55 #include "print_fields.h"
57 #include "xlat/blkpg_ops.h"
60 print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg)
62 struct_blkpg_partition p;
64 PRINT_FIELD_XVAL("{", *blkpg, op, blkpg_ops, "BLKPG_???");
65 PRINT_FIELD_D(", ", *blkpg, flags);
66 PRINT_FIELD_D(", ", *blkpg, datalen);
69 if (!umove_or_printaddr(tcp, ptr_to_kulong(blkpg->data), &p)) {
70 PRINT_FIELD_D("{", p, start);
71 PRINT_FIELD_D(", ", p, length);
72 PRINT_FIELD_D(", ", p, pno);
73 PRINT_FIELD_CSTRING(", ", p, devname);
74 PRINT_FIELD_CSTRING(", ", p, volname);
80 MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp,
81 const unsigned int code, const kernel_ulong_t arg)
84 /* take arg as a value, not as a pointer */
87 tprintf(", %" PRI_klu, arg);
90 /* return an unsigned short */
96 printnum_short(tcp, arg, "%hu");
99 /* return a signed int */
106 ATTRIBUTE_FALLTHROUGH;
107 /* take a signed int */
111 printnum_int(tcp, arg, "%d");
114 /* return an unsigned int */
118 case BLKDISCARDZEROES:
124 printnum_int(tcp, arg, "%u");
127 /* return a signed long */
133 printnum_slong(tcp, arg);
136 /* returns an unsigned long */
141 printnum_ulong(tcp, arg);
144 /* returns an uint64_t */
149 printnum_int64(tcp, arg, "%" PRIu64);
152 /* takes a pair of uint64_t */
157 printpair_int64(tcp, arg, "%" PRIu64);
160 /* More complex types */
162 struct_blkpg_ioctl_arg blkpg;
165 if (!umove_or_printaddr(tcp, arg, &blkpg))
166 print_blkpg_req(tcp, &blkpg);
172 struct_blk_user_trace_setup buts;
175 if (umove_or_printaddr(tcp, arg, &buts))
177 PRINT_FIELD_U("{", buts, act_mask);
178 PRINT_FIELD_U(", ", buts, buf_size);
179 PRINT_FIELD_U(", ", buts, buf_nr);
180 PRINT_FIELD_U(", ", buts, start_lba);
181 PRINT_FIELD_U(", ", buts, end_lba);
182 PRINT_FIELD_U(", ", buts, pid);
185 struct_blk_user_trace_setup buts;
187 if (!syserror(tcp) && !umove(tcp, arg, &buts))
188 PRINT_FIELD_CSTRING(", ", buts, name);
198 case BLKTRACETEARDOWN:
204 return RVAL_IOCTL_DECODED;