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