]> granicus.if.org Git - strace/blob - block.c
block.c: fix printing of uint64_t pairs
[strace] / block.c
1 /*
2  * Copyright (c) 2009, 2010 Jeff Mahoney <jeffm@suse.com>
3  * All rights reserved.
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/blkpg.h>
30 #include <linux/fs.h>
31
32 /* ioctls <= 114 are present in Linux 2.4. The following ones have been
33  * added since then and headers containing them may not be available on
34  * every system. */
35
36 #define BLKTRACE_BDEV_SIZE      32
37 struct blk_user_trace_setup {
38         char name[BLKTRACE_BDEV_SIZE];  /* output */
39         uint16_t act_mask;              /* input */
40         uint32_t buf_size;              /* input */
41         uint32_t buf_nr;                /* input */
42         uint64_t start_lba;
43         uint64_t end_lba;
44         uint32_t pid;
45 };
46
47 #ifndef BLKTRACESETUP
48 # define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
49 #endif
50 #ifndef BLKTRACESTART
51 # define BLKTRACESTART _IO(0x12,116)
52 #endif
53 #ifndef BLKTRACESTOP
54 # define BLKTRACESTOP _IO(0x12,117)
55 #endif
56 #ifndef BLKTRACETEARDOWN
57 # define BLKTRACETEARDOWN _IO(0x12,118)
58 #endif
59 #ifndef BLKDISCARD
60 # define BLKDISCARD _IO(0x12,119)
61 #endif
62 #ifndef BLKIOMIN
63 # define BLKIOMIN _IO(0x12,120)
64 #endif
65 #ifndef BLKIOOPT
66 # define BLKIOOPT _IO(0x12,121)
67 #endif
68 #ifndef BLKALIGNOFF
69 # define BLKALIGNOFF _IO(0x12,122)
70 #endif
71 #ifndef BLKPBSZGET
72 # define BLKPBSZGET _IO(0x12,123)
73 #endif
74 #ifndef BLKDISCARDZEROES
75 # define BLKDISCARDZEROES _IO(0x12,124)
76 #endif
77 #ifndef BLKSECDISCARD
78 # define BLKSECDISCARD _IO(0x12,125)
79 #endif
80 #ifndef BLKROTATIONAL
81 # define BLKROTATIONAL _IO(0x12,126)
82 #endif
83 #ifndef BLKZEROOUT
84 # define BLKZEROOUT _IO(0x12,127)
85 #endif
86 #ifndef BLKDAXGET
87 # define BLKDAXGET _IO(0x12,129)
88 #endif
89
90 #include "xlat/blkpg_ops.h"
91
92 static void
93 print_blkpg_req(struct tcb *tcp, const struct blkpg_ioctl_arg *blkpg)
94 {
95         struct blkpg_partition p;
96
97         tprints("{");
98         printxval(blkpg_ops, blkpg->op, "BLKPG_???");
99
100         tprintf(", flags=%d, datalen=%d, data=",
101                 blkpg->flags, blkpg->datalen);
102
103         if (!umove_or_printaddr(tcp, (long) blkpg->data, &p)) {
104                 tprintf("{start=%lld, length=%lld, pno=%d, devname=",
105                         p.start, p.length, p.pno);
106                 print_quoted_string(p.devname, sizeof(p.devname),
107                                     QUOTE_0_TERMINATED);
108                 tprints(", volname=");
109                 print_quoted_string(p.volname, sizeof(p.volname),
110                                     QUOTE_0_TERMINATED);
111                 tprints("}");
112         }
113         tprints("}");
114 }
115
116 int
117 block_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
118 {
119         switch (code) {
120         /* take arg as a value, not as a pointer */
121         case BLKRASET:
122         case BLKFRASET:
123                 tprintf(", %lu", arg);
124                 break;
125
126         /* take a signed int */
127         case BLKROSET:
128         case BLKBSZSET:
129                 tprints(", ");
130                 printnum_int(tcp, arg, "%d");
131                 break;
132
133         /* return an unsigned short */
134         case BLKSECTGET:
135         case BLKROTATIONAL:
136                 if (entering(tcp))
137                         return 0;
138                 tprints(", ");
139                 printnum_short(tcp, arg, "%hu");
140                 break;
141
142         /* return a signed int */
143         case BLKROGET:
144         case BLKBSZGET:
145         case BLKSSZGET:
146         case BLKALIGNOFF:
147         case BLKDAXGET:
148                 if (entering(tcp))
149                         return 0;
150                 tprints(", ");
151                 printnum_int(tcp, arg, "%d");
152                 break;
153
154         /* return an unsigned int */
155         case BLKPBSZGET:
156         case BLKIOMIN:
157         case BLKIOOPT:
158         case BLKDISCARDZEROES:
159                 if (entering(tcp))
160                         return 0;
161                 tprints(", ");
162                 printnum_int(tcp, arg, "%u");
163                 break;
164
165         /* return a signed long */
166         case BLKRAGET:
167         case BLKFRAGET:
168                 if (entering(tcp))
169                         return 0;
170                 tprints(", ");
171                 printnum_slong(tcp, arg);
172                 break;
173
174         /* returns an unsigned long */
175         case BLKGETSIZE:
176                 if (entering(tcp))
177                         return 0;
178                 tprints(", ");
179                 printnum_ulong(tcp, arg);
180                 break;
181
182 #ifdef HAVE_BLKGETSIZE64
183         /* returns an uint64_t */
184         case BLKGETSIZE64:
185                 if (entering(tcp))
186                         return 0;
187                 tprints(", ");
188                 printnum_int64(tcp, arg, "%" PRIu64);
189                 break;
190 #endif
191
192         /* takes a pair of uint64_t */
193         case BLKDISCARD:
194         case BLKSECDISCARD:
195         case BLKZEROOUT:
196                 tprints(", ");
197                 printpair_int64(tcp, arg, "%" PRIu64);
198                 break;
199
200         /* More complex types */
201         case BLKPG: {
202                 struct blkpg_ioctl_arg blkpg;
203
204                 tprints(", ");
205                 if (!umove_or_printaddr(tcp, arg, &blkpg))
206                         print_blkpg_req(tcp, &blkpg);
207                 break;
208         }
209
210         case BLKTRACESETUP:
211                 if (entering(tcp)) {
212                         struct blk_user_trace_setup buts;
213
214                         tprints(", ");
215                         if (umove_or_printaddr(tcp, arg, &buts))
216                                 break;
217                         tprintf("{act_mask=%u, buf_size=%u, "
218                                 "buf_nr=%u, start_lba=%" PRIu64 ", "
219                                 "end_lba=%" PRIu64 ", pid=%u",
220                                 (unsigned)buts.act_mask, buts.buf_size,
221                                 buts.buf_nr, buts.start_lba,
222                                 buts.end_lba, buts.pid);
223                         return 1;
224                 } else {
225                         struct blk_user_trace_setup buts;
226
227                         if (!syserror(tcp) && !umove(tcp, arg, &buts)) {
228                                 tprints(", name=");
229                                 print_quoted_string(buts.name, sizeof(buts.name),
230                                                     QUOTE_0_TERMINATED);
231                         }
232                         tprints("}");
233                         break;
234                 }
235
236         /* No arguments */
237         case BLKRRPART:
238         case BLKFLSBUF:
239         case BLKTRACESTART:
240         case BLKTRACESTOP:
241         case BLKTRACETEARDOWN:
242                 break;
243         default:
244                 return RVAL_DECODED;
245         }
246
247         return RVAL_DECODED | 1;
248 }