blob: 93fb52631c55af33f638fb5fdcec7522fa4c2f7d [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkermanc6c1ea52001-08-03 21:52:13 +00005 * Copyright (c) 1996-2001 Wichert Akkerman <wichert@cistron.nl>
Elliott Hughes28e98bc2018-06-14 16:59:04 -07006 * Copyright (c) 1999-2018 The strace developers.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00007 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000030 */
31
32#include "defs.h"
Felix Janda3460dc42015-03-28 18:40:13 +010033#include <linux/ioctl.h>
Dmitry V. Levin924996a2015-01-20 00:24:36 +000034#include "xlat/ioctl_dirs.h"
Wichert Akkermana9667852001-03-17 17:26:34 +000035
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010036#include "xlat/evdev_ev.h"
37
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038static int
Denys Vlasenko12014262011-05-30 14:00:14 +020039compare(const void *a, const void *b)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040{
Elliott Hughesd35df492017-02-15 15:19:05 -080041 const unsigned int code1 = (const uintptr_t) a;
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000042 const unsigned int code2 = ((struct_ioctlent *) b)->code;
Denys Vlasenkofeb40c42012-03-20 13:11:51 +010043 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044}
45
Dmitry V. Levin044eef22015-07-02 21:37:23 +000046static const struct_ioctlent *
Dmitry V. Levindf7aa2b2015-01-19 17:02:16 +000047ioctl_lookup(const unsigned int code)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048{
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010049 struct_ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050
Elliott Hughesd35df492017-02-15 15:19:05 -080051 iop = bsearch((const void *) (const uintptr_t) code, ioctlent,
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010052 nioctlents, sizeof(ioctlent[0]), compare);
53 while (iop > ioctlent) {
54 iop--;
55 if (iop->code != code) {
Roland McGrath2843a4e2003-11-14 02:54:03 +000056 iop++;
57 break;
58 }
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010059 }
Roland McGrath2843a4e2003-11-14 02:54:03 +000060 return iop;
61}
62
Dmitry V. Levin044eef22015-07-02 21:37:23 +000063static const struct_ioctlent *
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010064ioctl_next_match(const struct_ioctlent *iop)
Roland McGrath2843a4e2003-11-14 02:54:03 +000065{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000066 const unsigned int code = iop->code;
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010067 iop++;
Roland McGrath2843a4e2003-11-14 02:54:03 +000068 if (iop < ioctlent + nioctlents && iop->code == code)
69 return iop;
70 return NULL;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000071}
72
Dmitry V. Levin044eef22015-07-02 21:37:23 +000073static void
Dmitry V. Levin924996a2015-01-20 00:24:36 +000074ioctl_print_code(const unsigned int code)
75{
76 tprints("_IOC(");
77 printflags(ioctl_dirs, _IOC_DIR(code), "_IOC_???");
Elliott Hughesd35df492017-02-15 15:19:05 -080078 tprintf(", %#x, %#x, %#x)",
Dmitry V. Levin924996a2015-01-20 00:24:36 +000079 _IOC_TYPE(code), _IOC_NR(code), _IOC_SIZE(code));
80}
81
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010082static int
Dmitry V. Levin2803e752015-07-02 22:23:53 +000083evdev_decode_number(const unsigned int code)
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010084{
Dmitry V. Levin2803e752015-07-02 22:23:53 +000085 const unsigned int nr = _IOC_NR(code);
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010086
Dmitry V. Levin2803e752015-07-02 22:23:53 +000087 if (_IOC_DIR(code) == _IOC_WRITE) {
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010088 if (nr >= 0xc0 && nr <= 0xc0 + 0x3f) {
89 tprints("EVIOCSABS(");
Elliott Hughes03a418e2018-06-15 13:11:40 -070090 printxval_indexn(evdev_abs, evdev_abs_size, nr - 0xc0,
91 "ABS_???");
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010092 tprints(")");
93 return 1;
94 }
95 }
96
Dmitry V. Levin2803e752015-07-02 22:23:53 +000097 if (_IOC_DIR(code) != _IOC_READ)
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +010098 return 0;
99
100 if (nr >= 0x20 && nr <= 0x20 + 0x1f) {
101 tprints("EVIOCGBIT(");
102 printxval(evdev_ev, nr - 0x20, "EV_???");
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000103 tprintf(", %u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100104 return 1;
105 } else if (nr >= 0x40 && nr <= 0x40 + 0x3f) {
106 tprints("EVIOCGABS(");
Elliott Hughes03a418e2018-06-15 13:11:40 -0700107 printxval_indexn(evdev_abs, evdev_abs_size, nr - 0x40,
108 "ABS_???");
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100109 tprints(")");
110 return 1;
111 }
112
113 switch (_IOC_NR(nr)) {
114 case 0x06:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000115 tprintf("EVIOCGNAME(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100116 return 1;
117 case 0x07:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000118 tprintf("EVIOCGPHYS(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100119 return 1;
120 case 0x08:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000121 tprintf("EVIOCGUNIQ(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100122 return 1;
123 case 0x09:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000124 tprintf("EVIOCGPROP(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100125 return 1;
126 case 0x0a:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000127 tprintf("EVIOCGMTSLOTS(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100128 return 1;
129 case 0x18:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000130 tprintf("EVIOCGKEY(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100131 return 1;
132 case 0x19:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000133 tprintf("EVIOCGLED(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100134 return 1;
135 case 0x1a:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000136 tprintf("EVIOCGSND(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100137 return 1;
138 case 0x1b:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000139 tprintf("EVIOCGSW(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100140 return 1;
141 default:
142 return 0;
143 }
144}
145
146static int
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000147hiddev_decode_number(const unsigned int code)
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100148{
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000149 if (_IOC_DIR(code) == _IOC_READ) {
150 switch (_IOC_NR(code)) {
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100151 case 0x04:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000152 tprintf("HIDIOCGRAWNAME(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100153 return 1;
154 case 0x05:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000155 tprintf("HIDIOCGRAWPHYS(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100156 return 1;
157 case 0x06:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000158 tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100159 return 1;
160 case 0x12:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000161 tprintf("HIDIOCGPHYS(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100162 return 1;
163 default:
164 return 0;
165 }
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000166 } else if (_IOC_DIR(code) == (_IOC_READ | _IOC_WRITE)) {
167 switch (_IOC_NR(code)) {
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100168 case 0x06:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000169 tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100170 return 1;
171 case 0x07:
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000172 tprintf("HIDIOCGFEATURE(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100173 return 1;
174 default:
175 return 0;
176 }
177 }
178
179 return 0;
180}
181
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000182static int
Dmitry V. Levin4f63c112015-07-02 22:31:11 +0000183ioctl_decode_command_number(struct tcb *tcp)
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100184{
Dmitry V. Levin4f63c112015-07-02 22:31:11 +0000185 const unsigned int code = tcp->u_arg[1];
186
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000187 switch (_IOC_TYPE(code)) {
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100188 case 'E':
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000189 return evdev_decode_number(code);
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100190 case 'H':
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000191 return hiddev_decode_number(code);
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100192 case 'M':
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000193 if (_IOC_DIR(code) == _IOC_WRITE) {
194 tprintf("MIXER_WRITE(%u)", _IOC_NR(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100195 return 1;
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000196 } else if (_IOC_DIR(code) == _IOC_READ) {
197 tprintf("MIXER_READ(%u)", _IOC_NR(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100198 return 1;
199 }
200 return 0;
201 case 'U':
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000202 if (_IOC_DIR(code) == _IOC_READ && _IOC_NR(code) == 0x2c) {
203 tprintf("UI_GET_SYSNAME(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100204 return 1;
205 }
206 return 0;
207 case 'j':
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000208 if (_IOC_DIR(code) == _IOC_READ && _IOC_NR(code) == 0x13) {
209 tprintf("JSIOCGNAME(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100210 return 1;
211 }
212 return 0;
213 case 'k':
Dmitry V. Levin2803e752015-07-02 22:23:53 +0000214 if (_IOC_DIR(code) == _IOC_WRITE && _IOC_NR(code) == 0) {
215 tprintf("SPI_IOC_MESSAGE(%u)", _IOC_SIZE(code));
Gabriel Laskar6f9a01c2015-01-21 23:35:27 +0100216 return 1;
217 }
218 return 0;
219 default:
220 return 0;
221 }
222}
223
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700224/**
225 * Decode arg parameter of the ioctl call.
226 *
227 * @return There are two flags of the return value important for the purposes of
228 * processing by SYS_FUNC(ioctl):
229 * - RVAL_IOCTL_DECODED: indicates that ioctl decoder code
230 * has printed arg parameter;
231 * - RVAL_DECODED: indicates that decoding is done.
232 * As a result, the following behaviour is expected:
233 * - on entering:
234 * - 0: decoding should be continued on exiting;
235 * - RVAL_IOCTL_DECODED: decoding on exiting is not needed
236 * and decoder has printed arg value;
237 * - RVAL_DECODED: decoding on exiting is not needed
238 * and generic handler should print arg value.
239 * - on exiting:
240 * - 0: generic handler should print arg value;
241 * - RVAL_IOCTL_DECODED: decoder has printed arg value.
242 *
243 * Note that it makes no sense to return just RVAL_DECODED on exiting,
244 * but, of course, it is not prohibited (for example, it may be useful
245 * in cases where the return path is common on entering and on exiting
246 * the syscall).
247 *
248 * SYS_FUNC(ioctl) converts RVAL_IOCTL_DECODED flag to RVAL_DECODED,
249 * and passes all other bits of ioctl_decode return value unchanged.
250 */
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000251static int
Dmitry V. Levin802c9422015-07-02 22:27:51 +0000252ioctl_decode(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253{
Dmitry V. Levin802c9422015-07-02 22:27:51 +0000254 const unsigned int code = tcp->u_arg[1];
Elliott Hughesd35df492017-02-15 15:19:05 -0800255 const kernel_ulong_t arg = tcp->u_arg[2];
Dmitry V. Levin802c9422015-07-02 22:27:51 +0000256
Dmitry V. Levinc7afb482015-01-19 18:44:21 +0000257 switch (_IOC_TYPE(code)) {
Elliott Hughes03a418e2018-06-15 13:11:40 -0700258 case '$':
259 return perf_ioctl(tcp, code, arg);
Roland McGrathbb3af522003-01-14 07:53:34 +0000260#if defined(ALPHA) || defined(POWERPC)
Dmitry V. Levin25f37582016-05-24 00:19:03 +0000261 case 'f': {
262 int ret = file_ioctl(tcp, code, arg);
Jeff Mahoney398fe042016-05-18 18:09:40 -0400263 if (ret != RVAL_DECODED)
264 return ret;
Elliott Hughes28e98bc2018-06-14 16:59:04 -0700265 ATTRIBUTE_FALLTHROUGH;
Dmitry V. Levin25f37582016-05-24 00:19:03 +0000266 }
267 case 't':
Jeff Mahoney398fe042016-05-18 18:09:40 -0400268 case 'T':
269 return term_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270#else /* !ALPHA */
Jeff Mahoney398fe042016-05-18 18:09:40 -0400271 case 'f':
272 return file_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000273 case 0x54:
274#endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 return term_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276 case 0x89:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277 return sock_ioctl(tcp, code, arg);
Roland McGrathd83c50b2004-10-06 22:27:43 +0000278 case 'p':
279 return rtc_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +0000280 case 0x03:
Dmitry V. Levinb3f00402016-05-26 00:07:17 +0000281 return hdio_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +0000282 case 0x12:
283 return block_ioctl(tcp, code, arg);
Dmitry V. Levin4dd9f3f2016-05-26 00:37:26 +0000284 case 'X':
285 return fs_x_ioctl(tcp, code, arg);
Dmitry V. Levinb011af52007-06-30 11:37:09 +0000286 case 0x22:
287 return scsi_ioctl(tcp, code, arg);
Mike Frysingerebee04c2012-04-17 22:19:31 -0400288 case 'L':
289 return loop_ioctl(tcp, code, arg);
Elliott Hughesb7556142018-02-20 17:03:16 -0800290#ifdef HAVE_STRUCT_MTD_WRITE_REQ
Mike Frysinger0cbed352012-04-04 22:22:01 -0400291 case 'M':
292 return mtd_ioctl(tcp, code, arg);
Elliott Hughesb7556142018-02-20 17:03:16 -0800293#endif
294#ifdef HAVE_STRUCT_UBI_ATTACH_REQ_MAX_BEB_PER1024
Mike Frysingerd648f292013-05-01 23:35:30 -0400295 case 'o':
296 case 'O':
297 return ubi_ioctl(tcp, code, arg);
Elliott Hughesb7556142018-02-20 17:03:16 -0800298#endif
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100299 case 'V':
300 return v4l2_ioctl(tcp, code, arg);
Elliott Hughesb7556142018-02-20 17:03:16 -0800301#ifdef HAVE_STRUCT_PTP_SYS_OFFSET
Stefan Sørensenb88a6f82014-01-31 12:01:01 +0100302 case '=':
303 return ptp_ioctl(tcp, code, arg);
Elliott Hughesb7556142018-02-20 17:03:16 -0800304#endif
Etienne Gemsa4f750b92015-02-20 17:14:10 +0100305#ifdef HAVE_LINUX_INPUT_H
306 case 'E':
307 return evdev_ioctl(tcp, code, arg);
308#endif
Dr. David Alan Gilbert5d1216a2016-05-10 11:49:02 +0100309#ifdef HAVE_LINUX_USERFAULTFD_H
310 case 0xaa:
311 return uffdio_ioctl(tcp, code, arg);
312#endif
Jeff Mahoney8cc69622016-05-18 18:09:39 -0400313#ifdef HAVE_LINUX_BTRFS_H
314 case 0x94:
315 return btrfs_ioctl(tcp, code, arg);
316#endif
Elliott Hughes39bac052017-05-25 16:56:11 -0700317 case 0xb7:
318 return nsfs_ioctl(tcp, code, arg);
Elliott Hughesd35df492017-02-15 15:19:05 -0800319#ifdef HAVE_LINUX_DM_IOCTL_H
320 case 0xfd:
321 return dm_ioctl(tcp, code, arg);
322#endif
Elliott Hughesb7556142018-02-20 17:03:16 -0800323#ifdef HAVE_LINUX_KVM_H
324 case 0xae:
325 return kvm_ioctl(tcp, code, arg);
326#endif
Elliott Hughes03a418e2018-06-15 13:11:40 -0700327 case 'I':
328 return inotify_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 default:
330 break;
331 }
332 return 0;
333}
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000334
335SYS_FUNC(ioctl)
336{
337 const struct_ioctlent *iop;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000338 int ret;
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000339
340 if (entering(tcp)) {
341 printfd(tcp, tcp->u_arg[0]);
342 tprints(", ");
Elliott Hughes03a418e2018-06-15 13:11:40 -0700343
344 if (xlat_verbosity != XLAT_STYLE_ABBREV)
345 tprintf("%#x", (unsigned int) tcp->u_arg[1]);
346 if (xlat_verbosity == XLAT_STYLE_VERBOSE)
347 tprints(" /* ");
348 if (xlat_verbosity != XLAT_STYLE_RAW) {
349 ret = ioctl_decode_command_number(tcp);
350 if (!(ret & IOCTL_NUMBER_STOP_LOOKUP)) {
351 iop = ioctl_lookup(tcp->u_arg[1]);
352 if (iop) {
353 if (ret)
354 tprints(" or ");
355 tprints(iop->symbol);
356 while ((iop = ioctl_next_match(iop)))
357 tprintf(" or %s", iop->symbol);
358 } else if (!ret) {
359 ioctl_print_code(tcp->u_arg[1]);
360 }
Gabriel Laskar8b6046a2015-12-04 01:07:33 +0100361 }
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000362 }
Elliott Hughes03a418e2018-06-15 13:11:40 -0700363 if (xlat_verbosity == XLAT_STYLE_VERBOSE)
364 tprints(" */");
365
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000366 ret = ioctl_decode(tcp);
367 } else {
368 ret = ioctl_decode(tcp) | RVAL_DECODED;
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000369 }
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000370
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700371 if (ret & RVAL_IOCTL_DECODED) {
372 ret &= ~RVAL_IOCTL_DECODED;
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000373 ret |= RVAL_DECODED;
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700374 } else if (ret & RVAL_DECODED) {
375 tprintf(", %#" PRI_klx, tcp->u_arg[2]);
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000376 }
Dmitry V. Levin204c2bc2015-07-08 14:10:56 +0000377
378 return ret;
Dmitry V. Levin044eef22015-07-02 21:37:23 +0000379}