blob: 23b438f9fe42865a2c9308a9fbc015bffdc378c2 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
4 *
5 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
6 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
8 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
9 *
10 * These routines maintain argument size conversion between 32bit and 64bit
11 * ioctls.
12 */
13
14#include <linux/joystick.h>
15
16#include <linux/types.h>
17#include <linux/compat.h>
18#include <linux/kernel.h>
19#include <linux/capability.h>
20#include <linux/compiler.h>
21#include <linux/sched.h>
22#include <linux/smp.h>
23#include <linux/ioctl.h>
24#include <linux/if.h>
25#include <linux/raid/md_u.h>
26#include <linux/falloc.h>
27#include <linux/file.h>
28#include <linux/ppp-ioctl.h>
29#include <linux/if_pppox.h>
30#include <linux/mtio.h>
31#include <linux/tty.h>
32#include <linux/vt_kern.h>
33#include <linux/raw.h>
34#include <linux/blkdev.h>
35#include <linux/rtc.h>
36#include <linux/pci.h>
37#include <linux/serial.h>
38#include <linux/ctype.h>
39#include <linux/syscalls.h>
40#include <linux/gfp.h>
41#include <linux/cec.h>
42
43#include "internal.h"
44
45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_sock.h>
47#include <net/bluetooth/rfcomm.h>
48
49#include <linux/capi.h>
50#include <linux/gigaset_dev.h>
51
52#ifdef CONFIG_BLOCK
53#include <linux/cdrom.h>
54#include <linux/fd.h>
55#include <scsi/scsi.h>
56#include <scsi/scsi_ioctl.h>
57#include <scsi/sg.h>
58#endif
59
60#include <linux/uaccess.h>
61#include <linux/watchdog.h>
62
63#include <linux/soundcard.h>
64
65#include <linux/hiddev.h>
66
67
68#include <linux/sort.h>
69
70#ifdef CONFIG_SPARC
71#include <linux/fb.h>
72#include <asm/fbio.h>
73#endif
74
75#define convert_in_user(srcptr, dstptr) \
76({ \
77 typeof(*srcptr) val; \
78 \
79 get_user(val, srcptr) || put_user(val, dstptr); \
80})
81
82static int do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
83{
84 int err;
85
86 err = security_file_ioctl(file, cmd, arg);
87 if (err)
88 return err;
89
90 return vfs_ioctl(file, cmd, arg);
91}
92
93#ifdef CONFIG_BLOCK
94typedef struct sg_io_hdr32 {
95 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
96 compat_int_t dxfer_direction; /* [i] data transfer direction */
97 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
98 unsigned char mx_sb_len; /* [i] max length to write to sbp */
99 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
100 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
101 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
102 or scatter gather list */
103 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
104 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
105 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
106 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
107 compat_int_t pack_id; /* [i->o] unused internally (normally) */
108 compat_uptr_t usr_ptr; /* [i->o] unused internally */
109 unsigned char status; /* [o] scsi status */
110 unsigned char masked_status; /* [o] shifted, masked scsi status */
111 unsigned char msg_status; /* [o] messaging level data (optional) */
112 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
113 unsigned short host_status; /* [o] errors from host adapter */
114 unsigned short driver_status; /* [o] errors from software driver */
115 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
116 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
117 compat_uint_t info; /* [o] auxiliary information */
118} sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
119
120typedef struct sg_iovec32 {
121 compat_uint_t iov_base;
122 compat_uint_t iov_len;
123} sg_iovec32_t;
124
125static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
126{
127 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
128 sg_iovec32_t __user *iov32 = dxferp;
129 int i;
130
131 for (i = 0; i < iovec_count; i++) {
132 u32 base, len;
133
134 if (get_user(base, &iov32[i].iov_base) ||
135 get_user(len, &iov32[i].iov_len) ||
136 put_user(compat_ptr(base), &iov[i].iov_base) ||
137 put_user(len, &iov[i].iov_len))
138 return -EFAULT;
139 }
140
141 if (put_user(iov, &sgio->dxferp))
142 return -EFAULT;
143 return 0;
144}
145
146static int sg_ioctl_trans(struct file *file, unsigned int cmd,
147 sg_io_hdr32_t __user *sgio32)
148{
149 sg_io_hdr_t __user *sgio;
150 u16 iovec_count;
151 u32 data;
152 void __user *dxferp;
153 int err;
154 int interface_id;
155
156 if (get_user(interface_id, &sgio32->interface_id))
157 return -EFAULT;
158 if (interface_id != 'S')
159 return do_ioctl(file, cmd, (unsigned long)sgio32);
160
161 if (get_user(iovec_count, &sgio32->iovec_count))
162 return -EFAULT;
163
164 {
165 void __user *top = compat_alloc_user_space(0);
166 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
167 (iovec_count * sizeof(sg_iovec_t)));
168 if (new > top)
169 return -EINVAL;
170
171 sgio = new;
172 }
173
174 /* Ok, now construct. */
175 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
176 (2 * sizeof(int)) +
177 (2 * sizeof(unsigned char)) +
178 (1 * sizeof(unsigned short)) +
179 (1 * sizeof(unsigned int))))
180 return -EFAULT;
181
182 if (get_user(data, &sgio32->dxferp))
183 return -EFAULT;
184 dxferp = compat_ptr(data);
185 if (iovec_count) {
186 if (sg_build_iovec(sgio, dxferp, iovec_count))
187 return -EFAULT;
188 } else {
189 if (put_user(dxferp, &sgio->dxferp))
190 return -EFAULT;
191 }
192
193 {
194 unsigned char __user *cmdp;
195 unsigned char __user *sbp;
196
197 if (get_user(data, &sgio32->cmdp))
198 return -EFAULT;
199 cmdp = compat_ptr(data);
200
201 if (get_user(data, &sgio32->sbp))
202 return -EFAULT;
203 sbp = compat_ptr(data);
204
205 if (put_user(cmdp, &sgio->cmdp) ||
206 put_user(sbp, &sgio->sbp))
207 return -EFAULT;
208 }
209
210 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
211 3 * sizeof(int)))
212 return -EFAULT;
213
214 if (get_user(data, &sgio32->usr_ptr))
215 return -EFAULT;
216 if (put_user(compat_ptr(data), &sgio->usr_ptr))
217 return -EFAULT;
218
219 err = do_ioctl(file, cmd, (unsigned long) sgio);
220
221 if (err >= 0) {
222 void __user *datap;
223
224 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
225 sizeof(int)) ||
226 get_user(datap, &sgio->usr_ptr) ||
227 put_user((u32)(unsigned long)datap,
228 &sgio32->usr_ptr) ||
229 copy_in_user(&sgio32->status, &sgio->status,
230 (4 * sizeof(unsigned char)) +
231 (2 * sizeof(unsigned short)) +
232 (3 * sizeof(int))))
233 err = -EFAULT;
234 }
235
236 return err;
237}
238
239struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
240 char req_state;
241 char orphan;
242 char sg_io_owned;
243 char problem;
244 int pack_id;
245 compat_uptr_t usr_ptr;
246 unsigned int duration;
247 int unused;
248};
249
250static int sg_grt_trans(struct file *file,
251 unsigned int cmd, struct compat_sg_req_info __user *o)
252{
253 int err, i;
254 sg_req_info_t __user *r;
255 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
256 err = do_ioctl(file, cmd, (unsigned long)r);
257 if (err < 0)
258 return err;
259 for (i = 0; i < SG_MAX_QUEUE; i++) {
260 void __user *ptr;
261 int d;
262
263 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
264 get_user(ptr, &r[i].usr_ptr) ||
265 get_user(d, &r[i].duration) ||
266 put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
267 put_user(d, &o[i].duration))
268 return -EFAULT;
269 }
270 return err;
271}
272#endif /* CONFIG_BLOCK */
273
274#ifdef CONFIG_BLOCK
275struct mtget32 {
276 compat_long_t mt_type;
277 compat_long_t mt_resid;
278 compat_long_t mt_dsreg;
279 compat_long_t mt_gstat;
280 compat_long_t mt_erreg;
281 compat_daddr_t mt_fileno;
282 compat_daddr_t mt_blkno;
283};
284#define MTIOCGET32 _IOR('m', 2, struct mtget32)
285
286struct mtpos32 {
287 compat_long_t mt_blkno;
288};
289#define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
290
291static int mt_ioctl_trans(struct file *file,
292 unsigned int cmd, void __user *argp)
293{
294 /* NULL initialization to make gcc shut up */
295 struct mtget __user *get = NULL;
296 struct mtget32 __user *umget32;
297 struct mtpos __user *pos = NULL;
298 struct mtpos32 __user *upos32;
299 unsigned long kcmd;
300 void *karg;
301 int err = 0;
302
303 switch(cmd) {
304 case MTIOCPOS32:
305 kcmd = MTIOCPOS;
306 pos = compat_alloc_user_space(sizeof(*pos));
307 karg = pos;
308 break;
309 default: /* MTIOCGET32 */
310 kcmd = MTIOCGET;
311 get = compat_alloc_user_space(sizeof(*get));
312 karg = get;
313 break;
314 }
315 if (karg == NULL)
316 return -EFAULT;
317 err = do_ioctl(file, kcmd, (unsigned long)karg);
318 if (err)
319 return err;
320 switch (cmd) {
321 case MTIOCPOS32:
322 upos32 = argp;
323 err = convert_in_user(&pos->mt_blkno, &upos32->mt_blkno);
324 break;
325 case MTIOCGET32:
326 umget32 = argp;
327 err = convert_in_user(&get->mt_type, &umget32->mt_type);
328 err |= convert_in_user(&get->mt_resid, &umget32->mt_resid);
329 err |= convert_in_user(&get->mt_dsreg, &umget32->mt_dsreg);
330 err |= convert_in_user(&get->mt_gstat, &umget32->mt_gstat);
331 err |= convert_in_user(&get->mt_erreg, &umget32->mt_erreg);
332 err |= convert_in_user(&get->mt_fileno, &umget32->mt_fileno);
333 err |= convert_in_user(&get->mt_blkno, &umget32->mt_blkno);
334 break;
335 }
336 return err ? -EFAULT: 0;
337}
338
339#endif /* CONFIG_BLOCK */
340
341/* Bluetooth ioctls */
342#define HCIUARTSETPROTO _IOW('U', 200, int)
343#define HCIUARTGETPROTO _IOR('U', 201, int)
344#define HCIUARTGETDEVICE _IOR('U', 202, int)
345#define HCIUARTSETFLAGS _IOW('U', 203, int)
346#define HCIUARTGETFLAGS _IOR('U', 204, int)
347
348#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
349#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
350#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
351#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
352
353static int rtc_ioctl(struct file *file,
354 unsigned cmd, void __user *argp)
355{
356 unsigned long __user *valp = compat_alloc_user_space(sizeof(*valp));
357 int ret;
358
359 if (valp == NULL)
360 return -EFAULT;
361 switch (cmd) {
362 case RTC_IRQP_READ32:
363 case RTC_EPOCH_READ32:
364 ret = do_ioctl(file, (cmd == RTC_IRQP_READ32) ?
365 RTC_IRQP_READ : RTC_EPOCH_READ,
366 (unsigned long)valp);
367 if (ret)
368 return ret;
369 return convert_in_user(valp, (unsigned int __user *)argp);
370 case RTC_IRQP_SET32:
371 return do_ioctl(file, RTC_IRQP_SET, (unsigned long)argp);
372 case RTC_EPOCH_SET32:
373 return do_ioctl(file, RTC_EPOCH_SET, (unsigned long)argp);
374 }
375
376 return -ENOIOCTLCMD;
377}
378
379/* on ia32 l_start is on a 32-bit boundary */
380#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
381struct space_resv_32 {
382 __s16 l_type;
383 __s16 l_whence;
384 __s64 l_start __attribute__((packed));
385 /* len == 0 means until end of file */
386 __s64 l_len __attribute__((packed));
387 __s32 l_sysid;
388 __u32 l_pid;
389 __s32 l_pad[4]; /* reserve area */
390};
391
392#define FS_IOC_RESVSP_32 _IOW ('X', 40, struct space_resv_32)
393#define FS_IOC_RESVSP64_32 _IOW ('X', 42, struct space_resv_32)
394
395/* just account for different alignment */
396static int compat_ioctl_preallocate(struct file *file,
397 struct space_resv_32 __user *p32)
398{
399 struct space_resv __user *p = compat_alloc_user_space(sizeof(*p));
400
401 if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
402 copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) ||
403 copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) ||
404 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
405 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
406 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
407 copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
408 return -EFAULT;
409
410 return ioctl_preallocate(file, p);
411}
412#endif
413
414/*
415 * simple reversible transform to make our table more evenly
416 * distributed after sorting.
417 */
418#define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff)
419
420#define COMPATIBLE_IOCTL(cmd) XFORM((u32)cmd),
421/* ioctl should not be warned about even if it's not implemented.
422 Valid reasons to use this:
423 - It is implemented with ->compat_ioctl on some device, but programs
424 call it on others too.
425 - The ioctl is not implemented in the native kernel, but programs
426 call it commonly anyways.
427 Most other reasons are not valid. */
428#define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
429
430static unsigned int ioctl_pointer[] = {
431/* compatible ioctls first */
432/* Little t */
433COMPATIBLE_IOCTL(TIOCOUTQ)
434/* Little f */
435COMPATIBLE_IOCTL(FIOCLEX)
436COMPATIBLE_IOCTL(FIONCLEX)
437COMPATIBLE_IOCTL(FIOASYNC)
438COMPATIBLE_IOCTL(FIONBIO)
439COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */
440COMPATIBLE_IOCTL(FS_IOC_FIEMAP)
441/* 0x00 */
442COMPATIBLE_IOCTL(FIBMAP)
443COMPATIBLE_IOCTL(FIGETBSZ)
444/* 'X' - originally XFS but some now in the VFS */
445COMPATIBLE_IOCTL(FIFREEZE)
446COMPATIBLE_IOCTL(FITHAW)
447COMPATIBLE_IOCTL(FITRIM)
448#ifdef CONFIG_BLOCK
449/* Big S */
450COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
451COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
452COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
453COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
454COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
455COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
456COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
457COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
458#endif
459/* Big V (don't complain on serial console) */
460IGNORE_IOCTL(VT_OPENQRY)
461IGNORE_IOCTL(VT_GETMODE)
462/* Little p (/dev/rtc, /dev/envctrl, etc.) */
463COMPATIBLE_IOCTL(RTC_AIE_ON)
464COMPATIBLE_IOCTL(RTC_AIE_OFF)
465COMPATIBLE_IOCTL(RTC_UIE_ON)
466COMPATIBLE_IOCTL(RTC_UIE_OFF)
467COMPATIBLE_IOCTL(RTC_PIE_ON)
468COMPATIBLE_IOCTL(RTC_PIE_OFF)
469COMPATIBLE_IOCTL(RTC_WIE_ON)
470COMPATIBLE_IOCTL(RTC_WIE_OFF)
471COMPATIBLE_IOCTL(RTC_ALM_SET)
472COMPATIBLE_IOCTL(RTC_ALM_READ)
473COMPATIBLE_IOCTL(RTC_RD_TIME)
474COMPATIBLE_IOCTL(RTC_SET_TIME)
475COMPATIBLE_IOCTL(RTC_WKALM_SET)
476COMPATIBLE_IOCTL(RTC_WKALM_RD)
477/*
478 * These two are only for the sbus rtc driver, but
479 * hwclock tries them on every rtc device first when
480 * running on sparc. On other architectures the entries
481 * are useless but harmless.
482 */
483COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
484COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
485/* Little m */
486COMPATIBLE_IOCTL(MTIOCTOP)
487/* Socket level stuff */
488COMPATIBLE_IOCTL(FIOQSIZE)
489#ifdef CONFIG_BLOCK
490/* md calls this on random blockdevs */
491IGNORE_IOCTL(RAID_VERSION)
492/* qemu/qemu-img might call these two on plain files for probing */
493IGNORE_IOCTL(CDROM_DRIVE_STATUS)
494IGNORE_IOCTL(FDGETPRM32)
495/* SG stuff */
496COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
497COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
498COMPATIBLE_IOCTL(SG_EMULATED_HOST)
499COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
500COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
501COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
502COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
503COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
504COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
505COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
506COMPATIBLE_IOCTL(SG_GET_PACK_ID)
507COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
508COMPATIBLE_IOCTL(SG_SET_DEBUG)
509COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
510COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
511COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
512COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
513COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
514COMPATIBLE_IOCTL(SG_SCSI_RESET)
515COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
516COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
517COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
518#endif
519/* PPP stuff */
520COMPATIBLE_IOCTL(PPPIOCGFLAGS)
521COMPATIBLE_IOCTL(PPPIOCSFLAGS)
522COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
523COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
524COMPATIBLE_IOCTL(PPPIOCGUNIT)
525COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
526COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
527COMPATIBLE_IOCTL(PPPIOCGMRU)
528COMPATIBLE_IOCTL(PPPIOCSMRU)
529COMPATIBLE_IOCTL(PPPIOCSMAXCID)
530COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
531COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
532COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
533/* PPPIOCSCOMPRESS is translated */
534COMPATIBLE_IOCTL(PPPIOCGNPMODE)
535COMPATIBLE_IOCTL(PPPIOCSNPMODE)
536COMPATIBLE_IOCTL(PPPIOCGDEBUG)
537COMPATIBLE_IOCTL(PPPIOCSDEBUG)
538/* PPPIOCSPASS is translated */
539/* PPPIOCSACTIVE is translated */
540COMPATIBLE_IOCTL(PPPIOCGIDLE32)
541COMPATIBLE_IOCTL(PPPIOCGIDLE64)
542COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
543COMPATIBLE_IOCTL(PPPIOCATTACH)
544COMPATIBLE_IOCTL(PPPIOCDETACH)
545COMPATIBLE_IOCTL(PPPIOCSMRRU)
546COMPATIBLE_IOCTL(PPPIOCCONNECT)
547COMPATIBLE_IOCTL(PPPIOCDISCONN)
548COMPATIBLE_IOCTL(PPPIOCATTCHAN)
549COMPATIBLE_IOCTL(PPPIOCGCHAN)
550COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS)
551/* Big A */
552/* sparc only */
553/* Big Q for sound/OSS */
554COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
555COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
556COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
557COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
558COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
559COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
560COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
561COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
562COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
563COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
564COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
565COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
566COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
567COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
568COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
569COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
570COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
571COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
572COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
573COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
574COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
575COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
576/* Big T for sound/OSS */
577COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
578COMPATIBLE_IOCTL(SNDCTL_TMR_START)
579COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
580COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
581COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
582COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
583COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
584COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
585/* Little m for sound/OSS */
586COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
587COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
588COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
589/* Big P for sound/OSS */
590COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
591COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
592COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
593COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
594COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
595COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
596COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
597COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
598COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
599COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
600COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
601COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
602COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
603COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
604COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
605COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
606COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
607COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
608COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
609COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
610/* SNDCTL_DSP_MAPINBUF, XXX needs translation */
611/* SNDCTL_DSP_MAPOUTBUF, XXX needs translation */
612COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
613COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
614COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
615COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
616COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
617COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
618COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
619COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
620/* Big C for sound/OSS */
621COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
622COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
623COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
624COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
625COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
626COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
627COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
628COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
629COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
630COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
631/* Big M for sound/OSS */
632COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
633COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
634COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
635COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
636COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
637COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
638COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
639COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
640COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
641COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
642COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
643COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
644COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
645COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
646COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
647COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
648COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
649COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
650COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
651COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
652COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
653COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
654COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
655COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
656COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
657COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
658/* SOUND_MIXER_READ_ENHANCE, same value as READ_MUTE */
659/* SOUND_MIXER_READ_LOUD, same value as READ_MUTE */
660COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
661COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
662COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
663COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
664COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
665COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
666COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
667COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
668COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
669COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
670COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
671COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
672COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
673COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
674COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
675COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
676COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
677COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
678COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
679COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
680COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
681COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
682COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
683COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
684COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
685COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
686COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
687COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
688COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
689COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
690COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
691/* SOUND_MIXER_WRITE_ENHANCE, same value as WRITE_MUTE */
692/* SOUND_MIXER_WRITE_LOUD, same value as WRITE_MUTE */
693COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
694COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
695COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
696COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
697COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
698COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
699COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
700COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
701COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
702COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
703COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
704COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
705COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
706COMPATIBLE_IOCTL(OSS_GETVERSION)
707/* Raw devices */
708COMPATIBLE_IOCTL(RAW_SETBIND)
709COMPATIBLE_IOCTL(RAW_GETBIND)
710/* Watchdog */
711COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
712COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
713COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
714COMPATIBLE_IOCTL(WDIOC_GETTEMP)
715COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
716COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
717COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
718COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
719COMPATIBLE_IOCTL(WDIOC_SETPRETIMEOUT)
720COMPATIBLE_IOCTL(WDIOC_GETPRETIMEOUT)
721/* Bluetooth */
722COMPATIBLE_IOCTL(HCIDEVUP)
723COMPATIBLE_IOCTL(HCIDEVDOWN)
724COMPATIBLE_IOCTL(HCIDEVRESET)
725COMPATIBLE_IOCTL(HCIDEVRESTAT)
726COMPATIBLE_IOCTL(HCIGETDEVLIST)
727COMPATIBLE_IOCTL(HCIGETDEVINFO)
728COMPATIBLE_IOCTL(HCIGETCONNLIST)
729COMPATIBLE_IOCTL(HCIGETCONNINFO)
730COMPATIBLE_IOCTL(HCIGETAUTHINFO)
731COMPATIBLE_IOCTL(HCISETRAW)
732COMPATIBLE_IOCTL(HCISETSCAN)
733COMPATIBLE_IOCTL(HCISETAUTH)
734COMPATIBLE_IOCTL(HCISETENCRYPT)
735COMPATIBLE_IOCTL(HCISETPTYPE)
736COMPATIBLE_IOCTL(HCISETLINKPOL)
737COMPATIBLE_IOCTL(HCISETLINKMODE)
738COMPATIBLE_IOCTL(HCISETACLMTU)
739COMPATIBLE_IOCTL(HCISETSCOMTU)
740COMPATIBLE_IOCTL(HCIBLOCKADDR)
741COMPATIBLE_IOCTL(HCIUNBLOCKADDR)
742COMPATIBLE_IOCTL(HCIINQUIRY)
743COMPATIBLE_IOCTL(HCIUARTSETPROTO)
744COMPATIBLE_IOCTL(HCIUARTGETPROTO)
745COMPATIBLE_IOCTL(HCIUARTGETDEVICE)
746COMPATIBLE_IOCTL(HCIUARTSETFLAGS)
747COMPATIBLE_IOCTL(HCIUARTGETFLAGS)
748COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
749COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
750COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
751COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
752COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
753/* CAPI */
754COMPATIBLE_IOCTL(CAPI_REGISTER)
755COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
756COMPATIBLE_IOCTL(CAPI_GET_VERSION)
757COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
758COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
759COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
760COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
761COMPATIBLE_IOCTL(CAPI_INSTALLED)
762COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
763COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
764COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
765COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
766COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
767/* Misc. */
768COMPATIBLE_IOCTL(0x41545900) /* ATYIO_CLKR */
769COMPATIBLE_IOCTL(0x41545901) /* ATYIO_CLKW */
770COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
771COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
772COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
773COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
774/* hiddev */
775COMPATIBLE_IOCTL(HIDIOCGVERSION)
776COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
777COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
778COMPATIBLE_IOCTL(HIDIOCGSTRING)
779COMPATIBLE_IOCTL(HIDIOCINITREPORT)
780COMPATIBLE_IOCTL(HIDIOCGREPORT)
781COMPATIBLE_IOCTL(HIDIOCSREPORT)
782COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
783COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
784COMPATIBLE_IOCTL(HIDIOCGUSAGE)
785COMPATIBLE_IOCTL(HIDIOCSUSAGE)
786COMPATIBLE_IOCTL(HIDIOCGUCODE)
787COMPATIBLE_IOCTL(HIDIOCGFLAG)
788COMPATIBLE_IOCTL(HIDIOCSFLAG)
789COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
790COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
791/* joystick */
792COMPATIBLE_IOCTL(JSIOCGVERSION)
793COMPATIBLE_IOCTL(JSIOCGAXES)
794COMPATIBLE_IOCTL(JSIOCGBUTTONS)
795COMPATIBLE_IOCTL(JSIOCGNAME(0))
796
797/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
798 but we don't want warnings on other file systems. So declare
799 them as compatible here. */
800#define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
801#define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
802
803IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
804IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
805
806#ifdef CONFIG_SPARC
807/* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
808IGNORE_IOCTL(FBIOGTYPE)
809IGNORE_IOCTL(FBIOSATTR)
810IGNORE_IOCTL(FBIOGATTR)
811IGNORE_IOCTL(FBIOSVIDEO)
812IGNORE_IOCTL(FBIOGVIDEO)
813IGNORE_IOCTL(FBIOSCURPOS)
814IGNORE_IOCTL(FBIOGCURPOS)
815IGNORE_IOCTL(FBIOGCURMAX)
816IGNORE_IOCTL(FBIOPUTCMAP32)
817IGNORE_IOCTL(FBIOGETCMAP32)
818IGNORE_IOCTL(FBIOSCURSOR32)
819IGNORE_IOCTL(FBIOGCURSOR32)
820#endif
821};
822
823/*
824 * Convert common ioctl arguments based on their command number
825 *
826 * Please do not add any code in here. Instead, implement
827 * a compat_ioctl operation in the place that handleѕ the
828 * ioctl for the native case.
829 */
830static long do_ioctl_trans(unsigned int cmd,
831 unsigned long arg, struct file *file)
832{
833 void __user *argp = compat_ptr(arg);
834
835 switch (cmd) {
836#ifdef CONFIG_BLOCK
837 case SG_IO:
838 return sg_ioctl_trans(file, cmd, argp);
839 case SG_GET_REQUEST_TABLE:
840 return sg_grt_trans(file, cmd, argp);
841 case MTIOCGET32:
842 case MTIOCPOS32:
843 return mt_ioctl_trans(file, cmd, argp);
844#endif
845 /* Not implemented in the native kernel */
846 case RTC_IRQP_READ32:
847 case RTC_IRQP_SET32:
848 case RTC_EPOCH_READ32:
849 case RTC_EPOCH_SET32:
850 return rtc_ioctl(file, cmd, argp);
851 }
852
853 /*
854 * These take an integer instead of a pointer as 'arg',
855 * so we must not do a compat_ptr() translation.
856 */
857 switch (cmd) {
858 /* RAID */
859 case HOT_REMOVE_DISK:
860 case HOT_ADD_DISK:
861 case SET_DISK_FAULTY:
862 case SET_BITMAP_FILE:
863 return vfs_ioctl(file, cmd, arg);
864 }
865
866 return -ENOIOCTLCMD;
867}
868
869static int compat_ioctl_check_table(unsigned int xcmd)
870{
871 int i;
872 const int max = ARRAY_SIZE(ioctl_pointer) - 1;
873
874 BUILD_BUG_ON(max >= (1 << 16));
875
876 /* guess initial offset into table, assuming a
877 normalized distribution */
878 i = ((xcmd >> 16) * max) >> 16;
879
880 /* do linear search up first, until greater or equal */
881 while (ioctl_pointer[i] < xcmd && i < max)
882 i++;
883
884 /* then do linear search down */
885 while (ioctl_pointer[i] > xcmd && i > 0)
886 i--;
887
888 return ioctl_pointer[i] == xcmd;
889}
890
891COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
892 compat_ulong_t, arg32)
893{
894 unsigned long arg = arg32;
895 struct fd f = fdget(fd);
896 int error = -EBADF;
897 if (!f.file)
898 goto out;
899
900 error = security_file_ioctl_compat(f.file, cmd, arg);
901 if (error)
902 goto out_fput;
903
904 /*
905 * To allow the compat_ioctl handlers to be self contained
906 * we need to check the common ioctls here first.
907 * Just handle them with the standard handlers below.
908 */
909 switch (cmd) {
910 case FIOCLEX:
911 case FIONCLEX:
912 case FIONBIO:
913 case FIOASYNC:
914 case FIOQSIZE:
915 break;
916
917#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
918 case FS_IOC_RESVSP_32:
919 case FS_IOC_RESVSP64_32:
920 error = compat_ioctl_preallocate(f.file, compat_ptr(arg));
921 goto out_fput;
922#else
923 case FS_IOC_RESVSP:
924 case FS_IOC_RESVSP64:
925 error = ioctl_preallocate(f.file, compat_ptr(arg));
926 goto out_fput;
927#endif
928
929 case FICLONE:
930 goto do_ioctl;
931 case FICLONERANGE:
932 case FIDEDUPERANGE:
933 case FS_IOC_FIEMAP:
934 goto found_handler;
935
936 case FIBMAP:
937 case FIGETBSZ:
938 case FIONREAD:
939 if (S_ISREG(file_inode(f.file)->i_mode))
940 break;
941 /*FALL THROUGH*/
942
943 default:
944 if (f.file->f_op->compat_ioctl) {
945 error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
946 if (error != -ENOIOCTLCMD)
947 goto out_fput;
948 }
949
950 if (!f.file->f_op->unlocked_ioctl)
951 goto do_ioctl;
952 break;
953 }
954
955 if (compat_ioctl_check_table(XFORM(cmd)))
956 goto found_handler;
957
958 error = do_ioctl_trans(cmd, arg, f.file);
959 if (error == -ENOIOCTLCMD)
960 error = -ENOTTY;
961
962 goto out_fput;
963
964 found_handler:
965 arg = (unsigned long)compat_ptr(arg);
966 do_ioctl:
967 error = do_vfs_ioctl(f.file, fd, cmd, arg);
968 out_fput:
969 fdput(f);
970 out:
971 return error;
972}
973
974static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
975{
976 unsigned int a, b;
977 a = *(unsigned int *)p;
978 b = *(unsigned int *)q;
979 if (a > b)
980 return 1;
981 if (a < b)
982 return -1;
983 return 0;
984}
985
986static int __init init_sys32_ioctl(void)
987{
988 sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer),
989 init_sys32_ioctl_cmp, NULL);
990 return 0;
991}
992__initcall(init_sys32_ioctl);