2 * Copyright (c) 2012 The Chromium OS Authors.
3 * Written by Mike Frysinger <vapier@gentoo.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include <linux/ioctl.h>
30 #include <linux/loop.h>
32 typedef struct loop_info struct_loop_info;
34 #include DEF_MPERS_TYPE(struct_loop_info)
38 #include "xlat/loop_cmds.h"
39 #include "xlat/loop_flags_options.h"
40 #include "xlat/loop_crypt_type_options.h"
43 decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr)
45 struct_loop_info info;
48 if (umove_or_printaddr(tcp, addr, &info))
51 tprintf("{lo_number=%d", info.lo_number);
54 tprints(", lo_device=");
55 print_dev_t(info.lo_device);
56 tprintf(", lo_inode=%" PRI_klu, (kernel_ulong_t) info.lo_inode);
57 tprints(", lo_rdevice=");
58 print_dev_t(info.lo_rdevice);
61 tprintf(", lo_offset=%#x", info.lo_offset);
63 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
64 tprints(", lo_encrypt_type=");
65 printxval(loop_crypt_type_options, info.lo_encrypt_type,
68 * It is converted to unsigned before use in kernel, see
69 * loop_info64_from_old in drivers/block/loop.c
71 tprintf(", lo_encrypt_key_size=%" PRIu32,
72 (uint32_t) info.lo_encrypt_key_size);
75 tprints(", lo_flags=");
76 printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
78 tprints(", lo_name=");
79 print_quoted_string(info.lo_name, LO_NAME_SIZE,
82 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
83 tprints(", lo_encrypt_key=");
84 print_quoted_string((void *) info.lo_encrypt_key,
85 MIN((uint32_t) info.lo_encrypt_key_size,
90 tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]"
91 ", reserved=[%#hhx, %#hhx, %#hhx, %#hhx]}",
92 (kernel_ulong_t) info.lo_init[0],
93 (kernel_ulong_t) info.lo_init[1],
94 info.reserved[0], info.reserved[1],
95 info.reserved[2], info.reserved[3]);
101 decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr)
103 struct loop_info64 info64;
106 if (umove_or_printaddr(tcp, addr, &info64))
110 tprints("{lo_device=");
111 print_dev_t(info64.lo_device);
112 tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode);
113 tprints(", lo_rdevice=");
114 print_dev_t(info64.lo_rdevice);
115 tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64
116 ", lo_number=%" PRIu32,
117 (uint64_t) info64.lo_offset,
118 (uint64_t) info64.lo_sizelimit,
119 (uint32_t) info64.lo_number);
121 tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32,
122 (uint64_t) info64.lo_offset,
123 (uint32_t) info64.lo_number);
126 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
127 tprints(", lo_encrypt_type=");
128 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
130 tprintf(", lo_encrypt_key_size=%" PRIu32,
131 info64.lo_encrypt_key_size);
134 tprints(", lo_flags=");
135 printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
137 tprints(", lo_file_name=");
138 print_quoted_string((void *) info64.lo_file_name,
139 LO_NAME_SIZE, QUOTE_0_TERMINATED);
141 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
142 tprints(", lo_crypt_name=");
143 print_quoted_string((void *) info64.lo_crypt_name,
144 LO_NAME_SIZE, QUOTE_0_TERMINATED);
145 tprints(", lo_encrypt_key=");
146 print_quoted_string((void *) info64.lo_encrypt_key,
147 MIN(info64.lo_encrypt_key_size,
152 tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}",
153 (uint64_t) info64.lo_init[0],
154 (uint64_t) info64.lo_init[1]);
159 MPERS_PRINTER_DECL(int, loop_ioctl,
160 struct tcb *tcp, const unsigned int code,
161 const kernel_ulong_t arg)
164 case LOOP_GET_STATUS:
168 case LOOP_SET_STATUS:
169 decode_loop_info(tcp, arg);
172 case LOOP_GET_STATUS64:
176 case LOOP_SET_STATUS64:
177 decode_loop_info64(tcp, arg);
181 case LOOP_SET_CAPACITY:
182 /* newer loop-control stuff */
183 case LOOP_CTL_GET_FREE:
184 /* Takes no arguments */
193 /* newer loop-control stuff */
195 case LOOP_CTL_REMOVE:
196 tprintf(", %d", (int) arg);
199 case LOOP_SET_DIRECT_IO:
200 tprintf(", %" PRI_klu, arg);
207 return RVAL_DECODED | 1;