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