compat_ioctl: move BLKPG handling to block/compat_ioctl.c
[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/types.h>
14 #include <linux/compat.h>
15 #include <linux/kernel.h>
16 #include <linux/capability.h>
17 #include <linux/compiler.h>
18 #include <linux/sched.h>
19 #include <linux/smp.h>
20 #include <linux/ioctl.h>
21 #include <linux/if.h>
22 #include <linux/if_bridge.h>
23 #include <linux/slab.h>
24 #include <linux/raid/md.h>
25 #include <linux/kd.h>
26 #include <linux/dirent.h>
27 #include <linux/route.h>
28 #include <linux/in6.h>
29 #include <linux/ipv6_route.h>
30 #include <linux/skbuff.h>
31 #include <linux/netlink.h>
32 #include <linux/vt.h>
33 #include <linux/fs.h>
34 #include <linux/file.h>
35 #include <linux/fd.h>
36 #include <linux/ppp_defs.h>
37 #include <linux/if_ppp.h>
38 #include <linux/if_pppox.h>
39 #include <linux/mtio.h>
40 #include <linux/cdrom.h>
41 #include <linux/auto_fs.h>
42 #include <linux/auto_fs4.h>
43 #include <linux/tty.h>
44 #include <linux/vt_kern.h>
45 #include <linux/fb.h>
46 #include <linux/videodev.h>
47 #include <linux/netdevice.h>
48 #include <linux/raw.h>
49 #include <linux/smb_fs.h>
50 #include <linux/blkdev.h>
51 #include <linux/elevator.h>
52 #include <linux/rtc.h>
53 #include <linux/pci.h>
54 #include <linux/module.h>
55 #include <linux/serial.h>
56 #include <linux/if_tun.h>
57 #include <linux/ctype.h>
58 #include <linux/syscalls.h>
59 #include <linux/i2c.h>
60 #include <linux/i2c-dev.h>
61 #include <linux/wireless.h>
62 #include <linux/atalk.h>
63 #include <linux/loop.h>
64
65 #include <net/bluetooth/bluetooth.h>
66 #include <net/bluetooth/hci.h>
67 #include <net/bluetooth/rfcomm.h>
68
69 #include <linux/capi.h>
70 #include <linux/gigaset_dev.h>
71
72 #include <scsi/scsi.h>
73 #include <scsi/scsi_ioctl.h>
74 #include <scsi/sg.h>
75
76 #include <asm/uaccess.h>
77 #include <linux/ethtool.h>
78 #include <linux/mii.h>
79 #include <linux/if_bonding.h>
80 #include <linux/watchdog.h>
81 #include <linux/dm-ioctl.h>
82
83 #include <linux/soundcard.h>
84 #include <linux/lp.h>
85 #include <linux/ppdev.h>
86
87 #include <linux/atm.h>
88 #include <linux/atmarp.h>
89 #include <linux/atmclip.h>
90 #include <linux/atmdev.h>
91 #include <linux/atmioc.h>
92 #include <linux/atmlec.h>
93 #include <linux/atmmpc.h>
94 #include <linux/atmsvc.h>
95 #include <linux/atm_tcp.h>
96 #include <linux/sonet.h>
97 #include <linux/atm_suni.h>
98 #include <linux/mtd/mtd.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 #include <linux/lp.h>
114
115 #ifdef CONFIG_SPARC
116 #include <asm/fbio.h>
117 #endif
118
119 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
120                               unsigned long arg, struct file *f)
121 {
122         return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
123 }
124
125 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
126 {
127         mm_segment_t old_fs = get_fs();
128         int err;
129         unsigned long val;
130         
131         set_fs (KERNEL_DS);
132         err = sys_ioctl(fd, cmd, (unsigned long)&val);
133         set_fs (old_fs);
134         if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
135                 return -EFAULT;
136         return err;
137 }
138  
139 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
140 {
141         mm_segment_t old_fs = get_fs();
142         u32 __user *argptr = compat_ptr(arg);
143         int err;
144         unsigned long val;
145         
146         if(get_user(val, argptr))
147                 return -EFAULT;
148         set_fs (KERNEL_DS);
149         err = sys_ioctl(fd, cmd, (unsigned long)&val);
150         set_fs (old_fs);
151         if (!err && put_user(val, argptr))
152                 return -EFAULT;
153         return err;
154 }
155
156 struct compat_video_event {
157         int32_t         type;
158         compat_time_t   timestamp;
159         union {
160                 video_size_t size;
161                 unsigned int frame_rate;
162         } u;
163 };
164
165 static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
166 {
167         struct video_event kevent;
168         mm_segment_t old_fs = get_fs();
169         int err;
170
171         set_fs(KERNEL_DS);
172         err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
173         set_fs(old_fs);
174
175         if (!err) {
176                 struct compat_video_event __user *up = compat_ptr(arg);
177
178                 err  = put_user(kevent.type, &up->type);
179                 err |= put_user(kevent.timestamp, &up->timestamp);
180                 err |= put_user(kevent.u.size.w, &up->u.size.w);
181                 err |= put_user(kevent.u.size.h, &up->u.size.h);
182                 err |= put_user(kevent.u.size.aspect_ratio,
183                                 &up->u.size.aspect_ratio);
184                 if (err)
185                         err = -EFAULT;
186         }
187
188         return err;
189 }
190
191 struct compat_video_still_picture {
192         compat_uptr_t iFrame;
193         int32_t size;
194 };
195
196 static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
197 {
198         struct compat_video_still_picture __user *up;
199         struct video_still_picture __user *up_native;
200         compat_uptr_t fp;
201         int32_t size;
202         int err;
203
204         up = (struct compat_video_still_picture __user *) arg;
205         err  = get_user(fp, &up->iFrame);
206         err |= get_user(size, &up->size);
207         if (err)
208                 return -EFAULT;
209
210         up_native =
211                 compat_alloc_user_space(sizeof(struct video_still_picture));
212
213         err =  put_user(compat_ptr(fp), &up_native->iFrame);
214         err |= put_user(size, &up_native->size);
215         if (err)
216                 return -EFAULT;
217
218         err = sys_ioctl(fd, cmd, (unsigned long) up_native);
219
220         return err;
221 }
222
223 struct compat_video_spu_palette {
224         int length;
225         compat_uptr_t palette;
226 };
227
228 static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
229 {
230         struct compat_video_spu_palette __user *up;
231         struct video_spu_palette __user *up_native;
232         compat_uptr_t palp;
233         int length, err;
234
235         up = (struct compat_video_spu_palette __user *) arg;
236         err  = get_user(palp, &up->palette);
237         err |= get_user(length, &up->length);
238
239         up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
240         err  = put_user(compat_ptr(palp), &up_native->palette);
241         err |= put_user(length, &up_native->length);
242         if (err)
243                 return -EFAULT;
244
245         err = sys_ioctl(fd, cmd, (unsigned long) up_native);
246
247         return err;
248 }
249
250 #ifdef CONFIG_NET
251 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
252 {
253         struct compat_timeval __user *up = compat_ptr(arg);
254         struct timeval ktv;
255         mm_segment_t old_fs = get_fs();
256         int err;
257
258         set_fs(KERNEL_DS);
259         err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
260         set_fs(old_fs);
261         if(!err) {
262                 err = put_user(ktv.tv_sec, &up->tv_sec);
263                 err |= __put_user(ktv.tv_usec, &up->tv_usec);
264         }
265         return err;
266 }
267
268 static int do_siocgstampns(unsigned int fd, unsigned int cmd, unsigned long arg)
269 {
270         struct compat_timespec __user *up = compat_ptr(arg);
271         struct timespec kts;
272         mm_segment_t old_fs = get_fs();
273         int err;
274
275         set_fs(KERNEL_DS);
276         err = sys_ioctl(fd, cmd, (unsigned long)&kts);
277         set_fs(old_fs);
278         if (!err) {
279                 err = put_user(kts.tv_sec, &up->tv_sec);
280                 err |= __put_user(kts.tv_nsec, &up->tv_nsec);
281         }
282         return err;
283 }
284
285 struct ifmap32 {
286         compat_ulong_t mem_start;
287         compat_ulong_t mem_end;
288         unsigned short base_addr;
289         unsigned char irq;
290         unsigned char dma;
291         unsigned char port;
292 };
293
294 struct ifreq32 {
295 #define IFHWADDRLEN     6
296 #define IFNAMSIZ        16
297         union {
298                 char    ifrn_name[IFNAMSIZ];            /* if name, e.g. "en0" */
299         } ifr_ifrn;
300         union {
301                 struct  sockaddr ifru_addr;
302                 struct  sockaddr ifru_dstaddr;
303                 struct  sockaddr ifru_broadaddr;
304                 struct  sockaddr ifru_netmask;
305                 struct  sockaddr ifru_hwaddr;
306                 short   ifru_flags;
307                 compat_int_t     ifru_ivalue;
308                 compat_int_t     ifru_mtu;
309                 struct  ifmap32 ifru_map;
310                 char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
311                 char    ifru_newname[IFNAMSIZ];
312                 compat_caddr_t ifru_data;
313             /* XXXX? ifru_settings should be here */
314         } ifr_ifru;
315 };
316
317 struct ifconf32 {
318         compat_int_t    ifc_len;                        /* size of buffer       */
319         compat_caddr_t  ifcbuf;
320 };
321
322 static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
323 {
324         struct net_device *dev;
325         struct ifreq32 ifr32;
326         int err;
327
328         if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
329                 return -EFAULT;
330
331         dev = dev_get_by_index(ifr32.ifr_ifindex);
332         if (!dev)
333                 return -ENODEV;
334
335         strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
336         dev_put(dev);
337         
338         err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
339         return (err ? -EFAULT : 0);
340 }
341
342 static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
343 {
344         struct ifconf32 ifc32;
345         struct ifconf ifc;
346         struct ifconf __user *uifc;
347         struct ifreq32 __user *ifr32;
348         struct ifreq __user *ifr;
349         unsigned int i, j;
350         int err;
351
352         if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
353                 return -EFAULT;
354
355         if (ifc32.ifcbuf == 0) {
356                 ifc32.ifc_len = 0;
357                 ifc.ifc_len = 0;
358                 ifc.ifc_req = NULL;
359                 uifc = compat_alloc_user_space(sizeof(struct ifconf));
360         } else {
361                 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
362                         sizeof (struct ifreq);
363                 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
364                 ifc.ifc_len = len;
365                 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
366                 ifr32 = compat_ptr(ifc32.ifcbuf);
367                 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
368                         if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
369                                 return -EFAULT;
370                         ifr++;
371                         ifr32++; 
372                 }
373         }
374         if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
375                 return -EFAULT;
376
377         err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc); 
378         if (err)
379                 return err;
380
381         if (copy_from_user(&ifc, uifc, sizeof(struct ifconf))) 
382                 return -EFAULT;
383
384         ifr = ifc.ifc_req;
385         ifr32 = compat_ptr(ifc32.ifcbuf);
386         for (i = 0, j = 0;
387              i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
388              i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
389                 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
390                         return -EFAULT;
391                 ifr32++;
392                 ifr++;
393         }
394
395         if (ifc32.ifcbuf == 0) {
396                 /* Translate from 64-bit structure multiple to
397                  * a 32-bit one.
398                  */
399                 i = ifc.ifc_len;
400                 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
401                 ifc32.ifc_len = i;
402         } else {
403                 ifc32.ifc_len = i;
404         }
405         if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
406                 return -EFAULT;
407
408         return 0;
409 }
410
411 static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
412 {
413         struct ifreq __user *ifr;
414         struct ifreq32 __user *ifr32;
415         u32 data;
416         void __user *datap;
417         
418         ifr = compat_alloc_user_space(sizeof(*ifr));
419         ifr32 = compat_ptr(arg);
420
421         if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
422                 return -EFAULT;
423
424         if (get_user(data, &ifr32->ifr_ifru.ifru_data))
425                 return -EFAULT;
426
427         datap = compat_ptr(data);
428         if (put_user(datap, &ifr->ifr_ifru.ifru_data))
429                 return -EFAULT;
430
431         return sys_ioctl(fd, cmd, (unsigned long) ifr);
432 }
433
434 static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
435 {
436         struct ifreq kifr;
437         struct ifreq __user *uifr;
438         struct ifreq32 __user *ifr32 = compat_ptr(arg);
439         mm_segment_t old_fs;
440         int err;
441         u32 data;
442         void __user *datap;
443
444         switch (cmd) {
445         case SIOCBONDENSLAVE:
446         case SIOCBONDRELEASE:
447         case SIOCBONDSETHWADDR:
448         case SIOCBONDCHANGEACTIVE:
449                 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
450                         return -EFAULT;
451
452                 old_fs = get_fs();
453                 set_fs (KERNEL_DS);
454                 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
455                 set_fs (old_fs);
456
457                 return err;
458         case SIOCBONDSLAVEINFOQUERY:
459         case SIOCBONDINFOQUERY:
460                 uifr = compat_alloc_user_space(sizeof(*uifr));
461                 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
462                         return -EFAULT;
463
464                 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
465                         return -EFAULT;
466
467                 datap = compat_ptr(data);
468                 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
469                         return -EFAULT;
470
471                 return sys_ioctl (fd, cmd, (unsigned long)uifr);
472         default:
473                 return -EINVAL;
474         };
475 }
476
477 static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
478 {
479         struct ifreq __user *u_ifreq64;
480         struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
481         char tmp_buf[IFNAMSIZ];
482         void __user *data64;
483         u32 data32;
484
485         if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
486                            IFNAMSIZ))
487                 return -EFAULT;
488         if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
489                 return -EFAULT;
490         data64 = compat_ptr(data32);
491
492         u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
493
494         /* Don't check these user accesses, just let that get trapped
495          * in the ioctl handler instead.
496          */
497         if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
498                          IFNAMSIZ))
499                 return -EFAULT;
500         if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
501                 return -EFAULT;
502
503         return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
504 }
505
506 static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
507 {
508         struct ifreq ifr;
509         struct ifreq32 __user *uifr32;
510         struct ifmap32 __user *uifmap32;
511         mm_segment_t old_fs;
512         int err;
513         
514         uifr32 = compat_ptr(arg);
515         uifmap32 = &uifr32->ifr_ifru.ifru_map;
516         switch (cmd) {
517         case SIOCSIFMAP:
518                 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
519                 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
520                 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
521                 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
522                 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
523                 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
524                 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
525                 if (err)
526                         return -EFAULT;
527                 break;
528         default:
529                 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
530                         return -EFAULT;
531                 break;
532         }
533         old_fs = get_fs();
534         set_fs (KERNEL_DS);
535         err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
536         set_fs (old_fs);
537         if (!err) {
538                 switch (cmd) {
539                 /* TUNSETIFF is defined as _IOW, it should be _IORW
540                  * as the data is copied back to user space, but that
541                  * cannot be fixed without breaking all existing apps.
542                  */
543                 case TUNSETIFF:
544                 case SIOCGIFFLAGS:
545                 case SIOCGIFMETRIC:
546                 case SIOCGIFMTU:
547                 case SIOCGIFMEM:
548                 case SIOCGIFHWADDR:
549                 case SIOCGIFINDEX:
550                 case SIOCGIFADDR:
551                 case SIOCGIFBRDADDR:
552                 case SIOCGIFDSTADDR:
553                 case SIOCGIFNETMASK:
554                 case SIOCGIFTXQLEN:
555                         if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
556                                 return -EFAULT;
557                         break;
558                 case SIOCGIFMAP:
559                         err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
560                         err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
561                         err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
562                         err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
563                         err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
564                         err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
565                         err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
566                         if (err)
567                                 err = -EFAULT;
568                         break;
569                 }
570         }
571         return err;
572 }
573
574 struct rtentry32 {
575         u32             rt_pad1;
576         struct sockaddr rt_dst;         /* target address               */
577         struct sockaddr rt_gateway;     /* gateway addr (RTF_GATEWAY)   */
578         struct sockaddr rt_genmask;     /* target network mask (IP)     */
579         unsigned short  rt_flags;
580         short           rt_pad2;
581         u32             rt_pad3;
582         unsigned char   rt_tos;
583         unsigned char   rt_class;
584         short           rt_pad4;
585         short           rt_metric;      /* +1 for binary compatibility! */
586         /* char * */ u32 rt_dev;        /* forcing the device at add    */
587         u32             rt_mtu;         /* per route MTU/Window         */
588         u32             rt_window;      /* Window clamping              */
589         unsigned short  rt_irtt;        /* Initial RTT                  */
590
591 };
592
593 struct in6_rtmsg32 {
594         struct in6_addr         rtmsg_dst;
595         struct in6_addr         rtmsg_src;
596         struct in6_addr         rtmsg_gateway;
597         u32                     rtmsg_type;
598         u16                     rtmsg_dst_len;
599         u16                     rtmsg_src_len;
600         u32                     rtmsg_metric;
601         u32                     rtmsg_info;
602         u32                     rtmsg_flags;
603         s32                     rtmsg_ifindex;
604 };
605
606 static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
607 {
608         int ret;
609         void *r = NULL;
610         struct in6_rtmsg r6;
611         struct rtentry r4;
612         char devname[16];
613         u32 rtdev;
614         mm_segment_t old_fs = get_fs();
615         
616         struct socket *mysock = sockfd_lookup(fd, &ret);
617
618         if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
619                 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
620                 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
621                         3 * sizeof(struct in6_addr));
622                 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
623                 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
624                 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
625                 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
626                 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
627                 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
628                 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
629                 
630                 r = (void *) &r6;
631         } else { /* ipv4 */
632                 struct rtentry32 __user *ur4 = compat_ptr(arg);
633                 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
634                                         3 * sizeof(struct sockaddr));
635                 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
636                 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
637                 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
638                 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
639                 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
640                 ret |= __get_user (rtdev, &(ur4->rt_dev));
641                 if (rtdev) {
642                         ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
643                         r4.rt_dev = devname; devname[15] = 0;
644                 } else
645                         r4.rt_dev = NULL;
646
647                 r = (void *) &r4;
648         }
649
650         if (ret) {
651                 ret = -EFAULT;
652                 goto out;
653         }
654
655         set_fs (KERNEL_DS);
656         ret = sys_ioctl (fd, cmd, (unsigned long) r);
657         set_fs (old_fs);
658
659 out:
660         if (mysock)
661                 sockfd_put(mysock);
662
663         return ret;
664 }
665 #endif
666
667 #ifdef CONFIG_BLOCK
668 typedef struct sg_io_hdr32 {
669         compat_int_t interface_id;      /* [i] 'S' for SCSI generic (required) */
670         compat_int_t dxfer_direction;   /* [i] data transfer direction  */
671         unsigned char cmd_len;          /* [i] SCSI command length ( <= 16 bytes) */
672         unsigned char mx_sb_len;                /* [i] max length to write to sbp */
673         unsigned short iovec_count;     /* [i] 0 implies no scatter gather */
674         compat_uint_t dxfer_len;                /* [i] byte count of data transfer */
675         compat_uint_t dxferp;           /* [i], [*io] points to data transfer memory
676                                               or scatter gather list */
677         compat_uptr_t cmdp;             /* [i], [*i] points to command to perform */
678         compat_uptr_t sbp;              /* [i], [*o] points to sense_buffer memory */
679         compat_uint_t timeout;          /* [i] MAX_UINT->no timeout (unit: millisec) */
680         compat_uint_t flags;            /* [i] 0 -> default, see SG_FLAG... */
681         compat_int_t pack_id;           /* [i->o] unused internally (normally) */
682         compat_uptr_t usr_ptr;          /* [i->o] unused internally */
683         unsigned char status;           /* [o] scsi status */
684         unsigned char masked_status;    /* [o] shifted, masked scsi status */
685         unsigned char msg_status;               /* [o] messaging level data (optional) */
686         unsigned char sb_len_wr;                /* [o] byte count actually written to sbp */
687         unsigned short host_status;     /* [o] errors from host adapter */
688         unsigned short driver_status;   /* [o] errors from software driver */
689         compat_int_t resid;             /* [o] dxfer_len - actual_transferred */
690         compat_uint_t duration;         /* [o] time taken by cmd (unit: millisec) */
691         compat_uint_t info;             /* [o] auxiliary information */
692 } sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
693
694 typedef struct sg_iovec32 {
695         compat_uint_t iov_base;
696         compat_uint_t iov_len;
697 } sg_iovec32_t;
698
699 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
700 {
701         sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
702         sg_iovec32_t __user *iov32 = dxferp;
703         int i;
704
705         for (i = 0; i < iovec_count; i++) {
706                 u32 base, len;
707
708                 if (get_user(base, &iov32[i].iov_base) ||
709                     get_user(len, &iov32[i].iov_len) ||
710                     put_user(compat_ptr(base), &iov[i].iov_base) ||
711                     put_user(len, &iov[i].iov_len))
712                         return -EFAULT;
713         }
714
715         if (put_user(iov, &sgio->dxferp))
716                 return -EFAULT;
717         return 0;
718 }
719
720 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
721 {
722         sg_io_hdr_t __user *sgio;
723         sg_io_hdr32_t __user *sgio32;
724         u16 iovec_count;
725         u32 data;
726         void __user *dxferp;
727         int err;
728
729         sgio32 = compat_ptr(arg);
730         if (get_user(iovec_count, &sgio32->iovec_count))
731                 return -EFAULT;
732
733         {
734                 void __user *top = compat_alloc_user_space(0);
735                 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
736                                        (iovec_count * sizeof(sg_iovec_t)));
737                 if (new > top)
738                         return -EINVAL;
739
740                 sgio = new;
741         }
742
743         /* Ok, now construct.  */
744         if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
745                          (2 * sizeof(int)) +
746                          (2 * sizeof(unsigned char)) +
747                          (1 * sizeof(unsigned short)) +
748                          (1 * sizeof(unsigned int))))
749                 return -EFAULT;
750
751         if (get_user(data, &sgio32->dxferp))
752                 return -EFAULT;
753         dxferp = compat_ptr(data);
754         if (iovec_count) {
755                 if (sg_build_iovec(sgio, dxferp, iovec_count))
756                         return -EFAULT;
757         } else {
758                 if (put_user(dxferp, &sgio->dxferp))
759                         return -EFAULT;
760         }
761
762         {
763                 unsigned char __user *cmdp;
764                 unsigned char __user *sbp;
765
766                 if (get_user(data, &sgio32->cmdp))
767                         return -EFAULT;
768                 cmdp = compat_ptr(data);
769
770                 if (get_user(data, &sgio32->sbp))
771                         return -EFAULT;
772                 sbp = compat_ptr(data);
773
774                 if (put_user(cmdp, &sgio->cmdp) ||
775                     put_user(sbp, &sgio->sbp))
776                         return -EFAULT;
777         }
778
779         if (copy_in_user(&sgio->timeout, &sgio32->timeout,
780                          3 * sizeof(int)))
781                 return -EFAULT;
782
783         if (get_user(data, &sgio32->usr_ptr))
784                 return -EFAULT;
785         if (put_user(compat_ptr(data), &sgio->usr_ptr))
786                 return -EFAULT;
787
788         if (copy_in_user(&sgio->status, &sgio32->status,
789                          (4 * sizeof(unsigned char)) +
790                          (2 * sizeof(unsigned (short))) +
791                          (3 * sizeof(int))))
792                 return -EFAULT;
793
794         err = sys_ioctl(fd, cmd, (unsigned long) sgio);
795
796         if (err >= 0) {
797                 void __user *datap;
798
799                 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
800                                  sizeof(int)) ||
801                     get_user(datap, &sgio->usr_ptr) ||
802                     put_user((u32)(unsigned long)datap,
803                              &sgio32->usr_ptr) ||
804                     copy_in_user(&sgio32->status, &sgio->status,
805                                  (4 * sizeof(unsigned char)) +
806                                  (2 * sizeof(unsigned short)) +
807                                  (3 * sizeof(int))))
808                         err = -EFAULT;
809         }
810
811         return err;
812 }
813
814 struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
815         char req_state;
816         char orphan;
817         char sg_io_owned;
818         char problem;
819         int pack_id;
820         compat_uptr_t usr_ptr;
821         unsigned int duration;
822         int unused;
823 };
824
825 static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
826 {
827         int err, i;
828         sg_req_info_t __user *r;
829         struct compat_sg_req_info __user *o = (void __user *)arg;
830         r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
831         err = sys_ioctl(fd,cmd,(unsigned long)r);
832         if (err < 0)
833                 return err;
834         for (i = 0; i < SG_MAX_QUEUE; i++) {
835                 void __user *ptr;
836                 int d;
837
838                 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
839                     get_user(ptr, &r[i].usr_ptr) ||
840                     get_user(d, &r[i].duration) ||
841                     put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
842                     put_user(d, &o[i].duration))
843                         return -EFAULT;
844         }
845         return err;
846 }
847 #endif /* CONFIG_BLOCK */
848
849 struct sock_fprog32 {
850         unsigned short  len;
851         compat_caddr_t  filter;
852 };
853
854 #define PPPIOCSPASS32   _IOW('t', 71, struct sock_fprog32)
855 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
856
857 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
858 {
859         struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
860         struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
861         void __user *fptr64;
862         u32 fptr32;
863         u16 flen;
864
865         if (get_user(flen, &u_fprog32->len) ||
866             get_user(fptr32, &u_fprog32->filter))
867                 return -EFAULT;
868
869         fptr64 = compat_ptr(fptr32);
870
871         if (put_user(flen, &u_fprog64->len) ||
872             put_user(fptr64, &u_fprog64->filter))
873                 return -EFAULT;
874
875         if (cmd == PPPIOCSPASS32)
876                 cmd = PPPIOCSPASS;
877         else
878                 cmd = PPPIOCSACTIVE;
879
880         return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
881 }
882
883 struct ppp_option_data32 {
884         compat_caddr_t  ptr;
885         u32                     length;
886         compat_int_t            transmit;
887 };
888 #define PPPIOCSCOMPRESS32       _IOW('t', 77, struct ppp_option_data32)
889
890 struct ppp_idle32 {
891         compat_time_t xmit_idle;
892         compat_time_t recv_idle;
893 };
894 #define PPPIOCGIDLE32           _IOR('t', 63, struct ppp_idle32)
895
896 static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
897 {
898         struct ppp_idle __user *idle;
899         struct ppp_idle32 __user *idle32;
900         __kernel_time_t xmit, recv;
901         int err;
902
903         idle = compat_alloc_user_space(sizeof(*idle));
904         idle32 = compat_ptr(arg);
905
906         err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
907
908         if (!err) {
909                 if (get_user(xmit, &idle->xmit_idle) ||
910                     get_user(recv, &idle->recv_idle) ||
911                     put_user(xmit, &idle32->xmit_idle) ||
912                     put_user(recv, &idle32->recv_idle))
913                         err = -EFAULT;
914         }
915         return err;
916 }
917
918 static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
919 {
920         struct ppp_option_data __user *odata;
921         struct ppp_option_data32 __user *odata32;
922         __u32 data;
923         void __user *datap;
924
925         odata = compat_alloc_user_space(sizeof(*odata));
926         odata32 = compat_ptr(arg);
927
928         if (get_user(data, &odata32->ptr))
929                 return -EFAULT;
930
931         datap = compat_ptr(data);
932         if (put_user(datap, &odata->ptr))
933                 return -EFAULT;
934
935         if (copy_in_user(&odata->length, &odata32->length,
936                          sizeof(__u32) + sizeof(int)))
937                 return -EFAULT;
938
939         return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
940 }
941
942 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
943 {
944         int err;
945
946         switch (cmd) {
947         case PPPIOCGIDLE32:
948                 err = ppp_gidle(fd, cmd, arg);
949                 break;
950
951         case PPPIOCSCOMPRESS32:
952                 err = ppp_scompress(fd, cmd, arg);
953                 break;
954
955         default:
956                 do {
957                         static int count;
958                         if (++count <= 20)
959                                 printk("ppp_ioctl: Unknown cmd fd(%d) "
960                                        "cmd(%08x) arg(%08x)\n",
961                                        (int)fd, (unsigned int)cmd, (unsigned int)arg);
962                 } while(0);
963                 err = -EINVAL;
964                 break;
965         };
966
967         return err;
968 }
969
970
971 #ifdef CONFIG_BLOCK
972 struct mtget32 {
973         compat_long_t   mt_type;
974         compat_long_t   mt_resid;
975         compat_long_t   mt_dsreg;
976         compat_long_t   mt_gstat;
977         compat_long_t   mt_erreg;
978         compat_daddr_t  mt_fileno;
979         compat_daddr_t  mt_blkno;
980 };
981 #define MTIOCGET32      _IOR('m', 2, struct mtget32)
982
983 struct mtpos32 {
984         compat_long_t   mt_blkno;
985 };
986 #define MTIOCPOS32      _IOR('m', 3, struct mtpos32)
987
988 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
989 {
990         mm_segment_t old_fs = get_fs();
991         struct mtget get;
992         struct mtget32 __user *umget32;
993         struct mtpos pos;
994         struct mtpos32 __user *upos32;
995         unsigned long kcmd;
996         void *karg;
997         int err = 0;
998
999         switch(cmd) {
1000         case MTIOCPOS32:
1001                 kcmd = MTIOCPOS;
1002                 karg = &pos;
1003                 break;
1004         case MTIOCGET32:
1005                 kcmd = MTIOCGET;
1006                 karg = &get;
1007                 break;
1008         default:
1009                 do {
1010                         static int count;
1011                         if (++count <= 20)
1012                                 printk("mt_ioctl: Unknown cmd fd(%d) "
1013                                        "cmd(%08x) arg(%08x)\n",
1014                                        (int)fd, (unsigned int)cmd, (unsigned int)arg);
1015                 } while(0);
1016                 return -EINVAL;
1017         }
1018         set_fs (KERNEL_DS);
1019         err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1020         set_fs (old_fs);
1021         if (err)
1022                 return err;
1023         switch (cmd) {
1024         case MTIOCPOS32:
1025                 upos32 = compat_ptr(arg);
1026                 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1027                 break;
1028         case MTIOCGET32:
1029                 umget32 = compat_ptr(arg);
1030                 err = __put_user(get.mt_type, &umget32->mt_type);
1031                 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1032                 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1033                 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1034                 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1035                 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1036                 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1037                 break;
1038         }
1039         return err ? -EFAULT: 0;
1040 }
1041
1042 struct cdrom_read_audio32 {
1043         union cdrom_addr        addr;
1044         u8                      addr_format;
1045         compat_int_t            nframes;
1046         compat_caddr_t          buf;
1047 };
1048
1049 struct cdrom_generic_command32 {
1050         unsigned char   cmd[CDROM_PACKET_SIZE];
1051         compat_caddr_t  buffer;
1052         compat_uint_t   buflen;
1053         compat_int_t    stat;
1054         compat_caddr_t  sense;
1055         unsigned char   data_direction;
1056         compat_int_t    quiet;
1057         compat_int_t    timeout;
1058         compat_caddr_t  reserved[1];
1059 };
1060   
1061 static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1062 {
1063         struct cdrom_read_audio __user *cdread_audio;
1064         struct cdrom_read_audio32 __user *cdread_audio32;
1065         __u32 data;
1066         void __user *datap;
1067
1068         cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1069         cdread_audio32 = compat_ptr(arg);
1070
1071         if (copy_in_user(&cdread_audio->addr,
1072                          &cdread_audio32->addr,
1073                          (sizeof(*cdread_audio32) -
1074                           sizeof(compat_caddr_t))))
1075                 return -EFAULT;
1076
1077         if (get_user(data, &cdread_audio32->buf))
1078                 return -EFAULT;
1079         datap = compat_ptr(data);
1080         if (put_user(datap, &cdread_audio->buf))
1081                 return -EFAULT;
1082
1083         return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1084 }
1085
1086 static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1087 {
1088         struct cdrom_generic_command __user *cgc;
1089         struct cdrom_generic_command32 __user *cgc32;
1090         u32 data;
1091         unsigned char dir;
1092         int itmp;
1093
1094         cgc = compat_alloc_user_space(sizeof(*cgc));
1095         cgc32 = compat_ptr(arg);
1096
1097         if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1098             get_user(data, &cgc32->buffer) ||
1099             put_user(compat_ptr(data), &cgc->buffer) ||
1100             copy_in_user(&cgc->buflen, &cgc32->buflen,
1101                          (sizeof(unsigned int) + sizeof(int))) ||
1102             get_user(data, &cgc32->sense) ||
1103             put_user(compat_ptr(data), &cgc->sense) ||
1104             get_user(dir, &cgc32->data_direction) ||
1105             put_user(dir, &cgc->data_direction) ||
1106             get_user(itmp, &cgc32->quiet) ||
1107             put_user(itmp, &cgc->quiet) ||
1108             get_user(itmp, &cgc32->timeout) ||
1109             put_user(itmp, &cgc->timeout) ||
1110             get_user(data, &cgc32->reserved[0]) ||
1111             put_user(compat_ptr(data), &cgc->reserved[0]))
1112                 return -EFAULT;
1113
1114         return sys_ioctl(fd, cmd, (unsigned long) cgc);
1115 }
1116
1117 static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1118 {
1119         int err;
1120
1121         switch(cmd) {
1122         case CDROMREADAUDIO:
1123                 err = cdrom_do_read_audio(fd, cmd, arg);
1124                 break;
1125
1126         case CDROM_SEND_PACKET:
1127                 err = cdrom_do_generic_command(fd, cmd, arg);
1128                 break;
1129
1130         default:
1131                 do {
1132                         static int count;
1133                         if (++count <= 20)
1134                                 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1135                                        "cmd(%08x) arg(%08x)\n",
1136                                        (int)fd, (unsigned int)cmd, (unsigned int)arg);
1137                 } while(0);
1138                 err = -EINVAL;
1139                 break;
1140         };
1141
1142         return err;
1143 }
1144 #endif /* CONFIG_BLOCK */
1145
1146 #ifdef CONFIG_VT
1147
1148 static int vt_check(struct file *file)
1149 {
1150         struct tty_struct *tty;
1151         struct inode *inode = file->f_path.dentry->d_inode;
1152         struct vc_data *vc;
1153         
1154         if (file->f_op->ioctl != tty_ioctl)
1155                 return -EINVAL;
1156                         
1157         tty = (struct tty_struct *)file->private_data;
1158         if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1159                 return -EINVAL;
1160                                                         
1161         if (tty->driver->ioctl != vt_ioctl)
1162                 return -EINVAL;
1163
1164         vc = (struct vc_data *)tty->driver_data;
1165         if (!vc_cons_allocated(vc->vc_num))     /* impossible? */
1166                 return -ENOIOCTLCMD;
1167
1168         /*
1169          * To have permissions to do most of the vt ioctls, we either have
1170          * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
1171          */
1172         if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1173                 return 1;
1174         return 0;                                                    
1175 }
1176
1177 struct consolefontdesc32 {
1178         unsigned short charcount;       /* characters in font (256 or 512) */
1179         unsigned short charheight;      /* scan lines per character (1-32) */
1180         compat_caddr_t chardata;        /* font data in expanded form */
1181 };
1182
1183 static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1184 {
1185         struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1186         struct console_font_op op;
1187         compat_caddr_t data;
1188         int i, perm;
1189
1190         perm = vt_check(file);
1191         if (perm < 0) return perm;
1192         
1193         switch (cmd) {
1194         case PIO_FONTX:
1195                 if (!perm)
1196                         return -EPERM;
1197                 op.op = KD_FONT_OP_SET;
1198                 op.flags = 0;
1199                 op.width = 8;
1200                 if (get_user(op.height, &user_cfd->charheight) ||
1201                     get_user(op.charcount, &user_cfd->charcount) ||
1202                     get_user(data, &user_cfd->chardata))
1203                         return -EFAULT;
1204                 op.data = compat_ptr(data);
1205                 return con_font_op(vc_cons[fg_console].d, &op);
1206         case GIO_FONTX:
1207                 op.op = KD_FONT_OP_GET;
1208                 op.flags = 0;
1209                 op.width = 8;
1210                 if (get_user(op.height, &user_cfd->charheight) ||
1211                     get_user(op.charcount, &user_cfd->charcount) ||
1212                     get_user(data, &user_cfd->chardata))
1213                         return -EFAULT;
1214                 if (!data)
1215                         return 0;
1216                 op.data = compat_ptr(data);
1217                 i = con_font_op(vc_cons[fg_console].d, &op);
1218                 if (i)
1219                         return i;
1220                 if (put_user(op.height, &user_cfd->charheight) ||
1221                     put_user(op.charcount, &user_cfd->charcount) ||
1222                     put_user((compat_caddr_t)(unsigned long)op.data,
1223                                 &user_cfd->chardata))
1224                         return -EFAULT;
1225                 return 0;
1226         }
1227         return -EINVAL;
1228 }
1229
1230 struct console_font_op32 {
1231         compat_uint_t op;        /* operation code KD_FONT_OP_* */
1232         compat_uint_t flags;     /* KD_FONT_FLAG_* */
1233         compat_uint_t width, height;     /* font size */
1234         compat_uint_t charcount;
1235         compat_caddr_t data;    /* font data with height fixed to 32 */
1236 };
1237                                         
1238 static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1239 {
1240         struct console_font_op op;
1241         struct console_font_op32 __user *fontop = compat_ptr(arg);
1242         int perm = vt_check(file), i;
1243         struct vc_data *vc;
1244         
1245         if (perm < 0) return perm;
1246         
1247         if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1248                 return -EFAULT;
1249         if (!perm && op.op != KD_FONT_OP_GET)
1250                 return -EPERM;
1251         op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1252         op.flags |= KD_FONT_FLAG_OLD;
1253         vc = ((struct tty_struct *)file->private_data)->driver_data;
1254         i = con_font_op(vc, &op);
1255         if (i)
1256                 return i;
1257         ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1258         if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1259                 return -EFAULT;
1260         return 0;
1261 }
1262
1263 struct unimapdesc32 {
1264         unsigned short entry_ct;
1265         compat_caddr_t entries;
1266 };
1267
1268 static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1269 {
1270         struct unimapdesc32 tmp;
1271         struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1272         int perm = vt_check(file);
1273         struct vc_data *vc;
1274
1275         if (perm < 0)
1276                 return perm;
1277         if (copy_from_user(&tmp, user_ud, sizeof tmp))
1278                 return -EFAULT;
1279         if (tmp.entries)
1280                 if (!access_ok(VERIFY_WRITE, compat_ptr(tmp.entries),
1281                                 tmp.entry_ct*sizeof(struct unipair)))
1282                         return -EFAULT;
1283         vc = ((struct tty_struct *)file->private_data)->driver_data;
1284         switch (cmd) {
1285         case PIO_UNIMAP:
1286                 if (!perm)
1287                         return -EPERM;
1288                 return con_set_unimap(vc, tmp.entry_ct,
1289                                                 compat_ptr(tmp.entries));
1290         case GIO_UNIMAP:
1291                 if (!perm && fg_console != vc->vc_num)
1292                         return -EPERM;
1293                 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct),
1294                                                 compat_ptr(tmp.entries));
1295         }
1296         return 0;
1297 }
1298
1299 #endif /* CONFIG_VT */
1300
1301 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1302 {
1303         mm_segment_t old_fs = get_fs();
1304         __kernel_uid_t kuid;
1305         int err;
1306
1307         cmd = SMB_IOC_GETMOUNTUID;
1308
1309         set_fs(KERNEL_DS);
1310         err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1311         set_fs(old_fs);
1312
1313         if (err >= 0)
1314                 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1315
1316         return err;
1317 }
1318
1319 struct atmif_sioc32 {
1320         compat_int_t    number;
1321         compat_int_t    length;
1322         compat_caddr_t  arg;
1323 };
1324
1325 struct atm_iobuf32 {
1326         compat_int_t    length;
1327         compat_caddr_t  buffer;
1328 };
1329
1330 #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1331 #define ATM_GETNAMES32    _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1332 #define ATM_GETTYPE32     _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1333 #define ATM_GETESI32      _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1334 #define ATM_GETADDR32     _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1335 #define ATM_RSTADDR32     _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1336 #define ATM_ADDADDR32     _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1337 #define ATM_DELADDR32     _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1338 #define ATM_GETCIRANGE32  _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1339 #define ATM_SETCIRANGE32  _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1340 #define ATM_SETESI32      _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1341 #define ATM_SETESIF32     _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1342 #define ATM_GETSTAT32     _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1343 #define ATM_GETSTATZ32    _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1344 #define ATM_GETLOOP32     _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1345 #define ATM_SETLOOP32     _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1346 #define ATM_QUERYLOOP32   _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1347
1348 static struct {
1349         unsigned int cmd32;
1350         unsigned int cmd;
1351 } atm_ioctl_map[] = {
1352         { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1353         { ATM_GETNAMES32,    ATM_GETNAMES },
1354         { ATM_GETTYPE32,     ATM_GETTYPE },
1355         { ATM_GETESI32,      ATM_GETESI },
1356         { ATM_GETADDR32,     ATM_GETADDR },
1357         { ATM_RSTADDR32,     ATM_RSTADDR },
1358         { ATM_ADDADDR32,     ATM_ADDADDR },
1359         { ATM_DELADDR32,     ATM_DELADDR },
1360         { ATM_GETCIRANGE32,  ATM_GETCIRANGE },
1361         { ATM_SETCIRANGE32,  ATM_SETCIRANGE },
1362         { ATM_SETESI32,      ATM_SETESI },
1363         { ATM_SETESIF32,     ATM_SETESIF },
1364         { ATM_GETSTAT32,     ATM_GETSTAT },
1365         { ATM_GETSTATZ32,    ATM_GETSTATZ },
1366         { ATM_GETLOOP32,     ATM_GETLOOP },
1367         { ATM_SETLOOP32,     ATM_SETLOOP },
1368         { ATM_QUERYLOOP32,   ATM_QUERYLOOP }
1369 };
1370
1371 #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
1372
1373 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1374 {
1375         struct atm_iobuf   __user *iobuf;
1376         struct atm_iobuf32 __user *iobuf32;
1377         u32 data;
1378         void __user *datap;
1379         int len, err;
1380
1381         iobuf = compat_alloc_user_space(sizeof(*iobuf));
1382         iobuf32 = compat_ptr(arg);
1383
1384         if (get_user(len, &iobuf32->length) ||
1385             get_user(data, &iobuf32->buffer))
1386                 return -EFAULT;
1387         datap = compat_ptr(data);
1388         if (put_user(len, &iobuf->length) ||
1389             put_user(datap, &iobuf->buffer))
1390                 return -EFAULT;
1391
1392         err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1393
1394         if (!err) {
1395                 if (copy_in_user(&iobuf32->length, &iobuf->length,
1396                                  sizeof(int)))
1397                         err = -EFAULT;
1398         }
1399
1400         return err;
1401 }
1402
1403 static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1404 {
1405         struct atmif_sioc   __user *sioc;
1406         struct atmif_sioc32 __user *sioc32;
1407         u32 data;
1408         void __user *datap;
1409         int err;
1410         
1411         sioc = compat_alloc_user_space(sizeof(*sioc));
1412         sioc32 = compat_ptr(arg);
1413
1414         if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1415             get_user(data, &sioc32->arg))
1416                 return -EFAULT;
1417         datap = compat_ptr(data);
1418         if (put_user(datap, &sioc->arg))
1419                 return -EFAULT;
1420
1421         err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1422
1423         if (!err) {
1424                 if (copy_in_user(&sioc32->length, &sioc->length,
1425                                  sizeof(int)))
1426                         err = -EFAULT;
1427         }
1428         return err;
1429 }
1430
1431 static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1432 {
1433         int i;
1434         unsigned int cmd = 0;
1435         
1436         switch (cmd32) {
1437         case SONET_GETSTAT:
1438         case SONET_GETSTATZ:
1439         case SONET_GETDIAG:
1440         case SONET_SETDIAG:
1441         case SONET_CLRDIAG:
1442         case SONET_SETFRAMING:
1443         case SONET_GETFRAMING:
1444         case SONET_GETFRSENSE:
1445                 return do_atmif_sioc(fd, cmd32, arg);
1446         }
1447
1448         for (i = 0; i < NR_ATM_IOCTL; i++) {
1449                 if (cmd32 == atm_ioctl_map[i].cmd32) {
1450                         cmd = atm_ioctl_map[i].cmd;
1451                         break;
1452                 }
1453         }
1454         if (i == NR_ATM_IOCTL)
1455                 return -EINVAL;
1456         
1457         switch (cmd) {
1458         case ATM_GETNAMES:
1459                 return do_atm_iobuf(fd, cmd, arg);
1460             
1461         case ATM_GETLINKRATE:
1462         case ATM_GETTYPE:
1463         case ATM_GETESI:
1464         case ATM_GETADDR:
1465         case ATM_RSTADDR:
1466         case ATM_ADDADDR:
1467         case ATM_DELADDR:
1468         case ATM_GETCIRANGE:
1469         case ATM_SETCIRANGE:
1470         case ATM_SETESI:
1471         case ATM_SETESIF:
1472         case ATM_GETSTAT:
1473         case ATM_GETSTATZ:
1474         case ATM_GETLOOP:
1475         case ATM_SETLOOP:
1476         case ATM_QUERYLOOP:
1477                 return do_atmif_sioc(fd, cmd, arg);
1478         }
1479
1480         return -EINVAL;
1481 }
1482
1483 static __attribute_used__ int 
1484 ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1485 {
1486         return -EINVAL;
1487 }
1488
1489 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1490 {
1491         return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1492 }
1493
1494 /* Bluetooth ioctls */
1495 #define HCIUARTSETPROTO _IOW('U', 200, int)
1496 #define HCIUARTGETPROTO _IOR('U', 201, int)
1497
1498 #define BNEPCONNADD     _IOW('B', 200, int)
1499 #define BNEPCONNDEL     _IOW('B', 201, int)
1500 #define BNEPGETCONNLIST _IOR('B', 210, int)
1501 #define BNEPGETCONNINFO _IOR('B', 211, int)
1502
1503 #define CMTPCONNADD     _IOW('C', 200, int)
1504 #define CMTPCONNDEL     _IOW('C', 201, int)
1505 #define CMTPGETCONNLIST _IOR('C', 210, int)
1506 #define CMTPGETCONNINFO _IOR('C', 211, int)
1507
1508 #define HIDPCONNADD     _IOW('H', 200, int)
1509 #define HIDPCONNDEL     _IOW('H', 201, int)
1510 #define HIDPGETCONNLIST _IOR('H', 210, int)
1511 #define HIDPGETCONNINFO _IOR('H', 211, int)
1512
1513 #ifdef CONFIG_BLOCK
1514 struct floppy_struct32 {
1515         compat_uint_t   size;
1516         compat_uint_t   sect;
1517         compat_uint_t   head;
1518         compat_uint_t   track;
1519         compat_uint_t   stretch;
1520         unsigned char   gap;
1521         unsigned char   rate;
1522         unsigned char   spec1;
1523         unsigned char   fmt_gap;
1524         const compat_caddr_t name;
1525 };
1526
1527 struct floppy_drive_params32 {
1528         char            cmos;
1529         compat_ulong_t  max_dtr;
1530         compat_ulong_t  hlt;
1531         compat_ulong_t  hut;
1532         compat_ulong_t  srt;
1533         compat_ulong_t  spinup;
1534         compat_ulong_t  spindown;
1535         unsigned char   spindown_offset;
1536         unsigned char   select_delay;
1537         unsigned char   rps;
1538         unsigned char   tracks;
1539         compat_ulong_t  timeout;
1540         unsigned char   interleave_sect;
1541         struct floppy_max_errors max_errors;
1542         char            flags;
1543         char            read_track;
1544         short           autodetect[8];
1545         compat_int_t    checkfreq;
1546         compat_int_t    native_format;
1547 };
1548
1549 struct floppy_drive_struct32 {
1550         signed char     flags;
1551         compat_ulong_t  spinup_date;
1552         compat_ulong_t  select_date;
1553         compat_ulong_t  first_read_date;
1554         short           probed_format;
1555         short           track;
1556         short           maxblock;
1557         short           maxtrack;
1558         compat_int_t    generation;
1559         compat_int_t    keep_data;
1560         compat_int_t    fd_ref;
1561         compat_int_t    fd_device;
1562         compat_int_t    last_checked;
1563         compat_caddr_t dmabuf;
1564         compat_int_t    bufblocks;
1565 };
1566
1567 struct floppy_fdc_state32 {
1568         compat_int_t    spec1;
1569         compat_int_t    spec2;
1570         compat_int_t    dtr;
1571         unsigned char   version;
1572         unsigned char   dor;
1573         compat_ulong_t  address;
1574         unsigned int    rawcmd:2;
1575         unsigned int    reset:1;
1576         unsigned int    need_configure:1;
1577         unsigned int    perp_mode:2;
1578         unsigned int    has_fifo:1;
1579         unsigned int    driver_version;
1580         unsigned char   track[4];
1581 };
1582
1583 struct floppy_write_errors32 {
1584         unsigned int    write_errors;
1585         compat_ulong_t  first_error_sector;
1586         compat_int_t    first_error_generation;
1587         compat_ulong_t  last_error_sector;
1588         compat_int_t    last_error_generation;
1589         compat_uint_t   badness;
1590 };
1591
1592 #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1593 #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1594 #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1595 #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1596 #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1597 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1598 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1599 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1600 #define FDWERRORGET32  _IOR(2, 0x17, struct floppy_write_errors32)
1601
1602 static struct {
1603         unsigned int    cmd32;
1604         unsigned int    cmd;
1605 } fd_ioctl_trans_table[] = {
1606         { FDSETPRM32, FDSETPRM },
1607         { FDDEFPRM32, FDDEFPRM },
1608         { FDGETPRM32, FDGETPRM },
1609         { FDSETDRVPRM32, FDSETDRVPRM },
1610         { FDGETDRVPRM32, FDGETDRVPRM },
1611         { FDGETDRVSTAT32, FDGETDRVSTAT },
1612         { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1613         { FDGETFDCSTAT32, FDGETFDCSTAT },
1614         { FDWERRORGET32, FDWERRORGET }
1615 };
1616
1617 #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
1618
1619 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1620 {
1621         mm_segment_t old_fs = get_fs();
1622         void *karg = NULL;
1623         unsigned int kcmd = 0;
1624         int i, err;
1625
1626         for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1627                 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1628                         kcmd = fd_ioctl_trans_table[i].cmd;
1629                         break;
1630                 }
1631         if (!kcmd)
1632                 return -EINVAL;
1633
1634         switch (cmd) {
1635                 case FDSETPRM32:
1636                 case FDDEFPRM32:
1637                 case FDGETPRM32:
1638                 {
1639                         compat_uptr_t name;
1640                         struct floppy_struct32 __user *uf;
1641                         struct floppy_struct *f;
1642
1643                         uf = compat_ptr(arg);
1644                         f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1645                         if (!karg)
1646                                 return -ENOMEM;
1647                         if (cmd == FDGETPRM32)
1648                                 break;
1649                         err = __get_user(f->size, &uf->size);
1650                         err |= __get_user(f->sect, &uf->sect);
1651                         err |= __get_user(f->head, &uf->head);
1652                         err |= __get_user(f->track, &uf->track);
1653                         err |= __get_user(f->stretch, &uf->stretch);
1654                         err |= __get_user(f->gap, &uf->gap);
1655                         err |= __get_user(f->rate, &uf->rate);
1656                         err |= __get_user(f->spec1, &uf->spec1);
1657                         err |= __get_user(f->fmt_gap, &uf->fmt_gap);
1658                         err |= __get_user(name, &uf->name);
1659                         f->name = compat_ptr(name);
1660                         if (err) {
1661                                 err = -EFAULT;
1662                                 goto out;
1663                         }
1664                         break;
1665                 }
1666                 case FDSETDRVPRM32:
1667                 case FDGETDRVPRM32:
1668                 {
1669                         struct floppy_drive_params32 __user *uf;
1670                         struct floppy_drive_params *f;
1671
1672                         uf = compat_ptr(arg);
1673                         f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1674                         if (!karg)
1675                                 return -ENOMEM;
1676                         if (cmd == FDGETDRVPRM32)
1677                                 break;
1678                         err = __get_user(f->cmos, &uf->cmos);
1679                         err |= __get_user(f->max_dtr, &uf->max_dtr);
1680                         err |= __get_user(f->hlt, &uf->hlt);
1681                         err |= __get_user(f->hut, &uf->hut);
1682                         err |= __get_user(f->srt, &uf->srt);
1683                         err |= __get_user(f->spinup, &uf->spinup);
1684                         err |= __get_user(f->spindown, &uf->spindown);
1685                         err |= __get_user(f->spindown_offset, &uf->spindown_offset);
1686                         err |= __get_user(f->select_delay, &uf->select_delay);
1687                         err |= __get_user(f->rps, &uf->rps);
1688                         err |= __get_user(f->tracks, &uf->tracks);
1689                         err |= __get_user(f->timeout, &uf->timeout);
1690                         err |= __get_user(f->interleave_sect, &uf->interleave_sect);
1691                         err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
1692                         err |= __get_user(f->flags, &uf->flags);
1693                         err |= __get_user(f->read_track, &uf->read_track);
1694                         err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
1695                         err |= __get_user(f->checkfreq, &uf->checkfreq);
1696                         err |= __get_user(f->native_format, &uf->native_format);
1697                         if (err) {
1698                                 err = -EFAULT;
1699                                 goto out;
1700                         }
1701                         break;
1702                 }
1703                 case FDGETDRVSTAT32:
1704                 case FDPOLLDRVSTAT32:
1705                         karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1706                         if (!karg)
1707                                 return -ENOMEM;
1708                         break;
1709                 case FDGETFDCSTAT32:
1710                         karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1711                         if (!karg)
1712                                 return -ENOMEM;
1713                         break;
1714                 case FDWERRORGET32:
1715                         karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1716                         if (!karg)
1717                                 return -ENOMEM;
1718                         break;
1719                 default:
1720                         return -EINVAL;
1721         }
1722         set_fs (KERNEL_DS);
1723         err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1724         set_fs (old_fs);
1725         if (err)
1726                 goto out;
1727         switch (cmd) {
1728                 case FDGETPRM32:
1729                 {
1730                         struct floppy_struct *f = karg;
1731                         struct floppy_struct32 __user *uf = compat_ptr(arg);
1732
1733                         err = __put_user(f->size, &uf->size);
1734                         err |= __put_user(f->sect, &uf->sect);
1735                         err |= __put_user(f->head, &uf->head);
1736                         err |= __put_user(f->track, &uf->track);
1737                         err |= __put_user(f->stretch, &uf->stretch);
1738                         err |= __put_user(f->gap, &uf->gap);
1739                         err |= __put_user(f->rate, &uf->rate);
1740                         err |= __put_user(f->spec1, &uf->spec1);
1741                         err |= __put_user(f->fmt_gap, &uf->fmt_gap);
1742                         err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
1743                         break;
1744                 }
1745                 case FDGETDRVPRM32:
1746                 {
1747                         struct floppy_drive_params32 __user *uf;
1748                         struct floppy_drive_params *f = karg;
1749
1750                         uf = compat_ptr(arg);
1751                         err = __put_user(f->cmos, &uf->cmos);
1752                         err |= __put_user(f->max_dtr, &uf->max_dtr);
1753                         err |= __put_user(f->hlt, &uf->hlt);
1754                         err |= __put_user(f->hut, &uf->hut);
1755                         err |= __put_user(f->srt, &uf->srt);
1756                         err |= __put_user(f->spinup, &uf->spinup);
1757                         err |= __put_user(f->spindown, &uf->spindown);
1758                         err |= __put_user(f->spindown_offset, &uf->spindown_offset);
1759                         err |= __put_user(f->select_delay, &uf->select_delay);
1760                         err |= __put_user(f->rps, &uf->rps);
1761                         err |= __put_user(f->tracks, &uf->tracks);
1762                         err |= __put_user(f->timeout, &uf->timeout);
1763                         err |= __put_user(f->interleave_sect, &uf->interleave_sect);
1764                         err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
1765                         err |= __put_user(f->flags, &uf->flags);
1766                         err |= __put_user(f->read_track, &uf->read_track);
1767                         err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
1768                         err |= __put_user(f->checkfreq, &uf->checkfreq);
1769                         err |= __put_user(f->native_format, &uf->native_format);
1770                         break;
1771                 }
1772                 case FDGETDRVSTAT32:
1773                 case FDPOLLDRVSTAT32:
1774                 {
1775                         struct floppy_drive_struct32 __user *uf;
1776                         struct floppy_drive_struct *f = karg;
1777
1778                         uf = compat_ptr(arg);
1779                         err = __put_user(f->flags, &uf->flags);
1780                         err |= __put_user(f->spinup_date, &uf->spinup_date);
1781                         err |= __put_user(f->select_date, &uf->select_date);
1782                         err |= __put_user(f->first_read_date, &uf->first_read_date);
1783                         err |= __put_user(f->probed_format, &uf->probed_format);
1784                         err |= __put_user(f->track, &uf->track);
1785                         err |= __put_user(f->maxblock, &uf->maxblock);
1786                         err |= __put_user(f->maxtrack, &uf->maxtrack);
1787                         err |= __put_user(f->generation, &uf->generation);
1788                         err |= __put_user(f->keep_data, &uf->keep_data);
1789                         err |= __put_user(f->fd_ref, &uf->fd_ref);
1790                         err |= __put_user(f->fd_device, &uf->fd_device);
1791                         err |= __put_user(f->last_checked, &uf->last_checked);
1792                         err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
1793                         err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
1794                         break;
1795                 }
1796                 case FDGETFDCSTAT32:
1797                 {
1798                         struct floppy_fdc_state32 __user *uf;
1799                         struct floppy_fdc_state *f = karg;
1800
1801                         uf = compat_ptr(arg);
1802                         err = __put_user(f->spec1, &uf->spec1);
1803                         err |= __put_user(f->spec2, &uf->spec2);
1804                         err |= __put_user(f->dtr, &uf->dtr);
1805                         err |= __put_user(f->version, &uf->version);
1806                         err |= __put_user(f->dor, &uf->dor);
1807                         err |= __put_user(f->address, &uf->address);
1808                         err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
1809                                            (char *)&f->address + sizeof(f->address), sizeof(int));
1810                         err |= __put_user(f->driver_version, &uf->driver_version);
1811                         err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
1812                         break;
1813                 }
1814                 case FDWERRORGET32:
1815                 {
1816                         struct floppy_write_errors32 __user *uf;
1817                         struct floppy_write_errors *f = karg;
1818
1819                         uf = compat_ptr(arg);
1820                         err = __put_user(f->write_errors, &uf->write_errors);
1821                         err |= __put_user(f->first_error_sector, &uf->first_error_sector);
1822                         err |= __put_user(f->first_error_generation, &uf->first_error_generation);
1823                         err |= __put_user(f->last_error_sector, &uf->last_error_sector);
1824                         err |= __put_user(f->last_error_generation, &uf->last_error_generation);
1825                         err |= __put_user(f->badness, &uf->badness);
1826                         break;
1827                 }
1828                 default:
1829                         break;
1830         }
1831         if (err)
1832                 err = -EFAULT;
1833
1834 out:
1835         kfree(karg);
1836         return err;
1837 }
1838 #endif
1839
1840 struct mtd_oob_buf32 {
1841         u_int32_t start;
1842         u_int32_t length;
1843         compat_caddr_t ptr;     /* unsigned char* */
1844 };
1845
1846 #define MEMWRITEOOB32   _IOWR('M',3,struct mtd_oob_buf32)
1847 #define MEMREADOOB32    _IOWR('M',4,struct mtd_oob_buf32)
1848
1849 static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
1850 {
1851         struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
1852         struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
1853         u32 data;
1854         char __user *datap;
1855         unsigned int real_cmd;
1856         int err;
1857
1858         real_cmd = (cmd == MEMREADOOB32) ?
1859                 MEMREADOOB : MEMWRITEOOB;
1860
1861         if (copy_in_user(&buf->start, &buf32->start,
1862                          2 * sizeof(u32)) ||
1863             get_user(data, &buf32->ptr))
1864                 return -EFAULT;
1865         datap = compat_ptr(data);
1866         if (put_user(datap, &buf->ptr))
1867                 return -EFAULT;
1868
1869         err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
1870
1871         if (!err) {
1872                 if (copy_in_user(&buf32->start, &buf->start,
1873                                  2 * sizeof(u32)))
1874                         err = -EFAULT;
1875         }
1876
1877         return err;
1878 }       
1879
1880 #ifdef CONFIG_BLOCK
1881 struct raw32_config_request
1882 {
1883         compat_int_t    raw_minor;
1884         __u64   block_major;
1885         __u64   block_minor;
1886 } __attribute__((packed));
1887
1888 static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1889 {
1890         int ret;
1891
1892         if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
1893                 return -EFAULT;
1894
1895         ret = __get_user(req->raw_minor, &user_req->raw_minor);
1896         ret |= __get_user(req->block_major, &user_req->block_major);
1897         ret |= __get_user(req->block_minor, &user_req->block_minor);
1898
1899         return ret ? -EFAULT : 0;
1900 }
1901
1902 static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1903 {
1904         int ret;
1905
1906         if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
1907                 return -EFAULT;
1908
1909         ret = __put_user(req->raw_minor, &user_req->raw_minor);
1910         ret |= __put_user(req->block_major, &user_req->block_major);
1911         ret |= __put_user(req->block_minor, &user_req->block_minor);
1912
1913         return ret ? -EFAULT : 0;
1914 }
1915
1916 static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1917 {
1918         int ret;
1919
1920         switch (cmd) {
1921         case RAW_SETBIND:
1922         case RAW_GETBIND: {
1923                 struct raw_config_request req;
1924                 struct raw32_config_request __user *user_req = compat_ptr(arg);
1925                 mm_segment_t oldfs = get_fs();
1926
1927                 if ((ret = get_raw32_request(&req, user_req)))
1928                         return ret;
1929
1930                 set_fs(KERNEL_DS);
1931                 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
1932                 set_fs(oldfs);
1933
1934                 if ((!ret) && (cmd == RAW_GETBIND)) {
1935                         ret = set_raw32_request(&req, user_req);
1936                 }
1937                 break;
1938         }
1939         default:
1940                 ret = sys_ioctl(fd, cmd, arg);
1941                 break;
1942         }
1943         return ret;
1944 }
1945 #endif /* CONFIG_BLOCK */
1946
1947 struct serial_struct32 {
1948         compat_int_t    type;
1949         compat_int_t    line;
1950         compat_uint_t   port;
1951         compat_int_t    irq;
1952         compat_int_t    flags;
1953         compat_int_t    xmit_fifo_size;
1954         compat_int_t    custom_divisor;
1955         compat_int_t    baud_base;
1956         unsigned short  close_delay;
1957         char    io_type;
1958         char    reserved_char[1];
1959         compat_int_t    hub6;
1960         unsigned short  closing_wait; /* time to wait before closing */
1961         unsigned short  closing_wait2; /* no longer used... */
1962         compat_uint_t   iomem_base;
1963         unsigned short  iomem_reg_shift;
1964         unsigned int    port_high;
1965      /* compat_ulong_t  iomap_base FIXME */
1966         compat_int_t    reserved[1];
1967 };
1968
1969 static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1970 {
1971         typedef struct serial_struct SS;
1972         typedef struct serial_struct32 SS32;
1973         struct serial_struct32 __user *ss32 = compat_ptr(arg);
1974         int err;
1975         struct serial_struct ss;
1976         mm_segment_t oldseg = get_fs();
1977         __u32 udata;
1978         unsigned int base;
1979
1980         if (cmd == TIOCSSERIAL) {
1981                 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
1982                         return -EFAULT;
1983                 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
1984                         return -EFAULT;
1985                 if (__get_user(udata, &ss32->iomem_base))
1986                         return -EFAULT;
1987                 ss.iomem_base = compat_ptr(udata);
1988                 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
1989                     __get_user(ss.port_high, &ss32->port_high))
1990                         return -EFAULT;
1991                 ss.iomap_base = 0UL;
1992         }
1993         set_fs(KERNEL_DS);
1994                 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
1995         set_fs(oldseg);
1996         if (cmd == TIOCGSERIAL && err >= 0) {
1997                 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
1998                         return -EFAULT;
1999                 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
2000                         return -EFAULT;
2001                 base = (unsigned long)ss.iomem_base  >> 32 ?
2002                         0xffffffff : (unsigned)(unsigned long)ss.iomem_base;
2003                 if (__put_user(base, &ss32->iomem_base) ||
2004                     __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
2005                     __put_user(ss.port_high, &ss32->port_high))
2006                         return -EFAULT;
2007         }
2008         return err;
2009 }
2010
2011 struct usbdevfs_ctrltransfer32 {
2012         u8 bRequestType;
2013         u8 bRequest;
2014         u16 wValue;
2015         u16 wIndex;
2016         u16 wLength;
2017         u32 timeout;  /* in milliseconds */
2018         compat_caddr_t data;
2019 };
2020
2021 #define USBDEVFS_CONTROL32           _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2022
2023 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2024 {
2025         struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2026         struct usbdevfs_ctrltransfer __user *p;
2027         __u32 udata;
2028         p = compat_alloc_user_space(sizeof(*p));
2029         if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2030             get_user(udata, &p32->data) ||
2031             put_user(compat_ptr(udata), &p->data))
2032                 return -EFAULT;
2033         return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2034 }
2035
2036
2037 struct usbdevfs_bulktransfer32 {
2038         compat_uint_t ep;
2039         compat_uint_t len;
2040         compat_uint_t timeout; /* in milliseconds */
2041         compat_caddr_t data;
2042 };
2043
2044 #define USBDEVFS_BULK32              _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2045
2046 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2047 {
2048         struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2049         struct usbdevfs_bulktransfer __user *p;
2050         compat_uint_t n;
2051         compat_caddr_t addr;
2052
2053         p = compat_alloc_user_space(sizeof(*p));
2054
2055         if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2056             get_user(n, &p32->len) || put_user(n, &p->len) ||
2057             get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2058             get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2059                 return -EFAULT;
2060
2061         return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2062 }
2063
2064
2065 /*
2066  *  USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
2067  *  are handled in usbdevfs core.                       -Christopher Li
2068  */
2069
2070 struct usbdevfs_disconnectsignal32 {
2071         compat_int_t signr;
2072         compat_caddr_t context;
2073 };
2074
2075 #define USBDEVFS_DISCSIGNAL32      _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2076
2077 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2078 {
2079         struct usbdevfs_disconnectsignal kdis;
2080         struct usbdevfs_disconnectsignal32 __user *udis;
2081         mm_segment_t old_fs;
2082         u32 uctx;
2083         int err;
2084
2085         udis = compat_ptr(arg);
2086
2087         if (get_user(kdis.signr, &udis->signr) ||
2088             __get_user(uctx, &udis->context))
2089                 return -EFAULT;
2090
2091         kdis.context = compat_ptr(uctx);
2092
2093         old_fs = get_fs();
2094         set_fs(KERNEL_DS);
2095         err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2096         set_fs(old_fs);
2097
2098         return err;
2099 }
2100
2101 /*
2102  * I2C layer ioctls
2103  */
2104
2105 struct i2c_msg32 {
2106         u16 addr;
2107         u16 flags;
2108         u16 len;
2109         compat_caddr_t buf;
2110 };
2111
2112 struct i2c_rdwr_ioctl_data32 {
2113         compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2114         u32 nmsgs;
2115 };
2116
2117 struct i2c_smbus_ioctl_data32 {
2118         u8 read_write;
2119         u8 command;
2120         u32 size;
2121         compat_caddr_t data; /* union i2c_smbus_data *data */
2122 };
2123
2124 struct i2c_rdwr_aligned {
2125         struct i2c_rdwr_ioctl_data cmd;
2126         struct i2c_msg msgs[0];
2127 };
2128
2129 static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2130 {
2131         struct i2c_rdwr_ioctl_data32    __user *udata = compat_ptr(arg);
2132         struct i2c_rdwr_aligned         __user *tdata;
2133         struct i2c_msg                  __user *tmsgs;
2134         struct i2c_msg32                __user *umsgs;
2135         compat_caddr_t                  datap;
2136         int                             nmsgs, i;
2137
2138         if (get_user(nmsgs, &udata->nmsgs))
2139                 return -EFAULT;
2140         if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2141                 return -EINVAL;
2142
2143         if (get_user(datap, &udata->msgs))
2144                 return -EFAULT;
2145         umsgs = compat_ptr(datap);
2146
2147         tdata = compat_alloc_user_space(sizeof(*tdata) +
2148                                       nmsgs * sizeof(struct i2c_msg));
2149         tmsgs = &tdata->msgs[0];
2150
2151         if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
2152             put_user(tmsgs, &tdata->cmd.msgs))
2153                 return -EFAULT;
2154
2155         for (i = 0; i < nmsgs; i++) {
2156                 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
2157                         return -EFAULT;
2158                 if (get_user(datap, &umsgs[i].buf) ||
2159                     put_user(compat_ptr(datap), &tmsgs[i].buf))
2160                         return -EFAULT;
2161         }
2162         return sys_ioctl(fd, cmd, (unsigned long)tdata);
2163 }
2164
2165 static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2166 {
2167         struct i2c_smbus_ioctl_data     __user *tdata;
2168         struct i2c_smbus_ioctl_data32   __user *udata;
2169         compat_caddr_t                  datap;
2170
2171         tdata = compat_alloc_user_space(sizeof(*tdata));
2172         if (tdata == NULL)
2173                 return -ENOMEM;
2174         if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
2175                 return -EFAULT;
2176
2177         udata = compat_ptr(arg);
2178         if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
2179                 return -EFAULT;
2180
2181         if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2182                 return -EFAULT;
2183         if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2184                 return -EFAULT;
2185         if (__get_user(datap, &udata->data) ||
2186             __put_user(compat_ptr(datap), &tdata->data))
2187                 return -EFAULT;
2188
2189         return sys_ioctl(fd, cmd, (unsigned long)tdata);
2190 }
2191
2192 struct compat_iw_point {
2193         compat_caddr_t pointer;
2194         __u16 length;
2195         __u16 flags;
2196 };
2197
2198 static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2199 {
2200         struct iwreq __user *iwr;
2201         struct iwreq __user *iwr_u;
2202         struct iw_point __user *iwp;
2203         struct compat_iw_point __user *iwp_u;
2204         compat_caddr_t pointer_u;
2205         void __user *pointer;
2206         __u16 length, flags;
2207         int ret;
2208
2209         iwr_u = compat_ptr(arg);
2210         iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2211         iwr = compat_alloc_user_space(sizeof(*iwr));
2212         if (iwr == NULL)
2213                 return -ENOMEM;
2214
2215         iwp = &iwr->u.data;
2216
2217         if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
2218                 return -EFAULT;
2219
2220         if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2221                            &iwr_u->ifr_ifrn.ifrn_name[0],
2222                            sizeof(iwr->ifr_ifrn.ifrn_name)))
2223                 return -EFAULT;
2224
2225         if (__get_user(pointer_u, &iwp_u->pointer) ||
2226             __get_user(length, &iwp_u->length) ||
2227             __get_user(flags, &iwp_u->flags))
2228                 return -EFAULT;
2229
2230         if (__put_user(compat_ptr(pointer_u), &iwp->pointer) ||
2231             __put_user(length, &iwp->length) ||
2232             __put_user(flags, &iwp->flags))
2233                 return -EFAULT;
2234
2235         ret = sys_ioctl(fd, cmd, (unsigned long) iwr);
2236
2237         if (__get_user(pointer, &iwp->pointer) ||
2238             __get_user(length, &iwp->length) ||
2239             __get_user(flags, &iwp->flags))
2240                 return -EFAULT;
2241
2242         if (__put_user(ptr_to_compat(pointer), &iwp_u->pointer) ||
2243             __put_user(length, &iwp_u->length) ||
2244             __put_user(flags, &iwp_u->flags))
2245                 return -EFAULT;
2246
2247         return ret;
2248 }
2249
2250 /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2251  * for some operations; this forces use of the newer bridge-utils that
2252  * use compatiable ioctls
2253  */
2254 static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2255 {
2256         u32 tmp;
2257
2258         if (get_user(tmp, (u32 __user *) arg))
2259                 return -EFAULT;
2260         if (tmp == BRCTL_GET_VERSION)
2261                 return BRCTL_VERSION + 1;
2262         return -EINVAL;
2263 }
2264
2265 #define RTC_IRQP_READ32         _IOR('p', 0x0b, compat_ulong_t)
2266 #define RTC_IRQP_SET32          _IOW('p', 0x0c, compat_ulong_t)
2267 #define RTC_EPOCH_READ32        _IOR('p', 0x0d, compat_ulong_t)
2268 #define RTC_EPOCH_SET32         _IOW('p', 0x0e, compat_ulong_t)
2269
2270 static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2271 {
2272         mm_segment_t oldfs = get_fs();
2273         compat_ulong_t val32;
2274         unsigned long kval;
2275         int ret;
2276
2277         switch (cmd) {
2278         case RTC_IRQP_READ32:
2279         case RTC_EPOCH_READ32:
2280                 set_fs(KERNEL_DS);
2281                 ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
2282                                         RTC_IRQP_READ : RTC_EPOCH_READ,
2283                                         (unsigned long)&kval);
2284                 set_fs(oldfs);
2285                 if (ret)
2286                         return ret;
2287                 val32 = kval;
2288                 return put_user(val32, (unsigned int __user *)arg);
2289         case RTC_IRQP_SET32:
2290                 return sys_ioctl(fd, RTC_IRQP_SET, arg); 
2291         case RTC_EPOCH_SET32:
2292                 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
2293         default:
2294                 /* unreached */
2295                 return -ENOIOCTLCMD;
2296         }
2297 }
2298
2299 static int
2300 lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2301 {
2302         struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
2303         struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
2304         struct timeval ts;
2305         if (get_user(ts.tv_sec, &tc->tv_sec) ||
2306             get_user(ts.tv_usec, &tc->tv_usec) ||
2307             put_user(ts.tv_sec, &tn->tv_sec) ||
2308             put_user(ts.tv_usec, &tn->tv_usec))
2309                 return -EFAULT;
2310         return sys_ioctl(fd, cmd, (unsigned long)tn);
2311 }
2312
2313
2314 typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int,
2315                                         unsigned long, struct file *);
2316
2317 struct ioctl_trans {
2318         unsigned long cmd;
2319         ioctl_trans_handler_t handler;
2320         struct ioctl_trans *next;
2321 };
2322
2323 #define HANDLE_IOCTL(cmd,handler) \
2324         { (cmd), (ioctl_trans_handler_t)(handler) },
2325
2326 /* pointer to compatible structure or no argument */
2327 #define COMPATIBLE_IOCTL(cmd) \
2328         { (cmd), do_ioctl32_pointer },
2329
2330 /* argument is an unsigned long integer, not a pointer */
2331 #define ULONG_IOCTL(cmd) \
2332         { (cmd), (ioctl_trans_handler_t)sys_ioctl },
2333
2334 /* ioctl should not be warned about even if it's not implemented.
2335    Valid reasons to use this:
2336    - It is implemented with ->compat_ioctl on some device, but programs
2337    call it on others too.
2338    - The ioctl is not implemented in the native kernel, but programs
2339    call it commonly anyways.
2340    Most other reasons are not valid. */
2341 #define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
2342
2343 static struct ioctl_trans ioctl_start[] = {
2344 /* compatible ioctls first */
2345 COMPATIBLE_IOCTL(0x4B50)   /* KDGHWCLK - not in the kernel, but don't complain */
2346 COMPATIBLE_IOCTL(0x4B51)   /* KDSHWCLK - not in the kernel, but don't complain */
2347
2348 /* Big T */
2349 COMPATIBLE_IOCTL(TCGETA)
2350 COMPATIBLE_IOCTL(TCSETA)
2351 COMPATIBLE_IOCTL(TCSETAW)
2352 COMPATIBLE_IOCTL(TCSETAF)
2353 COMPATIBLE_IOCTL(TCSBRK)
2354 ULONG_IOCTL(TCSBRKP)
2355 COMPATIBLE_IOCTL(TCXONC)
2356 COMPATIBLE_IOCTL(TCFLSH)
2357 COMPATIBLE_IOCTL(TCGETS)
2358 COMPATIBLE_IOCTL(TCSETS)
2359 COMPATIBLE_IOCTL(TCSETSW)
2360 COMPATIBLE_IOCTL(TCSETSF)
2361 COMPATIBLE_IOCTL(TIOCLINUX)
2362 COMPATIBLE_IOCTL(TIOCSBRK)
2363 COMPATIBLE_IOCTL(TIOCCBRK)
2364 ULONG_IOCTL(TIOCMIWAIT)
2365 COMPATIBLE_IOCTL(TIOCGICOUNT)
2366 /* Little t */
2367 COMPATIBLE_IOCTL(TIOCGETD)
2368 COMPATIBLE_IOCTL(TIOCSETD)
2369 COMPATIBLE_IOCTL(TIOCEXCL)
2370 COMPATIBLE_IOCTL(TIOCNXCL)
2371 COMPATIBLE_IOCTL(TIOCCONS)
2372 COMPATIBLE_IOCTL(TIOCGSOFTCAR)
2373 COMPATIBLE_IOCTL(TIOCSSOFTCAR)
2374 COMPATIBLE_IOCTL(TIOCSWINSZ)
2375 COMPATIBLE_IOCTL(TIOCGWINSZ)
2376 COMPATIBLE_IOCTL(TIOCMGET)
2377 COMPATIBLE_IOCTL(TIOCMBIC)
2378 COMPATIBLE_IOCTL(TIOCMBIS)
2379 COMPATIBLE_IOCTL(TIOCMSET)
2380 COMPATIBLE_IOCTL(TIOCPKT)
2381 COMPATIBLE_IOCTL(TIOCNOTTY)
2382 COMPATIBLE_IOCTL(TIOCSTI)
2383 COMPATIBLE_IOCTL(TIOCOUTQ)
2384 COMPATIBLE_IOCTL(TIOCSPGRP)
2385 COMPATIBLE_IOCTL(TIOCGPGRP)
2386 ULONG_IOCTL(TIOCSCTTY)
2387 COMPATIBLE_IOCTL(TIOCGPTN)
2388 COMPATIBLE_IOCTL(TIOCSPTLCK)
2389 COMPATIBLE_IOCTL(TIOCSERGETLSR)
2390 /* Little f */
2391 COMPATIBLE_IOCTL(FIOCLEX)
2392 COMPATIBLE_IOCTL(FIONCLEX)
2393 COMPATIBLE_IOCTL(FIOASYNC)
2394 COMPATIBLE_IOCTL(FIONBIO)
2395 COMPATIBLE_IOCTL(FIONREAD)  /* This is also TIOCINQ */
2396 /* 0x00 */
2397 COMPATIBLE_IOCTL(FIBMAP)
2398 COMPATIBLE_IOCTL(FIGETBSZ)
2399 /* RAID */
2400 COMPATIBLE_IOCTL(RAID_VERSION)
2401 COMPATIBLE_IOCTL(GET_ARRAY_INFO)
2402 COMPATIBLE_IOCTL(GET_DISK_INFO)
2403 COMPATIBLE_IOCTL(PRINT_RAID_DEBUG)
2404 COMPATIBLE_IOCTL(RAID_AUTORUN)
2405 COMPATIBLE_IOCTL(CLEAR_ARRAY)
2406 COMPATIBLE_IOCTL(ADD_NEW_DISK)
2407 ULONG_IOCTL(HOT_REMOVE_DISK)
2408 COMPATIBLE_IOCTL(SET_ARRAY_INFO)
2409 COMPATIBLE_IOCTL(SET_DISK_INFO)
2410 COMPATIBLE_IOCTL(WRITE_RAID_INFO)
2411 COMPATIBLE_IOCTL(UNPROTECT_ARRAY)
2412 COMPATIBLE_IOCTL(PROTECT_ARRAY)
2413 ULONG_IOCTL(HOT_ADD_DISK)
2414 ULONG_IOCTL(SET_DISK_FAULTY)
2415 COMPATIBLE_IOCTL(RUN_ARRAY)
2416 COMPATIBLE_IOCTL(STOP_ARRAY)
2417 COMPATIBLE_IOCTL(STOP_ARRAY_RO)
2418 COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
2419 COMPATIBLE_IOCTL(GET_BITMAP_FILE)
2420 ULONG_IOCTL(SET_BITMAP_FILE)
2421 /* DM */
2422 COMPATIBLE_IOCTL(DM_VERSION_32)
2423 COMPATIBLE_IOCTL(DM_REMOVE_ALL_32)
2424 COMPATIBLE_IOCTL(DM_LIST_DEVICES_32)
2425 COMPATIBLE_IOCTL(DM_DEV_CREATE_32)
2426 COMPATIBLE_IOCTL(DM_DEV_REMOVE_32)
2427 COMPATIBLE_IOCTL(DM_DEV_RENAME_32)
2428 COMPATIBLE_IOCTL(DM_DEV_SUSPEND_32)
2429 COMPATIBLE_IOCTL(DM_DEV_STATUS_32)
2430 COMPATIBLE_IOCTL(DM_DEV_WAIT_32)
2431 COMPATIBLE_IOCTL(DM_TABLE_LOAD_32)
2432 COMPATIBLE_IOCTL(DM_TABLE_CLEAR_32)
2433 COMPATIBLE_IOCTL(DM_TABLE_DEPS_32)
2434 COMPATIBLE_IOCTL(DM_TABLE_STATUS_32)
2435 COMPATIBLE_IOCTL(DM_LIST_VERSIONS_32)
2436 COMPATIBLE_IOCTL(DM_TARGET_MSG_32)
2437 COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY_32)
2438 COMPATIBLE_IOCTL(DM_VERSION)
2439 COMPATIBLE_IOCTL(DM_REMOVE_ALL)
2440 COMPATIBLE_IOCTL(DM_LIST_DEVICES)
2441 COMPATIBLE_IOCTL(DM_DEV_CREATE)
2442 COMPATIBLE_IOCTL(DM_DEV_REMOVE)
2443 COMPATIBLE_IOCTL(DM_DEV_RENAME)
2444 COMPATIBLE_IOCTL(DM_DEV_SUSPEND)
2445 COMPATIBLE_IOCTL(DM_DEV_STATUS)
2446 COMPATIBLE_IOCTL(DM_DEV_WAIT)
2447 COMPATIBLE_IOCTL(DM_TABLE_LOAD)
2448 COMPATIBLE_IOCTL(DM_TABLE_CLEAR)
2449 COMPATIBLE_IOCTL(DM_TABLE_DEPS)
2450 COMPATIBLE_IOCTL(DM_TABLE_STATUS)
2451 COMPATIBLE_IOCTL(DM_LIST_VERSIONS)
2452 COMPATIBLE_IOCTL(DM_TARGET_MSG)
2453 COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY)
2454 /* Big K */
2455 COMPATIBLE_IOCTL(PIO_FONT)
2456 COMPATIBLE_IOCTL(GIO_FONT)
2457 ULONG_IOCTL(KDSIGACCEPT)
2458 COMPATIBLE_IOCTL(KDGETKEYCODE)
2459 COMPATIBLE_IOCTL(KDSETKEYCODE)
2460 ULONG_IOCTL(KIOCSOUND)
2461 ULONG_IOCTL(KDMKTONE)
2462 COMPATIBLE_IOCTL(KDGKBTYPE)
2463 ULONG_IOCTL(KDSETMODE)
2464 COMPATIBLE_IOCTL(KDGETMODE)
2465 ULONG_IOCTL(KDSKBMODE)
2466 COMPATIBLE_IOCTL(KDGKBMODE)
2467 ULONG_IOCTL(KDSKBMETA)
2468 COMPATIBLE_IOCTL(KDGKBMETA)
2469 COMPATIBLE_IOCTL(KDGKBENT)
2470 COMPATIBLE_IOCTL(KDSKBENT)
2471 COMPATIBLE_IOCTL(KDGKBSENT)
2472 COMPATIBLE_IOCTL(KDSKBSENT)
2473 COMPATIBLE_IOCTL(KDGKBDIACR)
2474 COMPATIBLE_IOCTL(KDSKBDIACR)
2475 COMPATIBLE_IOCTL(KDKBDREP)
2476 COMPATIBLE_IOCTL(KDGKBLED)
2477 ULONG_IOCTL(KDSKBLED)
2478 COMPATIBLE_IOCTL(KDGETLED)
2479 ULONG_IOCTL(KDSETLED)
2480 COMPATIBLE_IOCTL(GIO_SCRNMAP)
2481 COMPATIBLE_IOCTL(PIO_SCRNMAP)
2482 COMPATIBLE_IOCTL(GIO_UNISCRNMAP)
2483 COMPATIBLE_IOCTL(PIO_UNISCRNMAP)
2484 COMPATIBLE_IOCTL(PIO_FONTRESET)
2485 COMPATIBLE_IOCTL(PIO_UNIMAPCLR)
2486 /* Big S */
2487 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
2488 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
2489 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
2490 COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
2491 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
2492 COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
2493 COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
2494 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
2495 /* Big T */
2496 COMPATIBLE_IOCTL(TUNSETNOCSUM)
2497 COMPATIBLE_IOCTL(TUNSETDEBUG)
2498 COMPATIBLE_IOCTL(TUNSETPERSIST)
2499 COMPATIBLE_IOCTL(TUNSETOWNER)
2500 /* Big V */
2501 COMPATIBLE_IOCTL(VT_SETMODE)
2502 COMPATIBLE_IOCTL(VT_GETMODE)
2503 COMPATIBLE_IOCTL(VT_GETSTATE)
2504 COMPATIBLE_IOCTL(VT_OPENQRY)
2505 ULONG_IOCTL(VT_ACTIVATE)
2506 ULONG_IOCTL(VT_WAITACTIVE)
2507 ULONG_IOCTL(VT_RELDISP)
2508 ULONG_IOCTL(VT_DISALLOCATE)
2509 COMPATIBLE_IOCTL(VT_RESIZE)
2510 COMPATIBLE_IOCTL(VT_RESIZEX)
2511 COMPATIBLE_IOCTL(VT_LOCKSWITCH)
2512 COMPATIBLE_IOCTL(VT_UNLOCKSWITCH)
2513 COMPATIBLE_IOCTL(VT_GETHIFONTMASK)
2514 /* Little p (/dev/rtc, /dev/envctrl, etc.) */
2515 COMPATIBLE_IOCTL(RTC_AIE_ON)
2516 COMPATIBLE_IOCTL(RTC_AIE_OFF)
2517 COMPATIBLE_IOCTL(RTC_UIE_ON)
2518 COMPATIBLE_IOCTL(RTC_UIE_OFF)
2519 COMPATIBLE_IOCTL(RTC_PIE_ON)
2520 COMPATIBLE_IOCTL(RTC_PIE_OFF)
2521 COMPATIBLE_IOCTL(RTC_WIE_ON)
2522 COMPATIBLE_IOCTL(RTC_WIE_OFF)
2523 COMPATIBLE_IOCTL(RTC_ALM_SET)
2524 COMPATIBLE_IOCTL(RTC_ALM_READ)
2525 COMPATIBLE_IOCTL(RTC_RD_TIME)
2526 COMPATIBLE_IOCTL(RTC_SET_TIME)
2527 COMPATIBLE_IOCTL(RTC_WKALM_SET)
2528 COMPATIBLE_IOCTL(RTC_WKALM_RD)
2529 /*
2530  * These two are only for the sbus rtc driver, but
2531  * hwclock tries them on every rtc device first when
2532  * running on sparc.  On other architectures the entries
2533  * are useless but harmless.
2534  */
2535 COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
2536 COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
2537 /* Little m */
2538 COMPATIBLE_IOCTL(MTIOCTOP)
2539 /* Socket level stuff */
2540 COMPATIBLE_IOCTL(FIOQSIZE)
2541 COMPATIBLE_IOCTL(FIOSETOWN)
2542 COMPATIBLE_IOCTL(SIOCSPGRP)
2543 COMPATIBLE_IOCTL(FIOGETOWN)
2544 COMPATIBLE_IOCTL(SIOCGPGRP)
2545 COMPATIBLE_IOCTL(SIOCATMARK)
2546 COMPATIBLE_IOCTL(SIOCSIFLINK)
2547 COMPATIBLE_IOCTL(SIOCSIFENCAP)
2548 COMPATIBLE_IOCTL(SIOCGIFENCAP)
2549 COMPATIBLE_IOCTL(SIOCSIFNAME)
2550 COMPATIBLE_IOCTL(SIOCSARP)
2551 COMPATIBLE_IOCTL(SIOCGARP)
2552 COMPATIBLE_IOCTL(SIOCDARP)
2553 COMPATIBLE_IOCTL(SIOCSRARP)
2554 COMPATIBLE_IOCTL(SIOCGRARP)
2555 COMPATIBLE_IOCTL(SIOCDRARP)
2556 COMPATIBLE_IOCTL(SIOCADDDLCI)
2557 COMPATIBLE_IOCTL(SIOCDELDLCI)
2558 COMPATIBLE_IOCTL(SIOCGMIIPHY)
2559 COMPATIBLE_IOCTL(SIOCGMIIREG)
2560 COMPATIBLE_IOCTL(SIOCSMIIREG)
2561 COMPATIBLE_IOCTL(SIOCGIFVLAN)
2562 COMPATIBLE_IOCTL(SIOCSIFVLAN)
2563 COMPATIBLE_IOCTL(SIOCBRADDBR)
2564 COMPATIBLE_IOCTL(SIOCBRDELBR)
2565 /* SG stuff */
2566 COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
2567 COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
2568 COMPATIBLE_IOCTL(SG_EMULATED_HOST)
2569 ULONG_IOCTL(SG_SET_TRANSFORM)
2570 COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
2571 COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
2572 COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
2573 COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
2574 COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
2575 COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
2576 COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
2577 COMPATIBLE_IOCTL(SG_GET_PACK_ID)
2578 COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
2579 COMPATIBLE_IOCTL(SG_SET_DEBUG)
2580 COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
2581 COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
2582 COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
2583 COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
2584 COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
2585 COMPATIBLE_IOCTL(SG_SCSI_RESET)
2586 COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
2587 COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
2588 COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
2589 /* PPP stuff */
2590 COMPATIBLE_IOCTL(PPPIOCGFLAGS)
2591 COMPATIBLE_IOCTL(PPPIOCSFLAGS)
2592 COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
2593 COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
2594 COMPATIBLE_IOCTL(PPPIOCGUNIT)
2595 COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
2596 COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
2597 COMPATIBLE_IOCTL(PPPIOCGMRU)
2598 COMPATIBLE_IOCTL(PPPIOCSMRU)
2599 COMPATIBLE_IOCTL(PPPIOCSMAXCID)
2600 COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
2601 COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
2602 COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
2603 /* PPPIOCSCOMPRESS is translated */
2604 COMPATIBLE_IOCTL(PPPIOCGNPMODE)
2605 COMPATIBLE_IOCTL(PPPIOCSNPMODE)
2606 COMPATIBLE_IOCTL(PPPIOCGDEBUG)
2607 COMPATIBLE_IOCTL(PPPIOCSDEBUG)
2608 /* PPPIOCSPASS is translated */
2609 /* PPPIOCSACTIVE is translated */
2610 /* PPPIOCGIDLE is translated */
2611 COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
2612 COMPATIBLE_IOCTL(PPPIOCATTACH)
2613 COMPATIBLE_IOCTL(PPPIOCDETACH)
2614 COMPATIBLE_IOCTL(PPPIOCSMRRU)
2615 COMPATIBLE_IOCTL(PPPIOCCONNECT)
2616 COMPATIBLE_IOCTL(PPPIOCDISCONN)
2617 COMPATIBLE_IOCTL(PPPIOCATTCHAN)
2618 COMPATIBLE_IOCTL(PPPIOCGCHAN)
2619 /* PPPOX */
2620 COMPATIBLE_IOCTL(PPPOEIOCSFWD)
2621 COMPATIBLE_IOCTL(PPPOEIOCDFWD)
2622 /* LP */
2623 COMPATIBLE_IOCTL(LPGETSTATUS)
2624 /* ppdev */
2625 COMPATIBLE_IOCTL(PPSETMODE)
2626 COMPATIBLE_IOCTL(PPRSTATUS)
2627 COMPATIBLE_IOCTL(PPRCONTROL)
2628 COMPATIBLE_IOCTL(PPWCONTROL)
2629 COMPATIBLE_IOCTL(PPFCONTROL)
2630 COMPATIBLE_IOCTL(PPRDATA)
2631 COMPATIBLE_IOCTL(PPWDATA)
2632 COMPATIBLE_IOCTL(PPCLAIM)
2633 COMPATIBLE_IOCTL(PPRELEASE)
2634 COMPATIBLE_IOCTL(PPYIELD)
2635 COMPATIBLE_IOCTL(PPEXCL)
2636 COMPATIBLE_IOCTL(PPDATADIR)
2637 COMPATIBLE_IOCTL(PPNEGOT)
2638 COMPATIBLE_IOCTL(PPWCTLONIRQ)
2639 COMPATIBLE_IOCTL(PPCLRIRQ)
2640 COMPATIBLE_IOCTL(PPSETPHASE)
2641 COMPATIBLE_IOCTL(PPGETMODES)
2642 COMPATIBLE_IOCTL(PPGETMODE)
2643 COMPATIBLE_IOCTL(PPGETPHASE)
2644 COMPATIBLE_IOCTL(PPGETFLAGS)
2645 COMPATIBLE_IOCTL(PPSETFLAGS)
2646 /* pktcdvd */
2647 COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
2648 /* Big A */
2649 /* sparc only */
2650 /* Big Q for sound/OSS */
2651 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
2652 COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
2653 COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
2654 COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
2655 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
2656 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
2657 COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
2658 COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
2659 COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
2660 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
2661 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
2662 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
2663 COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
2664 COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
2665 COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
2666 COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
2667 COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
2668 COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
2669 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
2670 COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
2671 COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
2672 COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
2673 /* Big T for sound/OSS */
2674 COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
2675 COMPATIBLE_IOCTL(SNDCTL_TMR_START)
2676 COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
2677 COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
2678 COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
2679 COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
2680 COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
2681 COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
2682 /* Little m for sound/OSS */
2683 COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
2684 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
2685 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
2686 /* Big P for sound/OSS */
2687 COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
2688 COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
2689 COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
2690 COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
2691 COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
2692 COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
2693 COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
2694 COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
2695 COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
2696 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
2697 COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
2698 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
2699 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
2700 COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
2701 COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
2702 COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
2703 COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
2704 COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
2705 COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
2706 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
2707 /* SNDCTL_DSP_MAPINBUF,  XXX needs translation */
2708 /* SNDCTL_DSP_MAPOUTBUF,  XXX needs translation */
2709 COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
2710 COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
2711 COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
2712 COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
2713 COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
2714 COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
2715 COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
2716 COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
2717 /* Big C for sound/OSS */
2718 COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
2719 COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
2720 COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
2721 COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
2722 COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
2723 COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
2724 COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
2725 COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
2726 COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
2727 COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
2728 /* Big M for sound/OSS */
2729 COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
2730 COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
2731 COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
2732 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
2733 COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
2734 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
2735 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
2736 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
2737 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
2738 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
2739 COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
2740 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
2741 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
2742 COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
2743 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
2744 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
2745 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
2746 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
2747 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
2748 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
2749 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
2750 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
2751 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
2752 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
2753 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
2754 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
2755 /* SOUND_MIXER_READ_ENHANCE,  same value as READ_MUTE */
2756 /* SOUND_MIXER_READ_LOUD,  same value as READ_MUTE */
2757 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
2758 COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
2759 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
2760 COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
2761 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
2762 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
2763 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
2764 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
2765 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
2766 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
2767 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
2768 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
2769 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
2770 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
2771 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
2772 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
2773 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
2774 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
2775 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
2776 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
2777 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
2778 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
2779 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
2780 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
2781 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
2782 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
2783 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
2784 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
2785 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
2786 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
2787 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
2788 /* SOUND_MIXER_WRITE_ENHANCE,  same value as WRITE_MUTE */
2789 /* SOUND_MIXER_WRITE_LOUD,  same value as WRITE_MUTE */
2790 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
2791 COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
2792 COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
2793 COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
2794 COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
2795 COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
2796 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
2797 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
2798 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
2799 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
2800 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
2801 COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
2802 COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
2803 COMPATIBLE_IOCTL(OSS_GETVERSION)
2804 /* AUTOFS */
2805 ULONG_IOCTL(AUTOFS_IOC_READY)
2806 ULONG_IOCTL(AUTOFS_IOC_FAIL)
2807 COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
2808 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
2809 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
2810 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
2811 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
2812 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
2813 COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
2814 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
2815 /* Raw devices */
2816 COMPATIBLE_IOCTL(RAW_SETBIND)
2817 COMPATIBLE_IOCTL(RAW_GETBIND)
2818 /* SMB ioctls which do not need any translations */
2819 COMPATIBLE_IOCTL(SMB_IOC_NEWCONN)
2820 /* Little a */
2821 COMPATIBLE_IOCTL(ATMSIGD_CTRL)
2822 COMPATIBLE_IOCTL(ATMARPD_CTRL)
2823 COMPATIBLE_IOCTL(ATMLEC_CTRL)
2824 COMPATIBLE_IOCTL(ATMLEC_MCAST)
2825 COMPATIBLE_IOCTL(ATMLEC_DATA)
2826 COMPATIBLE_IOCTL(ATM_SETSC)
2827 COMPATIBLE_IOCTL(SIOCSIFATMTCP)
2828 COMPATIBLE_IOCTL(SIOCMKCLIP)
2829 COMPATIBLE_IOCTL(ATMARP_MKIP)
2830 COMPATIBLE_IOCTL(ATMARP_SETENTRY)
2831 COMPATIBLE_IOCTL(ATMARP_ENCAP)
2832 COMPATIBLE_IOCTL(ATMTCP_CREATE)
2833 COMPATIBLE_IOCTL(ATMTCP_REMOVE)
2834 COMPATIBLE_IOCTL(ATMMPC_CTRL)
2835 COMPATIBLE_IOCTL(ATMMPC_DATA)
2836 /* Watchdog */
2837 COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
2838 COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
2839 COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
2840 COMPATIBLE_IOCTL(WDIOC_GETTEMP)
2841 COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
2842 COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
2843 COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
2844 COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
2845 /* Big R */
2846 COMPATIBLE_IOCTL(RNDGETENTCNT)
2847 COMPATIBLE_IOCTL(RNDADDTOENTCNT)
2848 COMPATIBLE_IOCTL(RNDGETPOOL)
2849 COMPATIBLE_IOCTL(RNDADDENTROPY)
2850 COMPATIBLE_IOCTL(RNDZAPENTCNT)
2851 COMPATIBLE_IOCTL(RNDCLEARPOOL)
2852 /* Bluetooth */
2853 COMPATIBLE_IOCTL(HCIDEVUP)
2854 COMPATIBLE_IOCTL(HCIDEVDOWN)
2855 COMPATIBLE_IOCTL(HCIDEVRESET)
2856 COMPATIBLE_IOCTL(HCIDEVRESTAT)
2857 COMPATIBLE_IOCTL(HCIGETDEVLIST)
2858 COMPATIBLE_IOCTL(HCIGETDEVINFO)
2859 COMPATIBLE_IOCTL(HCIGETCONNLIST)
2860 COMPATIBLE_IOCTL(HCIGETCONNINFO)
2861 COMPATIBLE_IOCTL(HCISETRAW)
2862 COMPATIBLE_IOCTL(HCISETSCAN)
2863 COMPATIBLE_IOCTL(HCISETAUTH)
2864 COMPATIBLE_IOCTL(HCISETENCRYPT)
2865 COMPATIBLE_IOCTL(HCISETPTYPE)
2866 COMPATIBLE_IOCTL(HCISETLINKPOL)
2867 COMPATIBLE_IOCTL(HCISETLINKMODE)
2868 COMPATIBLE_IOCTL(HCISETACLMTU)
2869 COMPATIBLE_IOCTL(HCISETSCOMTU)
2870 COMPATIBLE_IOCTL(HCIINQUIRY)
2871 COMPATIBLE_IOCTL(HCIUARTSETPROTO)
2872 COMPATIBLE_IOCTL(HCIUARTGETPROTO)
2873 COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
2874 COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
2875 COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
2876 COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
2877 COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
2878 COMPATIBLE_IOCTL(BNEPCONNADD)
2879 COMPATIBLE_IOCTL(BNEPCONNDEL)
2880 COMPATIBLE_IOCTL(BNEPGETCONNLIST)
2881 COMPATIBLE_IOCTL(BNEPGETCONNINFO)
2882 COMPATIBLE_IOCTL(CMTPCONNADD)
2883 COMPATIBLE_IOCTL(CMTPCONNDEL)
2884 COMPATIBLE_IOCTL(CMTPGETCONNLIST)
2885 COMPATIBLE_IOCTL(CMTPGETCONNINFO)
2886 COMPATIBLE_IOCTL(HIDPCONNADD)
2887 COMPATIBLE_IOCTL(HIDPCONNDEL)
2888 COMPATIBLE_IOCTL(HIDPGETCONNLIST)
2889 COMPATIBLE_IOCTL(HIDPGETCONNINFO)
2890 /* CAPI */
2891 COMPATIBLE_IOCTL(CAPI_REGISTER)
2892 COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
2893 COMPATIBLE_IOCTL(CAPI_GET_VERSION)
2894 COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
2895 COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
2896 COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
2897 COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
2898 COMPATIBLE_IOCTL(CAPI_INSTALLED)
2899 COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
2900 COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
2901 COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
2902 COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
2903 COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
2904 /* Siemens Gigaset */
2905 COMPATIBLE_IOCTL(GIGASET_REDIR)
2906 COMPATIBLE_IOCTL(GIGASET_CONFIG)
2907 COMPATIBLE_IOCTL(GIGASET_BRKCHARS)
2908 COMPATIBLE_IOCTL(GIGASET_VERSION)
2909 /* Misc. */
2910 COMPATIBLE_IOCTL(0x41545900)            /* ATYIO_CLKR */
2911 COMPATIBLE_IOCTL(0x41545901)            /* ATYIO_CLKW */
2912 COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
2913 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
2914 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
2915 COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
2916 /* USB */
2917 COMPATIBLE_IOCTL(USBDEVFS_RESETEP)
2918 COMPATIBLE_IOCTL(USBDEVFS_SETINTERFACE)
2919 COMPATIBLE_IOCTL(USBDEVFS_SETCONFIGURATION)
2920 COMPATIBLE_IOCTL(USBDEVFS_GETDRIVER)
2921 COMPATIBLE_IOCTL(USBDEVFS_DISCARDURB)
2922 COMPATIBLE_IOCTL(USBDEVFS_CLAIMINTERFACE)
2923 COMPATIBLE_IOCTL(USBDEVFS_RELEASEINTERFACE)
2924 COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
2925 COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
2926 COMPATIBLE_IOCTL(USBDEVFS_RESET)
2927 COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
2928 COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
2929 COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
2930 COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
2931 /* MTD */
2932 COMPATIBLE_IOCTL(MEMGETINFO)
2933 COMPATIBLE_IOCTL(MEMERASE)
2934 COMPATIBLE_IOCTL(MEMLOCK)
2935 COMPATIBLE_IOCTL(MEMUNLOCK)
2936 COMPATIBLE_IOCTL(MEMGETREGIONCOUNT)
2937 COMPATIBLE_IOCTL(MEMGETREGIONINFO)
2938 COMPATIBLE_IOCTL(MEMGETBADBLOCK)
2939 COMPATIBLE_IOCTL(MEMSETBADBLOCK)
2940 /* NBD */
2941 ULONG_IOCTL(NBD_SET_SOCK)
2942 ULONG_IOCTL(NBD_SET_BLKSIZE)
2943 ULONG_IOCTL(NBD_SET_SIZE)
2944 COMPATIBLE_IOCTL(NBD_DO_IT)
2945 COMPATIBLE_IOCTL(NBD_CLEAR_SOCK)
2946 COMPATIBLE_IOCTL(NBD_CLEAR_QUE)
2947 COMPATIBLE_IOCTL(NBD_PRINT_DEBUG)
2948 ULONG_IOCTL(NBD_SET_SIZE_BLOCKS)
2949 COMPATIBLE_IOCTL(NBD_DISCONNECT)
2950 /* i2c */
2951 COMPATIBLE_IOCTL(I2C_SLAVE)
2952 COMPATIBLE_IOCTL(I2C_SLAVE_FORCE)
2953 COMPATIBLE_IOCTL(I2C_TENBIT)
2954 COMPATIBLE_IOCTL(I2C_PEC)
2955 COMPATIBLE_IOCTL(I2C_RETRIES)
2956 COMPATIBLE_IOCTL(I2C_TIMEOUT)
2957 /* wireless */
2958 COMPATIBLE_IOCTL(SIOCSIWCOMMIT)
2959 COMPATIBLE_IOCTL(SIOCGIWNAME)
2960 COMPATIBLE_IOCTL(SIOCSIWNWID)
2961 COMPATIBLE_IOCTL(SIOCGIWNWID)
2962 COMPATIBLE_IOCTL(SIOCSIWFREQ)
2963 COMPATIBLE_IOCTL(SIOCGIWFREQ)
2964 COMPATIBLE_IOCTL(SIOCSIWMODE)
2965 COMPATIBLE_IOCTL(SIOCGIWMODE)
2966 COMPATIBLE_IOCTL(SIOCSIWSENS)
2967 COMPATIBLE_IOCTL(SIOCGIWSENS)
2968 COMPATIBLE_IOCTL(SIOCSIWRANGE)
2969 COMPATIBLE_IOCTL(SIOCSIWPRIV)
2970 COMPATIBLE_IOCTL(SIOCSIWSTATS)
2971 COMPATIBLE_IOCTL(SIOCSIWAP)
2972 COMPATIBLE_IOCTL(SIOCGIWAP)
2973 COMPATIBLE_IOCTL(SIOCSIWRATE)
2974 COMPATIBLE_IOCTL(SIOCGIWRATE)
2975 COMPATIBLE_IOCTL(SIOCSIWRTS)
2976 COMPATIBLE_IOCTL(SIOCGIWRTS)
2977 COMPATIBLE_IOCTL(SIOCSIWFRAG)
2978 COMPATIBLE_IOCTL(SIOCGIWFRAG)
2979 COMPATIBLE_IOCTL(SIOCSIWTXPOW)
2980 COMPATIBLE_IOCTL(SIOCGIWTXPOW)
2981 COMPATIBLE_IOCTL(SIOCSIWRETRY)
2982 COMPATIBLE_IOCTL(SIOCGIWRETRY)
2983 COMPATIBLE_IOCTL(SIOCSIWPOWER)
2984 COMPATIBLE_IOCTL(SIOCGIWPOWER)
2985 COMPATIBLE_IOCTL(SIOCSIWAUTH)
2986 COMPATIBLE_IOCTL(SIOCGIWAUTH)
2987 /* hiddev */
2988 COMPATIBLE_IOCTL(HIDIOCGVERSION)
2989 COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
2990 COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
2991 COMPATIBLE_IOCTL(HIDIOCGSTRING)
2992 COMPATIBLE_IOCTL(HIDIOCINITREPORT)
2993 COMPATIBLE_IOCTL(HIDIOCGREPORT)
2994 COMPATIBLE_IOCTL(HIDIOCSREPORT)
2995 COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
2996 COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
2997 COMPATIBLE_IOCTL(HIDIOCGUSAGE)
2998 COMPATIBLE_IOCTL(HIDIOCSUSAGE)
2999 COMPATIBLE_IOCTL(HIDIOCGUCODE)
3000 COMPATIBLE_IOCTL(HIDIOCGFLAG)
3001 COMPATIBLE_IOCTL(HIDIOCSFLAG)
3002 COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
3003 COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
3004 /* dvb */
3005 COMPATIBLE_IOCTL(AUDIO_STOP)
3006 COMPATIBLE_IOCTL(AUDIO_PLAY)
3007 COMPATIBLE_IOCTL(AUDIO_PAUSE)
3008 COMPATIBLE_IOCTL(AUDIO_CONTINUE)
3009 COMPATIBLE_IOCTL(AUDIO_SELECT_SOURCE)
3010 COMPATIBLE_IOCTL(AUDIO_SET_MUTE)
3011 COMPATIBLE_IOCTL(AUDIO_SET_AV_SYNC)
3012 COMPATIBLE_IOCTL(AUDIO_SET_BYPASS_MODE)
3013 COMPATIBLE_IOCTL(AUDIO_CHANNEL_SELECT)
3014 COMPATIBLE_IOCTL(AUDIO_GET_STATUS)
3015 COMPATIBLE_IOCTL(AUDIO_GET_CAPABILITIES)
3016 COMPATIBLE_IOCTL(AUDIO_CLEAR_BUFFER)
3017 COMPATIBLE_IOCTL(AUDIO_SET_ID)
3018 COMPATIBLE_IOCTL(AUDIO_SET_MIXER)
3019 COMPATIBLE_IOCTL(AUDIO_SET_STREAMTYPE)
3020 COMPATIBLE_IOCTL(AUDIO_SET_EXT_ID)
3021 COMPATIBLE_IOCTL(AUDIO_SET_ATTRIBUTES)
3022 COMPATIBLE_IOCTL(AUDIO_SET_KARAOKE)
3023 COMPATIBLE_IOCTL(DMX_START)
3024 COMPATIBLE_IOCTL(DMX_STOP)
3025 COMPATIBLE_IOCTL(DMX_SET_FILTER)
3026 COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
3027 COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
3028 COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
3029 COMPATIBLE_IOCTL(DMX_GET_CAPS)
3030 COMPATIBLE_IOCTL(DMX_SET_SOURCE)
3031 COMPATIBLE_IOCTL(DMX_GET_STC)
3032 COMPATIBLE_IOCTL(FE_GET_INFO)
3033 COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
3034 COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
3035 COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
3036 COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
3037 COMPATIBLE_IOCTL(FE_SET_TONE)
3038 COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
3039 COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
3040 COMPATIBLE_IOCTL(FE_READ_STATUS)
3041 COMPATIBLE_IOCTL(FE_READ_BER)
3042 COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
3043 COMPATIBLE_IOCTL(FE_READ_SNR)
3044 COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
3045 COMPATIBLE_IOCTL(FE_SET_FRONTEND)
3046 COMPATIBLE_IOCTL(FE_GET_FRONTEND)
3047 COMPATIBLE_IOCTL(FE_GET_EVENT)
3048 COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
3049 COMPATIBLE_IOCTL(VIDEO_STOP)
3050 COMPATIBLE_IOCTL(VIDEO_PLAY)
3051 COMPATIBLE_IOCTL(VIDEO_FREEZE)
3052 COMPATIBLE_IOCTL(VIDEO_CONTINUE)
3053 COMPATIBLE_IOCTL(VIDEO_SELECT_SOURCE)
3054 COMPATIBLE_IOCTL(VIDEO_SET_BLANK)
3055 COMPATIBLE_IOCTL(VIDEO_GET_STATUS)
3056 COMPATIBLE_IOCTL(VIDEO_SET_DISPLAY_FORMAT)
3057 COMPATIBLE_IOCTL(VIDEO_FAST_FORWARD)
3058 COMPATIBLE_IOCTL(VIDEO_SLOWMOTION)
3059 COMPATIBLE_IOCTL(VIDEO_GET_CAPABILITIES)
3060 COMPATIBLE_IOCTL(VIDEO_CLEAR_BUFFER)
3061 COMPATIBLE_IOCTL(VIDEO_SET_ID)
3062 COMPATIBLE_IOCTL(VIDEO_SET_STREAMTYPE)
3063 COMPATIBLE_IOCTL(VIDEO_SET_FORMAT)
3064 COMPATIBLE_IOCTL(VIDEO_SET_SYSTEM)
3065 COMPATIBLE_IOCTL(VIDEO_SET_HIGHLIGHT)
3066 COMPATIBLE_IOCTL(VIDEO_SET_SPU)
3067 COMPATIBLE_IOCTL(VIDEO_GET_NAVI)
3068 COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
3069 COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
3070 COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
3071
3072 /* now things that need handlers */
3073 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
3074 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
3075 #ifdef CONFIG_NET
3076 HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
3077 HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
3078 HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
3079 HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
3080 HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
3081 HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
3082 HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
3083 HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
3084 HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
3085 HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
3086 HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
3087 HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
3088 HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
3089 HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
3090 HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
3091 HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
3092 HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
3093 HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
3094 HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
3095 HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
3096
3097 /* ioctls used by appletalk ddp.c */
3098 HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
3099 HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
3100 HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
3101 HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
3102
3103 HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
3104 HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
3105 HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
3106 HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
3107 HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
3108 HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
3109 HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
3110 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
3111 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
3112 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
3113 HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
3114 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
3115 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
3116 HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
3117 HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
3118 HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
3119 HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
3120 HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
3121 HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
3122 HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
3123 HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
3124 HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
3125 /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
3126 HANDLE_IOCTL(SIOCRTMSG, ret_einval)
3127 HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
3128 HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
3129 #endif
3130 #ifdef CONFIG_BLOCK
3131 HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
3132 HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
3133 HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
3134 HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
3135 HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
3136 HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
3137 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
3138 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
3139 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
3140 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
3141 HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
3142 #endif
3143 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
3144 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
3145 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
3146 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
3147 #ifdef CONFIG_BLOCK
3148 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
3149 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
3150 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
3151 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
3152 #endif
3153 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
3154 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
3155 #ifdef CONFIG_VT
3156 HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
3157 HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
3158 HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
3159 HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
3160 HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
3161 #endif
3162 /* One SMB ioctl needs translations. */
3163 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
3164 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
3165 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
3166 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
3167 HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
3168 HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
3169 HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
3170 HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
3171 HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
3172 HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
3173 HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
3174 HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
3175 HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
3176 HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
3177 HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
3178 HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
3179 HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
3180 HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
3181 HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
3182 HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
3183 HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
3184 HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
3185 HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
3186 HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
3187 HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
3188 HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
3189 HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
3190 /* block stuff */
3191 #ifdef CONFIG_BLOCK
3192 /* Raw devices */
3193 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
3194 HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
3195 #endif
3196 /* Serial */
3197 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
3198 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
3199 #ifdef TIOCGLTC
3200 COMPATIBLE_IOCTL(TIOCGLTC)
3201 COMPATIBLE_IOCTL(TIOCSLTC)
3202 #endif
3203 #ifdef TIOCSTART
3204 /*
3205  * For these two we have defintions in ioctls.h and/or termios.h on
3206  * some architectures but no actual implemention.  Some applications
3207  * like bash call them if they are defined in the headers, so we provide
3208  * entries here to avoid syslog message spew.
3209  */
3210 COMPATIBLE_IOCTL(TIOCSTART)
3211 COMPATIBLE_IOCTL(TIOCSTOP)
3212 #endif
3213 /* Usbdevfs */
3214 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
3215 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
3216 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
3217 COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
3218 /* i2c */
3219 HANDLE_IOCTL(I2C_FUNCS, w_long)
3220 HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
3221 HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
3222 /* wireless */
3223 HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
3224 HANDLE_IOCTL(SIOCGIWPRIV, do_wireless_ioctl)
3225 HANDLE_IOCTL(SIOCGIWSTATS, do_wireless_ioctl)
3226 HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
3227 HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
3228 HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
3229 HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
3230 HANDLE_IOCTL(SIOCSIWMLME, do_wireless_ioctl)
3231 HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
3232 HANDLE_IOCTL(SIOCSIWSCAN, do_wireless_ioctl)
3233 HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
3234 HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
3235 HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
3236 HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
3237 HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
3238 HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
3239 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
3240 HANDLE_IOCTL(SIOCSIWGENIE, do_wireless_ioctl)
3241 HANDLE_IOCTL(SIOCGIWGENIE, do_wireless_ioctl)
3242 HANDLE_IOCTL(SIOCSIWENCODEEXT, do_wireless_ioctl)
3243 HANDLE_IOCTL(SIOCGIWENCODEEXT, do_wireless_ioctl)
3244 HANDLE_IOCTL(SIOCSIWPMKSA, do_wireless_ioctl)
3245 HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
3246 HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
3247 /* Not implemented in the native kernel */
3248 IGNORE_IOCTL(SIOCGIFCOUNT)
3249 HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
3250 HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
3251 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
3252 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
3253
3254 /* dvb */
3255 HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
3256 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
3257 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
3258
3259 /* parport */
3260 COMPATIBLE_IOCTL(LPTIME)
3261 COMPATIBLE_IOCTL(LPCHAR)
3262 COMPATIBLE_IOCTL(LPABORTOPEN)
3263 COMPATIBLE_IOCTL(LPCAREFUL)
3264 COMPATIBLE_IOCTL(LPWAIT)
3265 COMPATIBLE_IOCTL(LPSETIRQ)
3266 COMPATIBLE_IOCTL(LPGETSTATUS)
3267 COMPATIBLE_IOCTL(LPGETSTATUS)
3268 COMPATIBLE_IOCTL(LPRESET)
3269 /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
3270 COMPATIBLE_IOCTL(LPGETFLAGS)
3271 HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
3272
3273 /* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
3274    but we don't want warnings on other file systems. So declare
3275    them as compatible here. */
3276 #define VFAT_IOCTL_READDIR_BOTH32       _IOR('r', 1, struct compat_dirent[2])
3277 #define VFAT_IOCTL_READDIR_SHORT32      _IOR('r', 2, struct compat_dirent[2])
3278
3279 IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
3280 IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
3281
3282 /* loop */
3283 IGNORE_IOCTL(LOOP_CLR_FD)
3284
3285 #ifdef CONFIG_SPARC
3286 /* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
3287 IGNORE_IOCTL(FBIOGTYPE)
3288 IGNORE_IOCTL(FBIOSATTR)
3289 IGNORE_IOCTL(FBIOGATTR)
3290 IGNORE_IOCTL(FBIOSVIDEO)
3291 IGNORE_IOCTL(FBIOGVIDEO)
3292 IGNORE_IOCTL(FBIOSCURPOS)
3293 IGNORE_IOCTL(FBIOGCURPOS)
3294 IGNORE_IOCTL(FBIOGCURMAX)
3295 IGNORE_IOCTL(FBIOPUTCMAP32)
3296 IGNORE_IOCTL(FBIOGETCMAP32)
3297 IGNORE_IOCTL(FBIOSCURSOR32)
3298 IGNORE_IOCTL(FBIOGCURSOR32)
3299 #endif
3300 };
3301
3302 #define IOCTL_HASHSIZE 256
3303 static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
3304
3305 static inline unsigned long ioctl32_hash(unsigned long cmd)
3306 {
3307         return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
3308 }
3309
3310 static void compat_ioctl_error(struct file *filp, unsigned int fd,
3311                 unsigned int cmd, unsigned long arg)
3312 {
3313         char buf[10];
3314         char *fn = "?";
3315         char *path;
3316
3317         /* find the name of the device. */
3318         path = (char *)__get_free_page(GFP_KERNEL);
3319         if (path) {
3320                 fn = d_path(filp->f_path.dentry, filp->f_path.mnt, path, PAGE_SIZE);
3321                 if (IS_ERR(fn))
3322                         fn = "?";
3323         }
3324
3325          sprintf(buf,"'%c'", (cmd>>_IOC_TYPESHIFT) & _IOC_TYPEMASK);
3326         if (!isprint(buf[1]))
3327                 sprintf(buf, "%02x", buf[1]);
3328         compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
3329                         "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
3330                         current->comm, current->pid,
3331                         (int)fd, (unsigned int)cmd, buf,
3332                         (cmd >> _IOC_SIZESHIFT) & _IOC_SIZEMASK,
3333                         (unsigned int)arg, fn);
3334
3335         if (path)
3336                 free_page((unsigned long)path);
3337 }
3338
3339 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
3340                                 unsigned long arg)
3341 {
3342         struct file *filp;
3343         int error = -EBADF;
3344         struct ioctl_trans *t;
3345         int fput_needed;
3346
3347         filp = fget_light(fd, &fput_needed);
3348         if (!filp)
3349                 goto out;
3350
3351         /* RED-PEN how should LSM module know it's handling 32bit? */
3352         error = security_file_ioctl(filp, cmd, arg);
3353         if (error)
3354                 goto out_fput;
3355
3356         /*
3357          * To allow the compat_ioctl handlers to be self contained
3358          * we need to check the common ioctls here first.
3359          * Just handle them with the standard handlers below.
3360          */
3361         switch (cmd) {
3362         case FIOCLEX:
3363         case FIONCLEX:
3364         case FIONBIO:
3365         case FIOASYNC:
3366         case FIOQSIZE:
3367                 break;
3368
3369         case FIBMAP:
3370         case FIGETBSZ:
3371         case FIONREAD:
3372                 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
3373                         break;
3374                 /*FALL THROUGH*/
3375
3376         default:
3377                 if (filp->f_op && filp->f_op->compat_ioctl) {
3378                         error = filp->f_op->compat_ioctl(filp, cmd, arg);
3379                         if (error != -ENOIOCTLCMD)
3380                                 goto out_fput;
3381                 }
3382
3383                 if (!filp->f_op ||
3384                     (!filp->f_op->ioctl && !filp->f_op->unlocked_ioctl))
3385                         goto do_ioctl;
3386                 break;
3387         }
3388
3389         for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) {
3390                 if (t->cmd == cmd)
3391                         goto found_handler;
3392         }
3393
3394 #ifdef CONFIG_NET
3395         if (S_ISSOCK(filp->f_path.dentry->d_inode->i_mode) &&
3396             cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
3397                 error = siocdevprivate_ioctl(fd, cmd, arg);
3398         } else
3399 #endif
3400         {
3401                 static int count;
3402
3403                 if (++count <= 50)
3404                         compat_ioctl_error(filp, fd, cmd, arg);
3405                 error = -EINVAL;
3406         }
3407
3408         goto out_fput;
3409
3410  found_handler:
3411         if (t->handler) {
3412                 lock_kernel();
3413                 error = t->handler(fd, cmd, arg, filp);
3414                 unlock_kernel();
3415                 goto out_fput;
3416         }
3417
3418  do_ioctl:
3419         error = vfs_ioctl(filp, fd, cmd, arg);
3420  out_fput:
3421         fput_light(filp, fput_needed);
3422  out:
3423         return error;
3424 }
3425
3426 static void ioctl32_insert_translation(struct ioctl_trans *trans)
3427 {
3428         unsigned long hash;
3429         struct ioctl_trans *t;
3430
3431         hash = ioctl32_hash (trans->cmd);
3432         if (!ioctl32_hash_table[hash])
3433                 ioctl32_hash_table[hash] = trans;
3434         else {
3435                 t = ioctl32_hash_table[hash];
3436                 while (t->next)
3437                         t = t->next;
3438                 trans->next = NULL;
3439                 t->next = trans;
3440         }
3441 }
3442
3443 static int __init init_sys32_ioctl(void)
3444 {
3445         int i;
3446
3447         for (i = 0; i < ARRAY_SIZE(ioctl_start); i++) {
3448                 if (ioctl_start[i].next != 0) {
3449                         printk("ioctl translation %d bad\n",i);
3450                         return -1;
3451                 }
3452
3453                 ioctl32_insert_translation(&ioctl_start[i]);
3454         }
3455         return 0;
3456 }
3457 __initcall(init_sys32_ioctl);