blob: 83d91527ea258a118054d2366d67e462b2ee7f45 [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" },
Dmitry V. Levincf050db2012-05-02 10:21:49 +000036#if HAVE_DECL_LO_FLAGS_AUTOCLEAR
Mike Frysingerebee04c2012-04-17 22:19:31 -040037 { LO_FLAGS_AUTOCLEAR, "LO_FLAGS_AUTOCLEAR" },
Dmitry V. Levincf050db2012-05-02 10:21:49 +000038#endif
39#if HAVE_DECL_LO_FLAGS_PARTSCAN
Mike Frysingerebee04c2012-04-17 22:19:31 -040040 { LO_FLAGS_PARTSCAN, "LO_FLAGS_PARTSCAN" },
41#endif
42 { 0, NULL },
43};
44
45static const struct xlat loop_crypt_type_options[] = {
46 { LO_CRYPT_NONE, "LO_CRYPT_NONE" },
47 { LO_CRYPT_XOR, "LO_CRYPT_XOR" },
48 { LO_CRYPT_DES, "LO_CRYPT_DES" },
49 { LO_CRYPT_FISH2, "LO_CRYPT_FISH2" },
50 { LO_CRYPT_BLOW, "LO_CRYPT_BLOW" },
51 { LO_CRYPT_CAST128, "LO_CRYPT_CAST128" },
52 { LO_CRYPT_IDEA, "LO_CRYPT_IDEA" },
53 { LO_CRYPT_DUMMY, "LO_CRYPT_DUMMY" },
54 { LO_CRYPT_SKIPJACK, "LO_CRYPT_SKIPJACK" },
55 { LO_CRYPT_CRYPTOAPI, "LO_CRYPT_CRYPTOAPI" },
56 { 0, NULL },
57};
58
59int loop_ioctl(struct tcb *tcp, long code, long arg)
60{
61 struct loop_info info;
62 struct loop_info64 info64;
63 char *s = alloca((LO_NAME_SIZE + LO_KEY_SIZE) * 4);
64
65 if (entering(tcp))
66 return 0;
67
68 switch (code) {
69
70 case LOOP_SET_STATUS:
71 case LOOP_GET_STATUS:
72 if (!verbose(tcp) || umove(tcp, arg, &info) < 0)
73 return 0;
74
75 tprintf(", {number=%i", info.lo_number);
76
77 if (!abbrev(tcp)) {
78 tprintf(", device=%#lx, inode=%lu, rdevice=%#lx",
79 (unsigned long) info.lo_device,
80 info.lo_inode,
81 (unsigned long) info.lo_rdevice);
82 }
83
84 tprintf(", offset=%#x", info.lo_offset);
85
86 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
87 tprints(", encrypt_type=");
88 printxval(loop_crypt_type_options, info.lo_encrypt_type,
89 "LO_CRYPT_???");
90 tprintf(", encrypt_key_size=%i", info.lo_encrypt_key_size);
91 }
92
93 tprints(", flags=");
94 printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
95
96 string_quote(info.lo_name, s, -1, LO_NAME_SIZE);
97 tprintf(", name=%s", s);
98
99 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
100 string_quote((void *) info.lo_encrypt_key, s, 0, LO_KEY_SIZE);
101 tprintf(", encrypt_key=%s", s);
102 }
103
104 if (!abbrev(tcp))
105 tprintf(", init={%#lx, %#lx}"
106 ", reserved={%#x, %#x, %#x, %#x}}",
107 info.lo_init[0], info.lo_init[1],
108 info.reserved[0], info.reserved[1],
109 info.reserved[2], info.reserved[3]);
110 else
111 tprints(", ...}");
112
113 return 1;
114
115 case LOOP_SET_STATUS64:
116 case LOOP_GET_STATUS64:
117 if (!verbose(tcp) || umove(tcp, arg, &info64) < 0)
118 return 0;
119
120 tprints(", {");
121
122 if (!abbrev(tcp)) {
123 tprintf("device=%" PRIu64 ", inode=%" PRIu64 ", "
124 "rdevice=%" PRIu64 ", offset=%#" PRIx64 ", "
125 "sizelimit=%" PRIu64 ", number=%" PRIu32,
126 (uint64_t) info64.lo_device,
127 (uint64_t) info64.lo_inode,
128 (uint64_t) info64.lo_rdevice,
129 (uint64_t) info64.lo_offset,
130 (uint64_t) info64.lo_sizelimit,
131 (uint32_t) info64.lo_number);
132 } else {
133 tprintf("offset=%#" PRIx64 ", number=%" PRIu32,
134 (uint64_t) info64.lo_offset,
135 (uint32_t) info64.lo_number);
136 }
137
138 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
139 tprints(", encrypt_type=");
140 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
141 "LO_CRYPT_???");
142 tprintf(", encrypt_key_size=%" PRIu32,
143 info64.lo_encrypt_key_size);
144 }
145
146 tprints(", flags=");
147 printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
148
149 string_quote((void *) info64.lo_file_name, s, -1, LO_NAME_SIZE);
150 tprintf(", file_name=%s", s);
151
152 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
153 string_quote((void *) info64.lo_crypt_name, s, -1, LO_NAME_SIZE);
154 tprintf(", crypt_name=%s", s);
155 string_quote((void *) info64.lo_encrypt_key, s, 0, LO_KEY_SIZE);
156 tprintf(", encrypt_key=%s", s);
157 }
158
159 if (!abbrev(tcp))
160 tprintf(", init={%#" PRIx64 ", %#" PRIx64 "}}",
161 (uint64_t) info64.lo_init[0],
162 (uint64_t) info64.lo_init[1]);
163 else
164 tprints(", ...}");
165
166 return 1;
167
168 case LOOP_CLR_FD:
Dmitry V. Levincf050db2012-05-02 10:21:49 +0000169#ifdef LOOP_SET_CAPACITY
Mike Frysingerebee04c2012-04-17 22:19:31 -0400170 case LOOP_SET_CAPACITY:
Dmitry V. Levincf050db2012-05-02 10:21:49 +0000171#endif
Mike Frysingerebee04c2012-04-17 22:19:31 -0400172#ifdef LOOP_CTL_GET_FREE
173 /* newer loop-control stuff */
174 case LOOP_CTL_GET_FREE:
175#endif
176 /* Takes no arguments */
177 return 1;
178
179 case LOOP_SET_FD:
180 case LOOP_CHANGE_FD:
181#ifdef LOOP_CTL_ADD
182 /* newer loop-control stuff */
183 case LOOP_CTL_ADD:
184 case LOOP_CTL_REMOVE:
185#endif
186 /* These take simple args, so let default printer handle it */
187
188 default:
189 return 0;
190 }
191}