Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, 2010 Jeff Mahoney <jeffm@suse.com> |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 3 | * Copyright (c) 2011-2016 Dmitry V. Levin <ldv@altlinux.org> |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 4 | * Copyright (c) 2011-2018 The strace developers. |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 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. |
| 17 | * |
| 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. |
| 28 | */ |
| 29 | |
| 30 | #include "defs.h" |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 31 | |
| 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) |
| 35 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 36 | #include <linux/ioctl.h> |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 37 | #include <linux/fs.h> |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 38 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 39 | typedef struct { |
| 40 | int op; |
| 41 | int flags; |
| 42 | int datalen; |
| 43 | void *data; |
| 44 | } struct_blkpg_ioctl_arg; |
| 45 | |
| 46 | #define BLKPG_DEVNAMELTH 64 |
| 47 | #define BLKPG_VOLNAMELTH 64 |
| 48 | typedef struct { |
| 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; |
| 56 | |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 57 | #define BLKTRACE_BDEV_SIZE 32 |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 58 | typedef struct blk_user_trace_setup { |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 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 */ |
| 63 | uint64_t start_lba; |
| 64 | uint64_t end_lba; |
| 65 | uint32_t pid; |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 66 | } struct_blk_user_trace_setup; |
| 67 | |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame] | 68 | /* Provide fall-back definitions for BLK* ioctls */ |
| 69 | #define XLAT_MACROS_ONLY |
| 70 | # include "xlat/block_ioctl_cmds.h" |
| 71 | #undef XLAT_MACROS_ONLY |
| 72 | |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 73 | #include MPERS_DEFS |
| 74 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 75 | #include "print_fields.h" |
| 76 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 77 | #include "xlat/blkpg_ops.h" |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 78 | |
| 79 | static void |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 80 | print_blkpg_req(struct tcb *tcp, const struct_blkpg_ioctl_arg *blkpg) |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 81 | { |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 82 | struct_blkpg_partition p; |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 83 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 84 | PRINT_FIELD_XVAL("{", *blkpg, op, blkpg_ops, "BLKPG_???"); |
| 85 | PRINT_FIELD_D(", ", *blkpg, flags); |
| 86 | PRINT_FIELD_D(", ", *blkpg, datalen); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 87 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 88 | tprints(", data="); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 89 | if (!umove_or_printaddr(tcp, ptr_to_kulong(blkpg->data), &p)) { |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 90 | PRINT_FIELD_D("{", p, start); |
| 91 | PRINT_FIELD_D(", ", p, length); |
| 92 | PRINT_FIELD_D(", ", p, pno); |
| 93 | PRINT_FIELD_CSTRING(", ", p, devname); |
| 94 | PRINT_FIELD_CSTRING(", ", p, volname); |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 95 | tprints("}"); |
Dmitry V. Levin | 0a87058 | 2015-01-25 01:04:01 +0000 | [diff] [blame] | 96 | } |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 97 | tprints("}"); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 100 | MPERS_PRINTER_DECL(int, block_ioctl, struct tcb *const tcp, |
| 101 | const unsigned int code, const kernel_ulong_t arg) |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 102 | { |
| 103 | switch (code) { |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 104 | /* take arg as a value, not as a pointer */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 105 | case BLKRASET: |
| 106 | case BLKFRASET: |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 107 | tprintf(", %" PRI_klu, arg); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 108 | break; |
| 109 | |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 110 | /* return an unsigned short */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 111 | case BLKSECTGET: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 112 | case BLKROTATIONAL: |
| 113 | if (entering(tcp)) |
| 114 | return 0; |
| 115 | tprints(", "); |
| 116 | printnum_short(tcp, arg, "%hu"); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 117 | break; |
| 118 | |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 119 | /* return a signed int */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 120 | case BLKROGET: |
| 121 | case BLKBSZGET: |
| 122 | case BLKSSZGET: |
| 123 | case BLKALIGNOFF: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 124 | if (entering(tcp)) |
| 125 | return 0; |
Elliott Hughes | 28e98bc | 2018-06-14 16:59:04 -0700 | [diff] [blame] | 126 | ATTRIBUTE_FALLTHROUGH; |
Dmitry V. Levin | 0c9087c | 2016-05-26 12:36:56 +0000 | [diff] [blame] | 127 | /* take a signed int */ |
| 128 | case BLKROSET: |
| 129 | case BLKBSZSET: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 130 | tprints(", "); |
| 131 | printnum_int(tcp, arg, "%d"); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 132 | break; |
| 133 | |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 134 | /* return an unsigned int */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 135 | case BLKPBSZGET: |
| 136 | case BLKIOMIN: |
| 137 | case BLKIOOPT: |
| 138 | case BLKDISCARDZEROES: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 139 | if (entering(tcp)) |
| 140 | return 0; |
| 141 | tprints(", "); |
| 142 | printnum_int(tcp, arg, "%u"); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 143 | break; |
| 144 | |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 145 | /* return a signed long */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 146 | case BLKRAGET: |
| 147 | case BLKFRAGET: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 148 | if (entering(tcp)) |
| 149 | return 0; |
| 150 | tprints(", "); |
Dmitry V. Levin | 2479ef0 | 2015-08-18 14:58:27 +0000 | [diff] [blame] | 151 | printnum_slong(tcp, arg); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 152 | break; |
| 153 | |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 154 | /* returns an unsigned long */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 155 | case BLKGETSIZE: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 156 | if (entering(tcp)) |
| 157 | return 0; |
| 158 | tprints(", "); |
Dmitry V. Levin | 2479ef0 | 2015-08-18 14:58:27 +0000 | [diff] [blame] | 159 | printnum_ulong(tcp, arg); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 160 | break; |
| 161 | |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 162 | /* returns an uint64_t */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 163 | case BLKGETSIZE64: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 164 | if (entering(tcp)) |
| 165 | return 0; |
| 166 | tprints(", "); |
| 167 | printnum_int64(tcp, arg, "%" PRIu64); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 168 | break; |
| 169 | |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 170 | /* takes a pair of uint64_t */ |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 171 | case BLKDISCARD: |
| 172 | case BLKSECDISCARD: |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 173 | case BLKZEROOUT: |
| 174 | tprints(", "); |
Dmitry V. Levin | 46d25c2 | 2016-05-26 12:33:21 +0000 | [diff] [blame] | 175 | printpair_int64(tcp, arg, "%" PRIu64); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 176 | break; |
| 177 | |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 178 | /* More complex types */ |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 179 | case BLKPG: { |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 180 | struct_blkpg_ioctl_arg blkpg; |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 181 | |
| 182 | tprints(", "); |
| 183 | if (!umove_or_printaddr(tcp, arg, &blkpg)) |
| 184 | print_blkpg_req(tcp, &blkpg); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 185 | break; |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 186 | } |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 187 | |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 188 | case BLKTRACESETUP: |
| 189 | if (entering(tcp)) { |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 190 | struct_blk_user_trace_setup buts; |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 191 | |
| 192 | tprints(", "); |
| 193 | if (umove_or_printaddr(tcp, arg, &buts)) |
| 194 | break; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 195 | PRINT_FIELD_U("{", buts, act_mask); |
| 196 | PRINT_FIELD_U(", ", buts, buf_size); |
| 197 | PRINT_FIELD_U(", ", buts, buf_nr); |
| 198 | PRINT_FIELD_U(", ", buts, start_lba); |
| 199 | PRINT_FIELD_U(", ", buts, end_lba); |
| 200 | PRINT_FIELD_U(", ", buts, pid); |
| 201 | return 0; |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 202 | } else { |
Dmitry V. Levin | 37d1b3d | 2016-05-26 10:43:51 +0000 | [diff] [blame] | 203 | struct_blk_user_trace_setup buts; |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 204 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 205 | if (!syserror(tcp) && !umove(tcp, arg, &buts)) |
| 206 | PRINT_FIELD_CSTRING(", ", buts, name); |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 207 | tprints("}"); |
| 208 | break; |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 209 | } |
Dmitry V. Levin | be284ca | 2011-01-16 23:07:51 +0000 | [diff] [blame] | 210 | |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 211 | /* No arguments */ |
| 212 | case BLKRRPART: |
| 213 | case BLKFLSBUF: |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 214 | case BLKTRACESTART: |
| 215 | case BLKTRACESTOP: |
| 216 | case BLKTRACETEARDOWN: |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 217 | break; |
Dmitry V. Levin | a0beac1 | 2015-07-05 15:15:03 +0300 | [diff] [blame] | 218 | default: |
| 219 | return RVAL_DECODED; |
| 220 | } |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 221 | |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 222 | return RVAL_IOCTL_DECODED; |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 223 | } |