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