2 * Copyright (c) 2012 Mike Frysinger <vapier@gentoo.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include <linux/ioctl.h>
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"
36 # include <mtd/ubi-user.h>
39 #include "xlat/ubi_volume_types.h"
40 #include "xlat/ubi_volume_props.h"
43 ubi_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
51 struct ubi_mkvol_req mkvol;
54 if (umove_or_printaddr(tcp, arg, &mkvol))
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) {
73 printnum_int(tcp, arg, "%d");
78 struct ubi_rsvol_req rsvol;
81 if (umove_or_printaddr(tcp, arg, &rsvol))
84 tprintf("{vol_id=%" PRIi32 ", bytes=%" PRIi64 "}",
85 rsvol.vol_id, (int64_t)rsvol.bytes);
90 struct ubi_rnvol_req rnvol;
94 if (umove_or_printaddr(tcp, arg, &rnvol))
97 tprintf("{count=%" PRIi32 ", ents=[", rnvol.count);
98 for (c = 0; c < CLAMP(rnvol.count, 0, UBI_MAX_RNVOL); ++c) {
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) {
116 struct ubi_leb_change_req leb;
119 if (umove_or_printaddr(tcp, arg, &leb))
122 tprintf("{lnum=%d, bytes=%d}", leb.lnum, leb.bytes);
128 struct ubi_attach_req attach;
131 if (umove_or_printaddr(tcp, arg, &attach))
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);
141 if (!syserror(tcp)) {
143 printnum_int(tcp, arg, "%d");
148 struct ubi_map_req map;
151 if (umove_or_printaddr(tcp, arg, &map))
154 tprintf("{lnum=%" PRIi32 ", dtype=%" PRIi8 "}",
155 map.lnum, map.dtype);
159 case UBI_IOCSETVOLPROP: {
160 struct ubi_set_vol_prop_req prop;
163 if (umove_or_printaddr(tcp, arg, &prop))
166 tprints("{property=");
167 printxval(ubi_volume_props, prop.property, "UBI_VOL_PROP_???");
168 tprintf(", value=%#" PRIx64 "}", (uint64_t)prop.value);
175 printnum_int64(tcp, arg, "%" PRIi64);
184 printnum_int(tcp, arg, "%d");
187 #ifdef UBI_IOCVOLCRBLK
188 case UBI_IOCVOLCRBLK:
190 #ifdef UBI_IOCVOLRMBLK
191 case UBI_IOCVOLRMBLK:
200 return RVAL_DECODED | 1;