2 * Copyright (c) 2009, 2010 Jeff Mahoney <jeffm@suse.com>
3 * Copyright (c) 2011-2016 Dmitry V. Levin <ldv@altlinux.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include DEF_MPERS_TYPE(struct_blk_user_trace_setup)
32 #include DEF_MPERS_TYPE(struct_blkpg_ioctl_arg)
33 #include DEF_MPERS_TYPE(struct_blkpg_partition)
35 #include <linux/ioctl.h>
43 } struct_blkpg_ioctl_arg;
45 #define BLKPG_DEVNAMELTH 64
46 #define BLKPG_VOLNAMELTH 64
48 int64_t start; /* starting offset in bytes */
49 int64_t length; /* length in bytes */
50 int pno; /* partition number */
51 char devname[BLKPG_DEVNAMELTH]; /* partition name, like sda5 or c0d1p2,
52 to be used in kernel messages */
53 char volname[BLKPG_VOLNAMELTH]; /* volume label */
54 } struct_blkpg_partition;
56 #define BLKTRACE_BDEV_SIZE 32
57 typedef struct blk_user_trace_setup {
58 char name[BLKTRACE_BDEV_SIZE]; /* output */
59 uint16_t act_mask; /* input */
60 uint32_t buf_size; /* input */
61 uint32_t buf_nr; /* input */
65 } struct_blk_user_trace_setup;
69 #include "print_fields.h"
72 # define BLKPG _IO(0x12, 105)
76 * ioctl numbers <= 114 are present in Linux 2.4. The following ones have been
77 * added since then and headers containing them may not be available on every
82 # define BLKTRACESETUP _IOWR(0x12, 115, struct_blk_user_trace_setup)
85 # define BLKTRACESTART _IO(0x12, 116)
88 # define BLKTRACESTOP _IO(0x12, 117)
90 #ifndef BLKTRACETEARDOWN
91 # define BLKTRACETEARDOWN _IO(0x12, 118)
94 # define BLKDISCARD _IO(0x12, 119)
97 # define BLKIOMIN _IO(0x12, 120)
100 # define BLKIOOPT _IO(0x12, 121)
103 # define BLKALIGNOFF _IO(0x12, 122)
106 # define BLKPBSZGET _IO(0x12, 123)
108 #ifndef BLKDISCARDZEROES
109 # define BLKDISCARDZEROES _IO(0x12, 124)
111 #ifndef BLKSECDISCARD
112 # define BLKSECDISCARD _IO(0x12, 125)
114 #ifndef BLKROTATIONAL
115 # define BLKROTATIONAL _IO(0x12, 126)
118 # define BLKZEROOUT _IO(0x12, 127)
121 #include "xlat/blkpg_ops.h"
124 print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg)
126 struct_blkpg_partition p;
128 PRINT_FIELD_XVAL("{", *blkpg, op, blkpg_ops, "BLKPG_???");
129 PRINT_FIELD_D(", ", *blkpg, flags);
130 PRINT_FIELD_D(", ", *blkpg, datalen);
133 if (!umove_or_printaddr(tcp, ptr_to_kulong(blkpg->data), &p)) {
134 PRINT_FIELD_D("{", p, start);
135 PRINT_FIELD_D(", ", p, length);
136 PRINT_FIELD_D(", ", p, pno);
137 PRINT_FIELD_CSTRING(", ", p, devname);
138 PRINT_FIELD_CSTRING(", ", p, volname);
144 MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp,
145 const unsigned int code, const kernel_ulong_t arg)
148 /* take arg as a value, not as a pointer */
151 tprintf(", %" PRI_klu, arg);
154 /* return an unsigned short */
160 printnum_short(tcp, arg, "%hu");
163 /* return a signed int */
171 /* take a signed int */
175 printnum_int(tcp, arg, "%d");
178 /* return an unsigned int */
182 case BLKDISCARDZEROES:
186 printnum_int(tcp, arg, "%u");
189 /* return a signed long */
195 printnum_slong(tcp, arg);
198 /* returns an unsigned long */
203 printnum_ulong(tcp, arg);
206 #ifdef HAVE_BLKGETSIZE64
207 /* returns an uint64_t */
212 printnum_int64(tcp, arg, "%" PRIu64);
216 /* takes a pair of uint64_t */
221 printpair_int64(tcp, arg, "%" PRIu64);
224 /* More complex types */
226 struct_blkpg_ioctl_arg blkpg;
229 if (!umove_or_printaddr(tcp, arg, &blkpg))
230 print_blkpg_req(tcp, &blkpg);
236 struct_blk_user_trace_setup buts;
239 if (umove_or_printaddr(tcp, arg, &buts))
241 PRINT_FIELD_U("{", buts, act_mask);
242 PRINT_FIELD_U(", ", buts, buf_size);
243 PRINT_FIELD_U(", ", buts, buf_nr);
244 PRINT_FIELD_U(", ", buts, start_lba);
245 PRINT_FIELD_U(", ", buts, end_lba);
246 PRINT_FIELD_U(", ", buts, pid);
249 struct_blk_user_trace_setup buts;
251 if (!syserror(tcp) && !umove(tcp, arg, &buts))
252 PRINT_FIELD_CSTRING(", ", buts, name);
262 case BLKTRACETEARDOWN:
268 return RVAL_DECODED | RVAL_IOCTL_PARSED;