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,
89 tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]"
90 ", reserved=[%#hhx, %#hhx, %#hhx, %#hhx]}",
91 (kernel_ulong_t) info.lo_init[0],
92 (kernel_ulong_t) info.lo_init[1],
93 info.reserved[0], info.reserved[1],
94 info.reserved[2], info.reserved[3]);
100 decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr)
102 struct loop_info64 info64;
105 if (umove_or_printaddr(tcp, addr, &info64))
109 tprints("{lo_device=");
110 print_dev_t(info64.lo_device);
111 tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode);
112 tprints(", lo_rdevice=");
113 print_dev_t(info64.lo_rdevice);
114 tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64
115 ", lo_number=%" PRIu32,
116 (uint64_t) info64.lo_offset,
117 (uint64_t) info64.lo_sizelimit,
118 (uint32_t) info64.lo_number);
120 tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32,
121 (uint64_t) info64.lo_offset,
122 (uint32_t) info64.lo_number);
125 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
126 tprints(", lo_encrypt_type=");
127 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
129 tprintf(", lo_encrypt_key_size=%" PRIu32,
130 info64.lo_encrypt_key_size);
133 tprints(", lo_flags=");
134 printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
136 tprints(", lo_file_name=");
137 print_quoted_string((void *) info64.lo_file_name,
138 LO_NAME_SIZE, QUOTE_0_TERMINATED);
140 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
141 tprints(", lo_crypt_name=");
142 print_quoted_string((void *) info64.lo_crypt_name,
143 LO_NAME_SIZE, QUOTE_0_TERMINATED);
144 tprints(", lo_encrypt_key=");
145 print_quoted_string((void *) info64.lo_encrypt_key,
150 tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}",
151 (uint64_t) info64.lo_init[0],
152 (uint64_t) info64.lo_init[1]);
157 MPERS_PRINTER_DECL(int, loop_ioctl,
158 struct tcb *tcp, const unsigned int code,
159 const kernel_ulong_t arg)
165 case LOOP_GET_STATUS:
169 case LOOP_SET_STATUS:
170 decode_loop_info(tcp, arg);
173 case LOOP_GET_STATUS64:
177 case LOOP_SET_STATUS64:
178 decode_loop_info64(tcp, arg);
182 case LOOP_SET_CAPACITY:
183 /* newer loop-control stuff */
184 case LOOP_CTL_GET_FREE:
185 /* Takes no arguments */
194 /* newer loop-control stuff */
196 case LOOP_CTL_REMOVE:
197 tprintf(", %d", (int) arg);
200 case LOOP_SET_DIRECT_IO:
201 tprintf(", %" PRI_klu, arg);
208 return RVAL_DECODED | 1;