Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 Mike Frysinger <vapier@gentoo.org> |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * 3. The name of the author may not be used to endorse or promote products |
| 13 | * derived from this software without specific prior written permission. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "defs.h" |
| 28 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 29 | #include <linux/ioctl.h> |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 30 | |
| 31 | /* The mtd api changes quickly, so we have to keep a local copy */ |
| 32 | #include <linux/version.h> |
| 33 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) |
| 34 | # include "mtd-abi.h" |
| 35 | #else |
| 36 | # include <mtd/mtd-abi.h> |
| 37 | #endif |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 38 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) |
| 39 | # include "ubi-user.h" |
| 40 | #else |
| 41 | # include <mtd/ubi-user.h> |
| 42 | #endif |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 43 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 44 | #include "xlat/mtd_mode_options.h" |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 45 | #include "xlat/mtd_file_mode_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 46 | #include "xlat/mtd_type_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 47 | #include "xlat/mtd_flags_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 48 | #include "xlat/mtd_otp_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 49 | #include "xlat/mtd_nandecc_options.h" |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 50 | |
Dmitry V. Levin | c7afb48 | 2015-01-19 18:44:21 +0000 | [diff] [blame] | 51 | int |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 52 | mtd_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 53 | { |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 54 | if (!verbose(tcp)) |
| 55 | return RVAL_DECODED; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 56 | |
| 57 | switch (code) { |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 58 | case MEMERASE: |
| 59 | case MEMLOCK: |
| 60 | case MEMUNLOCK: |
| 61 | case MEMISLOCKED: { |
| 62 | struct erase_info_user einfo; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 63 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 64 | tprints(", "); |
| 65 | if (umove_or_printaddr(tcp, arg, &einfo)) |
| 66 | break; |
| 67 | |
| 68 | tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 "}", |
| 69 | einfo.start, einfo.length); |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | case MEMERASE64: { |
| 74 | struct erase_info_user64 einfo64; |
| 75 | |
| 76 | tprints(", "); |
| 77 | if (umove_or_printaddr(tcp, arg, &einfo64)) |
| 78 | break; |
| 79 | |
| 80 | tprintf("{start=%#" PRIx64 ", length=%#" PRIx64 "}", |
| 81 | (uint64_t) einfo64.start, (uint64_t) einfo64.length); |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | case MEMWRITEOOB: |
| 86 | case MEMREADOOB: { |
| 87 | struct mtd_oob_buf mbuf; |
| 88 | |
| 89 | tprints(", "); |
| 90 | if (umove_or_printaddr(tcp, arg, &mbuf)) |
| 91 | break; |
| 92 | |
| 93 | tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 ", ptr=...}", |
| 94 | mbuf.start, mbuf.length); |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | case MEMWRITEOOB64: |
| 99 | case MEMREADOOB64: { |
| 100 | struct mtd_oob_buf64 mbuf64; |
| 101 | |
| 102 | tprints(", "); |
| 103 | if (umove_or_printaddr(tcp, arg, &mbuf64)) |
| 104 | break; |
| 105 | |
| 106 | tprintf("{start=%#" PRIx64 ", length=%#" PRIx64 ", ptr=...}", |
| 107 | (uint64_t) mbuf64.start, (uint64_t) mbuf64.length); |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | case MEMGETREGIONINFO: { |
| 112 | struct region_info_user rinfo; |
| 113 | |
| 114 | if (entering(tcp)) { |
| 115 | tprints(", "); |
| 116 | if (umove_or_printaddr(tcp, arg, &rinfo)) |
| 117 | break; |
| 118 | tprintf("{regionindex=%#x", rinfo.regionindex); |
| 119 | return 1; |
| 120 | } else { |
| 121 | if (syserror(tcp)) { |
| 122 | tprints("}"); |
| 123 | break; |
| 124 | } |
| 125 | if (umove(tcp, arg, &rinfo) < 0) { |
| 126 | tprints(", ???}"); |
| 127 | break; |
| 128 | } |
| 129 | tprintf(", offset=%#x, erasesize=%#x, numblocks=%#x}", |
| 130 | rinfo.offset, rinfo.erasesize, rinfo.numblocks); |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | case OTPLOCK: { |
| 136 | struct otp_info oinfo; |
| 137 | |
| 138 | tprints(", "); |
| 139 | if (umove_or_printaddr(tcp, arg, &oinfo)) |
| 140 | break; |
| 141 | |
| 142 | tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 ", locked=%" PRIu32 "}", |
| 143 | oinfo.start, oinfo.length, oinfo.locked); |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | case MEMWRITE: { |
| 148 | struct mtd_write_req mreq; |
| 149 | |
| 150 | tprints(", "); |
| 151 | if (umove_or_printaddr(tcp, arg, &mreq)) |
| 152 | break; |
| 153 | |
| 154 | tprintf("{start=%#" PRIx64 ", len=%#" PRIx64, |
| 155 | (uint64_t) mreq.start, (uint64_t) mreq.len); |
| 156 | tprintf(", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64, |
| 157 | (uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data); |
| 158 | tprintf(", usr_oob=%#" PRIx64 ", mode=", |
| 159 | (uint64_t) mreq.usr_oob); |
| 160 | printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???"); |
| 161 | tprints(", padding=...}"); |
| 162 | break; |
| 163 | } |
| 164 | |
| 165 | case OTPSELECT: { |
| 166 | unsigned int i; |
| 167 | |
| 168 | tprints(", "); |
| 169 | if (umove_or_printaddr(tcp, arg, &i)) |
| 170 | break; |
| 171 | |
| 172 | tprints("["); |
| 173 | printxval(mtd_otp_options, i, "MTD_OTP_???"); |
| 174 | tprints("]"); |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | case MTDFILEMODE: |
| 179 | tprints(", "); |
Dmitry V. Levin | 942da9c | 2016-05-16 23:06:17 +0000 | [diff] [blame] | 180 | printxval_long(mtd_file_mode_options, arg, "MTD_FILE_MODE_???"); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 181 | break; |
| 182 | |
| 183 | case MEMGETBADBLOCK: |
| 184 | case MEMSETBADBLOCK: |
| 185 | tprints(", "); |
Dmitry V. Levin | dd5f0ce | 2015-07-20 11:14:12 +0000 | [diff] [blame] | 186 | printnum_int64(tcp, arg, "%" PRIu64); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 187 | break; |
| 188 | |
| 189 | case MEMGETINFO: { |
| 190 | struct mtd_info_user minfo; |
| 191 | |
| 192 | if (entering(tcp)) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 193 | return 0; |
| 194 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 195 | tprints(", "); |
| 196 | if (umove_or_printaddr(tcp, arg, &minfo)) |
| 197 | break; |
| 198 | |
| 199 | tprints("{type="); |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 200 | printxval(mtd_type_options, minfo.type, "MTD_???"); |
| 201 | tprints(", flags="); |
| 202 | printflags(mtd_flags_options, minfo.flags, "MTD_???"); |
| 203 | tprintf(", size=%#" PRIx32 ", erasesize=%#" PRIx32, |
| 204 | minfo.size, minfo.erasesize); |
| 205 | tprintf(", writesize=%#" PRIx32 ", oobsize=%#" PRIx32, |
| 206 | minfo.writesize, minfo.oobsize); |
| 207 | tprintf(", padding=%#" PRIx64 "}", |
| 208 | (uint64_t) minfo.padding); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 209 | break; |
| 210 | } |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 211 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 212 | case MEMGETOOBSEL: { |
| 213 | struct nand_oobinfo ninfo; |
| 214 | unsigned int i; |
| 215 | |
| 216 | if (entering(tcp)) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 217 | return 0; |
| 218 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 219 | tprints(", "); |
| 220 | if (umove_or_printaddr(tcp, arg, &ninfo)) |
| 221 | break; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 222 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 223 | tprints("{useecc="); |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 224 | printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???"); |
| 225 | tprintf(", eccbytes=%#" PRIx32, ninfo.eccbytes); |
| 226 | |
| 227 | tprints(", oobfree={"); |
| 228 | for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) { |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 229 | unsigned int j; |
| 230 | |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 231 | if (i) |
| 232 | tprints("}, "); |
| 233 | tprints("{"); |
| 234 | for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) { |
| 235 | if (j) |
| 236 | tprints(", "); |
| 237 | tprintf("%#" PRIx32, ninfo.oobfree[i][j]); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | tprints("}}, eccpos={"); |
| 242 | for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) { |
| 243 | if (i) |
| 244 | tprints(", "); |
| 245 | tprintf("%#" PRIx32, ninfo.eccpos[i]); |
| 246 | } |
| 247 | |
| 248 | tprints("}"); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 249 | break; |
| 250 | } |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 251 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 252 | case OTPGETREGIONINFO: { |
| 253 | struct otp_info oinfo; |
| 254 | |
| 255 | if (entering(tcp)) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 256 | return 0; |
| 257 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 258 | tprints(", "); |
| 259 | if (umove_or_printaddr(tcp, arg, &oinfo)) |
| 260 | break; |
| 261 | |
| 262 | tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 ", locked=%" PRIu32 "}", |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 263 | oinfo.start, oinfo.length, oinfo.locked); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 264 | break; |
| 265 | } |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 266 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 267 | case ECCGETLAYOUT: { |
| 268 | struct nand_ecclayout_user nlay; |
| 269 | unsigned int i; |
| 270 | |
| 271 | if (entering(tcp)) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 272 | return 0; |
| 273 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 274 | tprints(", "); |
| 275 | if (umove_or_printaddr(tcp, arg, &nlay)) |
| 276 | break; |
| 277 | |
| 278 | tprintf("{eccbytes=%#" PRIx32 ", eccpos={", nlay.eccbytes); |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 279 | for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) { |
| 280 | if (i) |
| 281 | tprints(", "); |
| 282 | tprintf("%#" PRIx32, nlay.eccpos[i]); |
| 283 | } |
| 284 | tprintf("}, oobavail=%#" PRIx32 ", oobfree={", nlay.oobavail); |
| 285 | for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) { |
| 286 | if (i) |
| 287 | tprints(", "); |
| 288 | tprintf("{offset=%#" PRIx32 ", length=%#" PRIx32 "}", |
| 289 | nlay.oobfree[i].offset, nlay.oobfree[i].length); |
| 290 | } |
| 291 | tprints("}"); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 292 | break; |
| 293 | } |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 294 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 295 | case ECCGETSTATS: { |
| 296 | struct mtd_ecc_stats estat; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 297 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 298 | if (entering(tcp)) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 299 | return 0; |
| 300 | |
| 301 | tprints(", "); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 302 | if (umove_or_printaddr(tcp, arg, &estat)) |
| 303 | break; |
| 304 | |
| 305 | tprintf("{corrected=%#" PRIx32 ", failed=%#" PRIx32, |
| 306 | estat.corrected, estat.failed); |
| 307 | tprintf(", badblocks=%#" PRIx32 ", bbtblocks=%#" PRIx32 "}", |
| 308 | estat.badblocks, estat.bbtblocks); |
| 309 | break; |
| 310 | } |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 311 | |
| 312 | case OTPGETREGIONCOUNT: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 313 | if (entering(tcp)) |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 314 | return 0; |
| 315 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 316 | tprints(", "); |
| 317 | printnum_int(tcp, arg, "%u"); |
| 318 | break; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 319 | |
| 320 | case MEMGETREGIONCOUNT: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 321 | if (entering(tcp)) |
| 322 | return 0; |
| 323 | |
| 324 | tprints(", "); |
| 325 | printnum_int(tcp, arg, "%d"); |
| 326 | break; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 327 | |
| 328 | default: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 329 | return RVAL_DECODED; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 330 | } |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 331 | |
| 332 | return RVAL_DECODED | 1; |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 333 | } |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 334 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 335 | #include "xlat/ubi_volume_types.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 336 | #include "xlat/ubi_volume_props.h" |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 337 | |
Dmitry V. Levin | c7afb48 | 2015-01-19 18:44:21 +0000 | [diff] [blame] | 338 | int |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 339 | ubi_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 340 | { |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 341 | if (!verbose(tcp)) |
| 342 | return RVAL_DECODED; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 343 | |
| 344 | switch (code) { |
| 345 | case UBI_IOCMKVOL: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 346 | if (entering(tcp)) { |
| 347 | struct ubi_mkvol_req mkvol; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 348 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 349 | tprints(", "); |
| 350 | if (umove_or_printaddr(tcp, arg, &mkvol)) |
| 351 | break; |
| 352 | |
| 353 | tprintf("{vol_id=%" PRIi32 ", alignment=%" PRIi32 |
| 354 | ", bytes=%" PRIi64 ", vol_type=", mkvol.vol_id, |
| 355 | mkvol.alignment, (int64_t)mkvol.bytes); |
Dmitry V. Levin | 2cad72f | 2016-05-16 22:25:46 +0000 | [diff] [blame] | 356 | printxval(ubi_volume_types, |
| 357 | (uint8_t) mkvol.vol_type, "UBI_???_VOLUME"); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 358 | tprintf(", name_len=%" PRIi16 ", name=", mkvol.name_len); |
| 359 | if (print_quoted_string(mkvol.name, |
| 360 | CLAMP(mkvol.name_len, 0, UBI_MAX_VOLUME_NAME), |
| 361 | QUOTE_0_TERMINATED) > 0) { |
| 362 | tprints("..."); |
| 363 | } |
| 364 | tprints("}"); |
| 365 | return 1; |
Dmitry V. Levin | 513e96e | 2015-01-26 01:17:08 +0000 | [diff] [blame] | 366 | } |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 367 | if (!syserror(tcp)) { |
| 368 | tprints(" => "); |
| 369 | printnum_int(tcp, arg, "%d"); |
| 370 | } |
| 371 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 372 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 373 | case UBI_IOCRSVOL: { |
| 374 | struct ubi_rsvol_req rsvol; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 375 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 376 | tprints(", "); |
| 377 | if (umove_or_printaddr(tcp, arg, &rsvol)) |
| 378 | break; |
| 379 | |
| 380 | tprintf("{vol_id=%" PRIi32 ", bytes=%" PRIi64 "}", |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 381 | rsvol.vol_id, (int64_t)rsvol.bytes); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 382 | break; |
| 383 | } |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 384 | |
| 385 | case UBI_IOCRNVOL: { |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 386 | struct ubi_rnvol_req rnvol; |
| 387 | int c; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 388 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 389 | tprints(", "); |
| 390 | if (umove_or_printaddr(tcp, arg, &rnvol)) |
| 391 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 392 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 393 | tprintf("{count=%" PRIi32 ", ents=[", rnvol.count); |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 394 | for (c = 0; c < CLAMP(rnvol.count, 0, UBI_MAX_RNVOL); ++c) { |
| 395 | if (c) |
| 396 | tprints(", "); |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 397 | tprintf("{vol_id=%" PRIi32 ", name_len=%" PRIi16 |
Dmitry V. Levin | 513e96e | 2015-01-26 01:17:08 +0000 | [diff] [blame] | 398 | ", name=", rnvol.ents[c].vol_id, |
| 399 | rnvol.ents[c].name_len); |
| 400 | if (print_quoted_string(rnvol.ents[c].name, |
| 401 | CLAMP(rnvol.ents[c].name_len, 0, UBI_MAX_VOLUME_NAME), |
| 402 | QUOTE_0_TERMINATED) > 0) { |
| 403 | tprints("..."); |
| 404 | } |
| 405 | tprints("}"); |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 406 | } |
| 407 | tprints("]}"); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 408 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 411 | case UBI_IOCEBCH: { |
| 412 | struct ubi_leb_change_req leb; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 413 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 414 | tprints(", "); |
| 415 | if (umove_or_printaddr(tcp, arg, &leb)) |
| 416 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 417 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 418 | tprintf("{lnum=%d, bytes=%d}", leb.lnum, leb.bytes); |
| 419 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | case UBI_IOCATT: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 423 | if (entering(tcp)) { |
| 424 | struct ubi_attach_req attach; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 425 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 426 | tprints(", "); |
| 427 | if (umove_or_printaddr(tcp, arg, &attach)) |
| 428 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 429 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 430 | tprintf("{ubi_num=%" PRIi32 ", mtd_num=%" PRIi32 |
| 431 | ", vid_hdr_offset=%" PRIi32 |
| 432 | ", max_beb_per1024=%" PRIi16 "}", |
| 433 | attach.ubi_num, attach.mtd_num, |
| 434 | attach.vid_hdr_offset, attach.max_beb_per1024); |
| 435 | return 1; |
| 436 | } |
| 437 | if (!syserror(tcp)) { |
| 438 | tprints(" => "); |
| 439 | printnum_int(tcp, arg, "%d"); |
| 440 | } |
| 441 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 442 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 443 | case UBI_IOCEBMAP: { |
| 444 | struct ubi_map_req map; |
| 445 | |
| 446 | tprints(", "); |
| 447 | if (umove_or_printaddr(tcp, arg, &map)) |
| 448 | break; |
| 449 | |
| 450 | tprintf("{lnum=%" PRIi32 ", dtype=%" PRIi8 "}", |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 451 | map.lnum, map.dtype); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 452 | break; |
| 453 | } |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 454 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 455 | case UBI_IOCSETVOLPROP: { |
| 456 | struct ubi_set_vol_prop_req prop; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 457 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 458 | tprints(", "); |
| 459 | if (umove_or_printaddr(tcp, arg, &prop)) |
| 460 | break; |
| 461 | |
| 462 | tprints("{property="); |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 463 | printxval(ubi_volume_props, prop.property, "UBI_VOL_PROP_???"); |
| 464 | tprintf(", value=%#" PRIx64 "}", (uint64_t)prop.value); |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 465 | break; |
| 466 | } |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 467 | |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 468 | |
| 469 | case UBI_IOCVOLUP: |
| 470 | tprints(", "); |
| 471 | printnum_int64(tcp, arg, "%" PRIi64); |
| 472 | break; |
| 473 | |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 474 | case UBI_IOCDET: |
| 475 | case UBI_IOCEBER: |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 476 | case UBI_IOCEBISMAP: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 477 | case UBI_IOCEBUNMAP: |
| 478 | case UBI_IOCRMVOL: |
| 479 | tprints(", "); |
| 480 | printnum_int(tcp, arg, "%d"); |
| 481 | break; |
| 482 | |
Dmitry V. Levin | 642ee79 | 2015-08-25 21:48:36 +0000 | [diff] [blame] | 483 | #ifdef UBI_IOCVOLCRBLK |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 484 | case UBI_IOCVOLCRBLK: |
Dmitry V. Levin | 642ee79 | 2015-08-25 21:48:36 +0000 | [diff] [blame] | 485 | #endif |
| 486 | #ifdef UBI_IOCVOLRMBLK |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 487 | case UBI_IOCVOLRMBLK: |
Dmitry V. Levin | 642ee79 | 2015-08-25 21:48:36 +0000 | [diff] [blame] | 488 | #endif |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 489 | /* no arguments */ |
| 490 | break; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 491 | |
| 492 | default: |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 493 | return RVAL_DECODED; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 494 | } |
Dmitry V. Levin | eddefd6 | 2015-07-07 04:12:12 +0300 | [diff] [blame] | 495 | |
| 496 | return RVAL_DECODED | 1; |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 497 | } |