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