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