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/blkpg.h>
38 #define BLKTRACE_BDEV_SIZE 32
39 typedef struct blk_user_trace_setup {
40 char name[BLKTRACE_BDEV_SIZE]; /* output */
41 uint16_t act_mask; /* input */
42 uint32_t buf_size; /* input */
43 uint32_t buf_nr; /* input */
47 } struct_blk_user_trace_setup;
49 typedef struct blkpg_ioctl_arg struct_blkpg_ioctl_arg;
50 typedef struct blkpg_partition struct_blkpg_partition;
55 * ioctl numbers <= 114 are present in Linux 2.4. The following ones have been
56 * added since then and headers containing them may not be available on every
61 # define BLKTRACESETUP _IOWR(0x12, 115, struct_blk_user_trace_setup)
64 # define BLKTRACESTART _IO(0x12,116)
67 # define BLKTRACESTOP _IO(0x12,117)
69 #ifndef BLKTRACETEARDOWN
70 # define BLKTRACETEARDOWN _IO(0x12,118)
73 # define BLKDISCARD _IO(0x12,119)
76 # define BLKIOMIN _IO(0x12,120)
79 # define BLKIOOPT _IO(0x12,121)
82 # define BLKALIGNOFF _IO(0x12,122)
85 # define BLKPBSZGET _IO(0x12,123)
87 #ifndef BLKDISCARDZEROES
88 # define BLKDISCARDZEROES _IO(0x12,124)
91 # define BLKSECDISCARD _IO(0x12,125)
94 # define BLKROTATIONAL _IO(0x12,126)
97 # define BLKZEROOUT _IO(0x12,127)
100 #include "xlat/blkpg_ops.h"
103 print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg)
105 struct_blkpg_partition p;
108 printxval(blkpg_ops, blkpg->op, "BLKPG_???");
110 tprintf(", flags=%d, datalen=%d, data=",
111 blkpg->flags, blkpg->datalen);
113 if (!umove_or_printaddr(tcp, (long) blkpg->data, &p)) {
114 tprintf("{start=%lld, length=%lld, pno=%d, devname=",
115 (long long) p.start, (long long) p.length, p.pno);
116 print_quoted_string(p.devname, sizeof(p.devname),
118 tprints(", volname=");
119 print_quoted_string(p.volname, sizeof(p.volname),
126 MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *tcp,
127 const unsigned int code, const long arg)
130 /* take arg as a value, not as a pointer */
133 tprintf(", %lu", arg);
136 /* return an unsigned short */
142 printnum_short(tcp, arg, "%hu");
145 /* return a signed int */
153 /* take a signed int */
157 printnum_int(tcp, arg, "%d");
160 /* return an unsigned int */
164 case BLKDISCARDZEROES:
168 printnum_int(tcp, arg, "%u");
171 /* return a signed long */
177 printnum_slong(tcp, arg);
180 /* returns an unsigned long */
185 printnum_ulong(tcp, arg);
188 #ifdef HAVE_BLKGETSIZE64
189 /* returns an uint64_t */
194 printnum_int64(tcp, arg, "%" PRIu64);
198 /* takes a pair of uint64_t */
203 printpair_int64(tcp, arg, "%" PRIu64);
206 /* More complex types */
208 struct_blkpg_ioctl_arg blkpg;
211 if (!umove_or_printaddr(tcp, arg, &blkpg))
212 print_blkpg_req(tcp, &blkpg);
218 struct_blk_user_trace_setup buts;
221 if (umove_or_printaddr(tcp, arg, &buts))
223 tprintf("{act_mask=%u, buf_size=%u, "
224 "buf_nr=%u, start_lba=%" PRIu64 ", "
225 "end_lba=%" PRIu64 ", pid=%u",
226 (unsigned)buts.act_mask, buts.buf_size,
227 buts.buf_nr, buts.start_lba,
228 buts.end_lba, buts.pid);
231 struct_blk_user_trace_setup buts;
233 if (!syserror(tcp) && !umove(tcp, arg, &buts)) {
235 print_quoted_string(buts.name, sizeof(buts.name),
247 case BLKTRACETEARDOWN:
253 return RVAL_DECODED | 1;