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