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-2017 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include DEF_MPERS_TYPE(struct_blk_user_trace_setup)
33 #include DEF_MPERS_TYPE(struct_blkpg_ioctl_arg)
34 #include DEF_MPERS_TYPE(struct_blkpg_partition)
36 #include <linux/ioctl.h>
44 } struct_blkpg_ioctl_arg;
46 #define BLKPG_DEVNAMELTH 64
47 #define BLKPG_VOLNAMELTH 64
49 int64_t start; /* starting offset in bytes */
50 int64_t length; /* length in bytes */
51 int pno; /* partition number */
52 char devname[BLKPG_DEVNAMELTH]; /* partition name, like sda5 or c0d1p2,
53 to be used in kernel messages */
54 char volname[BLKPG_VOLNAMELTH]; /* volume label */
55 } struct_blkpg_partition;
57 #define BLKTRACE_BDEV_SIZE 32
58 typedef struct blk_user_trace_setup {
59 char name[BLKTRACE_BDEV_SIZE]; /* output */
60 uint16_t act_mask; /* input */
61 uint32_t buf_size; /* input */
62 uint32_t buf_nr; /* input */
66 } struct_blk_user_trace_setup;
70 #include "print_fields.h"
73 # define BLKPG _IO(0x12, 105)
77 * ioctl numbers <= 114 are present in Linux 2.4. The following ones have been
78 * added since then and headers containing them may not be available on every
83 # define BLKTRACESETUP _IOWR(0x12, 115, struct_blk_user_trace_setup)
86 # define BLKTRACESTART _IO(0x12, 116)
89 # define BLKTRACESTOP _IO(0x12, 117)
91 #ifndef BLKTRACETEARDOWN
92 # define BLKTRACETEARDOWN _IO(0x12, 118)
95 # define BLKDISCARD _IO(0x12, 119)
98 # define BLKIOMIN _IO(0x12, 120)
101 # define BLKIOOPT _IO(0x12, 121)
104 # define BLKALIGNOFF _IO(0x12, 122)
107 # define BLKPBSZGET _IO(0x12, 123)
109 #ifndef BLKDISCARDZEROES
110 # define BLKDISCARDZEROES _IO(0x12, 124)
112 #ifndef BLKSECDISCARD
113 # define BLKSECDISCARD _IO(0x12, 125)
115 #ifndef BLKROTATIONAL
116 # define BLKROTATIONAL _IO(0x12, 126)
119 # define BLKZEROOUT _IO(0x12, 127)
122 #include "xlat/blkpg_ops.h"
125 print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg)
127 struct_blkpg_partition p;
129 PRINT_FIELD_XVAL("{", *blkpg, op, blkpg_ops, "BLKPG_???");
130 PRINT_FIELD_D(", ", *blkpg, flags);
131 PRINT_FIELD_D(", ", *blkpg, datalen);
134 if (!umove_or_printaddr(tcp, ptr_to_kulong(blkpg->data), &p)) {
135 PRINT_FIELD_D("{", p, start);
136 PRINT_FIELD_D(", ", p, length);
137 PRINT_FIELD_D(", ", p, pno);
138 PRINT_FIELD_CSTRING(", ", p, devname);
139 PRINT_FIELD_CSTRING(", ", p, volname);
145 MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp,
146 const unsigned int code, const kernel_ulong_t arg)
149 /* take arg as a value, not as a pointer */
152 tprintf(", %" PRI_klu, arg);
155 /* return an unsigned short */
161 printnum_short(tcp, arg, "%hu");
164 /* return a signed int */
172 /* take a signed int */
176 printnum_int(tcp, arg, "%d");
179 /* return an unsigned int */
183 case BLKDISCARDZEROES:
187 printnum_int(tcp, arg, "%u");
190 /* return a signed long */
196 printnum_slong(tcp, arg);
199 /* returns an unsigned long */
204 printnum_ulong(tcp, arg);
207 #ifdef HAVE_BLKGETSIZE64
208 /* returns an uint64_t */
213 printnum_int64(tcp, arg, "%" PRIu64);
217 /* takes a pair of uint64_t */
222 printpair_int64(tcp, arg, "%" PRIu64);
225 /* More complex types */
227 struct_blkpg_ioctl_arg blkpg;
230 if (!umove_or_printaddr(tcp, arg, &blkpg))
231 print_blkpg_req(tcp, &blkpg);
237 struct_blk_user_trace_setup buts;
240 if (umove_or_printaddr(tcp, arg, &buts))
242 PRINT_FIELD_U("{", buts, act_mask);
243 PRINT_FIELD_U(", ", buts, buf_size);
244 PRINT_FIELD_U(", ", buts, buf_nr);
245 PRINT_FIELD_U(", ", buts, start_lba);
246 PRINT_FIELD_U(", ", buts, end_lba);
247 PRINT_FIELD_U(", ", buts, pid);
250 struct_blk_user_trace_setup buts;
252 if (!syserror(tcp) && !umove(tcp, arg, &buts))
253 PRINT_FIELD_CSTRING(", ", buts, name);
263 case BLKTRACETEARDOWN:
269 return RVAL_IOCTL_DECODED;