1 /* 2 * Copyright (c) 2012 Mike Frysinger <vapier (at) gentoo.org> 3 * Copyright (c) 2012-2017 The strace developers. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 15 * 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. 26 */ 27 28 #include "defs.h" 29 30 #ifdef HAVE_STRUCT_UBI_ATTACH_REQ_MAX_BEB_PER1024 31 32 # include <linux/ioctl.h> 33 # include <mtd/ubi-user.h> 34 35 # include "xlat/ubi_volume_types.h" 36 # include "xlat/ubi_volume_props.h" 37 38 int 39 ubi_ioctl(struct tcb *const tcp, const unsigned int code, 40 const kernel_ulong_t arg) 41 { 42 if (!verbose(tcp)) 43 return RVAL_DECODED; 44 45 switch (code) { 46 case UBI_IOCMKVOL: 47 if (entering(tcp)) { 48 struct ubi_mkvol_req mkvol; 49 50 tprints(", "); 51 if (umove_or_printaddr(tcp, arg, &mkvol)) 52 break; 53 54 tprintf("{vol_id=%" PRIi32 ", alignment=%" PRIi32 55 ", bytes=%" PRIi64 ", vol_type=", mkvol.vol_id, 56 mkvol.alignment, (int64_t)mkvol.bytes); 57 printxval(ubi_volume_types, 58 (uint8_t) mkvol.vol_type, "UBI_???_VOLUME"); 59 tprintf(", name_len=%" PRIi16 ", name=", 60 mkvol.name_len); 61 print_quoted_cstring(mkvol.name, 62 CLAMP(mkvol.name_len, 0, 63 UBI_MAX_VOLUME_NAME)); 64 tprints("}"); 65 return 0; 66 } 67 if (!syserror(tcp)) { 68 tprints(" => "); 69 printnum_int(tcp, arg, "%d"); 70 } 71 break; 72 73 case UBI_IOCRSVOL: { 74 struct ubi_rsvol_req rsvol; 75 76 tprints(", "); 77 if (umove_or_printaddr(tcp, arg, &rsvol)) 78 break; 79 80 tprintf("{vol_id=%" PRIi32 ", bytes=%" PRIi64 "}", 81 rsvol.vol_id, (int64_t)rsvol.bytes); 82 break; 83 } 84 85 case UBI_IOCRNVOL: { 86 struct ubi_rnvol_req rnvol; 87 int c; 88 89 tprints(", "); 90 if (umove_or_printaddr(tcp, arg, &rnvol)) 91 break; 92 93 tprintf("{count=%" PRIi32 ", ents=[", rnvol.count); 94 for (c = 0; c < CLAMP(rnvol.count, 0, UBI_MAX_RNVOL); ++c) { 95 if (c) 96 tprints(", "); 97 tprintf("{vol_id=%" PRIi32 ", name_len=%" PRIi16 98 ", name=", rnvol.ents[c].vol_id, 99 rnvol.ents[c].name_len); 100 print_quoted_cstring(rnvol.ents[c].name, 101 CLAMP(rnvol.ents[c].name_len, 0, 102 UBI_MAX_VOLUME_NAME)); 103 tprints("}"); 104 } 105 tprints("]}"); 106 break; 107 } 108 109 case UBI_IOCEBCH: { 110 struct ubi_leb_change_req leb; 111 112 tprints(", "); 113 if (umove_or_printaddr(tcp, arg, &leb)) 114 break; 115 116 tprintf("{lnum=%d, bytes=%d}", leb.lnum, leb.bytes); 117 break; 118 } 119 120 case UBI_IOCATT: 121 if (entering(tcp)) { 122 struct ubi_attach_req attach; 123 124 tprints(", "); 125 if (umove_or_printaddr(tcp, arg, &attach)) 126 break; 127 128 tprintf("{ubi_num=%" PRIi32 ", mtd_num=%" PRIi32 129 ", vid_hdr_offset=%" PRIi32 130 ", max_beb_per1024=%" PRIi16 "}", 131 attach.ubi_num, attach.mtd_num, 132 attach.vid_hdr_offset, attach.max_beb_per1024); 133 return 0; 134 } 135 if (!syserror(tcp)) { 136 tprints(" => "); 137 printnum_int(tcp, arg, "%d"); 138 } 139 break; 140 141 case UBI_IOCEBMAP: { 142 struct ubi_map_req map; 143 144 tprints(", "); 145 if (umove_or_printaddr(tcp, arg, &map)) 146 break; 147 148 tprintf("{lnum=%" PRIi32 ", dtype=%" PRIi8 "}", 149 map.lnum, map.dtype); 150 break; 151 } 152 153 case UBI_IOCSETVOLPROP: { 154 struct ubi_set_vol_prop_req prop; 155 156 tprints(", "); 157 if (umove_or_printaddr(tcp, arg, &prop)) 158 break; 159 160 tprints("{property="); 161 printxval(ubi_volume_props, prop.property, "UBI_VOL_PROP_???"); 162 tprintf(", value=%#" PRIx64 "}", (uint64_t)prop.value); 163 break; 164 } 165 166 167 case UBI_IOCVOLUP: 168 tprints(", "); 169 printnum_int64(tcp, arg, "%" PRIi64); 170 break; 171 172 case UBI_IOCDET: 173 case UBI_IOCEBER: 174 case UBI_IOCEBISMAP: 175 case UBI_IOCEBUNMAP: 176 case UBI_IOCRMVOL: 177 tprints(", "); 178 printnum_int(tcp, arg, "%d"); 179 break; 180 181 # ifdef UBI_IOCVOLCRBLK 182 case UBI_IOCVOLCRBLK: 183 # endif 184 # ifdef UBI_IOCVOLRMBLK 185 case UBI_IOCVOLRMBLK: 186 # endif 187 /* no arguments */ 188 break; 189 190 default: 191 return RVAL_DECODED; 192 } 193 194 return RVAL_IOCTL_DECODED; 195 } 196 197 #endif /* HAVE_STRUCT_UBI_ATTACH_REQ_MAX_BEB_PER1024 */ 198