Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc
[linux-2.6-block.git] / fs / compat_ioctl.c
1 // 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 #define __DVB_CORE__
68 #include <linux/dvb/audio.h>
69 #include <linux/dvb/dmx.h>
70 #include <linux/dvb/frontend.h>
71 #include <linux/dvb/video.h>
72
73 #include <linux/sort.h>
74
75 #ifdef CONFIG_SPARC
76 #include <linux/fb.h>
77 #include <asm/fbio.h>
78 #endif
79
80 #define convert_in_user(srcptr, dstptr)                 \
81 ({                                                      \
82         typeof(*srcptr) val;                            \
83                                                         \
84         get_user(val, srcptr) || put_user(val, dstptr); \
85 })
86
87 static int do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
88 {
89         int err;
90
91         err = security_file_ioctl(file, cmd, arg);
92         if (err)
93                 return err;
94
95         return vfs_ioctl(file, cmd, arg);
96 }
97
98 struct compat_video_event {
99         int32_t         type;
100         compat_time_t   timestamp;
101         union {
102                 video_size_t size;
103                 unsigned int frame_rate;
104         } u;
105 };
106
107 static int do_video_get_event(struct file *file,
108                 unsigned int cmd, struct compat_video_event __user *up)
109 {
110         struct video_event __user *kevent =
111                 compat_alloc_user_space(sizeof(*kevent));
112         int err;
113
114         if (kevent == NULL)
115                 return -EFAULT;
116
117         err = do_ioctl(file, cmd, (unsigned long)kevent);
118         if (!err) {
119                 err  = convert_in_user(&kevent->type, &up->type);
120                 err |= convert_in_user(&kevent->timestamp, &up->timestamp);
121                 err |= convert_in_user(&kevent->u.size.w, &up->u.size.w);
122                 err |= convert_in_user(&kevent->u.size.h, &up->u.size.h);
123                 err |= convert_in_user(&kevent->u.size.aspect_ratio,
124                                 &up->u.size.aspect_ratio);
125                 if (err)
126                         err = -EFAULT;
127         }
128
129         return err;
130 }
131
132 struct compat_video_still_picture {
133         compat_uptr_t iFrame;
134         int32_t size;
135 };
136
137 static int do_video_stillpicture(struct file *file,
138                 unsigned int cmd, struct compat_video_still_picture __user *up)
139 {
140         struct video_still_picture __user *up_native;
141         compat_uptr_t fp;
142         int32_t size;
143         int err;
144
145         err  = get_user(fp, &up->iFrame);
146         err |= get_user(size, &up->size);
147         if (err)
148                 return -EFAULT;
149
150         up_native =
151                 compat_alloc_user_space(sizeof(struct video_still_picture));
152
153         err =  put_user(compat_ptr(fp), &up_native->iFrame);
154         err |= put_user(size, &up_native->size);
155         if (err)
156                 return -EFAULT;
157
158         err = do_ioctl(file, cmd, (unsigned long) up_native);
159
160         return err;
161 }
162
163 #ifdef CONFIG_BLOCK
164 typedef struct sg_io_hdr32 {
165         compat_int_t interface_id;      /* [i] 'S' for SCSI generic (required) */
166         compat_int_t dxfer_direction;   /* [i] data transfer direction  */
167         unsigned char cmd_len;          /* [i] SCSI command length ( <= 16 bytes) */
168         unsigned char mx_sb_len;                /* [i] max length to write to sbp */
169         unsigned short iovec_count;     /* [i] 0 implies no scatter gather */
170         compat_uint_t dxfer_len;                /* [i] byte count of data transfer */
171         compat_uint_t dxferp;           /* [i], [*io] points to data transfer memory
172                                               or scatter gather list */
173         compat_uptr_t cmdp;             /* [i], [*i] points to command to perform */
174         compat_uptr_t sbp;              /* [i], [*o] points to sense_buffer memory */
175         compat_uint_t timeout;          /* [i] MAX_UINT->no timeout (unit: millisec) */
176         compat_uint_t flags;            /* [i] 0 -> default, see SG_FLAG... */
177         compat_int_t pack_id;           /* [i->o] unused internally (normally) */
178         compat_uptr_t usr_ptr;          /* [i->o] unused internally */
179         unsigned char status;           /* [o] scsi status */
180         unsigned char masked_status;    /* [o] shifted, masked scsi status */
181         unsigned char msg_status;               /* [o] messaging level data (optional) */
182         unsigned char sb_len_wr;                /* [o] byte count actually written to sbp */
183         unsigned short host_status;     /* [o] errors from host adapter */
184         unsigned short driver_status;   /* [o] errors from software driver */
185         compat_int_t resid;             /* [o] dxfer_len - actual_transferred */
186         compat_uint_t duration;         /* [o] time taken by cmd (unit: millisec) */
187         compat_uint_t info;             /* [o] auxiliary information */
188 } sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
189
190 typedef struct sg_iovec32 {
191         compat_uint_t iov_base;
192         compat_uint_t iov_len;
193 } sg_iovec32_t;
194
195 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
196 {
197         sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
198         sg_iovec32_t __user *iov32 = dxferp;
199         int i;
200
201         for (i = 0; i < iovec_count; i++) {
202                 u32 base, len;
203
204                 if (get_user(base, &iov32[i].iov_base) ||
205                     get_user(len, &iov32[i].iov_len) ||
206                     put_user(compat_ptr(base), &iov[i].iov_base) ||
207                     put_user(len, &iov[i].iov_len))
208                         return -EFAULT;
209         }
210
211         if (put_user(iov, &sgio->dxferp))
212                 return -EFAULT;
213         return 0;
214 }
215
216 static int sg_ioctl_trans(struct file *file, unsigned int cmd,
217                         sg_io_hdr32_t __user *sgio32)
218 {
219         sg_io_hdr_t __user *sgio;
220         u16 iovec_count;
221         u32 data;
222         void __user *dxferp;
223         int err;
224         int interface_id;
225
226         if (get_user(interface_id, &sgio32->interface_id))
227                 return -EFAULT;
228         if (interface_id != 'S')
229                 return do_ioctl(file, cmd, (unsigned long)sgio32);
230
231         if (get_user(iovec_count, &sgio32->iovec_count))
232                 return -EFAULT;
233
234         {
235                 void __user *top = compat_alloc_user_space(0);
236                 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
237                                        (iovec_count * sizeof(sg_iovec_t)));
238                 if (new > top)
239                         return -EINVAL;
240
241                 sgio = new;
242         }
243
244         /* Ok, now construct.  */
245         if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
246                          (2 * sizeof(int)) +
247                          (2 * sizeof(unsigned char)) +
248                          (1 * sizeof(unsigned short)) +
249                          (1 * sizeof(unsigned int))))
250                 return -EFAULT;
251
252         if (get_user(data, &sgio32->dxferp))
253                 return -EFAULT;
254         dxferp = compat_ptr(data);
255         if (iovec_count) {
256                 if (sg_build_iovec(sgio, dxferp, iovec_count))
257                         return -EFAULT;
258         } else {
259                 if (put_user(dxferp, &sgio->dxferp))
260                         return -EFAULT;
261         }
262
263         {
264                 unsigned char __user *cmdp;
265                 unsigned char __user *sbp;
266
267                 if (get_user(data, &sgio32->cmdp))
268                         return -EFAULT;
269                 cmdp = compat_ptr(data);
270
271                 if (get_user(data, &sgio32->sbp))
272                         return -EFAULT;
273                 sbp = compat_ptr(data);
274
275                 if (put_user(cmdp, &sgio->cmdp) ||
276                     put_user(sbp, &sgio->sbp))
277                         return -EFAULT;
278         }
279
280         if (copy_in_user(&sgio->timeout, &sgio32->timeout,
281                          3 * sizeof(int)))
282                 return -EFAULT;
283
284         if (get_user(data, &sgio32->usr_ptr))
285                 return -EFAULT;
286         if (put_user(compat_ptr(data), &sgio->usr_ptr))
287                 return -EFAULT;
288
289         err = do_ioctl(file, cmd, (unsigned long) sgio);
290
291         if (err >= 0) {
292                 void __user *datap;
293
294                 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
295                                  sizeof(int)) ||
296                     get_user(datap, &sgio->usr_ptr) ||
297                     put_user((u32)(unsigned long)datap,
298                              &sgio32->usr_ptr) ||
299                     copy_in_user(&sgio32->status, &sgio->status,
300                                  (4 * sizeof(unsigned char)) +
301                                  (2 * sizeof(unsigned short)) +
302                                  (3 * sizeof(int))))
303                         err = -EFAULT;
304         }
305
306         return err;
307 }
308
309 struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
310         char req_state;
311         char orphan;
312         char sg_io_owned;
313         char problem;
314         int pack_id;
315         compat_uptr_t usr_ptr;
316         unsigned int duration;
317         int unused;
318 };
319
320 static int sg_grt_trans(struct file *file,
321                 unsigned int cmd, struct compat_sg_req_info __user *o)
322 {
323         int err, i;
324         sg_req_info_t __user *r;
325         r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
326         err = do_ioctl(file, cmd, (unsigned long)r);
327         if (err < 0)
328                 return err;
329         for (i = 0; i < SG_MAX_QUEUE; i++) {
330                 void __user *ptr;
331                 int d;
332
333                 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
334                     get_user(ptr, &r[i].usr_ptr) ||
335                     get_user(d, &r[i].duration) ||
336                     put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
337                     put_user(d, &o[i].duration))
338                         return -EFAULT;
339         }
340         return err;
341 }
342 #endif /* CONFIG_BLOCK */
343
344 struct sock_fprog32 {
345         unsigned short  len;
346         compat_caddr_t  filter;
347 };
348
349 #define PPPIOCSPASS32   _IOW('t', 71, struct sock_fprog32)
350 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
351
352 static int ppp_sock_fprog_ioctl_trans(struct file *file,
353                 unsigned int cmd, struct sock_fprog32 __user *u_fprog32)
354 {
355         struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
356         void __user *fptr64;
357         u32 fptr32;
358         u16 flen;
359
360         if (get_user(flen, &u_fprog32->len) ||
361             get_user(fptr32, &u_fprog32->filter))
362                 return -EFAULT;
363
364         fptr64 = compat_ptr(fptr32);
365
366         if (put_user(flen, &u_fprog64->len) ||
367             put_user(fptr64, &u_fprog64->filter))
368                 return -EFAULT;
369
370         if (cmd == PPPIOCSPASS32)
371                 cmd = PPPIOCSPASS;
372         else
373                 cmd = PPPIOCSACTIVE;
374
375         return do_ioctl(file, cmd, (unsigned long) u_fprog64);
376 }
377
378 struct ppp_option_data32 {
379         compat_caddr_t  ptr;
380         u32                     length;
381         compat_int_t            transmit;
382 };
383 #define PPPIOCSCOMPRESS32       _IOW('t', 77, struct ppp_option_data32)
384
385 struct ppp_idle32 {
386         compat_time_t xmit_idle;
387         compat_time_t recv_idle;
388 };
389 #define PPPIOCGIDLE32           _IOR('t', 63, struct ppp_idle32)
390
391 static int ppp_gidle(struct file *file, unsigned int cmd,
392                 struct ppp_idle32 __user *idle32)
393 {
394         struct ppp_idle __user *idle;
395         __kernel_time_t xmit, recv;
396         int err;
397
398         idle = compat_alloc_user_space(sizeof(*idle));
399
400         err = do_ioctl(file, PPPIOCGIDLE, (unsigned long) idle);
401
402         if (!err) {
403                 if (get_user(xmit, &idle->xmit_idle) ||
404                     get_user(recv, &idle->recv_idle) ||
405                     put_user(xmit, &idle32->xmit_idle) ||
406                     put_user(recv, &idle32->recv_idle))
407                         err = -EFAULT;
408         }
409         return err;
410 }
411
412 static int ppp_scompress(struct file *file, unsigned int cmd,
413         struct ppp_option_data32 __user *odata32)
414 {
415         struct ppp_option_data __user *odata;
416         __u32 data;
417         void __user *datap;
418
419         odata = compat_alloc_user_space(sizeof(*odata));
420
421         if (get_user(data, &odata32->ptr))
422                 return -EFAULT;
423
424         datap = compat_ptr(data);
425         if (put_user(datap, &odata->ptr))
426                 return -EFAULT;
427
428         if (copy_in_user(&odata->length, &odata32->length,
429                          sizeof(__u32) + sizeof(int)))
430                 return -EFAULT;
431
432         return do_ioctl(file, PPPIOCSCOMPRESS, (unsigned long) odata);
433 }
434
435 #ifdef CONFIG_BLOCK
436 struct mtget32 {
437         compat_long_t   mt_type;
438         compat_long_t   mt_resid;
439         compat_long_t   mt_dsreg;
440         compat_long_t   mt_gstat;
441         compat_long_t   mt_erreg;
442         compat_daddr_t  mt_fileno;
443         compat_daddr_t  mt_blkno;
444 };
445 #define MTIOCGET32      _IOR('m', 2, struct mtget32)
446
447 struct mtpos32 {
448         compat_long_t   mt_blkno;
449 };
450 #define MTIOCPOS32      _IOR('m', 3, struct mtpos32)
451
452 static int mt_ioctl_trans(struct file *file,
453                 unsigned int cmd, void __user *argp)
454 {
455         /* NULL initialization to make gcc shut up */
456         struct mtget __user *get = NULL;
457         struct mtget32 __user *umget32;
458         struct mtpos __user *pos = NULL;
459         struct mtpos32 __user *upos32;
460         unsigned long kcmd;
461         void *karg;
462         int err = 0;
463
464         switch(cmd) {
465         case MTIOCPOS32:
466                 kcmd = MTIOCPOS;
467                 pos = compat_alloc_user_space(sizeof(*pos));
468                 karg = pos;
469                 break;
470         default:        /* MTIOCGET32 */
471                 kcmd = MTIOCGET;
472                 get = compat_alloc_user_space(sizeof(*get));
473                 karg = get;
474                 break;
475         }
476         if (karg == NULL)
477                 return -EFAULT;
478         err = do_ioctl(file, kcmd, (unsigned long)karg);
479         if (err)
480                 return err;
481         switch (cmd) {
482         case MTIOCPOS32:
483                 upos32 = argp;
484                 err = convert_in_user(&pos->mt_blkno, &upos32->mt_blkno);
485                 break;
486         case MTIOCGET32:
487                 umget32 = argp;
488                 err = convert_in_user(&get->mt_type, &umget32->mt_type);
489                 err |= convert_in_user(&get->mt_resid, &umget32->mt_resid);
490                 err |= convert_in_user(&get->mt_dsreg, &umget32->mt_dsreg);
491                 err |= convert_in_user(&get->mt_gstat, &umget32->mt_gstat);
492                 err |= convert_in_user(&get->mt_erreg, &umget32->mt_erreg);
493                 err |= convert_in_user(&get->mt_fileno, &umget32->mt_fileno);
494                 err |= convert_in_user(&get->mt_blkno, &umget32->mt_blkno);
495                 break;
496         }
497         return err ? -EFAULT: 0;
498 }
499
500 #endif /* CONFIG_BLOCK */
501
502 /* Bluetooth ioctls */
503 #define HCIUARTSETPROTO         _IOW('U', 200, int)
504 #define HCIUARTGETPROTO         _IOR('U', 201, int)
505 #define HCIUARTGETDEVICE        _IOR('U', 202, int)
506 #define HCIUARTSETFLAGS         _IOW('U', 203, int)
507 #define HCIUARTGETFLAGS         _IOR('U', 204, int)
508
509 #define RTC_IRQP_READ32         _IOR('p', 0x0b, compat_ulong_t)
510 #define RTC_IRQP_SET32          _IOW('p', 0x0c, compat_ulong_t)
511 #define RTC_EPOCH_READ32        _IOR('p', 0x0d, compat_ulong_t)
512 #define RTC_EPOCH_SET32         _IOW('p', 0x0e, compat_ulong_t)
513
514 static int rtc_ioctl(struct file *file,
515                 unsigned cmd, void __user *argp)
516 {
517         unsigned long __user *valp = compat_alloc_user_space(sizeof(*valp));
518         int ret;
519
520         if (valp == NULL)
521                 return -EFAULT;
522         switch (cmd) {
523         case RTC_IRQP_READ32:
524         case RTC_EPOCH_READ32:
525                 ret = do_ioctl(file, (cmd == RTC_IRQP_READ32) ?
526                                         RTC_IRQP_READ : RTC_EPOCH_READ,
527                                         (unsigned long)valp);
528                 if (ret)
529                         return ret;
530                 return convert_in_user(valp, (unsigned int __user *)argp);
531         case RTC_IRQP_SET32:
532                 return do_ioctl(file, RTC_IRQP_SET, (unsigned long)argp);
533         case RTC_EPOCH_SET32:
534                 return do_ioctl(file, RTC_EPOCH_SET, (unsigned long)argp);
535         }
536
537         return -ENOIOCTLCMD;
538 }
539
540 /* on ia32 l_start is on a 32-bit boundary */
541 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
542 struct space_resv_32 {
543         __s16           l_type;
544         __s16           l_whence;
545         __s64           l_start __attribute__((packed));
546                         /* len == 0 means until end of file */
547         __s64           l_len __attribute__((packed));
548         __s32           l_sysid;
549         __u32           l_pid;
550         __s32           l_pad[4];       /* reserve area */
551 };
552
553 #define FS_IOC_RESVSP_32                _IOW ('X', 40, struct space_resv_32)
554 #define FS_IOC_RESVSP64_32      _IOW ('X', 42, struct space_resv_32)
555
556 /* just account for different alignment */
557 static int compat_ioctl_preallocate(struct file *file,
558                         struct space_resv_32    __user *p32)
559 {
560         struct space_resv       __user *p = compat_alloc_user_space(sizeof(*p));
561
562         if (copy_in_user(&p->l_type,    &p32->l_type,   sizeof(s16)) ||
563             copy_in_user(&p->l_whence,  &p32->l_whence, sizeof(s16)) ||
564             copy_in_user(&p->l_start,   &p32->l_start,  sizeof(s64)) ||
565             copy_in_user(&p->l_len,     &p32->l_len,    sizeof(s64)) ||
566             copy_in_user(&p->l_sysid,   &p32->l_sysid,  sizeof(s32)) ||
567             copy_in_user(&p->l_pid,     &p32->l_pid,    sizeof(u32)) ||
568             copy_in_user(&p->l_pad,     &p32->l_pad,    4*sizeof(u32)))
569                 return -EFAULT;
570
571         return ioctl_preallocate(file, p);
572 }
573 #endif
574
575 /*
576  * simple reversible transform to make our table more evenly
577  * distributed after sorting.
578  */
579 #define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff)
580
581 #define COMPATIBLE_IOCTL(cmd) XFORM((u32)cmd),
582 /* ioctl should not be warned about even if it's not implemented.
583    Valid reasons to use this:
584    - It is implemented with ->compat_ioctl on some device, but programs
585    call it on others too.
586    - The ioctl is not implemented in the native kernel, but programs
587    call it commonly anyways.
588    Most other reasons are not valid. */
589 #define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
590
591 static unsigned int ioctl_pointer[] = {
592 /* compatible ioctls first */
593 /* Little t */
594 COMPATIBLE_IOCTL(TIOCOUTQ)
595 /* Little f */
596 COMPATIBLE_IOCTL(FIOCLEX)
597 COMPATIBLE_IOCTL(FIONCLEX)
598 COMPATIBLE_IOCTL(FIOASYNC)
599 COMPATIBLE_IOCTL(FIONBIO)
600 COMPATIBLE_IOCTL(FIONREAD)  /* This is also TIOCINQ */
601 COMPATIBLE_IOCTL(FS_IOC_FIEMAP)
602 /* 0x00 */
603 COMPATIBLE_IOCTL(FIBMAP)
604 COMPATIBLE_IOCTL(FIGETBSZ)
605 /* 'X' - originally XFS but some now in the VFS */
606 COMPATIBLE_IOCTL(FIFREEZE)
607 COMPATIBLE_IOCTL(FITHAW)
608 COMPATIBLE_IOCTL(FITRIM)
609 #ifdef CONFIG_BLOCK
610 /* Big S */
611 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
612 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
613 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
614 COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
615 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
616 COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
617 COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
618 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
619 #endif
620 /* Big V (don't complain on serial console) */
621 IGNORE_IOCTL(VT_OPENQRY)
622 IGNORE_IOCTL(VT_GETMODE)
623 /* Little p (/dev/rtc, /dev/envctrl, etc.) */
624 COMPATIBLE_IOCTL(RTC_AIE_ON)
625 COMPATIBLE_IOCTL(RTC_AIE_OFF)
626 COMPATIBLE_IOCTL(RTC_UIE_ON)
627 COMPATIBLE_IOCTL(RTC_UIE_OFF)
628 COMPATIBLE_IOCTL(RTC_PIE_ON)
629 COMPATIBLE_IOCTL(RTC_PIE_OFF)
630 COMPATIBLE_IOCTL(RTC_WIE_ON)
631 COMPATIBLE_IOCTL(RTC_WIE_OFF)
632 COMPATIBLE_IOCTL(RTC_ALM_SET)
633 COMPATIBLE_IOCTL(RTC_ALM_READ)
634 COMPATIBLE_IOCTL(RTC_RD_TIME)
635 COMPATIBLE_IOCTL(RTC_SET_TIME)
636 COMPATIBLE_IOCTL(RTC_WKALM_SET)
637 COMPATIBLE_IOCTL(RTC_WKALM_RD)
638 /*
639  * These two are only for the sbus rtc driver, but
640  * hwclock tries them on every rtc device first when
641  * running on sparc.  On other architectures the entries
642  * are useless but harmless.
643  */
644 COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
645 COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
646 /* Little m */
647 COMPATIBLE_IOCTL(MTIOCTOP)
648 /* Socket level stuff */
649 COMPATIBLE_IOCTL(FIOQSIZE)
650 #ifdef CONFIG_BLOCK
651 /* md calls this on random blockdevs */
652 IGNORE_IOCTL(RAID_VERSION)
653 /* qemu/qemu-img might call these two on plain files for probing */
654 IGNORE_IOCTL(CDROM_DRIVE_STATUS)
655 IGNORE_IOCTL(FDGETPRM32)
656 /* SG stuff */
657 COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
658 COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
659 COMPATIBLE_IOCTL(SG_EMULATED_HOST)
660 COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
661 COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
662 COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
663 COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
664 COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
665 COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
666 COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
667 COMPATIBLE_IOCTL(SG_GET_PACK_ID)
668 COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
669 COMPATIBLE_IOCTL(SG_SET_DEBUG)
670 COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
671 COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
672 COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
673 COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
674 COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
675 COMPATIBLE_IOCTL(SG_SCSI_RESET)
676 COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
677 COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
678 COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
679 #endif
680 /* PPP stuff */
681 COMPATIBLE_IOCTL(PPPIOCGFLAGS)
682 COMPATIBLE_IOCTL(PPPIOCSFLAGS)
683 COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
684 COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
685 COMPATIBLE_IOCTL(PPPIOCGUNIT)
686 COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
687 COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
688 COMPATIBLE_IOCTL(PPPIOCGMRU)
689 COMPATIBLE_IOCTL(PPPIOCSMRU)
690 COMPATIBLE_IOCTL(PPPIOCSMAXCID)
691 COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
692 COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
693 COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
694 /* PPPIOCSCOMPRESS is translated */
695 COMPATIBLE_IOCTL(PPPIOCGNPMODE)
696 COMPATIBLE_IOCTL(PPPIOCSNPMODE)
697 COMPATIBLE_IOCTL(PPPIOCGDEBUG)
698 COMPATIBLE_IOCTL(PPPIOCSDEBUG)
699 /* PPPIOCSPASS is translated */
700 /* PPPIOCSACTIVE is translated */
701 /* PPPIOCGIDLE is translated */
702 COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
703 COMPATIBLE_IOCTL(PPPIOCATTACH)
704 COMPATIBLE_IOCTL(PPPIOCDETACH)
705 COMPATIBLE_IOCTL(PPPIOCSMRRU)
706 COMPATIBLE_IOCTL(PPPIOCCONNECT)
707 COMPATIBLE_IOCTL(PPPIOCDISCONN)
708 COMPATIBLE_IOCTL(PPPIOCATTCHAN)
709 COMPATIBLE_IOCTL(PPPIOCGCHAN)
710 COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS)
711 /* PPPOX */
712 COMPATIBLE_IOCTL(PPPOEIOCSFWD)
713 COMPATIBLE_IOCTL(PPPOEIOCDFWD)
714 /* Big A */
715 /* sparc only */
716 /* Big Q for sound/OSS */
717 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
718 COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
719 COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
720 COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
721 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
722 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
723 COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
724 COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
725 COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
726 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
727 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
728 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
729 COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
730 COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
731 COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
732 COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
733 COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
734 COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
735 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
736 COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
737 COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
738 COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
739 /* Big T for sound/OSS */
740 COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
741 COMPATIBLE_IOCTL(SNDCTL_TMR_START)
742 COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
743 COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
744 COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
745 COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
746 COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
747 COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
748 /* Little m for sound/OSS */
749 COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
750 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
751 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
752 /* Big P for sound/OSS */
753 COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
754 COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
755 COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
756 COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
757 COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
758 COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
759 COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
760 COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
761 COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
762 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
763 COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
764 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
765 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
766 COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
767 COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
768 COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
769 COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
770 COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
771 COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
772 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
773 /* SNDCTL_DSP_MAPINBUF,  XXX needs translation */
774 /* SNDCTL_DSP_MAPOUTBUF,  XXX needs translation */
775 COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
776 COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
777 COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
778 COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
779 COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
780 COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
781 COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
782 COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
783 /* Big C for sound/OSS */
784 COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
785 COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
786 COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
787 COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
788 COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
789 COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
790 COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
791 COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
792 COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
793 COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
794 /* Big M for sound/OSS */
795 COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
796 COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
797 COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
798 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
799 COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
800 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
801 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
802 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
803 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
804 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
805 COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
806 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
807 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
808 COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
809 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
810 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
811 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
812 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
813 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
814 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
815 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
816 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
817 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
818 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
819 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
820 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
821 /* SOUND_MIXER_READ_ENHANCE,  same value as READ_MUTE */
822 /* SOUND_MIXER_READ_LOUD,  same value as READ_MUTE */
823 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
824 COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
825 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
826 COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
827 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
828 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
829 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
830 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
831 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
832 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
833 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
834 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
835 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
836 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
837 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
838 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
839 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
840 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
841 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
842 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
843 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
844 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
845 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
846 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
847 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
848 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
849 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
850 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
851 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
852 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
853 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
854 /* SOUND_MIXER_WRITE_ENHANCE,  same value as WRITE_MUTE */
855 /* SOUND_MIXER_WRITE_LOUD,  same value as WRITE_MUTE */
856 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
857 COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
858 COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
859 COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
860 COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
861 COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
862 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
863 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
864 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
865 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
866 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
867 COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
868 COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
869 COMPATIBLE_IOCTL(OSS_GETVERSION)
870 /* Raw devices */
871 COMPATIBLE_IOCTL(RAW_SETBIND)
872 COMPATIBLE_IOCTL(RAW_GETBIND)
873 /* Watchdog */
874 COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
875 COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
876 COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
877 COMPATIBLE_IOCTL(WDIOC_GETTEMP)
878 COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
879 COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
880 COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
881 COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
882 COMPATIBLE_IOCTL(WDIOC_SETPRETIMEOUT)
883 COMPATIBLE_IOCTL(WDIOC_GETPRETIMEOUT)
884 /* Big R */
885 COMPATIBLE_IOCTL(RNDGETENTCNT)
886 COMPATIBLE_IOCTL(RNDADDTOENTCNT)
887 COMPATIBLE_IOCTL(RNDGETPOOL)
888 COMPATIBLE_IOCTL(RNDADDENTROPY)
889 COMPATIBLE_IOCTL(RNDZAPENTCNT)
890 COMPATIBLE_IOCTL(RNDCLEARPOOL)
891 /* Bluetooth */
892 COMPATIBLE_IOCTL(HCIDEVUP)
893 COMPATIBLE_IOCTL(HCIDEVDOWN)
894 COMPATIBLE_IOCTL(HCIDEVRESET)
895 COMPATIBLE_IOCTL(HCIDEVRESTAT)
896 COMPATIBLE_IOCTL(HCIGETDEVLIST)
897 COMPATIBLE_IOCTL(HCIGETDEVINFO)
898 COMPATIBLE_IOCTL(HCIGETCONNLIST)
899 COMPATIBLE_IOCTL(HCIGETCONNINFO)
900 COMPATIBLE_IOCTL(HCIGETAUTHINFO)
901 COMPATIBLE_IOCTL(HCISETRAW)
902 COMPATIBLE_IOCTL(HCISETSCAN)
903 COMPATIBLE_IOCTL(HCISETAUTH)
904 COMPATIBLE_IOCTL(HCISETENCRYPT)
905 COMPATIBLE_IOCTL(HCISETPTYPE)
906 COMPATIBLE_IOCTL(HCISETLINKPOL)
907 COMPATIBLE_IOCTL(HCISETLINKMODE)
908 COMPATIBLE_IOCTL(HCISETACLMTU)
909 COMPATIBLE_IOCTL(HCISETSCOMTU)
910 COMPATIBLE_IOCTL(HCIBLOCKADDR)
911 COMPATIBLE_IOCTL(HCIUNBLOCKADDR)
912 COMPATIBLE_IOCTL(HCIINQUIRY)
913 COMPATIBLE_IOCTL(HCIUARTSETPROTO)
914 COMPATIBLE_IOCTL(HCIUARTGETPROTO)
915 COMPATIBLE_IOCTL(HCIUARTGETDEVICE)
916 COMPATIBLE_IOCTL(HCIUARTSETFLAGS)
917 COMPATIBLE_IOCTL(HCIUARTGETFLAGS)
918 COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
919 COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
920 COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
921 COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
922 COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
923 /* CAPI */
924 COMPATIBLE_IOCTL(CAPI_REGISTER)
925 COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
926 COMPATIBLE_IOCTL(CAPI_GET_VERSION)
927 COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
928 COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
929 COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
930 COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
931 COMPATIBLE_IOCTL(CAPI_INSTALLED)
932 COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
933 COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
934 COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
935 COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
936 COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
937 /* Misc. */
938 COMPATIBLE_IOCTL(0x41545900)            /* ATYIO_CLKR */
939 COMPATIBLE_IOCTL(0x41545901)            /* ATYIO_CLKW */
940 COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
941 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
942 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
943 COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
944 /* hiddev */
945 COMPATIBLE_IOCTL(HIDIOCGVERSION)
946 COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
947 COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
948 COMPATIBLE_IOCTL(HIDIOCGSTRING)
949 COMPATIBLE_IOCTL(HIDIOCINITREPORT)
950 COMPATIBLE_IOCTL(HIDIOCGREPORT)
951 COMPATIBLE_IOCTL(HIDIOCSREPORT)
952 COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
953 COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
954 COMPATIBLE_IOCTL(HIDIOCGUSAGE)
955 COMPATIBLE_IOCTL(HIDIOCSUSAGE)
956 COMPATIBLE_IOCTL(HIDIOCGUCODE)
957 COMPATIBLE_IOCTL(HIDIOCGFLAG)
958 COMPATIBLE_IOCTL(HIDIOCSFLAG)
959 COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
960 COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
961 /* dvb */
962 COMPATIBLE_IOCTL(AUDIO_STOP)
963 COMPATIBLE_IOCTL(AUDIO_PLAY)
964 COMPATIBLE_IOCTL(AUDIO_PAUSE)
965 COMPATIBLE_IOCTL(AUDIO_CONTINUE)
966 COMPATIBLE_IOCTL(AUDIO_SELECT_SOURCE)
967 COMPATIBLE_IOCTL(AUDIO_SET_MUTE)
968 COMPATIBLE_IOCTL(AUDIO_SET_AV_SYNC)
969 COMPATIBLE_IOCTL(AUDIO_SET_BYPASS_MODE)
970 COMPATIBLE_IOCTL(AUDIO_CHANNEL_SELECT)
971 COMPATIBLE_IOCTL(AUDIO_GET_STATUS)
972 COMPATIBLE_IOCTL(AUDIO_GET_CAPABILITIES)
973 COMPATIBLE_IOCTL(AUDIO_CLEAR_BUFFER)
974 COMPATIBLE_IOCTL(AUDIO_SET_ID)
975 COMPATIBLE_IOCTL(AUDIO_SET_MIXER)
976 COMPATIBLE_IOCTL(AUDIO_SET_STREAMTYPE)
977 COMPATIBLE_IOCTL(DMX_START)
978 COMPATIBLE_IOCTL(DMX_STOP)
979 COMPATIBLE_IOCTL(DMX_SET_FILTER)
980 COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
981 COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
982 COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
983 COMPATIBLE_IOCTL(DMX_GET_STC)
984 COMPATIBLE_IOCTL(DMX_REQBUFS)
985 COMPATIBLE_IOCTL(DMX_QUERYBUF)
986 COMPATIBLE_IOCTL(DMX_EXPBUF)
987 COMPATIBLE_IOCTL(DMX_QBUF)
988 COMPATIBLE_IOCTL(DMX_DQBUF)
989 COMPATIBLE_IOCTL(VIDEO_STOP)
990 COMPATIBLE_IOCTL(VIDEO_PLAY)
991 COMPATIBLE_IOCTL(VIDEO_FREEZE)
992 COMPATIBLE_IOCTL(VIDEO_CONTINUE)
993 COMPATIBLE_IOCTL(VIDEO_SELECT_SOURCE)
994 COMPATIBLE_IOCTL(VIDEO_SET_BLANK)
995 COMPATIBLE_IOCTL(VIDEO_GET_STATUS)
996 COMPATIBLE_IOCTL(VIDEO_SET_DISPLAY_FORMAT)
997 COMPATIBLE_IOCTL(VIDEO_FAST_FORWARD)
998 COMPATIBLE_IOCTL(VIDEO_SLOWMOTION)
999 COMPATIBLE_IOCTL(VIDEO_GET_CAPABILITIES)
1000 COMPATIBLE_IOCTL(VIDEO_CLEAR_BUFFER)
1001 COMPATIBLE_IOCTL(VIDEO_SET_STREAMTYPE)
1002 COMPATIBLE_IOCTL(VIDEO_SET_FORMAT)
1003 COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
1004 /* cec */
1005 COMPATIBLE_IOCTL(CEC_ADAP_G_CAPS)
1006 COMPATIBLE_IOCTL(CEC_ADAP_G_LOG_ADDRS)
1007 COMPATIBLE_IOCTL(CEC_ADAP_S_LOG_ADDRS)
1008 COMPATIBLE_IOCTL(CEC_ADAP_G_PHYS_ADDR)
1009 COMPATIBLE_IOCTL(CEC_ADAP_S_PHYS_ADDR)
1010 COMPATIBLE_IOCTL(CEC_G_MODE)
1011 COMPATIBLE_IOCTL(CEC_S_MODE)
1012 COMPATIBLE_IOCTL(CEC_TRANSMIT)
1013 COMPATIBLE_IOCTL(CEC_RECEIVE)
1014 COMPATIBLE_IOCTL(CEC_DQEVENT)
1015
1016 /* joystick */
1017 COMPATIBLE_IOCTL(JSIOCGVERSION)
1018 COMPATIBLE_IOCTL(JSIOCGAXES)
1019 COMPATIBLE_IOCTL(JSIOCGBUTTONS)
1020 COMPATIBLE_IOCTL(JSIOCGNAME(0))
1021
1022 /* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
1023    but we don't want warnings on other file systems. So declare
1024    them as compatible here. */
1025 #define VFAT_IOCTL_READDIR_BOTH32       _IOR('r', 1, struct compat_dirent[2])
1026 #define VFAT_IOCTL_READDIR_SHORT32      _IOR('r', 2, struct compat_dirent[2])
1027
1028 IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
1029 IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
1030
1031 #ifdef CONFIG_SPARC
1032 /* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
1033 IGNORE_IOCTL(FBIOGTYPE)
1034 IGNORE_IOCTL(FBIOSATTR)
1035 IGNORE_IOCTL(FBIOGATTR)
1036 IGNORE_IOCTL(FBIOSVIDEO)
1037 IGNORE_IOCTL(FBIOGVIDEO)
1038 IGNORE_IOCTL(FBIOSCURPOS)
1039 IGNORE_IOCTL(FBIOGCURPOS)
1040 IGNORE_IOCTL(FBIOGCURMAX)
1041 IGNORE_IOCTL(FBIOPUTCMAP32)
1042 IGNORE_IOCTL(FBIOGETCMAP32)
1043 IGNORE_IOCTL(FBIOSCURSOR32)
1044 IGNORE_IOCTL(FBIOGCURSOR32)
1045 #endif
1046 };
1047
1048 /*
1049  * Convert common ioctl arguments based on their command number
1050  *
1051  * Please do not add any code in here. Instead, implement
1052  * a compat_ioctl operation in the place that handleŃ• the
1053  * ioctl for the native case.
1054  */
1055 static long do_ioctl_trans(unsigned int cmd,
1056                  unsigned long arg, struct file *file)
1057 {
1058         void __user *argp = compat_ptr(arg);
1059
1060         switch (cmd) {
1061         case PPPIOCGIDLE32:
1062                 return ppp_gidle(file, cmd, argp);
1063         case PPPIOCSCOMPRESS32:
1064                 return ppp_scompress(file, cmd, argp);
1065         case PPPIOCSPASS32:
1066         case PPPIOCSACTIVE32:
1067                 return ppp_sock_fprog_ioctl_trans(file, cmd, argp);
1068 #ifdef CONFIG_BLOCK
1069         case SG_IO:
1070                 return sg_ioctl_trans(file, cmd, argp);
1071         case SG_GET_REQUEST_TABLE:
1072                 return sg_grt_trans(file, cmd, argp);
1073         case MTIOCGET32:
1074         case MTIOCPOS32:
1075                 return mt_ioctl_trans(file, cmd, argp);
1076 #endif
1077         /* Not implemented in the native kernel */
1078         case RTC_IRQP_READ32:
1079         case RTC_IRQP_SET32:
1080         case RTC_EPOCH_READ32:
1081         case RTC_EPOCH_SET32:
1082                 return rtc_ioctl(file, cmd, argp);
1083
1084         /* dvb */
1085         case VIDEO_GET_EVENT:
1086                 return do_video_get_event(file, cmd, argp);
1087         case VIDEO_STILLPICTURE:
1088                 return do_video_stillpicture(file, cmd, argp);
1089         }
1090
1091         /*
1092          * These take an integer instead of a pointer as 'arg',
1093          * so we must not do a compat_ptr() translation.
1094          */
1095         switch (cmd) {
1096         /* RAID */
1097         case HOT_REMOVE_DISK:
1098         case HOT_ADD_DISK:
1099         case SET_DISK_FAULTY:
1100         case SET_BITMAP_FILE:
1101                 return vfs_ioctl(file, cmd, arg);
1102         }
1103
1104         return -ENOIOCTLCMD;
1105 }
1106
1107 static int compat_ioctl_check_table(unsigned int xcmd)
1108 {
1109         int i;
1110         const int max = ARRAY_SIZE(ioctl_pointer) - 1;
1111
1112         BUILD_BUG_ON(max >= (1 << 16));
1113
1114         /* guess initial offset into table, assuming a
1115            normalized distribution */
1116         i = ((xcmd >> 16) * max) >> 16;
1117
1118         /* do linear search up first, until greater or equal */
1119         while (ioctl_pointer[i] < xcmd && i < max)
1120                 i++;
1121
1122         /* then do linear search down */
1123         while (ioctl_pointer[i] > xcmd && i > 0)
1124                 i--;
1125
1126         return ioctl_pointer[i] == xcmd;
1127 }
1128
1129 COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
1130                        compat_ulong_t, arg32)
1131 {
1132         unsigned long arg = arg32;
1133         struct fd f = fdget(fd);
1134         int error = -EBADF;
1135         if (!f.file)
1136                 goto out;
1137
1138         /* RED-PEN how should LSM module know it's handling 32bit? */
1139         error = security_file_ioctl(f.file, cmd, arg);
1140         if (error)
1141                 goto out_fput;
1142
1143         /*
1144          * To allow the compat_ioctl handlers to be self contained
1145          * we need to check the common ioctls here first.
1146          * Just handle them with the standard handlers below.
1147          */
1148         switch (cmd) {
1149         case FIOCLEX:
1150         case FIONCLEX:
1151         case FIONBIO:
1152         case FIOASYNC:
1153         case FIOQSIZE:
1154                 break;
1155
1156 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
1157         case FS_IOC_RESVSP_32:
1158         case FS_IOC_RESVSP64_32:
1159                 error = compat_ioctl_preallocate(f.file, compat_ptr(arg));
1160                 goto out_fput;
1161 #else
1162         case FS_IOC_RESVSP:
1163         case FS_IOC_RESVSP64:
1164                 error = ioctl_preallocate(f.file, compat_ptr(arg));
1165                 goto out_fput;
1166 #endif
1167
1168         case FICLONE:
1169         case FICLONERANGE:
1170         case FIDEDUPERANGE:
1171         case FS_IOC_FIEMAP:
1172                 goto do_ioctl;
1173
1174         case FIBMAP:
1175         case FIGETBSZ:
1176         case FIONREAD:
1177                 if (S_ISREG(file_inode(f.file)->i_mode))
1178                         break;
1179                 /*FALL THROUGH*/
1180
1181         default:
1182                 if (f.file->f_op->compat_ioctl) {
1183                         error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
1184                         if (error != -ENOIOCTLCMD)
1185                                 goto out_fput;
1186                 }
1187
1188                 if (!f.file->f_op->unlocked_ioctl)
1189                         goto do_ioctl;
1190                 break;
1191         }
1192
1193         if (compat_ioctl_check_table(XFORM(cmd)))
1194                 goto found_handler;
1195
1196         error = do_ioctl_trans(cmd, arg, f.file);
1197         if (error == -ENOIOCTLCMD)
1198                 error = -ENOTTY;
1199
1200         goto out_fput;
1201
1202  found_handler:
1203         arg = (unsigned long)compat_ptr(arg);
1204  do_ioctl:
1205         error = do_vfs_ioctl(f.file, fd, cmd, arg);
1206  out_fput:
1207         fdput(f);
1208  out:
1209         return error;
1210 }
1211
1212 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
1213 {
1214         unsigned int a, b;
1215         a = *(unsigned int *)p;
1216         b = *(unsigned int *)q;
1217         if (a > b)
1218                 return 1;
1219         if (a < b)
1220                 return -1;
1221         return 0;
1222 }
1223
1224 static int __init init_sys32_ioctl(void)
1225 {
1226         sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer),
1227                 init_sys32_ioctl_cmp, NULL);
1228         return 0;
1229 }
1230 __initcall(init_sys32_ioctl);