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