2 * Copyright (c) 2009, 2010 Jeff Mahoney <jeffm@suse.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include <linux/blkpg.h>
31 #include <linux/hdreg.h>
33 /* ioctls <= 114 are present in Linux 2.4. The following ones have been
34 * added since then and headers containing them may not be available on
37 #define BLKTRACE_BDEV_SIZE 32
38 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 */
49 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
52 #define BLKTRACESTART _IO(0x12,116)
55 #define BLKTRACESTOP _IO(0x12,117)
57 #ifndef BLKTRACETEARDOWN
58 #define BLKTRACETEARDOWN _IO(0x12,118)
61 #define BLKDISCARD _IO(0x12,119)
64 #define BLKIOMIN _IO(0x12,120)
67 #define BLKIOOPT _IO(0x12,121)
70 #define BLKALIGNOFF _IO(0x12,122)
73 #define BLKPBSZGET _IO(0x12,123)
75 #ifndef BLKDISCARDZEROES
76 #define BLKDISCARDZEROES _IO(0x12,124)
79 #define BLKSECDISCARD _IO(0x12,125)
82 #include "xlat/blkpg_ops.h"
85 print_blkpg_req(struct tcb *tcp, struct blkpg_ioctl_arg *blkpg)
87 struct blkpg_partition p;
90 printxval(blkpg_ops, blkpg->op, "BLKPG_???");
92 tprintf(", flags=%d, datalen=%d, ",
93 blkpg->flags, blkpg->datalen);
95 if (umove(tcp, (long) blkpg->data, &p) < 0)
96 tprintf("%#lx}", (long) blkpg->data);
98 tprintf("{start=%lld, length=%lld, pno=%d, devname=",
99 p.start, p.length, p.pno);
100 print_quoted_string(p.devname, sizeof(p.devname),
102 tprints(", volname=");
103 print_quoted_string(p.volname, sizeof(p.volname),
110 block_ioctl(struct tcb *tcp, const unsigned int code, long arg)
113 /* take arg as a value, not as a pointer */
117 tprintf(", %ld", arg);
120 /* take a signed int */
124 /* First seen in linux-2.6.29 */
130 if (umove(tcp, arg, &val) < 0)
131 tprintf(", %#lx", arg);
133 tprintf(", %d", val);
137 /* returns an unsigned short */
141 if (syserror(tcp) || umove(tcp, arg, &val) < 0)
142 tprintf(", %#lx", arg);
144 tprintf(", %u", (unsigned)val);
148 /* return a signed int */
155 if (syserror(tcp) || umove(tcp, arg, &val) < 0)
156 tprintf(", %#lx", arg);
158 tprintf(", %d", val);
162 /* return an unsigned int */
166 case BLKDISCARDZEROES:
169 if (syserror(tcp) || umove(tcp, arg, &val) < 0)
170 tprintf(", %#lx", arg);
172 tprintf(", %u", val);
176 /* return a signed long */
181 if (syserror(tcp) || umove(tcp, arg, &val) < 0)
182 tprintf(", %#lx", arg);
184 tprintf(", %ld", val);
188 /* returns an unsigned long */
192 if (syserror(tcp) || umove(tcp, arg, &val) < 0)
193 tprintf(", %#lx", arg);
195 tprintf(", %lu", val);
199 #ifdef HAVE_BLKGETSIZE64
200 /* return an uint64_t */
204 if (syserror(tcp) || umove(tcp, arg, &val) < 0)
205 tprintf(", %#lx", arg);
207 tprintf(", %" PRIu64, val);
212 /* More complex types */
217 if (umove(tcp, arg, range) < 0)
218 tprintf(", %#lx", arg);
220 tprintf(", {%" PRIx64 ", %" PRIx64 "}",
227 struct hd_geometry geo;
228 if (syserror(tcp) || umove(tcp, arg, &geo) < 0)
229 tprintf(", %#lx", arg);
231 tprintf(", {heads=%u, sectors=%u, "
232 "cylinders=%u, start=%lu}",
234 (unsigned)geo.sectors,
235 (unsigned)geo.cylinders,
242 struct blkpg_ioctl_arg blkpg;
243 if (umove(tcp, arg, &blkpg) < 0)
244 tprintf(", %#lx", arg);
247 print_blkpg_req(tcp, &blkpg);
254 struct blk_user_trace_setup buts;
255 if (umove(tcp, arg, &buts) < 0)
256 tprintf(", %#lx", arg);
258 tprintf(", {act_mask=%u, buf_size=%u, "
259 "buf_nr=%u, start_lba=%" PRIu64 ", "
260 "end_lba=%" PRIu64 ", pid=%u}",
261 (unsigned)buts.act_mask, buts.buf_size,
262 buts.buf_nr, buts.start_lba,
263 buts.end_lba, buts.pid);
266 struct blk_user_trace_setup buts;
267 if (syserror(tcp) || umove(tcp, arg, &buts) < 0)
268 tprintf(", %#lx", arg);
271 print_quoted_string(buts.name, sizeof(buts.name),
279 /* First seen in linux-2.6.37 */
282 struct fstrim_range fstrim;
283 if (umove(tcp, arg, &fstrim))
284 tprintf(", %#lx", arg);
286 tprintf(", {start=%#" PRIx64 ", len=%#" PRIx64 ", "
287 "minlen=%#" PRIx64 "}", (uint64_t) fstrim.start,
288 (uint64_t) fstrim.len, (uint64_t) fstrim.minlen);
293 /* No arguments or unhandled */
296 case BLKTRACETEARDOWN:
297 case BLKFLSBUF: /* Requires driver knowlege */
298 case BLKRRPART: /* No args */
301 tprintf(", %#lx", arg);