compat_ioctl: Remove BKL
[safe/jmp/linux-2.6] / fs / compat_ioctl.c
1 /*
2  * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3  *
4  * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
5  * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
6  * Copyright (C) 2001,2002  Andi Kleen, SuSE Labs 
7  * Copyright (C) 2003       Pavel Machek (pavel@suse.cz)
8  *
9  * These routines maintain argument size conversion between 32bit and 64bit
10  * ioctls.
11  */
12
13 #include <linux/joystick.h>
14
15 #include <linux/types.h>
16 #include <linux/compat.h>
17 #include <linux/kernel.h>
18 #include <linux/capability.h>
19 #include <linux/compiler.h>
20 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
23 #include <linux/ioctl.h>
24 #include <linux/if.h>
25 #include <linux/if_bridge.h>
26 #include <linux/slab.h>
27 #include <linux/raid/md_u.h>
28 #include <linux/kd.h>
29 #include <linux/route.h>
30 #include <linux/in6.h>
31 #include <linux/ipv6_route.h>
32 #include <linux/skbuff.h>
33 #include <linux/netlink.h>
34 #include <linux/vt.h>
35 #include <linux/falloc.h>
36 #include <linux/fs.h>
37 #include <linux/file.h>
38 #include <linux/ppp_defs.h>
39 #include <linux/if_ppp.h>
40 #include <linux/if_pppox.h>
41 #include <linux/mtio.h>
42 #include <linux/auto_fs.h>
43 #include <linux/auto_fs4.h>
44 #include <linux/tty.h>
45 #include <linux/vt_kern.h>
46 #include <linux/fb.h>
47 #include <linux/videodev.h>
48 #include <linux/netdevice.h>
49 #include <linux/raw.h>
50 #include <linux/smb_fs.h>
51 #include <linux/blkdev.h>
52 #include <linux/elevator.h>
53 #include <linux/rtc.h>
54 #include <linux/pci.h>
55 #include <linux/module.h>
56 #include <linux/serial.h>
57 #include <linux/if_tun.h>
58 #include <linux/ctype.h>
59 #include <linux/syscalls.h>
60 #include <linux/i2c.h>
61 #include <linux/i2c-dev.h>
62 #include <linux/atalk.h>
63
64 #include <net/bluetooth/bluetooth.h>
65 #include <net/bluetooth/hci.h>
66 #include <net/bluetooth/rfcomm.h>
67
68 #include <linux/capi.h>
69 #include <linux/gigaset_dev.h>
70
71 #ifdef CONFIG_BLOCK
72 #include <linux/loop.h>
73 #include <scsi/scsi.h>
74 #include <scsi/scsi_ioctl.h>
75 #include <scsi/sg.h>
76 #endif
77
78 #include <asm/uaccess.h>
79 #include <linux/ethtool.h>
80 #include <linux/mii.h>
81 #include <linux/if_bonding.h>
82 #include <linux/watchdog.h>
83
84 #include <linux/soundcard.h>
85 #include <linux/lp.h>
86 #include <linux/ppdev.h>
87
88 #include <linux/atm.h>
89 #include <linux/atmarp.h>
90 #include <linux/atmclip.h>
91 #include <linux/atmdev.h>
92 #include <linux/atmioc.h>
93 #include <linux/atmlec.h>
94 #include <linux/atmmpc.h>
95 #include <linux/atmsvc.h>
96 #include <linux/atm_tcp.h>
97 #include <linux/sonet.h>
98 #include <linux/atm_suni.h>
99
100 #include <linux/usb.h>
101 #include <linux/usbdevice_fs.h>
102 #include <linux/nbd.h>
103 #include <linux/random.h>
104 #include <linux/filter.h>
105 #include <linux/pktcdvd.h>
106
107 #include <linux/hiddev.h>
108
109 #include <linux/dvb/audio.h>
110 #include <linux/dvb/dmx.h>
111 #include <linux/dvb/frontend.h>
112 #include <linux/dvb/video.h>
113
114 #ifdef CONFIG_SPARC
115 #include <asm/fbio.h>
116 #endif
117
118 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
119                               unsigned long arg, struct file *f)
120 {
121         return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
122 }
123
124 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
125 {
126         mm_segment_t old_fs = get_fs();
127         int err;
128         unsigned long val;
129         
130         set_fs (KERNEL_DS);
131         err = sys_ioctl(fd, cmd, (unsigned long)&val);
132         set_fs (old_fs);
133         if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
134                 return -EFAULT;
135         return err;
136 }
137  
138 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
139 {
140         mm_segment_t old_fs = get_fs();
141         u32 __user *argptr = compat_ptr(arg);
142         int err;
143         unsigned long val;
144         
145         if(get_user(val, argptr))
146                 return -EFAULT;
147         set_fs (KERNEL_DS);
148         err = sys_ioctl(fd, cmd, (unsigned long)&val);
149         set_fs (old_fs);
150         if (!err && put_user(val, argptr))
151                 return -EFAULT;
152         return err;
153 }
154
155 struct compat_video_event {
156         int32_t         type;
157         compat_time_t   timestamp;
158         union {
159                 video_size_t size;
160                 unsigned int frame_rate;
161         } u;
162 };
163
164 static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
165 {
166         struct video_event kevent;
167         mm_segment_t old_fs = get_fs();
168         int err;
169
170         set_fs(KERNEL_DS);
171         err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
172         set_fs(old_fs);
173
174         if (!err) {
175                 struct compat_video_event __user *up = compat_ptr(arg);
176
177                 err  = put_user(kevent.type, &up->type);
178                 err |= put_user(kevent.timestamp, &up->timestamp);
179                 err |= put_user(kevent.u.size.w, &up->u.size.w);
180                 err |= put_user(kevent.u.size.h, &up->u.size.h);
181                 err |= put_user(kevent.u.size.aspect_ratio,
182                                 &up->u.size.aspect_ratio);
183                 if (err)
184                         err = -EFAULT;
185         }
186
187         return err;
188 }
189
190 struct compat_video_still_picture {
191         compat_uptr_t iFrame;
192         int32_t size;
193 };
194
195 static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
196 {
197         struct compat_video_still_picture __user *up;
198         struct video_still_picture __user *up_native;
199         compat_uptr_t fp;
200         int32_t size;
201         int err;
202
203         up = (struct compat_video_still_picture __user *) arg;
204         err  = get_user(fp, &up->iFrame);
205         err |= get_user(size, &up->size);
206         if (err)
207                 return -EFAULT;
208
209         up_native =
210                 compat_alloc_user_space(sizeof(struct video_still_picture));
211
212         err =  put_user(compat_ptr(fp), &up_native->iFrame);
213         err |= put_user(size, &up_native->size);
214         if (err)
215                 return -EFAULT;
216
217         err = sys_ioctl(fd, cmd, (unsigned long) up_native);
218
219         return err;
220 }
221
222 struct compat_video_spu_palette {
223         int length;
224         compat_uptr_t palette;
225 };
226
227 static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
228 {
229         struct compat_video_spu_palette __user *up;
230         struct video_spu_palette __user *up_native;
231         compat_uptr_t palp;
232         int length, err;
233
234         up = (struct compat_video_spu_palette __user *) arg;
235         err  = get_user(palp, &up->palette);
236         err |= get_user(length, &up->length);
237
238         up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
239         err  = put_user(compat_ptr(palp), &up_native->palette);
240         err |= put_user(length, &up_native->length);
241         if (err)
242                 return -EFAULT;
243
244         err = sys_ioctl(fd, cmd, (unsigned long) up_native);
245
246         return err;
247 }
248
249 #ifdef CONFIG_BLOCK
250 typedef struct sg_io_hdr32 {
251         compat_int_t interface_id;      /* [i] 'S' for SCSI generic (required) */
252         compat_int_t dxfer_direction;   /* [i] data transfer direction  */
253         unsigned char cmd_len;          /* [i] SCSI command length ( <= 16 bytes) */
254         unsigned char mx_sb_len;                /* [i] max length to write to sbp */
255         unsigned short iovec_count;     /* [i] 0 implies no scatter gather */
256         compat_uint_t dxfer_len;                /* [i] byte count of data transfer */
257         compat_uint_t dxferp;           /* [i], [*io] points to data transfer memory
258                                               or scatter gather list */
259         compat_uptr_t cmdp;             /* [i], [*i] points to command to perform */
260         compat_uptr_t sbp;              /* [i], [*o] points to sense_buffer memory */
261         compat_uint_t timeout;          /* [i] MAX_UINT->no timeout (unit: millisec) */
262         compat_uint_t flags;            /* [i] 0 -> default, see SG_FLAG... */
263         compat_int_t pack_id;           /* [i->o] unused internally (normally) */
264         compat_uptr_t usr_ptr;          /* [i->o] unused internally */
265         unsigned char status;           /* [o] scsi status */
266         unsigned char masked_status;    /* [o] shifted, masked scsi status */
267         unsigned char msg_status;               /* [o] messaging level data (optional) */
268         unsigned char sb_len_wr;                /* [o] byte count actually written to sbp */
269         unsigned short host_status;     /* [o] errors from host adapter */
270         unsigned short driver_status;   /* [o] errors from software driver */
271         compat_int_t resid;             /* [o] dxfer_len - actual_transferred */
272         compat_uint_t duration;         /* [o] time taken by cmd (unit: millisec) */
273         compat_uint_t info;             /* [o] auxiliary information */
274 } sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
275
276 typedef struct sg_iovec32 {
277         compat_uint_t iov_base;
278         compat_uint_t iov_len;
279 } sg_iovec32_t;
280
281 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
282 {
283         sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
284         sg_iovec32_t __user *iov32 = dxferp;
285         int i;
286
287         for (i = 0; i < iovec_count; i++) {
288                 u32 base, len;
289
290                 if (get_user(base, &iov32[i].iov_base) ||
291                     get_user(len, &iov32[i].iov_len) ||
292                     put_user(compat_ptr(base), &iov[i].iov_base) ||
293                     put_user(len, &iov[i].iov_len))
294                         return -EFAULT;
295         }
296
297         if (put_user(iov, &sgio->dxferp))
298                 return -EFAULT;
299         return 0;
300 }
301
302 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
303 {
304         sg_io_hdr_t __user *sgio;
305         sg_io_hdr32_t __user *sgio32;
306         u16 iovec_count;
307         u32 data;
308         void __user *dxferp;
309         int err;
310
311         sgio32 = compat_ptr(arg);
312         if (get_user(iovec_count, &sgio32->iovec_count))
313                 return -EFAULT;
314
315         {
316                 void __user *top = compat_alloc_user_space(0);
317                 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
318                                        (iovec_count * sizeof(sg_iovec_t)));
319                 if (new > top)
320                         return -EINVAL;
321
322                 sgio = new;
323         }
324
325         /* Ok, now construct.  */
326         if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
327                          (2 * sizeof(int)) +
328                          (2 * sizeof(unsigned char)) +
329                          (1 * sizeof(unsigned short)) +
330                          (1 * sizeof(unsigned int))))
331                 return -EFAULT;
332
333         if (get_user(data, &sgio32->dxferp))
334                 return -EFAULT;
335         dxferp = compat_ptr(data);
336         if (iovec_count) {
337                 if (sg_build_iovec(sgio, dxferp, iovec_count))
338                         return -EFAULT;
339         } else {
340                 if (put_user(dxferp, &sgio->dxferp))
341                         return -EFAULT;
342         }
343
344         {
345                 unsigned char __user *cmdp;
346                 unsigned char __user *sbp;
347
348                 if (get_user(data, &sgio32->cmdp))
349                         return -EFAULT;
350                 cmdp = compat_ptr(data);
351
352                 if (get_user(data, &sgio32->sbp))
353                         return -EFAULT;
354                 sbp = compat_ptr(data);
355
356                 if (put_user(cmdp, &sgio->cmdp) ||
357                     put_user(sbp, &sgio->sbp))
358                         return -EFAULT;
359         }
360
361         if (copy_in_user(&sgio->timeout, &sgio32->timeout,
362                          3 * sizeof(int)))
363                 return -EFAULT;
364
365         if (get_user(data, &sgio32->usr_ptr))
366                 return -EFAULT;
367         if (put_user(compat_ptr(data), &sgio->usr_ptr))
368                 return -EFAULT;
369
370         err = sys_ioctl(fd, cmd, (unsigned long) sgio);
371
372         if (err >= 0) {
373                 void __user *datap;
374
375                 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
376                                  sizeof(int)) ||
377                     get_user(datap, &sgio->usr_ptr) ||
378                     put_user((u32)(unsigned long)datap,
379                              &sgio32->usr_ptr) ||
380                     copy_in_user(&sgio32->status, &sgio->status,
381                                  (4 * sizeof(unsigned char)) +
382                                  (2 * sizeof(unsigned short)) +
383                                  (3 * sizeof(int))))
384                         err = -EFAULT;
385         }
386
387         return err;
388 }
389
390 struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
391         char req_state;
392         char orphan;
393         char sg_io_owned;
394         char problem;
395         int pack_id;
396         compat_uptr_t usr_ptr;
397         unsigned int duration;
398         int unused;
399 };
400
401 static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
402 {
403         int err, i;
404         sg_req_info_t __user *r;
405         struct compat_sg_req_info __user *o = (void __user *)arg;
406         r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
407         err = sys_ioctl(fd,cmd,(unsigned long)r);
408         if (err < 0)
409                 return err;
410         for (i = 0; i < SG_MAX_QUEUE; i++) {
411                 void __user *ptr;
412                 int d;
413
414                 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
415                     get_user(ptr, &r[i].usr_ptr) ||
416                     get_user(d, &r[i].duration) ||
417                     put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
418                     put_user(d, &o[i].duration))
419                         return -EFAULT;
420         }
421         return err;
422 }
423 #endif /* CONFIG_BLOCK */
424
425 struct sock_fprog32 {
426         unsigned short  len;
427         compat_caddr_t  filter;
428 };
429
430 #define PPPIOCSPASS32   _IOW('t', 71, struct sock_fprog32)
431 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
432
433 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
434 {
435         struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
436         struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
437         void __user *fptr64;
438         u32 fptr32;
439         u16 flen;
440
441         if (get_user(flen, &u_fprog32->len) ||
442             get_user(fptr32, &u_fprog32->filter))
443                 return -EFAULT;
444
445         fptr64 = compat_ptr(fptr32);
446
447         if (put_user(flen, &u_fprog64->len) ||
448             put_user(fptr64, &u_fprog64->filter))
449                 return -EFAULT;
450
451         if (cmd == PPPIOCSPASS32)
452                 cmd = PPPIOCSPASS;
453         else
454                 cmd = PPPIOCSACTIVE;
455
456         return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
457 }
458
459 struct ppp_option_data32 {
460         compat_caddr_t  ptr;
461         u32                     length;
462         compat_int_t            transmit;
463 };
464 #define PPPIOCSCOMPRESS32       _IOW('t', 77, struct ppp_option_data32)
465
466 struct ppp_idle32 {
467         compat_time_t xmit_idle;
468         compat_time_t recv_idle;
469 };
470 #define PPPIOCGIDLE32           _IOR('t', 63, struct ppp_idle32)
471
472 static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
473 {
474         struct ppp_idle __user *idle;
475         struct ppp_idle32 __user *idle32;
476         __kernel_time_t xmit, recv;
477         int err;
478
479         idle = compat_alloc_user_space(sizeof(*idle));
480         idle32 = compat_ptr(arg);
481
482         err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
483
484         if (!err) {
485                 if (get_user(xmit, &idle->xmit_idle) ||
486                     get_user(recv, &idle->recv_idle) ||
487                     put_user(xmit, &idle32->xmit_idle) ||
488                     put_user(recv, &idle32->recv_idle))
489                         err = -EFAULT;
490         }
491         return err;
492 }
493
494 static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
495 {
496         struct ppp_option_data __user *odata;
497         struct ppp_option_data32 __user *odata32;
498         __u32 data;
499         void __user *datap;
500
501         odata = compat_alloc_user_space(sizeof(*odata));
502         odata32 = compat_ptr(arg);
503
504         if (get_user(data, &odata32->ptr))
505                 return -EFAULT;
506
507         datap = compat_ptr(data);
508         if (put_user(datap, &odata->ptr))
509                 return -EFAULT;
510
511         if (copy_in_user(&odata->length, &odata32->length,
512                          sizeof(__u32) + sizeof(int)))
513                 return -EFAULT;
514
515         return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
516 }
517
518 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
519 {
520         int err;
521
522         switch (cmd) {
523         case PPPIOCGIDLE32:
524                 err = ppp_gidle(fd, cmd, arg);
525                 break;
526
527         case PPPIOCSCOMPRESS32:
528                 err = ppp_scompress(fd, cmd, arg);
529                 break;
530
531         default:
532                 do {
533                         static int count;
534                         if (++count <= 20)
535                                 printk("ppp_ioctl: Unknown cmd fd(%d) "
536                                        "cmd(%08x) arg(%08x)\n",
537                                        (int)fd, (unsigned int)cmd, (unsigned int)arg);
538                 } while(0);
539                 err = -EINVAL;
540                 break;
541         };
542
543         return err;
544 }
545
546
547 #ifdef CONFIG_BLOCK
548 struct mtget32 {
549         compat_long_t   mt_type;
550         compat_long_t   mt_resid;
551         compat_long_t   mt_dsreg;
552         compat_long_t   mt_gstat;
553         compat_long_t   mt_erreg;
554         compat_daddr_t  mt_fileno;
555         compat_daddr_t  mt_blkno;
556 };
557 #define MTIOCGET32      _IOR('m', 2, struct mtget32)
558
559 struct mtpos32 {
560         compat_long_t   mt_blkno;
561 };
562 #define MTIOCPOS32      _IOR('m', 3, struct mtpos32)
563
564 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
565 {
566         mm_segment_t old_fs = get_fs();
567         struct mtget get;
568         struct mtget32 __user *umget32;
569         struct mtpos pos;
570         struct mtpos32 __user *upos32;
571         unsigned long kcmd;
572         void *karg;
573         int err = 0;
574
575         switch(cmd) {
576         case MTIOCPOS32:
577                 kcmd = MTIOCPOS;
578                 karg = &pos;
579                 break;
580         case MTIOCGET32:
581                 kcmd = MTIOCGET;
582                 karg = &get;
583                 break;
584         default:
585                 do {
586                         static int count;
587                         if (++count <= 20)
588                                 printk("mt_ioctl: Unknown cmd fd(%d) "
589                                        "cmd(%08x) arg(%08x)\n",
590                                        (int)fd, (unsigned int)cmd, (unsigned int)arg);
591                 } while(0);
592                 return -EINVAL;
593         }
594         set_fs (KERNEL_DS);
595         err = sys_ioctl (fd, kcmd, (unsigned long)karg);
596         set_fs (old_fs);
597         if (err)
598                 return err;
599         switch (cmd) {
600         case MTIOCPOS32:
601                 upos32 = compat_ptr(arg);
602                 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
603                 break;
604         case MTIOCGET32:
605                 umget32 = compat_ptr(arg);
606                 err = __put_user(get.mt_type, &umget32->mt_type);
607                 err |= __put_user(get.mt_resid, &umget32->mt_resid);
608                 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
609                 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
610                 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
611                 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
612                 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
613                 break;
614         }
615         return err ? -EFAULT: 0;
616 }
617
618 #endif /* CONFIG_BLOCK */
619
620 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
621 {
622         mm_segment_t old_fs = get_fs();
623         __kernel_uid_t kuid;
624         int err;
625
626         cmd = SMB_IOC_GETMOUNTUID;
627
628         set_fs(KERNEL_DS);
629         err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
630         set_fs(old_fs);
631
632         if (err >= 0)
633                 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
634
635         return err;
636 }
637
638 static __used int
639 ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
640 {
641         return -EINVAL;
642 }
643
644 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
645 {
646         return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
647 }
648
649 /* Bluetooth ioctls */
650 #define HCIUARTSETPROTO _IOW('U', 200, int)
651 #define HCIUARTGETPROTO _IOR('U', 201, int)
652
653 #define BNEPCONNADD     _IOW('B', 200, int)
654 #define BNEPCONNDEL     _IOW('B', 201, int)
655 #define BNEPGETCONNLIST _IOR('B', 210, int)
656 #define BNEPGETCONNINFO _IOR('B', 211, int)
657
658 #define CMTPCONNADD     _IOW('C', 200, int)
659 #define CMTPCONNDEL     _IOW('C', 201, int)
660 #define CMTPGETCONNLIST _IOR('C', 210, int)
661 #define CMTPGETCONNINFO _IOR('C', 211, int)
662
663 #define HIDPCONNADD     _IOW('H', 200, int)
664 #define HIDPCONNDEL     _IOW('H', 201, int)
665 #define HIDPGETCONNLIST _IOR('H', 210, int)
666 #define HIDPGETCONNINFO _IOR('H', 211, int)
667
668 #ifdef CONFIG_BLOCK
669 struct raw32_config_request
670 {
671         compat_int_t    raw_minor;
672         __u64   block_major;
673         __u64   block_minor;
674 } __attribute__((packed));
675
676 static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
677 {
678         int ret;
679
680         if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
681                 return -EFAULT;
682
683         ret = __get_user(req->raw_minor, &user_req->raw_minor);
684         ret |= __get_user(req->block_major, &user_req->block_major);
685         ret |= __get_user(req->block_minor, &user_req->block_minor);
686
687         return ret ? -EFAULT : 0;
688 }
689
690 static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
691 {
692         int ret;
693
694         if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
695                 return -EFAULT;
696
697         ret = __put_user(req->raw_minor, &user_req->raw_minor);
698         ret |= __put_user(req->block_major, &user_req->block_major);
699         ret |= __put_user(req->block_minor, &user_req->block_minor);
700
701         return ret ? -EFAULT : 0;
702 }
703
704 static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
705 {
706         int ret;
707
708         switch (cmd) {
709         case RAW_SETBIND:
710         case RAW_GETBIND: {
711                 struct raw_config_request req;
712                 struct raw32_config_request __user *user_req = compat_ptr(arg);
713                 mm_segment_t oldfs = get_fs();
714
715                 if ((ret = get_raw32_request(&req, user_req)))
716                         return ret;
717
718                 set_fs(KERNEL_DS);
719                 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
720                 set_fs(oldfs);
721
722                 if ((!ret) && (cmd == RAW_GETBIND)) {
723                         ret = set_raw32_request(&req, user_req);
724                 }
725                 break;
726         }
727         default:
728                 ret = sys_ioctl(fd, cmd, arg);
729                 break;
730         }
731         return ret;
732 }
733 #endif /* CONFIG_BLOCK */
734
735 struct serial_struct32 {
736         compat_int_t    type;
737         compat_int_t    line;
738         compat_uint_t   port;
739         compat_int_t    irq;
740         compat_int_t    flags;
741         compat_int_t    xmit_fifo_size;
742         compat_int_t    custom_divisor;
743         compat_int_t    baud_base;
744         unsigned short  close_delay;
745         char    io_type;
746         char    reserved_char[1];
747         compat_int_t    hub6;
748         unsigned short  closing_wait; /* time to wait before closing */
749         unsigned short  closing_wait2; /* no longer used... */
750         compat_uint_t   iomem_base;
751         unsigned short  iomem_reg_shift;
752         unsigned int    port_high;
753      /* compat_ulong_t  iomap_base FIXME */
754         compat_int_t    reserved[1];
755 };
756
757 static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
758 {
759         typedef struct serial_struct SS;
760         typedef struct serial_struct32 SS32;
761         struct serial_struct32 __user *ss32 = compat_ptr(arg);
762         int err;
763         struct serial_struct ss;
764         mm_segment_t oldseg = get_fs();
765         __u32 udata;
766         unsigned int base;
767
768         if (cmd == TIOCSSERIAL) {
769                 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
770                         return -EFAULT;
771                 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
772                         return -EFAULT;
773                 if (__get_user(udata, &ss32->iomem_base))
774                         return -EFAULT;
775                 ss.iomem_base = compat_ptr(udata);
776                 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
777                     __get_user(ss.port_high, &ss32->port_high))
778                         return -EFAULT;
779                 ss.iomap_base = 0UL;
780         }
781         set_fs(KERNEL_DS);
782                 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
783         set_fs(oldseg);
784         if (cmd == TIOCGSERIAL && err >= 0) {
785                 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
786                         return -EFAULT;
787                 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
788                         return -EFAULT;
789                 base = (unsigned long)ss.iomem_base  >> 32 ?
790                         0xffffffff : (unsigned)(unsigned long)ss.iomem_base;
791                 if (__put_user(base, &ss32->iomem_base) ||
792                     __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
793                     __put_user(ss.port_high, &ss32->port_high))
794                         return -EFAULT;
795         }
796         return err;
797 }
798
799 struct usbdevfs_ctrltransfer32 {
800         u8 bRequestType;
801         u8 bRequest;
802         u16 wValue;
803         u16 wIndex;
804         u16 wLength;
805         u32 timeout;  /* in milliseconds */
806         compat_caddr_t data;
807 };
808
809 #define USBDEVFS_CONTROL32           _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
810
811 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
812 {
813         struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
814         struct usbdevfs_ctrltransfer __user *p;
815         __u32 udata;
816         p = compat_alloc_user_space(sizeof(*p));
817         if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
818             get_user(udata, &p32->data) ||
819             put_user(compat_ptr(udata), &p->data))
820                 return -EFAULT;
821         return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
822 }
823
824
825 struct usbdevfs_bulktransfer32 {
826         compat_uint_t ep;
827         compat_uint_t len;
828         compat_uint_t timeout; /* in milliseconds */
829         compat_caddr_t data;
830 };
831
832 #define USBDEVFS_BULK32              _IOWR('U', 2, struct usbdevfs_bulktransfer32)
833
834 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
835 {
836         struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
837         struct usbdevfs_bulktransfer __user *p;
838         compat_uint_t n;
839         compat_caddr_t addr;
840
841         p = compat_alloc_user_space(sizeof(*p));
842
843         if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
844             get_user(n, &p32->len) || put_user(n, &p->len) ||
845             get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
846             get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
847                 return -EFAULT;
848
849         return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
850 }
851
852
853 /*
854  *  USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
855  *  are handled in usbdevfs core.                       -Christopher Li
856  */
857
858 struct usbdevfs_disconnectsignal32 {
859         compat_int_t signr;
860         compat_caddr_t context;
861 };
862
863 #define USBDEVFS_DISCSIGNAL32      _IOR('U', 14, struct usbdevfs_disconnectsignal32)
864
865 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
866 {
867         struct usbdevfs_disconnectsignal kdis;
868         struct usbdevfs_disconnectsignal32 __user *udis;
869         mm_segment_t old_fs;
870         u32 uctx;
871         int err;
872
873         udis = compat_ptr(arg);
874
875         if (get_user(kdis.signr, &udis->signr) ||
876             __get_user(uctx, &udis->context))
877                 return -EFAULT;
878
879         kdis.context = compat_ptr(uctx);
880
881         old_fs = get_fs();
882         set_fs(KERNEL_DS);
883         err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
884         set_fs(old_fs);
885
886         return err;
887 }
888
889 /*
890  * I2C layer ioctls
891  */
892
893 struct i2c_msg32 {
894         u16 addr;
895         u16 flags;
896         u16 len;
897         compat_caddr_t buf;
898 };
899
900 struct i2c_rdwr_ioctl_data32 {
901         compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
902         u32 nmsgs;
903 };
904
905 struct i2c_smbus_ioctl_data32 {
906         u8 read_write;
907         u8 command;
908         u32 size;
909         compat_caddr_t data; /* union i2c_smbus_data *data */
910 };
911
912 struct i2c_rdwr_aligned {
913         struct i2c_rdwr_ioctl_data cmd;
914         struct i2c_msg msgs[0];
915 };
916
917 static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
918 {
919         struct i2c_rdwr_ioctl_data32    __user *udata = compat_ptr(arg);
920         struct i2c_rdwr_aligned         __user *tdata;
921         struct i2c_msg                  __user *tmsgs;
922         struct i2c_msg32                __user *umsgs;
923         compat_caddr_t                  datap;
924         int                             nmsgs, i;
925
926         if (get_user(nmsgs, &udata->nmsgs))
927                 return -EFAULT;
928         if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
929                 return -EINVAL;
930
931         if (get_user(datap, &udata->msgs))
932                 return -EFAULT;
933         umsgs = compat_ptr(datap);
934
935         tdata = compat_alloc_user_space(sizeof(*tdata) +
936                                       nmsgs * sizeof(struct i2c_msg));
937         tmsgs = &tdata->msgs[0];
938
939         if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
940             put_user(tmsgs, &tdata->cmd.msgs))
941                 return -EFAULT;
942
943         for (i = 0; i < nmsgs; i++) {
944                 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
945                         return -EFAULT;
946                 if (get_user(datap, &umsgs[i].buf) ||
947                     put_user(compat_ptr(datap), &tmsgs[i].buf))
948                         return -EFAULT;
949         }
950         return sys_ioctl(fd, cmd, (unsigned long)tdata);
951 }
952
953 static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
954 {
955         struct i2c_smbus_ioctl_data     __user *tdata;
956         struct i2c_smbus_ioctl_data32   __user *udata;
957         compat_caddr_t                  datap;
958
959         tdata = compat_alloc_user_space(sizeof(*tdata));
960         if (tdata == NULL)
961                 return -ENOMEM;
962         if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
963                 return -EFAULT;
964
965         udata = compat_ptr(arg);
966         if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
967                 return -EFAULT;
968
969         if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
970                 return -EFAULT;
971         if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
972                 return -EFAULT;
973         if (__get_user(datap, &udata->data) ||
974             __put_user(compat_ptr(datap), &tdata->data))
975                 return -EFAULT;
976
977         return sys_ioctl(fd, cmd, (unsigned long)tdata);
978 }
979
980 #define RTC_IRQP_READ32         _IOR('p', 0x0b, compat_ulong_t)
981 #define RTC_IRQP_SET32          _IOW('p', 0x0c, compat_ulong_t)
982 #define RTC_EPOCH_READ32        _IOR('p', 0x0d, compat_ulong_t)
983 #define RTC_EPOCH_SET32         _IOW('p', 0x0e, compat_ulong_t)
984
985 static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
986 {
987         mm_segment_t oldfs = get_fs();
988         compat_ulong_t val32;
989         unsigned long kval;
990         int ret;
991
992         switch (cmd) {
993         case RTC_IRQP_READ32:
994         case RTC_EPOCH_READ32:
995                 set_fs(KERNEL_DS);
996                 ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
997                                         RTC_IRQP_READ : RTC_EPOCH_READ,
998                                         (unsigned long)&kval);
999                 set_fs(oldfs);
1000                 if (ret)
1001                         return ret;
1002                 val32 = kval;
1003                 return put_user(val32, (unsigned int __user *)arg);
1004         case RTC_IRQP_SET32:
1005                 return sys_ioctl(fd, RTC_IRQP_SET, arg); 
1006         case RTC_EPOCH_SET32:
1007                 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
1008         default:
1009                 /* unreached */
1010                 return -ENOIOCTLCMD;
1011         }
1012 }
1013
1014 static int
1015 lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1016 {
1017         struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
1018         struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
1019         struct timeval ts;
1020         if (get_user(ts.tv_sec, &tc->tv_sec) ||
1021             get_user(ts.tv_usec, &tc->tv_usec) ||
1022             put_user(ts.tv_sec, &tn->tv_sec) ||
1023             put_user(ts.tv_usec, &tn->tv_usec))
1024                 return -EFAULT;
1025         return sys_ioctl(fd, cmd, (unsigned long)tn);
1026 }
1027
1028 /* on ia32 l_start is on a 32-bit boundary */
1029 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
1030 struct space_resv_32 {
1031         __s16           l_type;
1032         __s16           l_whence;
1033         __s64           l_start __attribute__((packed));
1034                         /* len == 0 means until end of file */
1035         __s64           l_len __attribute__((packed));
1036         __s32           l_sysid;
1037         __u32           l_pid;
1038         __s32           l_pad[4];       /* reserve area */
1039 };
1040
1041 #define FS_IOC_RESVSP_32                _IOW ('X', 40, struct space_resv_32)
1042 #define FS_IOC_RESVSP64_32      _IOW ('X', 42, struct space_resv_32)
1043
1044 /* just account for different alignment */
1045 static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
1046 {
1047         struct space_resv_32    __user *p32 = compat_ptr(arg);
1048         struct space_resv       __user *p = compat_alloc_user_space(sizeof(*p));
1049
1050         if (copy_in_user(&p->l_type,    &p32->l_type,   sizeof(s16)) ||
1051             copy_in_user(&p->l_whence,  &p32->l_whence, sizeof(s16)) ||
1052             copy_in_user(&p->l_start,   &p32->l_start,  sizeof(s64)) ||
1053             copy_in_user(&p->l_len,     &p32->l_len,    sizeof(s64)) ||
1054             copy_in_user(&p->l_sysid,   &p32->l_sysid,  sizeof(s32)) ||
1055             copy_in_user(&p->l_pid,     &p32->l_pid,    sizeof(u32)) ||
1056             copy_in_user(&p->l_pad,     &p32->l_pad,    4*sizeof(u32)))
1057                 return -EFAULT;
1058
1059         return ioctl_preallocate(file, p);
1060 }
1061 #endif
1062
1063
1064 typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int,
1065                                         unsigned long, struct file *);
1066
1067 struct ioctl_trans {
1068         unsigned long cmd;
1069         ioctl_trans_handler_t handler;
1070         struct ioctl_trans *next;
1071 };
1072
1073 #define HANDLE_IOCTL(cmd,handler) \
1074         { (cmd), (ioctl_trans_handler_t)(handler) },
1075
1076 /* pointer to compatible structure or no argument */
1077 #define COMPATIBLE_IOCTL(cmd) \
1078         { (cmd), do_ioctl32_pointer },
1079
1080 /* argument is an unsigned long integer, not a pointer */
1081 #define ULONG_IOCTL(cmd) \
1082         { (cmd), (ioctl_trans_handler_t)sys_ioctl },
1083
1084 /* ioctl should not be warned about even if it's not implemented.
1085    Valid reasons to use this:
1086    - It is implemented with ->compat_ioctl on some device, but programs
1087    call it on others too.
1088    - The ioctl is not implemented in the native kernel, but programs
1089    call it commonly anyways.
1090    Most other reasons are not valid. */
1091 #define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
1092
1093 static struct ioctl_trans ioctl_start[] = {
1094 /* compatible ioctls first */
1095 COMPATIBLE_IOCTL(0x4B50)   /* KDGHWCLK - not in the kernel, but don't complain */
1096 COMPATIBLE_IOCTL(0x4B51)   /* KDSHWCLK - not in the kernel, but don't complain */
1097
1098 /* Big T */
1099 COMPATIBLE_IOCTL(TCGETA)
1100 COMPATIBLE_IOCTL(TCSETA)
1101 COMPATIBLE_IOCTL(TCSETAW)
1102 COMPATIBLE_IOCTL(TCSETAF)
1103 COMPATIBLE_IOCTL(TCSBRK)
1104 ULONG_IOCTL(TCSBRKP)
1105 COMPATIBLE_IOCTL(TCXONC)
1106 COMPATIBLE_IOCTL(TCFLSH)
1107 COMPATIBLE_IOCTL(TCGETS)
1108 COMPATIBLE_IOCTL(TCSETS)
1109 COMPATIBLE_IOCTL(TCSETSW)
1110 COMPATIBLE_IOCTL(TCSETSF)
1111 COMPATIBLE_IOCTL(TIOCLINUX)
1112 COMPATIBLE_IOCTL(TIOCSBRK)
1113 COMPATIBLE_IOCTL(TIOCCBRK)
1114 ULONG_IOCTL(TIOCMIWAIT)
1115 COMPATIBLE_IOCTL(TIOCGICOUNT)
1116 /* Little t */
1117 COMPATIBLE_IOCTL(TIOCGETD)
1118 COMPATIBLE_IOCTL(TIOCSETD)
1119 COMPATIBLE_IOCTL(TIOCEXCL)
1120 COMPATIBLE_IOCTL(TIOCNXCL)
1121 COMPATIBLE_IOCTL(TIOCCONS)
1122 COMPATIBLE_IOCTL(TIOCGSOFTCAR)
1123 COMPATIBLE_IOCTL(TIOCSSOFTCAR)
1124 COMPATIBLE_IOCTL(TIOCSWINSZ)
1125 COMPATIBLE_IOCTL(TIOCGWINSZ)
1126 COMPATIBLE_IOCTL(TIOCMGET)
1127 COMPATIBLE_IOCTL(TIOCMBIC)
1128 COMPATIBLE_IOCTL(TIOCMBIS)
1129 COMPATIBLE_IOCTL(TIOCMSET)
1130 COMPATIBLE_IOCTL(TIOCPKT)
1131 COMPATIBLE_IOCTL(TIOCNOTTY)
1132 COMPATIBLE_IOCTL(TIOCSTI)
1133 COMPATIBLE_IOCTL(TIOCOUTQ)
1134 COMPATIBLE_IOCTL(TIOCSPGRP)
1135 COMPATIBLE_IOCTL(TIOCGPGRP)
1136 ULONG_IOCTL(TIOCSCTTY)
1137 COMPATIBLE_IOCTL(TIOCGPTN)
1138 COMPATIBLE_IOCTL(TIOCSPTLCK)
1139 COMPATIBLE_IOCTL(TIOCSERGETLSR)
1140 #ifdef TCGETS2
1141 COMPATIBLE_IOCTL(TCGETS2)
1142 COMPATIBLE_IOCTL(TCSETS2)
1143 COMPATIBLE_IOCTL(TCSETSW2)
1144 COMPATIBLE_IOCTL(TCSETSF2)
1145 #endif
1146 /* Little f */
1147 COMPATIBLE_IOCTL(FIOCLEX)
1148 COMPATIBLE_IOCTL(FIONCLEX)
1149 COMPATIBLE_IOCTL(FIOASYNC)
1150 COMPATIBLE_IOCTL(FIONBIO)
1151 COMPATIBLE_IOCTL(FIONREAD)  /* This is also TIOCINQ */
1152 COMPATIBLE_IOCTL(FS_IOC_FIEMAP)
1153 /* 0x00 */
1154 COMPATIBLE_IOCTL(FIBMAP)
1155 COMPATIBLE_IOCTL(FIGETBSZ)
1156 /* 'X' - originally XFS but some now in the VFS */
1157 COMPATIBLE_IOCTL(FIFREEZE)
1158 COMPATIBLE_IOCTL(FITHAW)
1159 /* RAID */
1160 COMPATIBLE_IOCTL(RAID_VERSION)
1161 COMPATIBLE_IOCTL(GET_ARRAY_INFO)
1162 COMPATIBLE_IOCTL(GET_DISK_INFO)
1163 COMPATIBLE_IOCTL(PRINT_RAID_DEBUG)
1164 COMPATIBLE_IOCTL(RAID_AUTORUN)
1165 COMPATIBLE_IOCTL(CLEAR_ARRAY)
1166 COMPATIBLE_IOCTL(ADD_NEW_DISK)
1167 ULONG_IOCTL(HOT_REMOVE_DISK)
1168 COMPATIBLE_IOCTL(SET_ARRAY_INFO)
1169 COMPATIBLE_IOCTL(SET_DISK_INFO)
1170 COMPATIBLE_IOCTL(WRITE_RAID_INFO)
1171 COMPATIBLE_IOCTL(UNPROTECT_ARRAY)
1172 COMPATIBLE_IOCTL(PROTECT_ARRAY)
1173 ULONG_IOCTL(HOT_ADD_DISK)
1174 ULONG_IOCTL(SET_DISK_FAULTY)
1175 COMPATIBLE_IOCTL(RUN_ARRAY)
1176 COMPATIBLE_IOCTL(STOP_ARRAY)
1177 COMPATIBLE_IOCTL(STOP_ARRAY_RO)
1178 COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
1179 COMPATIBLE_IOCTL(GET_BITMAP_FILE)
1180 ULONG_IOCTL(SET_BITMAP_FILE)
1181 /* Keyboard -- can be removed once tty3270 uses ops->compat_ioctl */
1182 ULONG_IOCTL(KDSIGACCEPT)
1183 COMPATIBLE_IOCTL(KDGETKEYCODE)
1184 COMPATIBLE_IOCTL(KDSETKEYCODE)
1185 ULONG_IOCTL(KIOCSOUND)
1186 ULONG_IOCTL(KDMKTONE)
1187 COMPATIBLE_IOCTL(KDGKBTYPE)
1188 ULONG_IOCTL(KDSETMODE)
1189 COMPATIBLE_IOCTL(KDGETMODE)
1190 ULONG_IOCTL(KDSKBMODE)
1191 COMPATIBLE_IOCTL(KDGKBMODE)
1192 ULONG_IOCTL(KDSKBMETA)
1193 COMPATIBLE_IOCTL(KDGKBMETA)
1194 COMPATIBLE_IOCTL(KDGKBENT)
1195 COMPATIBLE_IOCTL(KDSKBENT)
1196 COMPATIBLE_IOCTL(KDGKBSENT)
1197 COMPATIBLE_IOCTL(KDSKBSENT)
1198 COMPATIBLE_IOCTL(KDGKBDIACR)
1199 COMPATIBLE_IOCTL(KDSKBDIACR)
1200 COMPATIBLE_IOCTL(KDKBDREP)
1201 COMPATIBLE_IOCTL(KDGKBLED)
1202 ULONG_IOCTL(KDSKBLED)
1203 COMPATIBLE_IOCTL(KDGETLED)
1204 ULONG_IOCTL(KDSETLED)
1205 #ifdef CONFIG_BLOCK
1206 /* Big S */
1207 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
1208 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
1209 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
1210 COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
1211 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
1212 COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
1213 COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
1214 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
1215 #endif
1216 /* Little p (/dev/rtc, /dev/envctrl, etc.) */
1217 COMPATIBLE_IOCTL(RTC_AIE_ON)
1218 COMPATIBLE_IOCTL(RTC_AIE_OFF)
1219 COMPATIBLE_IOCTL(RTC_UIE_ON)
1220 COMPATIBLE_IOCTL(RTC_UIE_OFF)
1221 COMPATIBLE_IOCTL(RTC_PIE_ON)
1222 COMPATIBLE_IOCTL(RTC_PIE_OFF)
1223 COMPATIBLE_IOCTL(RTC_WIE_ON)
1224 COMPATIBLE_IOCTL(RTC_WIE_OFF)
1225 COMPATIBLE_IOCTL(RTC_ALM_SET)
1226 COMPATIBLE_IOCTL(RTC_ALM_READ)
1227 COMPATIBLE_IOCTL(RTC_RD_TIME)
1228 COMPATIBLE_IOCTL(RTC_SET_TIME)
1229 COMPATIBLE_IOCTL(RTC_WKALM_SET)
1230 COMPATIBLE_IOCTL(RTC_WKALM_RD)
1231 /*
1232  * These two are only for the sbus rtc driver, but
1233  * hwclock tries them on every rtc device first when
1234  * running on sparc.  On other architectures the entries
1235  * are useless but harmless.
1236  */
1237 COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
1238 COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
1239 /* Little m */
1240 COMPATIBLE_IOCTL(MTIOCTOP)
1241 /* Socket level stuff */
1242 COMPATIBLE_IOCTL(FIOQSIZE)
1243 #ifdef CONFIG_BLOCK
1244 /* SG stuff */
1245 COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
1246 COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
1247 COMPATIBLE_IOCTL(SG_EMULATED_HOST)
1248 ULONG_IOCTL(SG_SET_TRANSFORM)
1249 COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
1250 COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
1251 COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
1252 COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
1253 COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
1254 COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
1255 COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
1256 COMPATIBLE_IOCTL(SG_GET_PACK_ID)
1257 COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
1258 COMPATIBLE_IOCTL(SG_SET_DEBUG)
1259 COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
1260 COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
1261 COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
1262 COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
1263 COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
1264 COMPATIBLE_IOCTL(SG_SCSI_RESET)
1265 COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
1266 COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
1267 COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
1268 #endif
1269 /* PPP stuff */
1270 COMPATIBLE_IOCTL(PPPIOCGFLAGS)
1271 COMPATIBLE_IOCTL(PPPIOCSFLAGS)
1272 COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
1273 COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
1274 COMPATIBLE_IOCTL(PPPIOCGUNIT)
1275 COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
1276 COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
1277 COMPATIBLE_IOCTL(PPPIOCGMRU)
1278 COMPATIBLE_IOCTL(PPPIOCSMRU)
1279 COMPATIBLE_IOCTL(PPPIOCSMAXCID)
1280 COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
1281 COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
1282 COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
1283 /* PPPIOCSCOMPRESS is translated */
1284 COMPATIBLE_IOCTL(PPPIOCGNPMODE)
1285 COMPATIBLE_IOCTL(PPPIOCSNPMODE)
1286 COMPATIBLE_IOCTL(PPPIOCGDEBUG)
1287 COMPATIBLE_IOCTL(PPPIOCSDEBUG)
1288 /* PPPIOCSPASS is translated */
1289 /* PPPIOCSACTIVE is translated */
1290 /* PPPIOCGIDLE is translated */
1291 COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
1292 COMPATIBLE_IOCTL(PPPIOCATTACH)
1293 COMPATIBLE_IOCTL(PPPIOCDETACH)
1294 COMPATIBLE_IOCTL(PPPIOCSMRRU)
1295 COMPATIBLE_IOCTL(PPPIOCCONNECT)
1296 COMPATIBLE_IOCTL(PPPIOCDISCONN)
1297 COMPATIBLE_IOCTL(PPPIOCATTCHAN)
1298 COMPATIBLE_IOCTL(PPPIOCGCHAN)
1299 /* PPPOX */
1300 COMPATIBLE_IOCTL(PPPOEIOCSFWD)
1301 COMPATIBLE_IOCTL(PPPOEIOCDFWD)
1302 /* LP */
1303 COMPATIBLE_IOCTL(LPGETSTATUS)
1304 /* ppdev */
1305 COMPATIBLE_IOCTL(PPSETMODE)
1306 COMPATIBLE_IOCTL(PPRSTATUS)
1307 COMPATIBLE_IOCTL(PPRCONTROL)
1308 COMPATIBLE_IOCTL(PPWCONTROL)
1309 COMPATIBLE_IOCTL(PPFCONTROL)
1310 COMPATIBLE_IOCTL(PPRDATA)
1311 COMPATIBLE_IOCTL(PPWDATA)
1312 COMPATIBLE_IOCTL(PPCLAIM)
1313 COMPATIBLE_IOCTL(PPRELEASE)
1314 COMPATIBLE_IOCTL(PPYIELD)
1315 COMPATIBLE_IOCTL(PPEXCL)
1316 COMPATIBLE_IOCTL(PPDATADIR)
1317 COMPATIBLE_IOCTL(PPNEGOT)
1318 COMPATIBLE_IOCTL(PPWCTLONIRQ)
1319 COMPATIBLE_IOCTL(PPCLRIRQ)
1320 COMPATIBLE_IOCTL(PPSETPHASE)
1321 COMPATIBLE_IOCTL(PPGETMODES)
1322 COMPATIBLE_IOCTL(PPGETMODE)
1323 COMPATIBLE_IOCTL(PPGETPHASE)
1324 COMPATIBLE_IOCTL(PPGETFLAGS)
1325 COMPATIBLE_IOCTL(PPSETFLAGS)
1326 /* pktcdvd */
1327 COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
1328 /* Big A */
1329 /* sparc only */
1330 /* Big Q for sound/OSS */
1331 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
1332 COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
1333 COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
1334 COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
1335 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
1336 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
1337 COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
1338 COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
1339 COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
1340 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
1341 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
1342 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
1343 COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
1344 COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
1345 COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
1346 COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
1347 COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
1348 COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
1349 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
1350 COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
1351 COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
1352 COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
1353 /* Big T for sound/OSS */
1354 COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
1355 COMPATIBLE_IOCTL(SNDCTL_TMR_START)
1356 COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
1357 COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
1358 COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
1359 COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
1360 COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
1361 COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
1362 /* Little m for sound/OSS */
1363 COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
1364 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
1365 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
1366 /* Big P for sound/OSS */
1367 COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
1368 COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
1369 COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
1370 COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
1371 COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
1372 COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
1373 COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
1374 COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
1375 COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
1376 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
1377 COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
1378 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
1379 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
1380 COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
1381 COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
1382 COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
1383 COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
1384 COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
1385 COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
1386 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
1387 /* SNDCTL_DSP_MAPINBUF,  XXX needs translation */
1388 /* SNDCTL_DSP_MAPOUTBUF,  XXX needs translation */
1389 COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
1390 COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
1391 COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
1392 COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
1393 COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
1394 COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
1395 COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
1396 COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
1397 /* Big C for sound/OSS */
1398 COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
1399 COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
1400 COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
1401 COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
1402 COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
1403 COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
1404 COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
1405 COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
1406 COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
1407 COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
1408 /* Big M for sound/OSS */
1409 COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
1410 COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
1411 COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
1412 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
1413 COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
1414 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
1415 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
1416 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
1417 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
1418 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
1419 COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
1420 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
1421 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
1422 COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
1423 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
1424 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
1425 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
1426 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
1427 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
1428 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
1429 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
1430 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
1431 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
1432 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
1433 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
1434 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
1435 /* SOUND_MIXER_READ_ENHANCE,  same value as READ_MUTE */
1436 /* SOUND_MIXER_READ_LOUD,  same value as READ_MUTE */
1437 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
1438 COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
1439 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
1440 COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
1441 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
1442 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
1443 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
1444 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
1445 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
1446 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
1447 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
1448 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
1449 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
1450 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
1451 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
1452 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
1453 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
1454 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
1455 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
1456 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
1457 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
1458 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
1459 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
1460 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
1461 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
1462 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
1463 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
1464 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
1465 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
1466 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
1467 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
1468 /* SOUND_MIXER_WRITE_ENHANCE,  same value as WRITE_MUTE */
1469 /* SOUND_MIXER_WRITE_LOUD,  same value as WRITE_MUTE */
1470 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
1471 COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
1472 COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
1473 COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
1474 COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
1475 COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
1476 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
1477 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
1478 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
1479 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
1480 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
1481 COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
1482 COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
1483 COMPATIBLE_IOCTL(OSS_GETVERSION)
1484 /* AUTOFS */
1485 ULONG_IOCTL(AUTOFS_IOC_READY)
1486 ULONG_IOCTL(AUTOFS_IOC_FAIL)
1487 COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
1488 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
1489 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
1490 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
1491 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
1492 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
1493 /* Raw devices */
1494 COMPATIBLE_IOCTL(RAW_SETBIND)
1495 COMPATIBLE_IOCTL(RAW_GETBIND)
1496 /* SMB ioctls which do not need any translations */
1497 COMPATIBLE_IOCTL(SMB_IOC_NEWCONN)
1498 /* Watchdog */
1499 COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
1500 COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
1501 COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
1502 COMPATIBLE_IOCTL(WDIOC_GETTEMP)
1503 COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
1504 COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
1505 COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
1506 COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
1507 /* Big R */
1508 COMPATIBLE_IOCTL(RNDGETENTCNT)
1509 COMPATIBLE_IOCTL(RNDADDTOENTCNT)
1510 COMPATIBLE_IOCTL(RNDGETPOOL)
1511 COMPATIBLE_IOCTL(RNDADDENTROPY)
1512 COMPATIBLE_IOCTL(RNDZAPENTCNT)
1513 COMPATIBLE_IOCTL(RNDCLEARPOOL)
1514 /* Bluetooth */
1515 COMPATIBLE_IOCTL(HCIDEVUP)
1516 COMPATIBLE_IOCTL(HCIDEVDOWN)
1517 COMPATIBLE_IOCTL(HCIDEVRESET)
1518 COMPATIBLE_IOCTL(HCIDEVRESTAT)
1519 COMPATIBLE_IOCTL(HCIGETDEVLIST)
1520 COMPATIBLE_IOCTL(HCIGETDEVINFO)
1521 COMPATIBLE_IOCTL(HCIGETCONNLIST)
1522 COMPATIBLE_IOCTL(HCIGETCONNINFO)
1523 COMPATIBLE_IOCTL(HCIGETAUTHINFO)
1524 COMPATIBLE_IOCTL(HCISETRAW)
1525 COMPATIBLE_IOCTL(HCISETSCAN)
1526 COMPATIBLE_IOCTL(HCISETAUTH)
1527 COMPATIBLE_IOCTL(HCISETENCRYPT)
1528 COMPATIBLE_IOCTL(HCISETPTYPE)
1529 COMPATIBLE_IOCTL(HCISETLINKPOL)
1530 COMPATIBLE_IOCTL(HCISETLINKMODE)
1531 COMPATIBLE_IOCTL(HCISETACLMTU)
1532 COMPATIBLE_IOCTL(HCISETSCOMTU)
1533 COMPATIBLE_IOCTL(HCIINQUIRY)
1534 COMPATIBLE_IOCTL(HCIUARTSETPROTO)
1535 COMPATIBLE_IOCTL(HCIUARTGETPROTO)
1536 COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
1537 COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
1538 COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
1539 COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
1540 COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
1541 COMPATIBLE_IOCTL(BNEPCONNADD)
1542 COMPATIBLE_IOCTL(BNEPCONNDEL)
1543 COMPATIBLE_IOCTL(BNEPGETCONNLIST)
1544 COMPATIBLE_IOCTL(BNEPGETCONNINFO)
1545 COMPATIBLE_IOCTL(CMTPCONNADD)
1546 COMPATIBLE_IOCTL(CMTPCONNDEL)
1547 COMPATIBLE_IOCTL(CMTPGETCONNLIST)
1548 COMPATIBLE_IOCTL(CMTPGETCONNINFO)
1549 COMPATIBLE_IOCTL(HIDPCONNADD)
1550 COMPATIBLE_IOCTL(HIDPCONNDEL)
1551 COMPATIBLE_IOCTL(HIDPGETCONNLIST)
1552 COMPATIBLE_IOCTL(HIDPGETCONNINFO)
1553 /* CAPI */
1554 COMPATIBLE_IOCTL(CAPI_REGISTER)
1555 COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
1556 COMPATIBLE_IOCTL(CAPI_GET_VERSION)
1557 COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
1558 COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
1559 COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
1560 COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
1561 COMPATIBLE_IOCTL(CAPI_INSTALLED)
1562 COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
1563 COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
1564 COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
1565 COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
1566 COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
1567 /* Siemens Gigaset */
1568 COMPATIBLE_IOCTL(GIGASET_REDIR)
1569 COMPATIBLE_IOCTL(GIGASET_CONFIG)
1570 COMPATIBLE_IOCTL(GIGASET_BRKCHARS)
1571 COMPATIBLE_IOCTL(GIGASET_VERSION)
1572 /* Misc. */
1573 COMPATIBLE_IOCTL(0x41545900)            /* ATYIO_CLKR */
1574 COMPATIBLE_IOCTL(0x41545901)            /* ATYIO_CLKW */
1575 COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
1576 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
1577 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
1578 COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
1579 /* USB */
1580 COMPATIBLE_IOCTL(USBDEVFS_RESETEP)
1581 COMPATIBLE_IOCTL(USBDEVFS_SETINTERFACE)
1582 COMPATIBLE_IOCTL(USBDEVFS_SETCONFIGURATION)
1583 COMPATIBLE_IOCTL(USBDEVFS_GETDRIVER)
1584 COMPATIBLE_IOCTL(USBDEVFS_DISCARDURB)
1585 COMPATIBLE_IOCTL(USBDEVFS_CLAIMINTERFACE)
1586 COMPATIBLE_IOCTL(USBDEVFS_RELEASEINTERFACE)
1587 COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
1588 COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
1589 COMPATIBLE_IOCTL(USBDEVFS_RESET)
1590 COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
1591 COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
1592 COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
1593 COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
1594 /* NBD */
1595 ULONG_IOCTL(NBD_SET_SOCK)
1596 ULONG_IOCTL(NBD_SET_BLKSIZE)
1597 ULONG_IOCTL(NBD_SET_SIZE)
1598 COMPATIBLE_IOCTL(NBD_DO_IT)
1599 COMPATIBLE_IOCTL(NBD_CLEAR_SOCK)
1600 COMPATIBLE_IOCTL(NBD_CLEAR_QUE)
1601 COMPATIBLE_IOCTL(NBD_PRINT_DEBUG)
1602 ULONG_IOCTL(NBD_SET_SIZE_BLOCKS)
1603 COMPATIBLE_IOCTL(NBD_DISCONNECT)
1604 /* i2c */
1605 COMPATIBLE_IOCTL(I2C_SLAVE)
1606 COMPATIBLE_IOCTL(I2C_SLAVE_FORCE)
1607 COMPATIBLE_IOCTL(I2C_TENBIT)
1608 COMPATIBLE_IOCTL(I2C_PEC)
1609 COMPATIBLE_IOCTL(I2C_RETRIES)
1610 COMPATIBLE_IOCTL(I2C_TIMEOUT)
1611 /* hiddev */
1612 COMPATIBLE_IOCTL(HIDIOCGVERSION)
1613 COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
1614 COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
1615 COMPATIBLE_IOCTL(HIDIOCGSTRING)
1616 COMPATIBLE_IOCTL(HIDIOCINITREPORT)
1617 COMPATIBLE_IOCTL(HIDIOCGREPORT)
1618 COMPATIBLE_IOCTL(HIDIOCSREPORT)
1619 COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
1620 COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
1621 COMPATIBLE_IOCTL(HIDIOCGUSAGE)
1622 COMPATIBLE_IOCTL(HIDIOCSUSAGE)
1623 COMPATIBLE_IOCTL(HIDIOCGUCODE)
1624 COMPATIBLE_IOCTL(HIDIOCGFLAG)
1625 COMPATIBLE_IOCTL(HIDIOCSFLAG)
1626 COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
1627 COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
1628 /* dvb */
1629 COMPATIBLE_IOCTL(AUDIO_STOP)
1630 COMPATIBLE_IOCTL(AUDIO_PLAY)
1631 COMPATIBLE_IOCTL(AUDIO_PAUSE)
1632 COMPATIBLE_IOCTL(AUDIO_CONTINUE)
1633 COMPATIBLE_IOCTL(AUDIO_SELECT_SOURCE)
1634 COMPATIBLE_IOCTL(AUDIO_SET_MUTE)
1635 COMPATIBLE_IOCTL(AUDIO_SET_AV_SYNC)
1636 COMPATIBLE_IOCTL(AUDIO_SET_BYPASS_MODE)
1637 COMPATIBLE_IOCTL(AUDIO_CHANNEL_SELECT)
1638 COMPATIBLE_IOCTL(AUDIO_GET_STATUS)
1639 COMPATIBLE_IOCTL(AUDIO_GET_CAPABILITIES)
1640 COMPATIBLE_IOCTL(AUDIO_CLEAR_BUFFER)
1641 COMPATIBLE_IOCTL(AUDIO_SET_ID)
1642 COMPATIBLE_IOCTL(AUDIO_SET_MIXER)
1643 COMPATIBLE_IOCTL(AUDIO_SET_STREAMTYPE)
1644 COMPATIBLE_IOCTL(AUDIO_SET_EXT_ID)
1645 COMPATIBLE_IOCTL(AUDIO_SET_ATTRIBUTES)
1646 COMPATIBLE_IOCTL(AUDIO_SET_KARAOKE)
1647 COMPATIBLE_IOCTL(DMX_START)
1648 COMPATIBLE_IOCTL(DMX_STOP)
1649 COMPATIBLE_IOCTL(DMX_SET_FILTER)
1650 COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
1651 COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
1652 COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
1653 COMPATIBLE_IOCTL(DMX_GET_CAPS)
1654 COMPATIBLE_IOCTL(DMX_SET_SOURCE)
1655 COMPATIBLE_IOCTL(DMX_GET_STC)
1656 COMPATIBLE_IOCTL(FE_GET_INFO)
1657 COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
1658 COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
1659 COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
1660 COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
1661 COMPATIBLE_IOCTL(FE_SET_TONE)
1662 COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
1663 COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
1664 COMPATIBLE_IOCTL(FE_READ_STATUS)
1665 COMPATIBLE_IOCTL(FE_READ_BER)
1666 COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
1667 COMPATIBLE_IOCTL(FE_READ_SNR)
1668 COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
1669 COMPATIBLE_IOCTL(FE_SET_FRONTEND)
1670 COMPATIBLE_IOCTL(FE_GET_FRONTEND)
1671 COMPATIBLE_IOCTL(FE_GET_EVENT)
1672 COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
1673 COMPATIBLE_IOCTL(VIDEO_STOP)
1674 COMPATIBLE_IOCTL(VIDEO_PLAY)
1675 COMPATIBLE_IOCTL(VIDEO_FREEZE)
1676 COMPATIBLE_IOCTL(VIDEO_CONTINUE)
1677 COMPATIBLE_IOCTL(VIDEO_SELECT_SOURCE)
1678 COMPATIBLE_IOCTL(VIDEO_SET_BLANK)
1679 COMPATIBLE_IOCTL(VIDEO_GET_STATUS)
1680 COMPATIBLE_IOCTL(VIDEO_SET_DISPLAY_FORMAT)
1681 COMPATIBLE_IOCTL(VIDEO_FAST_FORWARD)
1682 COMPATIBLE_IOCTL(VIDEO_SLOWMOTION)
1683 COMPATIBLE_IOCTL(VIDEO_GET_CAPABILITIES)
1684 COMPATIBLE_IOCTL(VIDEO_CLEAR_BUFFER)
1685 COMPATIBLE_IOCTL(VIDEO_SET_ID)
1686 COMPATIBLE_IOCTL(VIDEO_SET_STREAMTYPE)
1687 COMPATIBLE_IOCTL(VIDEO_SET_FORMAT)
1688 COMPATIBLE_IOCTL(VIDEO_SET_SYSTEM)
1689 COMPATIBLE_IOCTL(VIDEO_SET_HIGHLIGHT)
1690 COMPATIBLE_IOCTL(VIDEO_SET_SPU)
1691 COMPATIBLE_IOCTL(VIDEO_GET_NAVI)
1692 COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
1693 COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
1694 COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
1695
1696 /* joystick */
1697 COMPATIBLE_IOCTL(JSIOCGVERSION)
1698 COMPATIBLE_IOCTL(JSIOCGAXES)
1699 COMPATIBLE_IOCTL(JSIOCGBUTTONS)
1700 COMPATIBLE_IOCTL(JSIOCGNAME(0))
1701
1702 /* now things that need handlers */
1703 #ifdef CONFIG_BLOCK
1704 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
1705 HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
1706 #endif
1707 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
1708 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
1709 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
1710 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
1711 #ifdef CONFIG_BLOCK
1712 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
1713 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
1714 #endif
1715 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
1716 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
1717 /* One SMB ioctl needs translations. */
1718 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
1719 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
1720 /* block stuff */
1721 #ifdef CONFIG_BLOCK
1722 /* loop */
1723 IGNORE_IOCTL(LOOP_CLR_FD)
1724 /* Raw devices */
1725 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
1726 HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
1727 #endif
1728 /* Serial */
1729 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
1730 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
1731 #ifdef TIOCGLTC
1732 COMPATIBLE_IOCTL(TIOCGLTC)
1733 COMPATIBLE_IOCTL(TIOCSLTC)
1734 #endif
1735 #ifdef TIOCSTART
1736 /*
1737  * For these two we have definitions in ioctls.h and/or termios.h on
1738  * some architectures but no actual implemention.  Some applications
1739  * like bash call them if they are defined in the headers, so we provide
1740  * entries here to avoid syslog message spew.
1741  */
1742 COMPATIBLE_IOCTL(TIOCSTART)
1743 COMPATIBLE_IOCTL(TIOCSTOP)
1744 #endif
1745 /* Usbdevfs */
1746 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
1747 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
1748 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
1749 COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
1750 /* i2c */
1751 HANDLE_IOCTL(I2C_FUNCS, w_long)
1752 HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
1753 HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
1754 /* Not implemented in the native kernel */
1755 HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
1756 HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
1757 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
1758 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
1759
1760 /* dvb */
1761 HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
1762 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
1763 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
1764
1765 /* parport */
1766 COMPATIBLE_IOCTL(LPTIME)
1767 COMPATIBLE_IOCTL(LPCHAR)
1768 COMPATIBLE_IOCTL(LPABORTOPEN)
1769 COMPATIBLE_IOCTL(LPCAREFUL)
1770 COMPATIBLE_IOCTL(LPWAIT)
1771 COMPATIBLE_IOCTL(LPSETIRQ)
1772 COMPATIBLE_IOCTL(LPGETSTATUS)
1773 COMPATIBLE_IOCTL(LPGETSTATUS)
1774 COMPATIBLE_IOCTL(LPRESET)
1775 /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
1776 COMPATIBLE_IOCTL(LPGETFLAGS)
1777 HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
1778
1779 /* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
1780    but we don't want warnings on other file systems. So declare
1781    them as compatible here. */
1782 #define VFAT_IOCTL_READDIR_BOTH32       _IOR('r', 1, struct compat_dirent[2])
1783 #define VFAT_IOCTL_READDIR_SHORT32      _IOR('r', 2, struct compat_dirent[2])
1784
1785 IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
1786 IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
1787
1788 #ifdef CONFIG_SPARC
1789 /* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
1790 IGNORE_IOCTL(FBIOGTYPE)
1791 IGNORE_IOCTL(FBIOSATTR)
1792 IGNORE_IOCTL(FBIOGATTR)
1793 IGNORE_IOCTL(FBIOSVIDEO)
1794 IGNORE_IOCTL(FBIOGVIDEO)
1795 IGNORE_IOCTL(FBIOSCURPOS)
1796 IGNORE_IOCTL(FBIOGCURPOS)
1797 IGNORE_IOCTL(FBIOGCURMAX)
1798 IGNORE_IOCTL(FBIOPUTCMAP32)
1799 IGNORE_IOCTL(FBIOGETCMAP32)
1800 IGNORE_IOCTL(FBIOSCURSOR32)
1801 IGNORE_IOCTL(FBIOGCURSOR32)
1802 #endif
1803 };
1804
1805 #define IOCTL_HASHSIZE 256
1806 static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
1807
1808 static inline unsigned long ioctl32_hash(unsigned long cmd)
1809 {
1810         return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
1811 }
1812
1813 static void compat_ioctl_error(struct file *filp, unsigned int fd,
1814                 unsigned int cmd, unsigned long arg)
1815 {
1816         char buf[10];
1817         char *fn = "?";
1818         char *path;
1819
1820         /* find the name of the device. */
1821         path = (char *)__get_free_page(GFP_KERNEL);
1822         if (path) {
1823                 fn = d_path(&filp->f_path, path, PAGE_SIZE);
1824                 if (IS_ERR(fn))
1825                         fn = "?";
1826         }
1827
1828          sprintf(buf,"'%c'", (cmd>>_IOC_TYPESHIFT) & _IOC_TYPEMASK);
1829         if (!isprint(buf[1]))
1830                 sprintf(buf, "%02x", buf[1]);
1831         compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
1832                         "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
1833                         current->comm, current->pid,
1834                         (int)fd, (unsigned int)cmd, buf,
1835                         (cmd >> _IOC_SIZESHIFT) & _IOC_SIZEMASK,
1836                         (unsigned int)arg, fn);
1837
1838         if (path)
1839                 free_page((unsigned long)path);
1840 }
1841
1842 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
1843                                 unsigned long arg)
1844 {
1845         struct file *filp;
1846         int error = -EBADF;
1847         struct ioctl_trans *t;
1848         int fput_needed;
1849
1850         filp = fget_light(fd, &fput_needed);
1851         if (!filp)
1852                 goto out;
1853
1854         /* RED-PEN how should LSM module know it's handling 32bit? */
1855         error = security_file_ioctl(filp, cmd, arg);
1856         if (error)
1857                 goto out_fput;
1858
1859         /*
1860          * To allow the compat_ioctl handlers to be self contained
1861          * we need to check the common ioctls here first.
1862          * Just handle them with the standard handlers below.
1863          */
1864         switch (cmd) {
1865         case FIOCLEX:
1866         case FIONCLEX:
1867         case FIONBIO:
1868         case FIOASYNC:
1869         case FIOQSIZE:
1870                 break;
1871
1872 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
1873         case FS_IOC_RESVSP_32:
1874         case FS_IOC_RESVSP64_32:
1875                 error = compat_ioctl_preallocate(filp, arg);
1876                 goto out_fput;
1877 #else
1878         case FS_IOC_RESVSP:
1879         case FS_IOC_RESVSP64:
1880                 error = ioctl_preallocate(filp, compat_ptr(arg));
1881                 goto out_fput;
1882 #endif
1883
1884         case FIBMAP:
1885         case FIGETBSZ:
1886         case FIONREAD:
1887                 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
1888                         break;
1889                 /*FALL THROUGH*/
1890
1891         default:
1892                 if (filp->f_op && filp->f_op->compat_ioctl) {
1893                         error = filp->f_op->compat_ioctl(filp, cmd, arg);
1894                         if (error != -ENOIOCTLCMD)
1895                                 goto out_fput;
1896                 }
1897
1898                 if (!filp->f_op ||
1899                     (!filp->f_op->ioctl && !filp->f_op->unlocked_ioctl))
1900                         goto do_ioctl;
1901                 break;
1902         }
1903
1904         for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) {
1905                 if (t->cmd == cmd)
1906                         goto found_handler;
1907         }
1908
1909         {
1910                 static int count;
1911
1912                 if (++count <= 50)
1913                         compat_ioctl_error(filp, fd, cmd, arg);
1914                 error = -EINVAL;
1915         }
1916
1917         goto out_fput;
1918
1919  found_handler:
1920         if (t->handler) {
1921                 error = t->handler(fd, cmd, arg, filp);
1922                 goto out_fput;
1923         }
1924
1925  do_ioctl:
1926         error = do_vfs_ioctl(filp, fd, cmd, arg);
1927  out_fput:
1928         fput_light(filp, fput_needed);
1929  out:
1930         return error;
1931 }
1932
1933 static void ioctl32_insert_translation(struct ioctl_trans *trans)
1934 {
1935         unsigned long hash;
1936         struct ioctl_trans *t;
1937
1938         hash = ioctl32_hash (trans->cmd);
1939         if (!ioctl32_hash_table[hash])
1940                 ioctl32_hash_table[hash] = trans;
1941         else {
1942                 t = ioctl32_hash_table[hash];
1943                 while (t->next)
1944                         t = t->next;
1945                 trans->next = NULL;
1946                 t->next = trans;
1947         }
1948 }
1949
1950 static int __init init_sys32_ioctl(void)
1951 {
1952         int i;
1953
1954         for (i = 0; i < ARRAY_SIZE(ioctl_start); i++) {
1955                 if (ioctl_start[i].next) {
1956                         printk("ioctl translation %d bad\n",i);
1957                         return -1;
1958                 }
1959
1960                 ioctl32_insert_translation(&ioctl_start[i]);
1961         }
1962         return 0;
1963 }
1964 __initcall(init_sys32_ioctl);