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 *const tcp, const unsigned int code,
44 const kernel_ulong_t arg)
52 struct ubi_mkvol_req mkvol;
55 if (umove_or_printaddr(tcp, arg, &mkvol))
58 tprintf("{vol_id=%" PRIi32 ", alignment=%" PRIi32
59 ", bytes=%" PRIi64 ", vol_type=", mkvol.vol_id,
60 mkvol.alignment, (int64_t)mkvol.bytes);
61 printxval(ubi_volume_types,
62 (uint8_t) mkvol.vol_type, "UBI_???_VOLUME");
63 tprintf(", name_len=%" PRIi16 ", name=", mkvol.name_len);
64 if (print_quoted_string(mkvol.name,
65 CLAMP(mkvol.name_len, 0, UBI_MAX_VOLUME_NAME),
66 QUOTE_0_TERMINATED) > 0) {
74 printnum_int(tcp, arg, "%d");
79 struct ubi_rsvol_req rsvol;
82 if (umove_or_printaddr(tcp, arg, &rsvol))
85 tprintf("{vol_id=%" PRIi32 ", bytes=%" PRIi64 "}",
86 rsvol.vol_id, (int64_t)rsvol.bytes);
91 struct ubi_rnvol_req rnvol;
95 if (umove_or_printaddr(tcp, arg, &rnvol))
98 tprintf("{count=%" PRIi32 ", ents=[", rnvol.count);
99 for (c = 0; c < CLAMP(rnvol.count, 0, UBI_MAX_RNVOL); ++c) {
102 tprintf("{vol_id=%" PRIi32 ", name_len=%" PRIi16
103 ", name=", rnvol.ents[c].vol_id,
104 rnvol.ents[c].name_len);
105 if (print_quoted_string(rnvol.ents[c].name,
106 CLAMP(rnvol.ents[c].name_len, 0, UBI_MAX_VOLUME_NAME),
107 QUOTE_0_TERMINATED) > 0) {
117 struct ubi_leb_change_req leb;
120 if (umove_or_printaddr(tcp, arg, &leb))
123 tprintf("{lnum=%d, bytes=%d}", leb.lnum, leb.bytes);
129 struct ubi_attach_req attach;
132 if (umove_or_printaddr(tcp, arg, &attach))
135 tprintf("{ubi_num=%" PRIi32 ", mtd_num=%" PRIi32
136 ", vid_hdr_offset=%" PRIi32
137 ", max_beb_per1024=%" PRIi16 "}",
138 attach.ubi_num, attach.mtd_num,
139 attach.vid_hdr_offset, attach.max_beb_per1024);
142 if (!syserror(tcp)) {
144 printnum_int(tcp, arg, "%d");
149 struct ubi_map_req map;
152 if (umove_or_printaddr(tcp, arg, &map))
155 tprintf("{lnum=%" PRIi32 ", dtype=%" PRIi8 "}",
156 map.lnum, map.dtype);
160 case UBI_IOCSETVOLPROP: {
161 struct ubi_set_vol_prop_req prop;
164 if (umove_or_printaddr(tcp, arg, &prop))
167 tprints("{property=");
168 printxval(ubi_volume_props, prop.property, "UBI_VOL_PROP_???");
169 tprintf(", value=%#" PRIx64 "}", (uint64_t)prop.value);
176 printnum_int64(tcp, arg, "%" PRIi64);
185 printnum_int(tcp, arg, "%d");
188 #ifdef UBI_IOCVOLCRBLK
189 case UBI_IOCVOLCRBLK:
191 #ifdef UBI_IOCVOLRMBLK
192 case UBI_IOCVOLRMBLK:
201 return RVAL_DECODED | 1;