1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
/*
* Copyright (c) 2012 Mike Frysinger <vapier@gentoo.org>
* Copyright (c) 2012-2018 The strace developers.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "defs.h"
#ifdef HAVE_STRUCT_MTD_WRITE_REQ
# include DEF_MPERS_TYPE(struct_mtd_oob_buf)
# include <linux/ioctl.h>
# include <mtd/mtd-abi.h>
typedef struct mtd_oob_buf struct_mtd_oob_buf;
#endif /* HAVE_STRUCT_MTD_WRITE_REQ */
#include MPERS_DEFS
#ifdef HAVE_STRUCT_MTD_WRITE_REQ
# include "xlat/mtd_mode_options.h"
# include "xlat/mtd_file_mode_options.h"
# include "xlat/mtd_type_options.h"
# include "xlat/mtd_flags_options.h"
# include "xlat/mtd_otp_options.h"
# include "xlat/mtd_nandecc_options.h"
static void
decode_erase_info_user(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct erase_info_user einfo;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &einfo))
return;
tprint_struct_begin();
PRINT_FIELD_X(einfo, start);
tprint_struct_next();
PRINT_FIELD_X(einfo, length);
tprint_struct_end();
}
static void
decode_erase_info_user64(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct erase_info_user64 einfo64;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &einfo64))
return;
tprint_struct_begin();
PRINT_FIELD_X(einfo64, start);
tprint_struct_next();
PRINT_FIELD_X(einfo64, length);
tprint_struct_end();
}
static void
decode_mtd_oob_buf(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct_mtd_oob_buf mbuf;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &mbuf))
return;
tprint_struct_begin();
PRINT_FIELD_X(mbuf, start);
tprint_struct_next();
PRINT_FIELD_X(mbuf, length);
tprint_struct_next();
PRINT_FIELD_PTR(mbuf, ptr);
tprint_struct_end();
}
static void
decode_mtd_oob_buf64(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct mtd_oob_buf64 mbuf64;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &mbuf64))
return;
tprint_struct_begin();
PRINT_FIELD_X(mbuf64, start);
tprint_struct_next();
PRINT_FIELD_X(mbuf64, length);
tprint_struct_next();
PRINT_FIELD_ADDR64(mbuf64, usr_ptr);
tprint_struct_end();
}
static void
decode_otp_info(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct otp_info oinfo;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &oinfo))
return;
tprint_struct_begin();
PRINT_FIELD_X(oinfo, start);
tprint_struct_next();
PRINT_FIELD_X(oinfo, length);
tprint_struct_next();
PRINT_FIELD_U(oinfo, locked);
tprint_struct_end();
}
static void
decode_otp_select(struct tcb *const tcp, const kernel_ulong_t addr)
{
unsigned int i;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &i))
return;
tprints("[");
printxval(mtd_otp_options, i, "MTD_OTP_???");
tprints("]");
}
static void
decode_mtd_write_req(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct mtd_write_req mreq;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &mreq))
return;
tprint_struct_begin();
PRINT_FIELD_X(mreq, start);
tprint_struct_next();
PRINT_FIELD_X(mreq, len);
tprint_struct_next();
PRINT_FIELD_X(mreq, ooblen);
tprint_struct_next();
PRINT_FIELD_ADDR64(mreq, usr_data);
tprint_struct_next();
PRINT_FIELD_ADDR64(mreq, usr_oob);
tprint_struct_next();
PRINT_FIELD_XVAL(mreq, mode, mtd_mode_options, "MTD_OPS_???");
tprint_struct_end();
}
static void
decode_mtd_info_user(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct mtd_info_user minfo;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &minfo))
return;
tprint_struct_begin();
PRINT_FIELD_XVAL(minfo, type, mtd_type_options, "MTD_???");
tprint_struct_next();
PRINT_FIELD_FLAGS(minfo, flags, mtd_flags_options, "MTD_???");
tprint_struct_next();
PRINT_FIELD_X(minfo, size);
tprint_struct_next();
PRINT_FIELD_X(minfo, erasesize);
tprint_struct_next();
PRINT_FIELD_X(minfo, writesize);
tprint_struct_next();
PRINT_FIELD_X(minfo, oobsize);
tprint_struct_next();
PRINT_FIELD_X(minfo, padding);
tprint_struct_end();
}
static bool
print_xint32x2_array_member(struct tcb *tcp, void *elem_buf, size_t elem_size,
void *data)
{
print_local_array_ex(tcp, elem_buf, 2, sizeof(int),
print_xint32_array_member, NULL, 0, NULL, NULL);
return true;
}
static void
decode_nand_oobinfo(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct nand_oobinfo ninfo;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &ninfo))
return;
tprint_struct_begin();
PRINT_FIELD_XVAL(ninfo, useecc, mtd_nandecc_options, "MTD_NANDECC_???");
tprint_struct_next();
PRINT_FIELD_X(ninfo, eccbytes);
tprint_struct_next();
PRINT_FIELD_ARRAY(ninfo, oobfree, tcp, print_xint32x2_array_member);
tprint_struct_next();
PRINT_FIELD_ARRAY(ninfo, eccpos, tcp, print_xint32_array_member);
tprint_struct_end();
}
static bool
print_nand_oobfree_array_member(struct tcb *tcp, void *elem_buf,
size_t elem_size, void *data)
{
const struct nand_oobfree *p = elem_buf;
tprint_struct_begin();
PRINT_FIELD_X(*p, offset);
tprint_struct_next();
PRINT_FIELD_X(*p, length);
tprint_struct_end();
return true;
}
static void
decode_nand_ecclayout_user(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct nand_ecclayout_user nlay;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &nlay))
return;
tprint_struct_begin();
PRINT_FIELD_X(nlay, eccbytes);
tprint_struct_next();
PRINT_FIELD_ARRAY(nlay, eccpos, tcp, print_xint32_array_member);
tprint_struct_next();
PRINT_FIELD_X(nlay, oobavail);
tprint_struct_next();
PRINT_FIELD_ARRAY(nlay, oobfree, tcp, print_nand_oobfree_array_member);
tprint_struct_end();
}
static void
decode_mtd_ecc_stats(struct tcb *const tcp, const kernel_ulong_t addr)
{
struct mtd_ecc_stats es;
tprints(", ");
if (umove_or_printaddr(tcp, addr, &es))
return;
tprint_struct_begin();
PRINT_FIELD_X(es, corrected);
tprint_struct_next();
PRINT_FIELD_X(es, failed);
tprint_struct_next();
PRINT_FIELD_X(es, badblocks);
tprint_struct_next();
PRINT_FIELD_X(es, bbtblocks);
tprint_struct_end();
}
MPERS_PRINTER_DECL(int, mtd_ioctl, struct tcb *const tcp,
const unsigned int code, const kernel_ulong_t arg)
{
switch (code) {
case MEMERASE:
case MEMLOCK:
case MEMUNLOCK:
case MEMISLOCKED:
decode_erase_info_user(tcp, arg);
break;
case MEMERASE64:
decode_erase_info_user64(tcp, arg);
break;
case MEMWRITEOOB:
case MEMREADOOB:
decode_mtd_oob_buf(tcp, arg);
break;
case MEMWRITEOOB64:
case MEMREADOOB64:
decode_mtd_oob_buf64(tcp, arg);
break;
case MEMWRITE:
decode_mtd_write_req(tcp, arg);
break;
case OTPGETREGIONINFO:
if (entering(tcp))
return 0;
ATTRIBUTE_FALLTHROUGH;
case OTPLOCK:
decode_otp_info(tcp, arg);
break;
case OTPSELECT:
decode_otp_select(tcp, arg);
break;
case MTDFILEMODE:
tprints(", ");
printxval64(mtd_file_mode_options, arg, "MTD_FILE_MODE_???");
break;
case MEMGETBADBLOCK:
case MEMSETBADBLOCK:
tprints(", ");
printnum_int64(tcp, arg, "%" PRIu64);
break;
case MEMGETINFO:
if (entering(tcp))
return 0;
decode_mtd_info_user(tcp, arg);
break;
case MEMGETOOBSEL:
if (entering(tcp))
return 0;
decode_nand_oobinfo(tcp, arg);
break;
case ECCGETLAYOUT:
if (entering(tcp))
return 0;
decode_nand_ecclayout_user(tcp, arg);
break;
case ECCGETSTATS:
if (entering(tcp))
return 0;
decode_mtd_ecc_stats(tcp, arg);
break;
case OTPGETREGIONCOUNT:
if (entering(tcp))
return 0;
tprints(", ");
printnum_int(tcp, arg, "%u");
break;
case MEMGETREGIONCOUNT:
if (entering(tcp))
return 0;
tprints(", ");
printnum_int(tcp, arg, "%d");
break;
case MEMGETREGIONINFO:
if (entering(tcp)) {
struct region_info_user rinfo;
tprints(", ");
if (umove_or_printaddr(tcp, arg, &rinfo))
break;
tprint_struct_begin();
PRINT_FIELD_X(rinfo, regionindex);
return 0;
} else {
struct region_info_user rinfo;
if (!syserror(tcp) && !umove(tcp, arg, &rinfo)) {
tprint_struct_next();
PRINT_FIELD_X(rinfo, offset);
tprint_struct_next();
PRINT_FIELD_X(rinfo, erasesize);
tprint_struct_next();
PRINT_FIELD_X(rinfo, numblocks);
}
tprint_struct_end();
break;
}
default:
return RVAL_DECODED;
}
return RVAL_IOCTL_DECODED;
}
#endif /* HAVE_STRUCT_MTD_WRITE_REQ */
|