blob: a350135491d7d7be52c9469549cc44602b78569c [file] [log] [blame]
Mike Frysingerebee04c2012-04-17 22:19:31 -04001/*
2 * Copyright (c) 2012 The Chromium OS Authors.
3 * Written by Mike Frysinger <vapier@gentoo.org>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
15 *
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.
26 */
27
28#include "defs.h"
29
30#include <sys/ioctl.h>
31
32#include <linux/loop.h>
33
34static const struct xlat loop_flags_options[] = {
35 { LO_FLAGS_READ_ONLY, "LO_FLAGS_READ_ONLY" },
36 { LO_FLAGS_AUTOCLEAR, "LO_FLAGS_AUTOCLEAR" },
37#ifdef LO_FLAGS_PARTSCAN
38 { LO_FLAGS_PARTSCAN, "LO_FLAGS_PARTSCAN" },
39#endif
40 { 0, NULL },
41};
42
43static const struct xlat loop_crypt_type_options[] = {
44 { LO_CRYPT_NONE, "LO_CRYPT_NONE" },
45 { LO_CRYPT_XOR, "LO_CRYPT_XOR" },
46 { LO_CRYPT_DES, "LO_CRYPT_DES" },
47 { LO_CRYPT_FISH2, "LO_CRYPT_FISH2" },
48 { LO_CRYPT_BLOW, "LO_CRYPT_BLOW" },
49 { LO_CRYPT_CAST128, "LO_CRYPT_CAST128" },
50 { LO_CRYPT_IDEA, "LO_CRYPT_IDEA" },
51 { LO_CRYPT_DUMMY, "LO_CRYPT_DUMMY" },
52 { LO_CRYPT_SKIPJACK, "LO_CRYPT_SKIPJACK" },
53 { LO_CRYPT_CRYPTOAPI, "LO_CRYPT_CRYPTOAPI" },
54 { 0, NULL },
55};
56
57int loop_ioctl(struct tcb *tcp, long code, long arg)
58{
59 struct loop_info info;
60 struct loop_info64 info64;
61 char *s = alloca((LO_NAME_SIZE + LO_KEY_SIZE) * 4);
62
63 if (entering(tcp))
64 return 0;
65
66 switch (code) {
67
68 case LOOP_SET_STATUS:
69 case LOOP_GET_STATUS:
70 if (!verbose(tcp) || umove(tcp, arg, &info) < 0)
71 return 0;
72
73 tprintf(", {number=%i", info.lo_number);
74
75 if (!abbrev(tcp)) {
76 tprintf(", device=%#lx, inode=%lu, rdevice=%#lx",
77 (unsigned long) info.lo_device,
78 info.lo_inode,
79 (unsigned long) info.lo_rdevice);
80 }
81
82 tprintf(", offset=%#x", info.lo_offset);
83
84 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
85 tprints(", encrypt_type=");
86 printxval(loop_crypt_type_options, info.lo_encrypt_type,
87 "LO_CRYPT_???");
88 tprintf(", encrypt_key_size=%i", info.lo_encrypt_key_size);
89 }
90
91 tprints(", flags=");
92 printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
93
94 string_quote(info.lo_name, s, -1, LO_NAME_SIZE);
95 tprintf(", name=%s", s);
96
97 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
98 string_quote((void *) info.lo_encrypt_key, s, 0, LO_KEY_SIZE);
99 tprintf(", encrypt_key=%s", s);
100 }
101
102 if (!abbrev(tcp))
103 tprintf(", init={%#lx, %#lx}"
104 ", reserved={%#x, %#x, %#x, %#x}}",
105 info.lo_init[0], info.lo_init[1],
106 info.reserved[0], info.reserved[1],
107 info.reserved[2], info.reserved[3]);
108 else
109 tprints(", ...}");
110
111 return 1;
112
113 case LOOP_SET_STATUS64:
114 case LOOP_GET_STATUS64:
115 if (!verbose(tcp) || umove(tcp, arg, &info64) < 0)
116 return 0;
117
118 tprints(", {");
119
120 if (!abbrev(tcp)) {
121 tprintf("device=%" PRIu64 ", inode=%" PRIu64 ", "
122 "rdevice=%" PRIu64 ", offset=%#" PRIx64 ", "
123 "sizelimit=%" PRIu64 ", number=%" PRIu32,
124 (uint64_t) info64.lo_device,
125 (uint64_t) info64.lo_inode,
126 (uint64_t) info64.lo_rdevice,
127 (uint64_t) info64.lo_offset,
128 (uint64_t) info64.lo_sizelimit,
129 (uint32_t) info64.lo_number);
130 } else {
131 tprintf("offset=%#" PRIx64 ", number=%" PRIu32,
132 (uint64_t) info64.lo_offset,
133 (uint32_t) info64.lo_number);
134 }
135
136 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
137 tprints(", encrypt_type=");
138 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
139 "LO_CRYPT_???");
140 tprintf(", encrypt_key_size=%" PRIu32,
141 info64.lo_encrypt_key_size);
142 }
143
144 tprints(", flags=");
145 printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
146
147 string_quote((void *) info64.lo_file_name, s, -1, LO_NAME_SIZE);
148 tprintf(", file_name=%s", s);
149
150 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
151 string_quote((void *) info64.lo_crypt_name, s, -1, LO_NAME_SIZE);
152 tprintf(", crypt_name=%s", s);
153 string_quote((void *) info64.lo_encrypt_key, s, 0, LO_KEY_SIZE);
154 tprintf(", encrypt_key=%s", s);
155 }
156
157 if (!abbrev(tcp))
158 tprintf(", init={%#" PRIx64 ", %#" PRIx64 "}}",
159 (uint64_t) info64.lo_init[0],
160 (uint64_t) info64.lo_init[1]);
161 else
162 tprints(", ...}");
163
164 return 1;
165
166 case LOOP_CLR_FD:
167 case LOOP_SET_CAPACITY:
168#ifdef LOOP_CTL_GET_FREE
169 /* newer loop-control stuff */
170 case LOOP_CTL_GET_FREE:
171#endif
172 /* Takes no arguments */
173 return 1;
174
175 case LOOP_SET_FD:
176 case LOOP_CHANGE_FD:
177#ifdef LOOP_CTL_ADD
178 /* newer loop-control stuff */
179 case LOOP_CTL_ADD:
180 case LOOP_CTL_REMOVE:
181#endif
182 /* These take simple args, so let default printer handle it */
183
184 default:
185 return 0;
186 }
187}