]> granicus.if.org Git - strace/blob - loop.c
loop: mpersify struct loop_info and loop_ioctl function
[strace] / loop.c
1 /*
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 #include <linux/ioctl.h>
30 #include <linux/loop.h>
31
32 typedef struct loop_info struct_loop_info;
33
34 #include DEF_MPERS_TYPE(struct_loop_info)
35
36 #include MPERS_DEFS
37
38 #include "xlat/loop_flags_options.h"
39 #include "xlat/loop_crypt_type_options.h"
40
41 static void
42 decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr)
43 {
44         struct_loop_info info;
45
46         tprints(", ");
47         if (umove_or_printaddr(tcp, addr, &info))
48                 return;
49
50         tprintf("{lo_number=%d", info.lo_number);
51
52         if (!abbrev(tcp)) {
53                 tprints(", lo_device=");
54                 print_dev_t(info.lo_device);
55                 tprintf(", lo_inode=%" PRI_klu, (kernel_ulong_t) info.lo_inode);
56                 tprints(", lo_rdevice=");
57                 print_dev_t(info.lo_rdevice);
58         }
59
60         tprintf(", lo_offset=%#x", info.lo_offset);
61
62         if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
63                 tprints(", lo_encrypt_type=");
64                 printxval(loop_crypt_type_options, info.lo_encrypt_type,
65                         "LO_CRYPT_???");
66                 tprintf(", lo_encrypt_key_size=%d", info.lo_encrypt_key_size);
67         }
68
69         tprints(", lo_flags=");
70         printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
71
72         tprints(", lo_name=");
73         print_quoted_string(info.lo_name, LO_NAME_SIZE,
74                             QUOTE_0_TERMINATED);
75
76         if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
77                 tprints(", lo_encrypt_key=");
78                 print_quoted_string((void *) info.lo_encrypt_key,
79                                     LO_KEY_SIZE, 0);
80         }
81
82         if (!abbrev(tcp))
83                 tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]"
84                         ", reserved=[%#x, %#x, %#x, %#x]}",
85                         (kernel_ulong_t) info.lo_init[0],
86                         (kernel_ulong_t) info.lo_init[1],
87                         info.reserved[0], info.reserved[1],
88                         info.reserved[2], info.reserved[3]);
89         else
90                 tprints(", ...}");
91 }
92
93 static void
94 decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr)
95 {
96         struct loop_info64 info64;
97
98         tprints(", ");
99         if (umove_or_printaddr(tcp, addr, &info64))
100                 return;
101
102         if (!abbrev(tcp)) {
103                 tprints("{lo_device=");
104                 print_dev_t(info64.lo_device);
105                 tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode);
106                 tprints(", lo_rdevice=");
107                 print_dev_t(info64.lo_rdevice);
108                 tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64
109                         ", lo_number=%" PRIu32,
110                         (uint64_t) info64.lo_offset,
111                         (uint64_t) info64.lo_sizelimit,
112                         (uint32_t) info64.lo_number);
113         } else {
114                 tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32,
115                         (uint64_t) info64.lo_offset,
116                         (uint32_t) info64.lo_number);
117         }
118
119         if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
120                 tprints(", lo_encrypt_type=");
121                 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
122                         "LO_CRYPT_???");
123                 tprintf(", lo_encrypt_key_size=%" PRIu32,
124                         info64.lo_encrypt_key_size);
125         }
126
127         tprints(", lo_flags=");
128         printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
129
130         tprints(", lo_file_name=");
131         print_quoted_string((void *) info64.lo_file_name,
132                             LO_NAME_SIZE, QUOTE_0_TERMINATED);
133
134         if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
135                 tprints(", lo_crypt_name=");
136                 print_quoted_string((void *) info64.lo_crypt_name,
137                                     LO_NAME_SIZE, QUOTE_0_TERMINATED);
138                 tprints(", lo_encrypt_key=");
139                 print_quoted_string((void *) info64.lo_encrypt_key,
140                                     LO_KEY_SIZE, 0);
141         }
142
143         if (!abbrev(tcp))
144                 tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}",
145                         (uint64_t) info64.lo_init[0],
146                         (uint64_t) info64.lo_init[1]);
147         else
148                 tprints(", ...}");
149 }
150
151 MPERS_PRINTER_DECL(int, loop_ioctl,
152                    struct tcb *tcp, const unsigned int code,
153                    const kernel_ulong_t arg)
154 {
155         if (!verbose(tcp))
156                 return RVAL_DECODED;
157
158         switch (code) {
159         case LOOP_GET_STATUS:
160                 if (entering(tcp))
161                         return 0;
162                 /* fall through */
163         case LOOP_SET_STATUS:
164                 decode_loop_info(tcp, arg);
165                 break;
166
167         case LOOP_GET_STATUS64:
168                 if (entering(tcp))
169                         return 0;
170                 /* fall through */
171         case LOOP_SET_STATUS64:
172                 decode_loop_info64(tcp, arg);
173                 break;
174
175         case LOOP_CLR_FD:
176 #ifdef LOOP_SET_CAPACITY
177         case LOOP_SET_CAPACITY:
178 #endif
179 #ifdef LOOP_CTL_GET_FREE
180         /* newer loop-control stuff */
181         case LOOP_CTL_GET_FREE:
182 #endif
183                 /* Takes no arguments */
184                 break;
185
186         case LOOP_SET_FD:
187         case LOOP_CHANGE_FD:
188                 tprints(", ");
189                 printfd(tcp, arg);
190                 break;
191
192 #ifdef LOOP_CTL_ADD
193         /* newer loop-control stuff */
194         case LOOP_CTL_ADD:
195         case LOOP_CTL_REMOVE:
196                 tprintf(", %d", (int) arg);
197                 break;
198 #endif
199
200 #ifdef LOOP_SET_DIRECT_IO
201         case LOOP_SET_DIRECT_IO:
202                 tprintf(", %" PRI_klu, arg);
203                 break;
204 #endif
205
206         default:
207                 return RVAL_DECODED;
208         }
209
210         return RVAL_DECODED | 1;
211 }