blob: 20145b0d3a6c7b1bef401f015f6d80e7b559ec7c [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
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000034#include "xlat/loop_flags_options.h"
Mike Frysingerebee04c2012-04-17 22:19:31 -040035
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000036#include "xlat/loop_crypt_type_options.h"
Mike Frysingerebee04c2012-04-17 22:19:31 -040037
38int loop_ioctl(struct tcb *tcp, long code, long arg)
39{
40 struct loop_info info;
41 struct loop_info64 info64;
42 char *s = alloca((LO_NAME_SIZE + LO_KEY_SIZE) * 4);
43
44 if (entering(tcp))
45 return 0;
46
47 switch (code) {
48
49 case LOOP_SET_STATUS:
50 case LOOP_GET_STATUS:
51 if (!verbose(tcp) || umove(tcp, arg, &info) < 0)
52 return 0;
53
Denys Vlasenko318a2732012-05-16 12:29:09 +020054 tprintf(", {number=%d", info.lo_number);
Mike Frysingerebee04c2012-04-17 22:19:31 -040055
56 if (!abbrev(tcp)) {
57 tprintf(", device=%#lx, inode=%lu, rdevice=%#lx",
58 (unsigned long) info.lo_device,
59 info.lo_inode,
60 (unsigned long) info.lo_rdevice);
61 }
62
63 tprintf(", offset=%#x", info.lo_offset);
64
65 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
66 tprints(", encrypt_type=");
67 printxval(loop_crypt_type_options, info.lo_encrypt_type,
68 "LO_CRYPT_???");
Denys Vlasenko318a2732012-05-16 12:29:09 +020069 tprintf(", encrypt_key_size=%d", info.lo_encrypt_key_size);
Mike Frysingerebee04c2012-04-17 22:19:31 -040070 }
71
72 tprints(", flags=");
73 printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
74
75 string_quote(info.lo_name, s, -1, LO_NAME_SIZE);
76 tprintf(", name=%s", s);
77
78 if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
79 string_quote((void *) info.lo_encrypt_key, s, 0, LO_KEY_SIZE);
80 tprintf(", encrypt_key=%s", s);
81 }
82
83 if (!abbrev(tcp))
84 tprintf(", init={%#lx, %#lx}"
85 ", reserved={%#x, %#x, %#x, %#x}}",
86 info.lo_init[0], info.lo_init[1],
87 info.reserved[0], info.reserved[1],
88 info.reserved[2], info.reserved[3]);
89 else
90 tprints(", ...}");
91
92 return 1;
93
94 case LOOP_SET_STATUS64:
95 case LOOP_GET_STATUS64:
96 if (!verbose(tcp) || umove(tcp, arg, &info64) < 0)
97 return 0;
98
99 tprints(", {");
100
101 if (!abbrev(tcp)) {
102 tprintf("device=%" PRIu64 ", inode=%" PRIu64 ", "
103 "rdevice=%" PRIu64 ", offset=%#" PRIx64 ", "
104 "sizelimit=%" PRIu64 ", number=%" PRIu32,
105 (uint64_t) info64.lo_device,
106 (uint64_t) info64.lo_inode,
107 (uint64_t) info64.lo_rdevice,
108 (uint64_t) info64.lo_offset,
109 (uint64_t) info64.lo_sizelimit,
110 (uint32_t) info64.lo_number);
111 } else {
112 tprintf("offset=%#" PRIx64 ", number=%" PRIu32,
113 (uint64_t) info64.lo_offset,
114 (uint32_t) info64.lo_number);
115 }
116
117 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
118 tprints(", encrypt_type=");
119 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
120 "LO_CRYPT_???");
121 tprintf(", encrypt_key_size=%" PRIu32,
122 info64.lo_encrypt_key_size);
123 }
124
125 tprints(", flags=");
126 printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
127
128 string_quote((void *) info64.lo_file_name, s, -1, LO_NAME_SIZE);
129 tprintf(", file_name=%s", s);
130
131 if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
132 string_quote((void *) info64.lo_crypt_name, s, -1, LO_NAME_SIZE);
133 tprintf(", crypt_name=%s", s);
134 string_quote((void *) info64.lo_encrypt_key, s, 0, LO_KEY_SIZE);
135 tprintf(", encrypt_key=%s", s);
136 }
137
138 if (!abbrev(tcp))
139 tprintf(", init={%#" PRIx64 ", %#" PRIx64 "}}",
140 (uint64_t) info64.lo_init[0],
141 (uint64_t) info64.lo_init[1]);
142 else
143 tprints(", ...}");
144
145 return 1;
146
147 case LOOP_CLR_FD:
Dmitry V. Levincf050db2012-05-02 10:21:49 +0000148#ifdef LOOP_SET_CAPACITY
Mike Frysingerebee04c2012-04-17 22:19:31 -0400149 case LOOP_SET_CAPACITY:
Dmitry V. Levincf050db2012-05-02 10:21:49 +0000150#endif
Mike Frysingerebee04c2012-04-17 22:19:31 -0400151#ifdef LOOP_CTL_GET_FREE
152 /* newer loop-control stuff */
153 case LOOP_CTL_GET_FREE:
154#endif
155 /* Takes no arguments */
156 return 1;
157
158 case LOOP_SET_FD:
159 case LOOP_CHANGE_FD:
160#ifdef LOOP_CTL_ADD
161 /* newer loop-control stuff */
162 case LOOP_CTL_ADD:
163 case LOOP_CTL_REMOVE:
164#endif
165 /* These take simple args, so let default printer handle it */
166
167 default:
168 return 0;
169 }
170}