]> granicus.if.org Git - strace/blob - loop.c
netlink_sock_diag: print inet_diag_sockid.idiag_if as an interface index
[strace] / loop.c
1 /*
2  * Copyright (c) 2012 The Chromium OS Authors.
3  * Copyright (c) 2012-2017 The strace developers.
4  * Written by Mike Frysinger <vapier@gentoo.org>.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #include "defs.h"
30 #include <linux/ioctl.h>
31 #include <linux/loop.h>
32
33 typedef struct loop_info struct_loop_info;
34
35 #include DEF_MPERS_TYPE(struct_loop_info)
36
37 #include MPERS_DEFS
38
39 #include "xlat/loop_cmds.h"
40 #include "xlat/loop_flags_options.h"
41 #include "xlat/loop_crypt_type_options.h"
42
43 static void
44 decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr)
45 {
46         struct_loop_info info;
47
48         tprints(", ");
49         if (umove_or_printaddr(tcp, addr, &info))
50                 return;
51
52         tprintf("{lo_number=%d", info.lo_number);
53
54         if (!abbrev(tcp)) {
55                 tprints(", lo_device=");
56                 print_dev_t(info.lo_device);
57                 tprintf(", lo_inode=%" PRI_klu, (kernel_ulong_t) info.lo_inode);
58                 tprints(", lo_rdevice=");
59                 print_dev_t(info.lo_rdevice);
60         }
61
62         tprintf(", lo_offset=%#x", info.lo_offset);
63
64         if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
65                 tprints(", lo_encrypt_type=");
66                 printxval(loop_crypt_type_options, info.lo_encrypt_type,
67                         "LO_CRYPT_???");
68                 /*
69                  * It is converted to unsigned before use in kernel, see
70                  * loop_info64_from_old in drivers/block/loop.c
71                  */
72                 tprintf(", lo_encrypt_key_size=%" PRIu32,
73                         (uint32_t) info.lo_encrypt_key_size);
74         }
75
76         tprints(", lo_flags=");
77         printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
78
79         tprints(", lo_name=");
80         print_quoted_string(info.lo_name, LO_NAME_SIZE,
81                             QUOTE_0_TERMINATED);
82
83         if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
84                 tprints(", lo_encrypt_key=");
85                 print_quoted_string((void *) info.lo_encrypt_key,
86                                     MIN((uint32_t) info.lo_encrypt_key_size,
87                                     LO_KEY_SIZE), 0);
88         }
89
90         if (!abbrev(tcp))
91                 tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]"
92                         ", reserved=[%#hhx, %#hhx, %#hhx, %#hhx]}",
93                         (kernel_ulong_t) info.lo_init[0],
94                         (kernel_ulong_t) info.lo_init[1],
95                         info.reserved[0], info.reserved[1],
96                         info.reserved[2], info.reserved[3]);
97         else
98                 tprints(", ...}");
99 }
100
101 static void
102 decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr)
103 {
104         struct loop_info64 info64;
105
106         tprints(", ");
107         if (umove_or_printaddr(tcp, addr, &info64))
108                 return;
109
110         if (!abbrev(tcp)) {
111                 tprints("{lo_device=");
112                 print_dev_t(info64.lo_device);
113                 tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode);
114                 tprints(", lo_rdevice=");
115                 print_dev_t(info64.lo_rdevice);
116                 tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64
117                         ", lo_number=%" PRIu32,
118                         (uint64_t) info64.lo_offset,
119                         (uint64_t) info64.lo_sizelimit,
120                         (uint32_t) info64.lo_number);
121         } else {
122                 tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32,
123                         (uint64_t) info64.lo_offset,
124                         (uint32_t) info64.lo_number);
125         }
126
127         if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
128                 tprints(", lo_encrypt_type=");
129                 printxval(loop_crypt_type_options, info64.lo_encrypt_type,
130                         "LO_CRYPT_???");
131                 tprintf(", lo_encrypt_key_size=%" PRIu32,
132                         info64.lo_encrypt_key_size);
133         }
134
135         tprints(", lo_flags=");
136         printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
137
138         tprints(", lo_file_name=");
139         print_quoted_string((void *) info64.lo_file_name,
140                             LO_NAME_SIZE, QUOTE_0_TERMINATED);
141
142         if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
143                 tprints(", lo_crypt_name=");
144                 print_quoted_string((void *) info64.lo_crypt_name,
145                                     LO_NAME_SIZE, QUOTE_0_TERMINATED);
146                 tprints(", lo_encrypt_key=");
147                 print_quoted_string((void *) info64.lo_encrypt_key,
148                                     MIN(info64.lo_encrypt_key_size,
149                                     LO_KEY_SIZE), 0);
150         }
151
152         if (!abbrev(tcp))
153                 tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}",
154                         (uint64_t) info64.lo_init[0],
155                         (uint64_t) info64.lo_init[1]);
156         else
157                 tprints(", ...}");
158 }
159
160 MPERS_PRINTER_DECL(int, loop_ioctl,
161                    struct tcb *tcp, const unsigned int code,
162                    const kernel_ulong_t arg)
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 }