2 * Copyright (c) 2012 The Chromium OS Authors.
3 * Copyright (c) 2012-2017 The strace developers.
4 * Written by Mike Frysinger <vapier@gentoo.org>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <linux/ioctl.h>
31 #include <linux/loop.h>
33 typedef struct loop_info struct_loop_info;
35 #include DEF_MPERS_TYPE(struct_loop_info)
39 #include "xlat/loop_cmds.h"
40 #include "xlat/loop_flags_options.h"
41 #include "xlat/loop_crypt_type_options.h"
44 decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr)
46 struct_loop_info info;
49 if (umove_or_printaddr(tcp, addr, &info))
52 tprintf("{lo_number=%d", info.lo_number);
55 tprints(", lo_device=");
56 print_dev_t(info.lo_device);
57 tprintf(", lo_inode=%" PRI_klu, (kernel_ulong_t) info.lo_inode);
58 tprints(", lo_rdevice=");
59 print_dev_t(info.lo_rdevice);
62 tprintf(", lo_offset=%#x", info.lo_offset);
64 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
65 tprints(", lo_encrypt_type=");
66 printxval(loop_crypt_type_options, info.lo_encrypt_type,
69 * It is converted to unsigned before use in kernel, see
70 * loop_info64_from_old in drivers/block/loop.c
72 tprintf(", lo_encrypt_key_size=%" PRIu32,
73 (uint32_t) info.lo_encrypt_key_size);
76 tprints(", lo_flags=");
77 printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
79 tprints(", lo_name=");
80 print_quoted_string(info.lo_name, LO_NAME_SIZE,
83 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
84 tprints(", lo_encrypt_key=");
85 print_quoted_string((void *) info.lo_encrypt_key,
86 MIN((uint32_t) info.lo_encrypt_key_size,
91 tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]"
92 ", reserved=[%#hhx, %#hhx, %#hhx, %#hhx]}",
93 (kernel_ulong_t) info.lo_init[0],
94 (kernel_ulong_t) info.lo_init[1],
95 info.reserved[0], info.reserved[1],
96 info.reserved[2], info.reserved[3]);
102 decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr)
104 struct loop_info64 info64;
107 if (umove_or_printaddr(tcp, addr, &info64))
111 tprints("{lo_device=");
112 print_dev_t(info64.lo_device);
113 tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode);
114 tprints(", lo_rdevice=");
115 print_dev_t(info64.lo_rdevice);
116 tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64
117 ", lo_number=%" PRIu32,
118 (uint64_t) info64.lo_offset,
119 (uint64_t) info64.lo_sizelimit,
120 (uint32_t) info64.lo_number);
122 tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32,
123 (uint64_t) info64.lo_offset,
124 (uint32_t) info64.lo_number);
127 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
128 tprints(", lo_encrypt_type=");
129 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
131 tprintf(", lo_encrypt_key_size=%" PRIu32,
132 info64.lo_encrypt_key_size);
135 tprints(", lo_flags=");
136 printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
138 tprints(", lo_file_name=");
139 print_quoted_string((void *) info64.lo_file_name,
140 LO_NAME_SIZE, QUOTE_0_TERMINATED);
142 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
143 tprints(", lo_crypt_name=");
144 print_quoted_string((void *) info64.lo_crypt_name,
145 LO_NAME_SIZE, QUOTE_0_TERMINATED);
146 tprints(", lo_encrypt_key=");
147 print_quoted_string((void *) info64.lo_encrypt_key,
148 MIN(info64.lo_encrypt_key_size,
153 tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}",
154 (uint64_t) info64.lo_init[0],
155 (uint64_t) info64.lo_init[1]);
160 MPERS_PRINTER_DECL(int, loop_ioctl,
161 struct tcb *tcp, const unsigned int code,
162 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;