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