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;
70 # define BLKPG _IO(0x12,105)
74 * ioctl numbers <= 114 are present in Linux 2.4. The following ones have been
75 * added since then and headers containing them may not be available on every
80 # define BLKTRACESETUP _IOWR(0x12, 115, struct_blk_user_trace_setup)
83 # define BLKTRACESTART _IO(0x12,116)
86 # define BLKTRACESTOP _IO(0x12,117)
88 #ifndef BLKTRACETEARDOWN
89 # define BLKTRACETEARDOWN _IO(0x12,118)
92 # define BLKDISCARD _IO(0x12,119)
95 # define BLKIOMIN _IO(0x12,120)
98 # define BLKIOOPT _IO(0x12,121)
101 # define BLKALIGNOFF _IO(0x12,122)
104 # define BLKPBSZGET _IO(0x12,123)
106 #ifndef BLKDISCARDZEROES
107 # define BLKDISCARDZEROES _IO(0x12,124)
109 #ifndef BLKSECDISCARD
110 # define BLKSECDISCARD _IO(0x12,125)
112 #ifndef BLKROTATIONAL
113 # define BLKROTATIONAL _IO(0x12,126)
116 # define BLKZEROOUT _IO(0x12,127)
119 #include "xlat/blkpg_ops.h"
122 print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg)
124 struct_blkpg_partition p;
127 printxval(blkpg_ops, blkpg->op, "BLKPG_???");
129 tprintf(", flags=%d, datalen=%d, data=",
130 blkpg->flags, blkpg->datalen);
132 if (!umove_or_printaddr(tcp, ptr_to_kulong(blkpg->data), &p)) {
133 tprintf("{start=%" PRId64 ", length=%" PRId64
134 ", pno=%d, devname=",
135 p.start, p.length, p.pno);
136 print_quoted_string(p.devname, sizeof(p.devname),
138 tprints(", volname=");
139 print_quoted_string(p.volname, sizeof(p.volname),
146 MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp,
147 const unsigned int code, const kernel_ureg_t arg)
150 /* take arg as a value, not as a pointer */
153 tprintf(", %lu", arg);
156 /* return an unsigned short */
162 printnum_short(tcp, arg, "%hu");
165 /* return a signed int */
173 /* take a signed int */
177 printnum_int(tcp, arg, "%d");
180 /* return an unsigned int */
184 case BLKDISCARDZEROES:
188 printnum_int(tcp, arg, "%u");
191 /* return a signed long */
197 printnum_slong(tcp, arg);
200 /* returns an unsigned long */
205 printnum_ulong(tcp, arg);
208 #ifdef HAVE_BLKGETSIZE64
209 /* returns an uint64_t */
214 printnum_int64(tcp, arg, "%" PRIu64);
218 /* takes a pair of uint64_t */
223 printpair_int64(tcp, arg, "%" PRIu64);
226 /* More complex types */
228 struct_blkpg_ioctl_arg blkpg;
231 if (!umove_or_printaddr(tcp, arg, &blkpg))
232 print_blkpg_req(tcp, &blkpg);
238 struct_blk_user_trace_setup buts;
241 if (umove_or_printaddr(tcp, arg, &buts))
243 tprintf("{act_mask=%u, buf_size=%u, "
244 "buf_nr=%u, start_lba=%" PRIu64 ", "
245 "end_lba=%" PRIu64 ", pid=%u",
246 (unsigned)buts.act_mask, buts.buf_size,
247 buts.buf_nr, buts.start_lba,
248 buts.end_lba, buts.pid);
251 struct_blk_user_trace_setup buts;
253 if (!syserror(tcp) && !umove(tcp, arg, &buts)) {
255 print_quoted_string(buts.name, sizeof(buts.name),
267 case BLKTRACETEARDOWN:
273 return RVAL_DECODED | 1;