MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / compat_ioctl.c
blob2edf63444ccbdf9570cfb7e6054cff56a68c7377
1 /*
2 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
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)
9 * These routines maintain argument size conversion between 32bit and 64bit
10 * ioctls.
13 #ifdef INCLUDES
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <linux/compat.h>
17 #include <linux/kernel.h>
18 #include <linux/compiler.h>
19 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/ioctl.h>
23 #include <linux/if.h>
24 #include <linux/if_bridge.h>
25 #include <linux/slab.h>
26 #include <linux/hdreg.h>
27 #include <linux/raid/md.h>
28 #include <linux/kd.h>
29 #include <linux/dirent.h>
30 #include <linux/route.h>
31 #include <linux/in6.h>
32 #include <linux/ipv6_route.h>
33 #include <linux/skbuff.h>
34 #include <linux/netlink.h>
35 #include <linux/vt.h>
36 #include <linux/fs.h>
37 #include <linux/file.h>
38 #include <linux/fd.h>
39 #include <linux/ppp_defs.h>
40 #include <linux/if_ppp.h>
41 #include <linux/if_pppox.h>
42 #include <linux/mtio.h>
43 #include <linux/cdrom.h>
44 #include <linux/loop.h>
45 #include <linux/auto_fs.h>
46 #include <linux/auto_fs4.h>
47 #include <linux/devfs_fs.h>
48 #include <linux/tty.h>
49 #include <linux/vt_kern.h>
50 #include <linux/fb.h>
51 #include <linux/ext2_fs.h>
52 #include <linux/videodev.h>
53 #include <linux/netdevice.h>
54 #include <linux/raw.h>
55 #include <linux/smb_fs.h>
56 #include <linux/blkpg.h>
57 #include <linux/blkdev.h>
58 #include <linux/elevator.h>
59 #include <linux/rtc.h>
60 #include <linux/pci.h>
61 #include <linux/module.h>
62 #include <linux/serial.h>
63 #include <linux/reiserfs_fs.h>
64 #include <linux/if_tun.h>
65 #include <linux/ctype.h>
66 #include <linux/ioctl32.h>
67 #include <linux/syscalls.h>
68 #include <linux/ncp_fs.h>
69 #include <linux/i2c.h>
70 #include <linux/i2c-dev.h>
71 #include <linux/wireless.h>
73 #include <net/sock.h> /* siocdevprivate_ioctl */
74 #include <net/bluetooth/bluetooth.h>
75 #include <net/bluetooth/hci.h>
76 #include <net/bluetooth/rfcomm.h>
78 #include <linux/capi.h>
80 #include <scsi/scsi.h>
81 /* Ugly hack. */
82 #undef __KERNEL__
83 #include <scsi/scsi_ioctl.h>
84 #define __KERNEL__
85 #include <scsi/sg.h>
87 #include <asm/types.h>
88 #include <asm/uaccess.h>
89 #include <linux/ethtool.h>
90 #include <linux/mii.h>
91 #include <linux/if_bonding.h>
92 #include <linux/watchdog.h>
93 #include <linux/dm-ioctl.h>
95 #include <asm/module.h>
96 #include <linux/soundcard.h>
97 #include <linux/lp.h>
99 #include <linux/atm.h>
100 #include <linux/atmarp.h>
101 #include <linux/atmclip.h>
102 #include <linux/atmdev.h>
103 #include <linux/atmioc.h>
104 #include <linux/atmlec.h>
105 #include <linux/atmmpc.h>
106 #include <linux/atmsvc.h>
107 #include <linux/atm_tcp.h>
108 #include <linux/sonet.h>
109 #include <linux/atm_suni.h>
110 #include <linux/mtd/mtd.h>
112 #include <linux/usb.h>
113 #include <linux/usbdevice_fs.h>
114 #include <linux/nbd.h>
115 #include <linux/random.h>
116 #include <linux/filter.h>
117 #include <linux/msdos_fs.h>
119 #include <linux/hiddev.h>
121 #undef INCLUDES
122 #endif
124 #ifdef CODE
126 /* Aiee. Someone does not find a difference between int and long */
127 #define EXT2_IOC32_GETFLAGS _IOR('f', 1, int)
128 #define EXT2_IOC32_SETFLAGS _IOW('f', 2, int)
129 #define EXT2_IOC32_GETVERSION _IOR('v', 1, int)
130 #define EXT2_IOC32_SETVERSION _IOW('v', 2, int)
132 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
134 mm_segment_t old_fs = get_fs();
135 int err;
136 unsigned long val;
138 set_fs (KERNEL_DS);
139 err = sys_ioctl(fd, cmd, (unsigned long)&val);
140 set_fs (old_fs);
141 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
142 return -EFAULT;
143 return err;
146 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
148 mm_segment_t old_fs = get_fs();
149 u32 __user *argptr = compat_ptr(arg);
150 int err;
151 unsigned long val;
153 if(get_user(val, argptr))
154 return -EFAULT;
155 set_fs (KERNEL_DS);
156 err = sys_ioctl(fd, cmd, (unsigned long)&val);
157 set_fs (old_fs);
158 if (!err && put_user(val, argptr))
159 return -EFAULT;
160 return err;
163 static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
165 /* These are just misnamed, they actually get/put from/to user an int */
166 switch (cmd) {
167 case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
168 case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
169 case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
170 case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
172 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
175 struct video_tuner32 {
176 compat_int_t tuner;
177 char name[32];
178 compat_ulong_t rangelow, rangehigh;
179 u32 flags; /* It is really u32 in videodev.h */
180 u16 mode, signal;
183 static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
185 int i;
187 if(get_user(kp->tuner, &up->tuner))
188 return -EFAULT;
189 for(i = 0; i < 32; i++)
190 __get_user(kp->name[i], &up->name[i]);
191 __get_user(kp->rangelow, &up->rangelow);
192 __get_user(kp->rangehigh, &up->rangehigh);
193 __get_user(kp->flags, &up->flags);
194 __get_user(kp->mode, &up->mode);
195 __get_user(kp->signal, &up->signal);
196 return 0;
199 static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
201 int i;
203 if(put_user(kp->tuner, &up->tuner))
204 return -EFAULT;
205 for(i = 0; i < 32; i++)
206 __put_user(kp->name[i], &up->name[i]);
207 __put_user(kp->rangelow, &up->rangelow);
208 __put_user(kp->rangehigh, &up->rangehigh);
209 __put_user(kp->flags, &up->flags);
210 __put_user(kp->mode, &up->mode);
211 __put_user(kp->signal, &up->signal);
212 return 0;
215 struct video_buffer32 {
216 compat_caddr_t base;
217 compat_int_t height, width, depth, bytesperline;
220 static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
222 u32 tmp;
224 if (get_user(tmp, &up->base))
225 return -EFAULT;
227 /* This is actually a physical address stored
228 * as a void pointer.
230 kp->base = (void *)(unsigned long) tmp;
232 __get_user(kp->height, &up->height);
233 __get_user(kp->width, &up->width);
234 __get_user(kp->depth, &up->depth);
235 __get_user(kp->bytesperline, &up->bytesperline);
236 return 0;
239 static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
241 u32 tmp = (u32)((unsigned long)kp->base);
243 if(put_user(tmp, &up->base))
244 return -EFAULT;
245 __put_user(kp->height, &up->height);
246 __put_user(kp->width, &up->width);
247 __put_user(kp->depth, &up->depth);
248 __put_user(kp->bytesperline, &up->bytesperline);
249 return 0;
252 struct video_clip32 {
253 s32 x, y, width, height; /* Its really s32 in videodev.h */
254 compat_caddr_t next;
257 struct video_window32 {
258 u32 x, y, width, height, chromakey, flags;
259 compat_caddr_t clips;
260 compat_int_t clipcount;
263 /* You get back everything except the clips... */
264 static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
266 if(put_user(kp->x, &up->x))
267 return -EFAULT;
268 __put_user(kp->y, &up->y);
269 __put_user(kp->width, &up->width);
270 __put_user(kp->height, &up->height);
271 __put_user(kp->chromakey, &up->chromakey);
272 __put_user(kp->flags, &up->flags);
273 __put_user(kp->clipcount, &up->clipcount);
274 return 0;
277 #define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
278 #define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
279 #define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
280 #define VIDIOCSWIN32 _IOW('v',10, struct video_window32)
281 #define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32)
282 #define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
283 #define VIDIOCGFREQ32 _IOR('v',14, u32)
284 #define VIDIOCSFREQ32 _IOW('v',15, u32)
286 enum {
287 MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip)
290 static int do_set_window(unsigned int fd, unsigned int cmd, unsigned long arg)
292 struct video_window32 __user *up = compat_ptr(arg);
293 struct video_window __user *vw;
294 struct video_clip __user *p;
295 int nclips;
296 u32 n;
298 if (get_user(nclips, &up->clipcount))
299 return -EFAULT;
301 /* Peculiar interface... */
302 if (nclips < 0)
303 nclips = VIDEO_CLIPMAP_SIZE;
305 if (nclips > MaxClips)
306 return -ENOMEM;
308 vw = compat_alloc_user_space(sizeof(struct video_window) +
309 nclips * sizeof(struct video_clip));
311 p = nclips ? (struct video_clip __user *)(vw + 1) : NULL;
313 if (get_user(n, &up->x) || put_user(n, &vw->x) ||
314 get_user(n, &up->y) || put_user(n, &vw->y) ||
315 get_user(n, &up->width) || put_user(n, &vw->width) ||
316 get_user(n, &up->height) || put_user(n, &vw->height) ||
317 get_user(n, &up->chromakey) || put_user(n, &vw->chromakey) ||
318 get_user(n, &up->flags) || put_user(n, &vw->flags) ||
319 get_user(n, &up->clipcount) || put_user(n, &vw->clipcount) ||
320 get_user(n, &up->clips) || put_user(p, &vw->clips))
321 return -EFAULT;
323 if (nclips) {
324 struct video_clip32 __user *u = compat_ptr(n);
325 int i;
326 if (!u)
327 return -EINVAL;
328 for (i = 0; i < nclips; i++, u++, p++) {
329 s32 v;
330 if (get_user(v, &u->x) ||
331 put_user(v, &p->x) ||
332 get_user(v, &u->y) ||
333 put_user(v, &p->y) ||
334 get_user(v, &u->width) ||
335 put_user(v, &p->width) ||
336 get_user(v, &u->height) ||
337 put_user(v, &p->height) ||
338 put_user(NULL, &p->next))
339 return -EFAULT;
343 return sys_ioctl(fd, VIDIOCSWIN, (unsigned long)p);
346 static int do_video_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
348 union {
349 struct video_tuner vt;
350 struct video_buffer vb;
351 struct video_window vw;
352 unsigned long vx;
353 } karg;
354 mm_segment_t old_fs = get_fs();
355 void __user *up = compat_ptr(arg);
356 int err = 0;
358 /* First, convert the command. */
359 switch(cmd) {
360 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
361 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
362 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
363 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
364 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
365 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
366 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
369 switch(cmd) {
370 case VIDIOCSTUNER:
371 case VIDIOCGTUNER:
372 err = get_video_tuner32(&karg.vt, up);
373 break;
375 case VIDIOCSFBUF:
376 err = get_video_buffer32(&karg.vb, up);
377 break;
379 case VIDIOCSFREQ:
380 err = get_user(karg.vx, (u32 __user *)up);
381 break;
383 if(err)
384 goto out;
386 set_fs(KERNEL_DS);
387 err = sys_ioctl(fd, cmd, (unsigned long)&karg);
388 set_fs(old_fs);
390 if(err == 0) {
391 switch(cmd) {
392 case VIDIOCGTUNER:
393 err = put_video_tuner32(&karg.vt, up);
394 break;
396 case VIDIOCGWIN:
397 err = put_video_window32(&karg.vw, up);
398 break;
400 case VIDIOCGFBUF:
401 err = put_video_buffer32(&karg.vb, up);
402 break;
404 case VIDIOCGFREQ:
405 err = put_user(((u32)karg.vx), (u32 __user *)up);
406 break;
409 out:
410 return err;
413 #ifdef CONFIG_NET
414 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
416 struct compat_timeval __user *up = compat_ptr(arg);
417 struct timeval ktv;
418 mm_segment_t old_fs = get_fs();
419 int err;
421 set_fs(KERNEL_DS);
422 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
423 set_fs(old_fs);
424 if(!err) {
425 err = put_user(ktv.tv_sec, &up->tv_sec);
426 err |= __put_user(ktv.tv_usec, &up->tv_usec);
428 return err;
431 struct ifmap32 {
432 compat_ulong_t mem_start;
433 compat_ulong_t mem_end;
434 unsigned short base_addr;
435 unsigned char irq;
436 unsigned char dma;
437 unsigned char port;
440 struct ifreq32 {
441 #define IFHWADDRLEN 6
442 #define IFNAMSIZ 16
443 union {
444 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
445 } ifr_ifrn;
446 union {
447 struct sockaddr ifru_addr;
448 struct sockaddr ifru_dstaddr;
449 struct sockaddr ifru_broadaddr;
450 struct sockaddr ifru_netmask;
451 struct sockaddr ifru_hwaddr;
452 short ifru_flags;
453 compat_int_t ifru_ivalue;
454 compat_int_t ifru_mtu;
455 struct ifmap32 ifru_map;
456 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
457 char ifru_newname[IFNAMSIZ];
458 compat_caddr_t ifru_data;
459 /* XXXX? ifru_settings should be here */
460 } ifr_ifru;
463 struct ifconf32 {
464 compat_int_t ifc_len; /* size of buffer */
465 compat_caddr_t ifcbuf;
468 static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
470 struct net_device *dev;
471 struct ifreq32 ifr32;
472 int err;
474 if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
475 return -EFAULT;
477 dev = dev_get_by_index(ifr32.ifr_ifindex);
478 if (!dev)
479 return -ENODEV;
481 strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
482 dev_put(dev);
484 err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
485 return (err ? -EFAULT : 0);
488 static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
490 struct ifconf32 ifc32;
491 struct ifconf ifc;
492 struct ifconf __user *uifc;
493 struct ifreq32 __user *ifr32;
494 struct ifreq __user *ifr;
495 unsigned int i, j;
496 int err;
498 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
499 return -EFAULT;
501 if (ifc32.ifcbuf == 0) {
502 ifc32.ifc_len = 0;
503 ifc.ifc_len = 0;
504 ifc.ifc_req = NULL;
505 uifc = compat_alloc_user_space(sizeof(struct ifconf));
506 } else {
507 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
508 sizeof (struct ifreq);
509 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
510 ifc.ifc_len = len;
511 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
512 ifr32 = compat_ptr(ifc32.ifcbuf);
513 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
514 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
515 return -EFAULT;
516 ifr++;
517 ifr32++;
520 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
521 return -EFAULT;
523 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
524 if (err)
525 return err;
527 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
528 return -EFAULT;
530 ifr = ifc.ifc_req;
531 ifr32 = compat_ptr(ifc32.ifcbuf);
532 for (i = 0, j = 0; i < ifc32.ifc_len && j < ifc.ifc_len;
533 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
534 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
535 return -EFAULT;
536 ifr32++;
537 ifr++;
540 if (ifc32.ifcbuf == 0) {
541 /* Translate from 64-bit structure multiple to
542 * a 32-bit one.
544 i = ifc.ifc_len;
545 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
546 ifc32.ifc_len = i;
547 } else {
548 if (i <= ifc32.ifc_len)
549 ifc32.ifc_len = i;
550 else
551 ifc32.ifc_len = i - sizeof (struct ifreq32);
553 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
554 return -EFAULT;
556 return 0;
559 static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
561 struct ifreq __user *ifr;
562 struct ifreq32 __user *ifr32;
563 u32 data;
564 void __user *datap;
566 ifr = compat_alloc_user_space(sizeof(*ifr));
567 ifr32 = compat_ptr(arg);
569 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
570 return -EFAULT;
572 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
573 return -EFAULT;
575 datap = compat_ptr(data);
576 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
577 return -EFAULT;
579 return sys_ioctl(fd, cmd, (unsigned long) ifr);
582 static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
584 struct ifreq kifr;
585 struct ifreq __user *uifr;
586 struct ifreq32 __user *ifr32 = compat_ptr(arg);
587 mm_segment_t old_fs;
588 int err;
589 u32 data;
590 void __user *datap;
592 switch (cmd) {
593 case SIOCBONDENSLAVE:
594 case SIOCBONDRELEASE:
595 case SIOCBONDSETHWADDR:
596 case SIOCBONDCHANGEACTIVE:
597 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
598 return -EFAULT;
600 old_fs = get_fs();
601 set_fs (KERNEL_DS);
602 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
603 set_fs (old_fs);
605 return err;
606 case SIOCBONDSLAVEINFOQUERY:
607 case SIOCBONDINFOQUERY:
608 uifr = compat_alloc_user_space(sizeof(*uifr));
609 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
610 return -EFAULT;
612 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
613 return -EFAULT;
615 datap = compat_ptr(data);
616 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
617 return -EFAULT;
619 return sys_ioctl (fd, cmd, (unsigned long)uifr);
620 default:
621 return -EINVAL;
625 int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
627 struct ifreq __user *u_ifreq64;
628 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
629 char tmp_buf[IFNAMSIZ];
630 void __user *data64;
631 u32 data32;
633 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
634 IFNAMSIZ))
635 return -EFAULT;
636 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
637 return -EFAULT;
638 data64 = compat_ptr(data32);
640 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
642 /* Don't check these user accesses, just let that get trapped
643 * in the ioctl handler instead.
645 copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], IFNAMSIZ);
646 __put_user(data64, &u_ifreq64->ifr_ifru.ifru_data);
648 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
651 static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
653 struct ifreq ifr;
654 struct ifreq32 __user *uifr32;
655 struct ifmap32 __user *uifmap32;
656 mm_segment_t old_fs;
657 int err;
659 uifr32 = compat_ptr(arg);
660 uifmap32 = &uifr32->ifr_ifru.ifru_map;
661 switch (cmd) {
662 case SIOCSIFMAP:
663 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
664 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
665 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
666 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
667 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
668 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
669 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
670 if (err)
671 return -EFAULT;
672 break;
673 default:
674 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
675 return -EFAULT;
676 break;
678 old_fs = get_fs();
679 set_fs (KERNEL_DS);
680 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
681 set_fs (old_fs);
682 if (!err) {
683 switch (cmd) {
684 case SIOCGIFFLAGS:
685 case SIOCGIFMETRIC:
686 case SIOCGIFMTU:
687 case SIOCGIFMEM:
688 case SIOCGIFHWADDR:
689 case SIOCGIFINDEX:
690 case SIOCGIFADDR:
691 case SIOCGIFBRDADDR:
692 case SIOCGIFDSTADDR:
693 case SIOCGIFNETMASK:
694 case SIOCGIFTXQLEN:
695 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
696 return -EFAULT;
697 break;
698 case SIOCGIFMAP:
699 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
700 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
701 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
702 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
703 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
704 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
705 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
706 if (err)
707 err = -EFAULT;
708 break;
711 return err;
714 struct rtentry32 {
715 u32 rt_pad1;
716 struct sockaddr rt_dst; /* target address */
717 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
718 struct sockaddr rt_genmask; /* target network mask (IP) */
719 unsigned short rt_flags;
720 short rt_pad2;
721 u32 rt_pad3;
722 unsigned char rt_tos;
723 unsigned char rt_class;
724 short rt_pad4;
725 short rt_metric; /* +1 for binary compatibility! */
726 /* char * */ u32 rt_dev; /* forcing the device at add */
727 u32 rt_mtu; /* per route MTU/Window */
728 u32 rt_window; /* Window clamping */
729 unsigned short rt_irtt; /* Initial RTT */
733 struct in6_rtmsg32 {
734 struct in6_addr rtmsg_dst;
735 struct in6_addr rtmsg_src;
736 struct in6_addr rtmsg_gateway;
737 u32 rtmsg_type;
738 u16 rtmsg_dst_len;
739 u16 rtmsg_src_len;
740 u32 rtmsg_metric;
741 u32 rtmsg_info;
742 u32 rtmsg_flags;
743 s32 rtmsg_ifindex;
746 static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
748 int ret;
749 void *r = NULL;
750 struct in6_rtmsg r6;
751 struct rtentry r4;
752 char devname[16];
753 u32 rtdev;
754 mm_segment_t old_fs = get_fs();
756 struct socket *mysock = sockfd_lookup(fd, &ret);
758 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
759 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
760 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
761 3 * sizeof(struct in6_addr));
762 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
763 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
764 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
765 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
766 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
767 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
768 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
770 r = (void *) &r6;
771 } else { /* ipv4 */
772 struct rtentry32 __user *ur4 = compat_ptr(arg);
773 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
774 3 * sizeof(struct sockaddr));
775 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
776 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
777 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
778 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
779 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
780 ret |= __get_user (rtdev, &(ur4->rt_dev));
781 if (rtdev) {
782 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
783 r4.rt_dev = devname; devname[15] = 0;
784 } else
785 r4.rt_dev = NULL;
787 r = (void *) &r4;
790 if (ret)
791 return -EFAULT;
793 set_fs (KERNEL_DS);
794 ret = sys_ioctl (fd, cmd, (unsigned long) r);
795 set_fs (old_fs);
797 if (mysock)
798 sockfd_put(mysock);
800 return ret;
802 #endif
804 struct hd_geometry32 {
805 unsigned char heads;
806 unsigned char sectors;
807 unsigned short cylinders;
808 u32 start;
811 static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
813 mm_segment_t old_fs = get_fs();
814 struct hd_geometry geo;
815 struct hd_geometry32 __user *ugeo;
816 int err;
818 set_fs (KERNEL_DS);
819 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
820 set_fs (old_fs);
821 ugeo = compat_ptr(arg);
822 if (!err) {
823 err = copy_to_user (ugeo, &geo, 4);
824 err |= __put_user (geo.start, &ugeo->start);
826 return err ? -EFAULT : 0;
829 struct fb_fix_screeninfo32 {
830 char id[16];
831 compat_caddr_t smem_start;
832 u32 smem_len;
833 u32 type;
834 u32 type_aux;
835 u32 visual;
836 u16 xpanstep;
837 u16 ypanstep;
838 u16 ywrapstep;
839 u32 line_length;
840 compat_caddr_t mmio_start;
841 u32 mmio_len;
842 u32 accel;
843 u16 reserved[3];
846 struct fb_cmap32 {
847 u32 start;
848 u32 len;
849 compat_caddr_t red;
850 compat_caddr_t green;
851 compat_caddr_t blue;
852 compat_caddr_t transp;
855 static int fb_getput_cmap(unsigned int fd, unsigned int cmd, unsigned long arg)
857 struct fb_cmap_user __user *cmap;
858 struct fb_cmap32 __user *cmap32;
859 __u32 data;
860 int err;
862 cmap = compat_alloc_user_space(sizeof(*cmap));
863 cmap32 = compat_ptr(arg);
865 if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32)))
866 return -EFAULT;
868 if (get_user(data, &cmap32->red) ||
869 put_user(compat_ptr(data), &cmap->red) ||
870 get_user(data, &cmap32->green) ||
871 put_user(compat_ptr(data), &cmap->green) ||
872 get_user(data, &cmap32->blue) ||
873 put_user(compat_ptr(data), &cmap->blue) ||
874 get_user(data, &cmap32->transp) ||
875 put_user(compat_ptr(data), &cmap->transp))
876 return -EFAULT;
878 err = sys_ioctl(fd, cmd, (unsigned long) cmap);
880 if (!err) {
881 if (copy_in_user(&cmap32->start,
882 &cmap->start,
883 2 * sizeof(__u32)))
884 err = -EFAULT;
886 return err;
889 static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
890 struct fb_fix_screeninfo32 __user *fix32)
892 __u32 data;
893 int err;
895 err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
897 data = (__u32) (unsigned long) fix->smem_start;
898 err |= put_user(data, &fix32->smem_start);
900 err |= put_user(fix->smem_len, &fix32->smem_len);
901 err |= put_user(fix->type, &fix32->type);
902 err |= put_user(fix->type_aux, &fix32->type_aux);
903 err |= put_user(fix->visual, &fix32->visual);
904 err |= put_user(fix->xpanstep, &fix32->xpanstep);
905 err |= put_user(fix->ypanstep, &fix32->ypanstep);
906 err |= put_user(fix->ywrapstep, &fix32->ywrapstep);
907 err |= put_user(fix->line_length, &fix32->line_length);
909 data = (__u32) (unsigned long) fix->mmio_start;
910 err |= put_user(data, &fix32->mmio_start);
912 err |= put_user(fix->mmio_len, &fix32->mmio_len);
913 err |= put_user(fix->accel, &fix32->accel);
914 err |= copy_to_user(fix32->reserved, fix->reserved,
915 sizeof(fix->reserved));
917 return err;
920 static int fb_get_fscreeninfo(unsigned int fd, unsigned int cmd, unsigned long arg)
922 mm_segment_t old_fs;
923 struct fb_fix_screeninfo fix;
924 struct fb_fix_screeninfo32 __user *fix32;
925 int err;
927 fix32 = compat_ptr(arg);
929 old_fs = get_fs();
930 set_fs(KERNEL_DS);
931 err = sys_ioctl(fd, cmd, (unsigned long) &fix);
932 set_fs(old_fs);
934 if (!err)
935 err = do_fscreeninfo_to_user(&fix, fix32);
937 return err;
940 static int fb_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
942 int err;
944 switch (cmd) {
945 case FBIOGET_FSCREENINFO:
946 err = fb_get_fscreeninfo(fd,cmd, arg);
947 break;
949 case FBIOGETCMAP:
950 case FBIOPUTCMAP:
951 err = fb_getput_cmap(fd, cmd, arg);
952 break;
954 default:
955 do {
956 static int count;
957 if (++count <= 20)
958 printk("%s: Unknown fb ioctl cmd fd(%d) "
959 "cmd(%08x) arg(%08lx)\n",
960 __FUNCTION__, fd, cmd, arg);
961 } while(0);
962 err = -ENOSYS;
963 break;
966 return err;
969 static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
971 mm_segment_t old_fs = get_fs();
972 unsigned long kval;
973 unsigned int __user *uvp;
974 int error;
976 set_fs(KERNEL_DS);
977 error = sys_ioctl(fd, cmd, (long)&kval);
978 set_fs(old_fs);
980 if(error == 0) {
981 uvp = compat_ptr(arg);
982 if(put_user(kval, uvp))
983 error = -EFAULT;
985 return error;
989 typedef struct sg_io_hdr32 {
990 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
991 compat_int_t dxfer_direction; /* [i] data transfer direction */
992 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
993 unsigned char mx_sb_len; /* [i] max length to write to sbp */
994 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
995 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
996 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
997 or scatter gather list */
998 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
999 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
1000 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
1001 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
1002 compat_int_t pack_id; /* [i->o] unused internally (normally) */
1003 compat_uptr_t usr_ptr; /* [i->o] unused internally */
1004 unsigned char status; /* [o] scsi status */
1005 unsigned char masked_status; /* [o] shifted, masked scsi status */
1006 unsigned char msg_status; /* [o] messaging level data (optional) */
1007 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
1008 unsigned short host_status; /* [o] errors from host adapter */
1009 unsigned short driver_status; /* [o] errors from software driver */
1010 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
1011 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
1012 compat_uint_t info; /* [o] auxiliary information */
1013 } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
1015 typedef struct sg_iovec32 {
1016 compat_uint_t iov_base;
1017 compat_uint_t iov_len;
1018 } sg_iovec32_t;
1020 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
1022 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
1023 sg_iovec32_t __user *iov32 = dxferp;
1024 int i;
1026 for (i = 0; i < iovec_count; i++) {
1027 u32 base, len;
1029 if (get_user(base, &iov32[i].iov_base) ||
1030 get_user(len, &iov32[i].iov_len) ||
1031 put_user(compat_ptr(base), &iov[i].iov_base) ||
1032 put_user(len, &iov[i].iov_len))
1033 return -EFAULT;
1036 if (put_user(iov, &sgio->dxferp))
1037 return -EFAULT;
1038 return 0;
1041 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1043 sg_io_hdr_t __user *sgio;
1044 sg_io_hdr32_t __user *sgio32;
1045 u16 iovec_count;
1046 u32 data;
1047 void __user *dxferp;
1048 int err;
1050 sgio32 = compat_ptr(arg);
1051 if (get_user(iovec_count, &sgio32->iovec_count))
1052 return -EFAULT;
1055 void __user *top = compat_alloc_user_space(0);
1056 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
1057 (iovec_count * sizeof(sg_iovec_t)));
1058 if (new > top)
1059 return -EINVAL;
1061 sgio = new;
1064 /* Ok, now construct. */
1065 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
1066 (2 * sizeof(int)) +
1067 (2 * sizeof(unsigned char)) +
1068 (1 * sizeof(unsigned short)) +
1069 (1 * sizeof(unsigned int))))
1070 return -EFAULT;
1072 if (get_user(data, &sgio32->dxferp))
1073 return -EFAULT;
1074 dxferp = compat_ptr(data);
1075 if (iovec_count) {
1076 if (sg_build_iovec(sgio, dxferp, iovec_count))
1077 return -EFAULT;
1078 } else {
1079 if (put_user(dxferp, &sgio->dxferp))
1080 return -EFAULT;
1084 unsigned char __user *cmdp;
1085 unsigned char __user *sbp;
1087 if (get_user(data, &sgio32->cmdp))
1088 return -EFAULT;
1089 cmdp = compat_ptr(data);
1091 if (get_user(data, &sgio32->sbp))
1092 return -EFAULT;
1093 sbp = compat_ptr(data);
1095 if (put_user(cmdp, &sgio->cmdp) ||
1096 put_user(sbp, &sgio->sbp))
1097 return -EFAULT;
1100 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
1101 3 * sizeof(int)))
1102 return -EFAULT;
1104 if (get_user(data, &sgio32->usr_ptr))
1105 return -EFAULT;
1106 if (put_user(compat_ptr(data), &sgio->usr_ptr))
1107 return -EFAULT;
1109 if (copy_in_user(&sgio->status, &sgio32->status,
1110 (4 * sizeof(unsigned char)) +
1111 (2 * sizeof(unsigned (short))) +
1112 (3 * sizeof(int))))
1113 return -EFAULT;
1115 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
1117 if (err >= 0) {
1118 void __user *datap;
1120 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
1121 sizeof(int)) ||
1122 get_user(datap, &sgio->usr_ptr) ||
1123 put_user((u32)(unsigned long)datap,
1124 &sgio32->usr_ptr) ||
1125 copy_in_user(&sgio32->status, &sgio->status,
1126 (4 * sizeof(unsigned char)) +
1127 (2 * sizeof(unsigned short)) +
1128 (3 * sizeof(int))))
1129 err = -EFAULT;
1132 return err;
1135 struct sock_fprog32 {
1136 unsigned short len;
1137 compat_caddr_t filter;
1140 #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
1141 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
1143 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1145 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
1146 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
1147 void __user *fptr64;
1148 u32 fptr32;
1149 u16 flen;
1151 if (get_user(flen, &u_fprog32->len) ||
1152 get_user(fptr32, &u_fprog32->filter))
1153 return -EFAULT;
1155 fptr64 = compat_ptr(fptr32);
1157 if (put_user(flen, &u_fprog64->len) ||
1158 put_user(fptr64, &u_fprog64->filter))
1159 return -EFAULT;
1161 if (cmd == PPPIOCSPASS32)
1162 cmd = PPPIOCSPASS;
1163 else
1164 cmd = PPPIOCSACTIVE;
1166 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
1169 struct ppp_option_data32 {
1170 compat_caddr_t ptr;
1171 u32 length;
1172 compat_int_t transmit;
1174 #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
1176 struct ppp_idle32 {
1177 compat_time_t xmit_idle;
1178 compat_time_t recv_idle;
1180 #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
1182 static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
1184 struct ppp_idle __user *idle;
1185 struct ppp_idle32 __user *idle32;
1186 __kernel_time_t xmit, recv;
1187 int err;
1189 idle = compat_alloc_user_space(sizeof(*idle));
1190 idle32 = compat_ptr(arg);
1192 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
1194 if (!err) {
1195 if (get_user(xmit, &idle->xmit_idle) ||
1196 get_user(recv, &idle->recv_idle) ||
1197 put_user(xmit, &idle32->xmit_idle) ||
1198 put_user(recv, &idle32->recv_idle))
1199 err = -EFAULT;
1201 return err;
1204 static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
1206 struct ppp_option_data __user *odata;
1207 struct ppp_option_data32 __user *odata32;
1208 __u32 data;
1209 void __user *datap;
1211 odata = compat_alloc_user_space(sizeof(*odata));
1212 odata32 = compat_ptr(arg);
1214 if (get_user(data, &odata32->ptr))
1215 return -EFAULT;
1217 datap = compat_ptr(data);
1218 if (put_user(datap, &odata->ptr))
1219 return -EFAULT;
1221 if (copy_in_user(&odata->length, &odata32->length,
1222 sizeof(__u32) + sizeof(int)))
1223 return -EFAULT;
1225 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
1228 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1230 int err;
1232 switch (cmd) {
1233 case PPPIOCGIDLE32:
1234 err = ppp_gidle(fd, cmd, arg);
1235 break;
1237 case PPPIOCSCOMPRESS32:
1238 err = ppp_scompress(fd, cmd, arg);
1239 break;
1241 default:
1242 do {
1243 static int count;
1244 if (++count <= 20)
1245 printk("ppp_ioctl: Unknown cmd fd(%d) "
1246 "cmd(%08x) arg(%08x)\n",
1247 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1248 } while(0);
1249 err = -EINVAL;
1250 break;
1253 return err;
1257 struct mtget32 {
1258 compat_long_t mt_type;
1259 compat_long_t mt_resid;
1260 compat_long_t mt_dsreg;
1261 compat_long_t mt_gstat;
1262 compat_long_t mt_erreg;
1263 compat_daddr_t mt_fileno;
1264 compat_daddr_t mt_blkno;
1266 #define MTIOCGET32 _IOR('m', 2, struct mtget32)
1268 struct mtpos32 {
1269 compat_long_t mt_blkno;
1271 #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1273 struct mtconfiginfo32 {
1274 compat_long_t mt_type;
1275 compat_long_t ifc_type;
1276 unsigned short irqnr;
1277 unsigned short dmanr;
1278 unsigned short port;
1279 compat_ulong_t debug;
1280 compat_uint_t have_dens:1;
1281 compat_uint_t have_bsf:1;
1282 compat_uint_t have_fsr:1;
1283 compat_uint_t have_bsr:1;
1284 compat_uint_t have_eod:1;
1285 compat_uint_t have_seek:1;
1286 compat_uint_t have_tell:1;
1287 compat_uint_t have_ras1:1;
1288 compat_uint_t have_ras2:1;
1289 compat_uint_t have_ras3:1;
1290 compat_uint_t have_qfa:1;
1291 compat_uint_t pad1:5;
1292 char reserved[10];
1294 #define MTIOCGETCONFIG32 _IOR('m', 4, struct mtconfiginfo32)
1295 #define MTIOCSETCONFIG32 _IOW('m', 5, struct mtconfiginfo32)
1297 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1299 mm_segment_t old_fs = get_fs();
1300 struct mtconfiginfo info;
1301 struct mtconfiginfo32 __user *uinfo32;
1302 struct mtget get;
1303 struct mtget32 __user *umget32;
1304 struct mtpos pos;
1305 struct mtpos32 __user *upos32;
1306 unsigned long kcmd;
1307 void *karg;
1308 int err = 0;
1310 switch(cmd) {
1311 case MTIOCPOS32:
1312 kcmd = MTIOCPOS;
1313 karg = &pos;
1314 break;
1315 case MTIOCGET32:
1316 kcmd = MTIOCGET;
1317 karg = &get;
1318 break;
1319 case MTIOCGETCONFIG32:
1320 kcmd = MTIOCGETCONFIG;
1321 karg = &info;
1322 break;
1323 case MTIOCSETCONFIG32:
1324 kcmd = MTIOCSETCONFIG;
1325 karg = &info;
1326 uinfo32 = compat_ptr(arg);
1327 err = __get_user(info.mt_type, &uinfo32->mt_type);
1328 err |= __get_user(info.ifc_type, &uinfo32->ifc_type);
1329 err |= __get_user(info.irqnr, &uinfo32->irqnr);
1330 err |= __get_user(info.dmanr, &uinfo32->dmanr);
1331 err |= __get_user(info.port, &uinfo32->port);
1332 err |= __get_user(info.debug, &uinfo32->debug);
1333 err |= __copy_from_user((char *)&info.debug
1334 + sizeof(info.debug),
1335 (char __user *)&uinfo32->debug
1336 + sizeof(uinfo32->debug), sizeof(__u32));
1337 if (err)
1338 return -EFAULT;
1339 break;
1340 default:
1341 do {
1342 static int count;
1343 if (++count <= 20)
1344 printk("mt_ioctl: Unknown cmd fd(%d) "
1345 "cmd(%08x) arg(%08x)\n",
1346 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1347 } while(0);
1348 return -EINVAL;
1350 set_fs (KERNEL_DS);
1351 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1352 set_fs (old_fs);
1353 if (err)
1354 return err;
1355 switch (cmd) {
1356 case MTIOCPOS32:
1357 upos32 = compat_ptr(arg);
1358 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1359 break;
1360 case MTIOCGET32:
1361 umget32 = compat_ptr(arg);
1362 err = __put_user(get.mt_type, &umget32->mt_type);
1363 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1364 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1365 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1366 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1367 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1368 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1369 break;
1370 case MTIOCGETCONFIG32:
1371 uinfo32 = compat_ptr(arg);
1372 err = __put_user(info.mt_type, &uinfo32->mt_type);
1373 err |= __put_user(info.ifc_type, &uinfo32->ifc_type);
1374 err |= __put_user(info.irqnr, &uinfo32->irqnr);
1375 err |= __put_user(info.dmanr, &uinfo32->dmanr);
1376 err |= __put_user(info.port, &uinfo32->port);
1377 err |= __put_user(info.debug, &uinfo32->debug);
1378 err |= __copy_to_user((char __user *)&uinfo32->debug
1379 + sizeof(uinfo32->debug),
1380 (char *)&info.debug + sizeof(info.debug), sizeof(__u32));
1381 break;
1382 case MTIOCSETCONFIG32:
1383 break;
1385 return err ? -EFAULT: 0;
1388 struct cdrom_read_audio32 {
1389 union cdrom_addr addr;
1390 u8 addr_format;
1391 compat_int_t nframes;
1392 compat_caddr_t buf;
1395 struct cdrom_generic_command32 {
1396 unsigned char cmd[CDROM_PACKET_SIZE];
1397 compat_caddr_t buffer;
1398 compat_uint_t buflen;
1399 compat_int_t stat;
1400 compat_caddr_t sense;
1401 unsigned char data_direction;
1402 compat_int_t quiet;
1403 compat_int_t timeout;
1404 compat_caddr_t reserved[1];
1407 static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1409 struct cdrom_read_audio __user *cdread_audio;
1410 struct cdrom_read_audio32 __user *cdread_audio32;
1411 __u32 data;
1412 void __user *datap;
1414 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1415 cdread_audio32 = compat_ptr(arg);
1417 if (copy_in_user(&cdread_audio->addr,
1418 &cdread_audio32->addr,
1419 (sizeof(*cdread_audio32) -
1420 sizeof(compat_caddr_t))))
1421 return -EFAULT;
1423 if (get_user(data, &cdread_audio32->buf))
1424 return -EFAULT;
1425 datap = compat_ptr(data);
1426 if (put_user(datap, &cdread_audio->buf))
1427 return -EFAULT;
1429 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1432 static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1434 struct cdrom_generic_command __user *cgc;
1435 struct cdrom_generic_command32 __user *cgc32;
1436 u32 data;
1437 unsigned char dir;
1438 int itmp;
1440 cgc = compat_alloc_user_space(sizeof(*cgc));
1441 cgc32 = compat_ptr(arg);
1443 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1444 get_user(data, &cgc32->buffer) ||
1445 put_user(compat_ptr(data), &cgc->buffer) ||
1446 copy_in_user(&cgc->buflen, &cgc32->buflen,
1447 (sizeof(unsigned int) + sizeof(int))) ||
1448 get_user(data, &cgc32->sense) ||
1449 put_user(compat_ptr(data), &cgc->sense) ||
1450 get_user(dir, &cgc32->data_direction) ||
1451 put_user(dir, &cgc->data_direction) ||
1452 get_user(itmp, &cgc32->quiet) ||
1453 put_user(itmp, &cgc->quiet) ||
1454 get_user(itmp, &cgc32->timeout) ||
1455 put_user(itmp, &cgc->timeout) ||
1456 get_user(data, &cgc32->reserved[0]) ||
1457 put_user(compat_ptr(data), &cgc->reserved[0]))
1458 return -EFAULT;
1460 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1463 static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1465 int err;
1467 switch(cmd) {
1468 case CDROMREADAUDIO:
1469 err = cdrom_do_read_audio(fd, cmd, arg);
1470 break;
1472 case CDROM_SEND_PACKET:
1473 err = cdrom_do_generic_command(fd, cmd, arg);
1474 break;
1476 default:
1477 do {
1478 static int count;
1479 if (++count <= 20)
1480 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1481 "cmd(%08x) arg(%08x)\n",
1482 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1483 } while(0);
1484 err = -EINVAL;
1485 break;
1488 return err;
1491 struct loop_info32 {
1492 compat_int_t lo_number; /* ioctl r/o */
1493 compat_dev_t lo_device; /* ioctl r/o */
1494 compat_ulong_t lo_inode; /* ioctl r/o */
1495 compat_dev_t lo_rdevice; /* ioctl r/o */
1496 compat_int_t lo_offset;
1497 compat_int_t lo_encrypt_type;
1498 compat_int_t lo_encrypt_key_size; /* ioctl w/o */
1499 compat_int_t lo_flags; /* ioctl r/o */
1500 char lo_name[LO_NAME_SIZE];
1501 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
1502 compat_ulong_t lo_init[2];
1503 char reserved[4];
1506 static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg)
1508 mm_segment_t old_fs = get_fs();
1509 struct loop_info l;
1510 struct loop_info32 __user *ul;
1511 int err = -EINVAL;
1513 ul = compat_ptr(arg);
1514 switch(cmd) {
1515 case LOOP_SET_STATUS:
1516 err = get_user(l.lo_number, &ul->lo_number);
1517 err |= __get_user(l.lo_device, &ul->lo_device);
1518 err |= __get_user(l.lo_inode, &ul->lo_inode);
1519 err |= __get_user(l.lo_rdevice, &ul->lo_rdevice);
1520 err |= __copy_from_user(&l.lo_offset, &ul->lo_offset,
1521 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1522 if (err) {
1523 err = -EFAULT;
1524 } else {
1525 set_fs (KERNEL_DS);
1526 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1527 set_fs (old_fs);
1529 break;
1530 case LOOP_GET_STATUS:
1531 set_fs (KERNEL_DS);
1532 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1533 set_fs (old_fs);
1534 if (!err) {
1535 err = put_user(l.lo_number, &ul->lo_number);
1536 err |= __put_user(l.lo_device, &ul->lo_device);
1537 err |= __put_user(l.lo_inode, &ul->lo_inode);
1538 err |= __put_user(l.lo_rdevice, &ul->lo_rdevice);
1539 err |= __copy_to_user(&ul->lo_offset, &l.lo_offset,
1540 (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1541 if (err)
1542 err = -EFAULT;
1544 break;
1545 default: {
1546 static int count;
1547 if (++count <= 20)
1548 printk("%s: Unknown loop ioctl cmd, fd(%d) "
1549 "cmd(%08x) arg(%08lx)\n",
1550 __FUNCTION__, fd, cmd, arg);
1553 return err;
1556 extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);
1558 #ifdef CONFIG_VT
1560 static int vt_check(struct file *file)
1562 struct tty_struct *tty;
1563 struct inode *inode = file->f_dentry->d_inode;
1565 if (file->f_op->ioctl != tty_ioctl)
1566 return -EINVAL;
1568 tty = (struct tty_struct *)file->private_data;
1569 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1570 return -EINVAL;
1572 if (tty->driver->ioctl != vt_ioctl)
1573 return -EINVAL;
1576 * To have permissions to do most of the vt ioctls, we either have
1577 * to be the owner of the tty, or super-user.
1579 if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
1580 return 1;
1581 return 0;
1584 struct consolefontdesc32 {
1585 unsigned short charcount; /* characters in font (256 or 512) */
1586 unsigned short charheight; /* scan lines per character (1-32) */
1587 compat_caddr_t chardata; /* font data in expanded form */
1590 static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1592 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1593 struct console_font_op op;
1594 compat_caddr_t data;
1595 int i, perm;
1597 perm = vt_check(file);
1598 if (perm < 0) return perm;
1600 switch (cmd) {
1601 case PIO_FONTX:
1602 if (!perm)
1603 return -EPERM;
1604 op.op = KD_FONT_OP_SET;
1605 op.flags = 0;
1606 op.width = 8;
1607 if (get_user(op.height, &user_cfd->charheight) ||
1608 get_user(op.charcount, &user_cfd->charcount) ||
1609 get_user(data, &user_cfd->chardata))
1610 return -EFAULT;
1611 op.data = compat_ptr(data);
1612 return con_font_op(fg_console, &op);
1613 case GIO_FONTX:
1614 op.op = KD_FONT_OP_GET;
1615 op.flags = 0;
1616 op.width = 8;
1617 if (get_user(op.height, &user_cfd->charheight) ||
1618 get_user(op.charcount, &user_cfd->charcount) ||
1619 get_user(data, &user_cfd->chardata))
1620 return -EFAULT;
1621 if (!data)
1622 return 0;
1623 op.data = compat_ptr(data);
1624 i = con_font_op(fg_console, &op);
1625 if (i)
1626 return i;
1627 if (put_user(op.height, &user_cfd->charheight) ||
1628 put_user(op.charcount, &user_cfd->charcount) ||
1629 put_user((compat_caddr_t)(unsigned long)op.data,
1630 &user_cfd->chardata))
1631 return -EFAULT;
1632 return 0;
1634 return -EINVAL;
1637 struct console_font_op32 {
1638 compat_uint_t op; /* operation code KD_FONT_OP_* */
1639 compat_uint_t flags; /* KD_FONT_FLAG_* */
1640 compat_uint_t width, height; /* font size */
1641 compat_uint_t charcount;
1642 compat_caddr_t data; /* font data with height fixed to 32 */
1645 static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1647 struct console_font_op op;
1648 struct console_font_op32 __user *fontop = compat_ptr(arg);
1649 int perm = vt_check(file), i;
1650 struct vt_struct *vt;
1652 if (perm < 0) return perm;
1654 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1655 return -EFAULT;
1656 if (!perm && op.op != KD_FONT_OP_GET)
1657 return -EPERM;
1658 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1659 op.flags |= KD_FONT_FLAG_OLD;
1660 vt = (struct vt_struct *)((struct tty_struct *)file->private_data)->driver_data;
1661 i = con_font_op(vt->vc_num, &op);
1662 if (i) return i;
1663 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1664 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1665 return -EFAULT;
1666 return 0;
1669 struct unimapdesc32 {
1670 unsigned short entry_ct;
1671 compat_caddr_t entries;
1674 static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1676 struct unimapdesc32 tmp;
1677 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1678 int perm = vt_check(file);
1680 if (perm < 0) return perm;
1681 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1682 return -EFAULT;
1683 switch (cmd) {
1684 case PIO_UNIMAP:
1685 if (!perm) return -EPERM;
1686 return con_set_unimap(fg_console, tmp.entry_ct, compat_ptr(tmp.entries));
1687 case GIO_UNIMAP:
1688 return con_get_unimap(fg_console, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
1690 return 0;
1693 #endif /* CONFIG_VT */
1695 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1697 mm_segment_t old_fs = get_fs();
1698 __kernel_uid_t kuid;
1699 int err;
1701 cmd = SMB_IOC_GETMOUNTUID;
1703 set_fs(KERNEL_DS);
1704 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1705 set_fs(old_fs);
1707 if (err >= 0)
1708 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1710 return err;
1713 struct atmif_sioc32 {
1714 compat_int_t number;
1715 compat_int_t length;
1716 compat_caddr_t arg;
1719 struct atm_iobuf32 {
1720 compat_int_t length;
1721 compat_caddr_t buffer;
1724 #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1725 #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1726 #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1727 #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1728 #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1729 #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1730 #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1731 #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1732 #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1733 #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1734 #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1735 #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1736 #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1737 #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1738 #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1739 #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1740 #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1742 static struct {
1743 unsigned int cmd32;
1744 unsigned int cmd;
1745 } atm_ioctl_map[] = {
1746 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1747 { ATM_GETNAMES32, ATM_GETNAMES },
1748 { ATM_GETTYPE32, ATM_GETTYPE },
1749 { ATM_GETESI32, ATM_GETESI },
1750 { ATM_GETADDR32, ATM_GETADDR },
1751 { ATM_RSTADDR32, ATM_RSTADDR },
1752 { ATM_ADDADDR32, ATM_ADDADDR },
1753 { ATM_DELADDR32, ATM_DELADDR },
1754 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1755 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1756 { ATM_SETESI32, ATM_SETESI },
1757 { ATM_SETESIF32, ATM_SETESIF },
1758 { ATM_GETSTAT32, ATM_GETSTAT },
1759 { ATM_GETSTATZ32, ATM_GETSTATZ },
1760 { ATM_GETLOOP32, ATM_GETLOOP },
1761 { ATM_SETLOOP32, ATM_SETLOOP },
1762 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1765 #define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
1768 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1770 struct atm_iobuf __user *iobuf;
1771 struct atm_iobuf32 __user *iobuf32;
1772 u32 data;
1773 void __user *datap;
1774 int len, err;
1776 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1777 iobuf32 = compat_ptr(arg);
1779 if (get_user(len, &iobuf32->length) ||
1780 get_user(data, &iobuf32->buffer))
1781 return -EFAULT;
1782 datap = compat_ptr(data);
1783 if (put_user(len, &iobuf->length) ||
1784 put_user(datap, &iobuf->buffer))
1785 return -EFAULT;
1787 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1789 if (!err) {
1790 if (copy_in_user(&iobuf32->length, &iobuf->length,
1791 sizeof(int)))
1792 err = -EFAULT;
1795 return err;
1798 static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1800 struct atmif_sioc __user *sioc;
1801 struct atmif_sioc32 __user *sioc32;
1802 u32 data;
1803 void __user *datap;
1804 int err;
1806 sioc = compat_alloc_user_space(sizeof(*sioc));
1807 sioc32 = compat_ptr(arg);
1809 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1810 get_user(data, &sioc32->arg))
1811 return -EFAULT;
1812 datap = compat_ptr(data);
1813 if (put_user(datap, &sioc->arg))
1814 return -EFAULT;
1816 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1818 if (!err) {
1819 if (copy_in_user(&sioc32->length, &sioc->length,
1820 sizeof(int)))
1821 err = -EFAULT;
1823 return err;
1826 static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1828 int i;
1829 unsigned int cmd = 0;
1831 switch (cmd32) {
1832 case SONET_GETSTAT:
1833 case SONET_GETSTATZ:
1834 case SONET_GETDIAG:
1835 case SONET_SETDIAG:
1836 case SONET_CLRDIAG:
1837 case SONET_SETFRAMING:
1838 case SONET_GETFRAMING:
1839 case SONET_GETFRSENSE:
1840 return do_atmif_sioc(fd, cmd32, arg);
1843 for (i = 0; i < NR_ATM_IOCTL; i++) {
1844 if (cmd32 == atm_ioctl_map[i].cmd32) {
1845 cmd = atm_ioctl_map[i].cmd;
1846 break;
1849 if (i == NR_ATM_IOCTL)
1850 return -EINVAL;
1852 switch (cmd) {
1853 case ATM_GETNAMES:
1854 return do_atm_iobuf(fd, cmd, arg);
1856 case ATM_GETLINKRATE:
1857 case ATM_GETTYPE:
1858 case ATM_GETESI:
1859 case ATM_GETADDR:
1860 case ATM_RSTADDR:
1861 case ATM_ADDADDR:
1862 case ATM_DELADDR:
1863 case ATM_GETCIRANGE:
1864 case ATM_SETCIRANGE:
1865 case ATM_SETESI:
1866 case ATM_SETESIF:
1867 case ATM_GETSTAT:
1868 case ATM_GETSTATZ:
1869 case ATM_GETLOOP:
1870 case ATM_SETLOOP:
1871 case ATM_QUERYLOOP:
1872 return do_atmif_sioc(fd, cmd, arg);
1875 return -EINVAL;
1878 static __attribute_used__ int
1879 ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1881 return -EINVAL;
1884 static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1886 /* The mkswap binary hard codes it to Intel value :-((( */
1887 return w_long(fd, BLKGETSIZE, arg);
1890 struct blkpg_ioctl_arg32 {
1891 compat_int_t op;
1892 compat_int_t flags;
1893 compat_int_t datalen;
1894 compat_caddr_t data;
1897 static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1899 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1900 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1901 compat_caddr_t udata;
1902 compat_int_t n;
1903 int err;
1905 err = get_user(n, &ua32->op);
1906 err |= put_user(n, &a->op);
1907 err |= get_user(n, &ua32->flags);
1908 err |= put_user(n, &a->flags);
1909 err |= get_user(n, &ua32->datalen);
1910 err |= put_user(n, &a->datalen);
1911 err |= get_user(udata, &ua32->data);
1912 err |= put_user(compat_ptr(udata), &a->data);
1913 if (err)
1914 return err;
1916 return sys_ioctl(fd, cmd, (unsigned long)a);
1919 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1921 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1924 /* Fix sizeof(sizeof()) breakage */
1925 #define BLKBSZGET_32 _IOR(0x12,112,int)
1926 #define BLKBSZSET_32 _IOW(0x12,113,int)
1927 #define BLKGETSIZE64_32 _IOR(0x12,114,int)
1929 static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1931 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1934 static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1936 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1939 static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1940 unsigned long arg)
1942 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1945 /* Bluetooth ioctls */
1946 #define HCIUARTSETPROTO _IOW('U', 200, int)
1947 #define HCIUARTGETPROTO _IOR('U', 201, int)
1949 #define BNEPCONNADD _IOW('B', 200, int)
1950 #define BNEPCONNDEL _IOW('B', 201, int)
1951 #define BNEPGETCONNLIST _IOR('B', 210, int)
1952 #define BNEPGETCONNINFO _IOR('B', 211, int)
1954 #define CMTPCONNADD _IOW('C', 200, int)
1955 #define CMTPCONNDEL _IOW('C', 201, int)
1956 #define CMTPGETCONNLIST _IOR('C', 210, int)
1957 #define CMTPGETCONNINFO _IOR('C', 211, int)
1959 #define HIDPCONNADD _IOW('H', 200, int)
1960 #define HIDPCONNDEL _IOW('H', 201, int)
1961 #define HIDPGETCONNLIST _IOR('H', 210, int)
1962 #define HIDPGETCONNINFO _IOR('H', 211, int)
1964 struct floppy_struct32 {
1965 compat_uint_t size;
1966 compat_uint_t sect;
1967 compat_uint_t head;
1968 compat_uint_t track;
1969 compat_uint_t stretch;
1970 unsigned char gap;
1971 unsigned char rate;
1972 unsigned char spec1;
1973 unsigned char fmt_gap;
1974 const compat_caddr_t name;
1977 struct floppy_drive_params32 {
1978 char cmos;
1979 compat_ulong_t max_dtr;
1980 compat_ulong_t hlt;
1981 compat_ulong_t hut;
1982 compat_ulong_t srt;
1983 compat_ulong_t spinup;
1984 compat_ulong_t spindown;
1985 unsigned char spindown_offset;
1986 unsigned char select_delay;
1987 unsigned char rps;
1988 unsigned char tracks;
1989 compat_ulong_t timeout;
1990 unsigned char interleave_sect;
1991 struct floppy_max_errors max_errors;
1992 char flags;
1993 char read_track;
1994 short autodetect[8];
1995 compat_int_t checkfreq;
1996 compat_int_t native_format;
1999 struct floppy_drive_struct32 {
2000 signed char flags;
2001 compat_ulong_t spinup_date;
2002 compat_ulong_t select_date;
2003 compat_ulong_t first_read_date;
2004 short probed_format;
2005 short track;
2006 short maxblock;
2007 short maxtrack;
2008 compat_int_t generation;
2009 compat_int_t keep_data;
2010 compat_int_t fd_ref;
2011 compat_int_t fd_device;
2012 compat_int_t last_checked;
2013 compat_caddr_t dmabuf;
2014 compat_int_t bufblocks;
2017 struct floppy_fdc_state32 {
2018 compat_int_t spec1;
2019 compat_int_t spec2;
2020 compat_int_t dtr;
2021 unsigned char version;
2022 unsigned char dor;
2023 compat_ulong_t address;
2024 unsigned int rawcmd:2;
2025 unsigned int reset:1;
2026 unsigned int need_configure:1;
2027 unsigned int perp_mode:2;
2028 unsigned int has_fifo:1;
2029 unsigned int driver_version;
2030 unsigned char track[4];
2033 struct floppy_write_errors32 {
2034 unsigned int write_errors;
2035 compat_ulong_t first_error_sector;
2036 compat_int_t first_error_generation;
2037 compat_ulong_t last_error_sector;
2038 compat_int_t last_error_generation;
2039 compat_uint_t badness;
2042 #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
2043 #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
2044 #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
2045 #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
2046 #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
2047 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
2048 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
2049 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
2050 #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
2052 static struct {
2053 unsigned int cmd32;
2054 unsigned int cmd;
2055 } fd_ioctl_trans_table[] = {
2056 { FDSETPRM32, FDSETPRM },
2057 { FDDEFPRM32, FDDEFPRM },
2058 { FDGETPRM32, FDGETPRM },
2059 { FDSETDRVPRM32, FDSETDRVPRM },
2060 { FDGETDRVPRM32, FDGETDRVPRM },
2061 { FDGETDRVSTAT32, FDGETDRVSTAT },
2062 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
2063 { FDGETFDCSTAT32, FDGETFDCSTAT },
2064 { FDWERRORGET32, FDWERRORGET }
2067 #define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
2069 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2071 mm_segment_t old_fs = get_fs();
2072 void *karg = NULL;
2073 unsigned int kcmd = 0;
2074 int i, err;
2076 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
2077 if (cmd == fd_ioctl_trans_table[i].cmd32) {
2078 kcmd = fd_ioctl_trans_table[i].cmd;
2079 break;
2081 if (!kcmd)
2082 return -EINVAL;
2084 switch (cmd) {
2085 case FDSETPRM32:
2086 case FDDEFPRM32:
2087 case FDGETPRM32:
2089 compat_uptr_t name;
2090 struct floppy_struct32 __user *uf;
2091 struct floppy_struct *f;
2093 uf = compat_ptr(arg);
2094 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
2095 if (!karg)
2096 return -ENOMEM;
2097 if (cmd == FDGETPRM32)
2098 break;
2099 err = __get_user(f->size, &uf->size);
2100 err |= __get_user(f->sect, &uf->sect);
2101 err |= __get_user(f->head, &uf->head);
2102 err |= __get_user(f->track, &uf->track);
2103 err |= __get_user(f->stretch, &uf->stretch);
2104 err |= __get_user(f->gap, &uf->gap);
2105 err |= __get_user(f->rate, &uf->rate);
2106 err |= __get_user(f->spec1, &uf->spec1);
2107 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
2108 err |= __get_user(name, &uf->name);
2109 f->name = compat_ptr(name);
2110 if (err) {
2111 err = -EFAULT;
2112 goto out;
2114 break;
2116 case FDSETDRVPRM32:
2117 case FDGETDRVPRM32:
2119 struct floppy_drive_params32 __user *uf;
2120 struct floppy_drive_params *f;
2122 uf = compat_ptr(arg);
2123 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
2124 if (!karg)
2125 return -ENOMEM;
2126 if (cmd == FDGETDRVPRM32)
2127 break;
2128 err = __get_user(f->cmos, &uf->cmos);
2129 err |= __get_user(f->max_dtr, &uf->max_dtr);
2130 err |= __get_user(f->hlt, &uf->hlt);
2131 err |= __get_user(f->hut, &uf->hut);
2132 err |= __get_user(f->srt, &uf->srt);
2133 err |= __get_user(f->spinup, &uf->spinup);
2134 err |= __get_user(f->spindown, &uf->spindown);
2135 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
2136 err |= __get_user(f->select_delay, &uf->select_delay);
2137 err |= __get_user(f->rps, &uf->rps);
2138 err |= __get_user(f->tracks, &uf->tracks);
2139 err |= __get_user(f->timeout, &uf->timeout);
2140 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
2141 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
2142 err |= __get_user(f->flags, &uf->flags);
2143 err |= __get_user(f->read_track, &uf->read_track);
2144 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
2145 err |= __get_user(f->checkfreq, &uf->checkfreq);
2146 err |= __get_user(f->native_format, &uf->native_format);
2147 if (err) {
2148 err = -EFAULT;
2149 goto out;
2151 break;
2153 case FDGETDRVSTAT32:
2154 case FDPOLLDRVSTAT32:
2155 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
2156 if (!karg)
2157 return -ENOMEM;
2158 break;
2159 case FDGETFDCSTAT32:
2160 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
2161 if (!karg)
2162 return -ENOMEM;
2163 break;
2164 case FDWERRORGET32:
2165 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
2166 if (!karg)
2167 return -ENOMEM;
2168 break;
2169 default:
2170 return -EINVAL;
2172 set_fs (KERNEL_DS);
2173 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
2174 set_fs (old_fs);
2175 if (err)
2176 goto out;
2177 switch (cmd) {
2178 case FDGETPRM32:
2180 struct floppy_struct *f = karg;
2181 struct floppy_struct32 __user *uf = compat_ptr(arg);
2183 err = __put_user(f->size, &uf->size);
2184 err |= __put_user(f->sect, &uf->sect);
2185 err |= __put_user(f->head, &uf->head);
2186 err |= __put_user(f->track, &uf->track);
2187 err |= __put_user(f->stretch, &uf->stretch);
2188 err |= __put_user(f->gap, &uf->gap);
2189 err |= __put_user(f->rate, &uf->rate);
2190 err |= __put_user(f->spec1, &uf->spec1);
2191 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
2192 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
2193 break;
2195 case FDGETDRVPRM32:
2197 struct floppy_drive_params32 __user *uf;
2198 struct floppy_drive_params *f = karg;
2200 uf = compat_ptr(arg);
2201 err = __put_user(f->cmos, &uf->cmos);
2202 err |= __put_user(f->max_dtr, &uf->max_dtr);
2203 err |= __put_user(f->hlt, &uf->hlt);
2204 err |= __put_user(f->hut, &uf->hut);
2205 err |= __put_user(f->srt, &uf->srt);
2206 err |= __put_user(f->spinup, &uf->spinup);
2207 err |= __put_user(f->spindown, &uf->spindown);
2208 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
2209 err |= __put_user(f->select_delay, &uf->select_delay);
2210 err |= __put_user(f->rps, &uf->rps);
2211 err |= __put_user(f->tracks, &uf->tracks);
2212 err |= __put_user(f->timeout, &uf->timeout);
2213 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
2214 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
2215 err |= __put_user(f->flags, &uf->flags);
2216 err |= __put_user(f->read_track, &uf->read_track);
2217 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
2218 err |= __put_user(f->checkfreq, &uf->checkfreq);
2219 err |= __put_user(f->native_format, &uf->native_format);
2220 break;
2222 case FDGETDRVSTAT32:
2223 case FDPOLLDRVSTAT32:
2225 struct floppy_drive_struct32 __user *uf;
2226 struct floppy_drive_struct *f = karg;
2228 uf = compat_ptr(arg);
2229 err = __put_user(f->flags, &uf->flags);
2230 err |= __put_user(f->spinup_date, &uf->spinup_date);
2231 err |= __put_user(f->select_date, &uf->select_date);
2232 err |= __put_user(f->first_read_date, &uf->first_read_date);
2233 err |= __put_user(f->probed_format, &uf->probed_format);
2234 err |= __put_user(f->track, &uf->track);
2235 err |= __put_user(f->maxblock, &uf->maxblock);
2236 err |= __put_user(f->maxtrack, &uf->maxtrack);
2237 err |= __put_user(f->generation, &uf->generation);
2238 err |= __put_user(f->keep_data, &uf->keep_data);
2239 err |= __put_user(f->fd_ref, &uf->fd_ref);
2240 err |= __put_user(f->fd_device, &uf->fd_device);
2241 err |= __put_user(f->last_checked, &uf->last_checked);
2242 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
2243 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
2244 break;
2246 case FDGETFDCSTAT32:
2248 struct floppy_fdc_state32 __user *uf;
2249 struct floppy_fdc_state *f = karg;
2251 uf = compat_ptr(arg);
2252 err = __put_user(f->spec1, &uf->spec1);
2253 err |= __put_user(f->spec2, &uf->spec2);
2254 err |= __put_user(f->dtr, &uf->dtr);
2255 err |= __put_user(f->version, &uf->version);
2256 err |= __put_user(f->dor, &uf->dor);
2257 err |= __put_user(f->address, &uf->address);
2258 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
2259 (char *)&f->address + sizeof(f->address), sizeof(int));
2260 err |= __put_user(f->driver_version, &uf->driver_version);
2261 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
2262 break;
2264 case FDWERRORGET32:
2266 struct floppy_write_errors32 __user *uf;
2267 struct floppy_write_errors *f = karg;
2269 uf = compat_ptr(arg);
2270 err = __put_user(f->write_errors, &uf->write_errors);
2271 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
2272 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
2273 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
2274 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
2275 err |= __put_user(f->badness, &uf->badness);
2276 break;
2278 default:
2279 break;
2281 if (err)
2282 err = -EFAULT;
2284 out: if (karg) kfree(karg);
2285 return err;
2288 struct mtd_oob_buf32 {
2289 u_int32_t start;
2290 u_int32_t length;
2291 compat_caddr_t ptr; /* unsigned char* */
2294 #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
2295 #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
2297 static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
2299 struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
2300 struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
2301 u32 data;
2302 char __user *datap;
2303 unsigned int real_cmd;
2304 int err;
2306 real_cmd = (cmd == MEMREADOOB32) ?
2307 MEMREADOOB : MEMWRITEOOB;
2309 if (copy_in_user(&buf->start, &buf32->start,
2310 2 * sizeof(u32)) ||
2311 get_user(data, &buf32->ptr))
2312 return -EFAULT;
2313 datap = compat_ptr(data);
2314 if (put_user(datap, &buf->ptr))
2315 return -EFAULT;
2317 err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
2319 if (!err) {
2320 if (copy_in_user(&buf32->start, &buf->start,
2321 2 * sizeof(u32)))
2322 err = -EFAULT;
2325 return err;
2328 #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
2329 #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
2331 static long
2332 put_dirent32 (struct dirent *d, struct compat_dirent __user *d32)
2334 int ret;
2336 if ((ret = verify_area(VERIFY_WRITE, d32,
2337 sizeof(struct compat_dirent))))
2338 return ret;
2340 __put_user(d->d_ino, &d32->d_ino);
2341 __put_user(d->d_off, &d32->d_off);
2342 __put_user(d->d_reclen, &d32->d_reclen);
2343 __copy_to_user(d32->d_name, d->d_name, d->d_reclen);
2344 return ret;
2347 static int vfat_ioctl32(unsigned fd, unsigned cmd, unsigned long arg)
2349 struct compat_dirent __user *p = compat_ptr(arg);
2350 int ret;
2351 mm_segment_t oldfs = get_fs();
2352 struct dirent d[2];
2354 switch(cmd)
2356 case VFAT_IOCTL_READDIR_BOTH32:
2357 cmd = VFAT_IOCTL_READDIR_BOTH;
2358 break;
2359 case VFAT_IOCTL_READDIR_SHORT32:
2360 cmd = VFAT_IOCTL_READDIR_SHORT;
2361 break;
2364 set_fs(KERNEL_DS);
2365 ret = sys_ioctl(fd,cmd,(unsigned long)&d);
2366 set_fs(oldfs);
2367 if (ret >= 0) {
2368 ret |= put_dirent32(&d[0], p);
2369 ret |= put_dirent32(&d[1], p + 1);
2371 return ret;
2374 #define REISERFS_IOC_UNPACK32 _IOW(0xCD,1,int)
2376 static int reiserfs_ioctl32(unsigned fd, unsigned cmd, unsigned long ptr)
2378 if (cmd == REISERFS_IOC_UNPACK32)
2379 cmd = REISERFS_IOC_UNPACK;
2381 return sys_ioctl(fd,cmd,ptr);
2384 struct raw32_config_request
2386 compat_int_t raw_minor;
2387 __u64 block_major;
2388 __u64 block_minor;
2389 } __attribute__((packed));
2391 static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2393 int ret;
2395 if ((ret = verify_area(VERIFY_READ, user_req,
2396 sizeof(struct raw32_config_request))))
2397 return ret;
2399 ret = __get_user(req->raw_minor, &user_req->raw_minor);
2400 ret |= __get_user(req->block_major, &user_req->block_major);
2401 ret |= __get_user(req->block_minor, &user_req->block_minor);
2403 return ret ? -EFAULT : 0;
2406 static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2408 int ret;
2410 if ((ret = verify_area(VERIFY_WRITE, user_req,
2411 sizeof(struct raw32_config_request))))
2412 return ret;
2414 ret = __put_user(req->raw_minor, &user_req->raw_minor);
2415 ret |= __put_user(req->block_major, &user_req->block_major);
2416 ret |= __put_user(req->block_minor, &user_req->block_minor);
2418 return ret ? -EFAULT : 0;
2421 static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2423 int ret;
2425 switch (cmd) {
2426 case RAW_SETBIND:
2427 case RAW_GETBIND: {
2428 struct raw_config_request req;
2429 struct raw32_config_request __user *user_req = compat_ptr(arg);
2430 mm_segment_t oldfs = get_fs();
2432 if ((ret = get_raw32_request(&req, user_req)))
2433 return ret;
2435 set_fs(KERNEL_DS);
2436 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2437 set_fs(oldfs);
2439 if ((!ret) && (cmd == RAW_GETBIND)) {
2440 ret = set_raw32_request(&req, user_req);
2442 break;
2444 default:
2445 ret = sys_ioctl(fd, cmd, arg);
2446 break;
2448 return ret;
2451 struct serial_struct32 {
2452 compat_int_t type;
2453 compat_int_t line;
2454 compat_uint_t port;
2455 compat_int_t irq;
2456 compat_int_t flags;
2457 compat_int_t xmit_fifo_size;
2458 compat_int_t custom_divisor;
2459 compat_int_t baud_base;
2460 unsigned short close_delay;
2461 char io_type;
2462 char reserved_char[1];
2463 compat_int_t hub6;
2464 unsigned short closing_wait; /* time to wait before closing */
2465 unsigned short closing_wait2; /* no longer used... */
2466 compat_uint_t iomem_base;
2467 unsigned short iomem_reg_shift;
2468 unsigned int port_high;
2469 /* compat_ulong_t iomap_base FIXME */
2470 compat_int_t reserved[1];
2473 static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2475 typedef struct serial_struct SS;
2476 typedef struct serial_struct32 SS32;
2477 struct serial_struct32 __user *ss32 = compat_ptr(arg);
2478 int err;
2479 struct serial_struct ss;
2480 mm_segment_t oldseg = get_fs();
2481 __u32 udata;
2483 if (cmd == TIOCSSERIAL) {
2484 if (verify_area(VERIFY_READ, ss32, sizeof(SS32)))
2485 return -EFAULT;
2486 __copy_from_user(&ss, ss32, offsetof(SS32, iomem_base));
2487 __get_user(udata, &ss32->iomem_base);
2488 ss.iomem_base = compat_ptr(udata);
2489 __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2490 __get_user(ss.port_high, &ss32->port_high);
2491 ss.iomap_base = 0UL;
2493 set_fs(KERNEL_DS);
2494 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2495 set_fs(oldseg);
2496 if (cmd == TIOCGSERIAL && err >= 0) {
2497 if (verify_area(VERIFY_WRITE, ss32, sizeof(SS32)))
2498 return -EFAULT;
2499 __copy_to_user(ss32,&ss,offsetof(SS32,iomem_base));
2500 __put_user((unsigned long)ss.iomem_base >> 32 ?
2501 0xffffffff : (unsigned)(unsigned long)ss.iomem_base,
2502 &ss32->iomem_base);
2503 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2504 __put_user(ss.port_high, &ss32->port_high);
2507 return err;
2510 struct usbdevfs_ctrltransfer32 {
2511 u8 bRequestType;
2512 u8 bRequest;
2513 u16 wValue;
2514 u16 wIndex;
2515 u16 wLength;
2516 u32 timeout; /* in milliseconds */
2517 compat_caddr_t data;
2520 #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2522 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2524 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2525 struct usbdevfs_ctrltransfer __user *p;
2526 __u32 udata;
2527 p = compat_alloc_user_space(sizeof(*p));
2528 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2529 get_user(udata, &p32->data) ||
2530 put_user(compat_ptr(udata), &p->data))
2531 return -EFAULT;
2532 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2536 struct usbdevfs_bulktransfer32 {
2537 compat_uint_t ep;
2538 compat_uint_t len;
2539 compat_uint_t timeout; /* in milliseconds */
2540 compat_caddr_t data;
2543 #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2545 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2547 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2548 struct usbdevfs_bulktransfer __user *p;
2549 compat_uint_t n;
2550 compat_caddr_t addr;
2552 p = compat_alloc_user_space(sizeof(*p));
2554 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2555 get_user(n, &p32->len) || put_user(n, &p->len) ||
2556 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2557 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2558 return -EFAULT;
2560 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2563 /* This needs more work before we can enable it. Unfortunately
2564 * because of the fancy asynchronous way URB status/error is written
2565 * back to userspace, we'll need to fiddle with USB devio internals
2566 * and/or reimplement entirely the frontend of it ourselves. -DaveM
2568 * The issue is:
2570 * When an URB is submitted via usbdevicefs it is put onto an
2571 * asynchronous queue. When the URB completes, it may be reaped
2572 * via another ioctl. During this reaping the status is written
2573 * back to userspace along with the length of the transfer.
2575 * We must translate into 64-bit kernel types so we pass in a kernel
2576 * space copy of the usbdevfs_urb structure. This would mean that we
2577 * must do something to deal with the async entry reaping. First we
2578 * have to deal somehow with this transitory memory we've allocated.
2579 * This is problematic since there are many call sites from which the
2580 * async entries can be destroyed (and thus when we'd need to free up
2581 * this kernel memory). One of which is the close() op of usbdevicefs.
2582 * To handle that we'd need to make our own file_operations struct which
2583 * overrides usbdevicefs's release op with our own which runs usbdevicefs's
2584 * real release op then frees up the kernel memory.
2586 * But how to keep track of these kernel buffers? We'd need to either
2587 * keep track of them in some table _or_ know about usbdevicefs internals
2588 * (ie. the exact layout of its file private, which is actually defined
2589 * in linux/usbdevice_fs.h, the layout of the async queues are private to
2590 * devio.c)
2592 * There is one possible other solution I considered, also involving knowledge
2593 * of usbdevicefs internals:
2595 * After an URB is submitted, we "fix up" the address back to the user
2596 * space one. This would work if the status/length fields written back
2597 * by the async URB completion lines up perfectly in the 32-bit type with
2598 * the 64-bit kernel type. Unfortunately, it does not because the iso
2599 * frame descriptors, at the end of the struct, can be written back.
2601 * I think we'll just need to simply duplicate the devio URB engine here.
2603 #if 0
2604 struct usbdevfs_urb32 {
2605 unsigned char type;
2606 unsigned char endpoint;
2607 compat_int_t status;
2608 compat_uint_t flags;
2609 compat_caddr_t buffer;
2610 compat_int_t buffer_length;
2611 compat_int_t actual_length;
2612 compat_int_t start_frame;
2613 compat_int_t number_of_packets;
2614 compat_int_t error_count;
2615 compat_uint_t signr;
2616 compat_caddr_t usercontext; /* unused */
2617 struct usbdevfs_iso_packet_desc iso_frame_desc[0];
2620 #define USBDEVFS_SUBMITURB32 _IOR('U', 10, struct usbdevfs_urb32)
2622 static int get_urb32(struct usbdevfs_urb *kurb,
2623 struct usbdevfs_urb32 *uurb)
2625 if (get_user(kurb->type, &uurb->type) ||
2626 __get_user(kurb->endpoint, &uurb->endpoint) ||
2627 __get_user(kurb->status, &uurb->status) ||
2628 __get_user(kurb->flags, &uurb->flags) ||
2629 __get_user(kurb->buffer_length, &uurb->buffer_length) ||
2630 __get_user(kurb->actual_length, &uurb->actual_length) ||
2631 __get_user(kurb->start_frame, &uurb->start_frame) ||
2632 __get_user(kurb->number_of_packets, &uurb->number_of_packets) ||
2633 __get_user(kurb->error_count, &uurb->error_count) ||
2634 __get_user(kurb->signr, &uurb->signr))
2635 return -EFAULT;
2637 kurb->usercontext = 0; /* unused currently */
2639 return 0;
2642 /* Just put back the values which usbdevfs actually changes. */
2643 static int put_urb32(struct usbdevfs_urb *kurb,
2644 struct usbdevfs_urb32 *uurb)
2646 if (put_user(kurb->status, &uurb->status) ||
2647 __put_user(kurb->actual_length, &uurb->actual_length) ||
2648 __put_user(kurb->error_count, &uurb->error_count))
2649 return -EFAULT;
2651 if (kurb->number_of_packets != 0) {
2652 int i;
2654 for (i = 0; i < kurb->number_of_packets; i++) {
2655 if (__put_user(kurb->iso_frame_desc[i].actual_length,
2656 &uurb->iso_frame_desc[i].actual_length) ||
2657 __put_user(kurb->iso_frame_desc[i].status,
2658 &uurb->iso_frame_desc[i].status))
2659 return -EFAULT;
2663 return 0;
2666 static int get_urb32_isoframes(struct usbdevfs_urb *kurb,
2667 struct usbdevfs_urb32 *uurb)
2669 unsigned int totlen;
2670 int i;
2672 if (kurb->type != USBDEVFS_URB_TYPE_ISO) {
2673 kurb->number_of_packets = 0;
2674 return 0;
2677 if (kurb->number_of_packets < 1 ||
2678 kurb->number_of_packets > 128)
2679 return -EINVAL;
2681 if (copy_from_user(&kurb->iso_frame_desc[0],
2682 &uurb->iso_frame_desc[0],
2683 sizeof(struct usbdevfs_iso_packet_desc) *
2684 kurb->number_of_packets))
2685 return -EFAULT;
2687 totlen = 0;
2688 for (i = 0; i < kurb->number_of_packets; i++) {
2689 unsigned int this_len;
2691 this_len = kurb->iso_frame_desc[i].length;
2692 if (this_len > 1023)
2693 return -EINVAL;
2695 totlen += this_len;
2698 if (totlen > 32768)
2699 return -EINVAL;
2701 kurb->buffer_length = totlen;
2703 return 0;
2706 static int do_usbdevfs_urb(unsigned int fd, unsigned int cmd, unsigned long arg)
2708 struct usbdevfs_urb *kurb;
2709 struct usbdevfs_urb32 *uurb;
2710 mm_segment_t old_fs;
2711 __u32 udata;
2712 void *uptr, *kptr;
2713 unsigned int buflen;
2714 int err;
2716 uurb = compat_ptr(arg);
2718 err = -ENOMEM;
2719 kurb = kmalloc(sizeof(struct usbdevfs_urb) +
2720 (sizeof(struct usbdevfs_iso_packet_desc) * 128),
2721 GFP_KERNEL);
2722 if (!kurb)
2723 goto out;
2725 err = -EFAULT;
2726 if (get_urb32(kurb, uurb))
2727 goto out;
2729 err = get_urb32_isoframes(kurb, uurb);
2730 if (err)
2731 goto out;
2733 err = -EFAULT;
2734 if (__get_user(udata, &uurb->buffer))
2735 goto out;
2736 uptr = compat_ptr(udata);
2738 buflen = kurb->buffer_length;
2739 err = verify_area(VERIFY_WRITE, uptr, buflen);
2740 if (err)
2741 goto out;
2744 old_fs = get_fs();
2745 set_fs(KERNEL_DS);
2746 err = sys_ioctl(fd, USBDEVFS_SUBMITURB, (unsigned long) kurb);
2747 set_fs(old_fs);
2749 if (err >= 0) {
2750 /* RED-PEN Shit, this doesn't work for async URBs :-( XXX */
2751 if (put_urb32(kurb, uurb)) {
2752 err = -EFAULT;
2756 out:
2757 kfree(kurb);
2758 return err;
2760 #endif
2762 #define USBDEVFS_REAPURB32 _IOW('U', 12, u32)
2763 #define USBDEVFS_REAPURBNDELAY32 _IOW('U', 13, u32)
2765 static int do_usbdevfs_reapurb(unsigned int fd, unsigned int cmd, unsigned long arg)
2767 mm_segment_t old_fs;
2768 void *kptr;
2769 int err;
2771 old_fs = get_fs();
2772 set_fs(KERNEL_DS);
2773 err = sys_ioctl(fd,
2774 (cmd == USBDEVFS_REAPURB32 ?
2775 USBDEVFS_REAPURB :
2776 USBDEVFS_REAPURBNDELAY),
2777 (unsigned long) &kptr);
2778 set_fs(old_fs);
2780 if (err >= 0 &&
2781 put_user((u32)(u64)kptr, (u32 __user *)compat_ptr(arg)))
2782 err = -EFAULT;
2784 return err;
2787 struct usbdevfs_disconnectsignal32 {
2788 compat_int_t signr;
2789 compat_caddr_t context;
2792 #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2794 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2796 struct usbdevfs_disconnectsignal kdis;
2797 struct usbdevfs_disconnectsignal32 __user *udis;
2798 mm_segment_t old_fs;
2799 u32 uctx;
2800 int err;
2802 udis = compat_ptr(arg);
2804 if (get_user(kdis.signr, &udis->signr) ||
2805 __get_user(uctx, &udis->context))
2806 return -EFAULT;
2808 kdis.context = compat_ptr(uctx);
2810 old_fs = get_fs();
2811 set_fs(KERNEL_DS);
2812 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2813 set_fs(old_fs);
2815 return err;
2819 * I2C layer ioctls
2822 struct i2c_msg32 {
2823 u16 addr;
2824 u16 flags;
2825 u16 len;
2826 compat_caddr_t buf;
2829 struct i2c_rdwr_ioctl_data32 {
2830 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2831 u32 nmsgs;
2834 struct i2c_smbus_ioctl_data32 {
2835 u8 read_write;
2836 u8 command;
2837 u32 size;
2838 compat_caddr_t data; /* union i2c_smbus_data *data */
2841 static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2843 struct i2c_rdwr_ioctl_data __user *tdata;
2844 struct i2c_rdwr_ioctl_data32 __user *udata;
2845 struct i2c_msg __user *tmsgs;
2846 struct i2c_msg32 __user *umsgs;
2847 compat_caddr_t datap;
2848 int nmsgs, i;
2850 tdata = compat_alloc_user_space(sizeof(*tdata));
2851 if (tdata == NULL)
2852 return -ENOMEM;
2853 if (verify_area(VERIFY_WRITE, tdata, sizeof(*tdata)))
2854 return -EFAULT;
2856 udata = compat_ptr(arg);
2857 if (verify_area(VERIFY_READ, udata, sizeof(*udata)))
2858 return -EFAULT;
2859 if (__get_user(nmsgs, &udata->nmsgs) || __put_user(nmsgs, &tdata->nmsgs))
2860 return -EFAULT;
2861 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2862 return -EINVAL;
2863 if (__get_user(datap, &udata->msgs))
2864 return -EFAULT;
2865 umsgs = compat_ptr(datap);
2866 if (verify_area(VERIFY_READ, umsgs, sizeof(struct i2c_msg) * nmsgs))
2867 return -EFAULT;
2869 tmsgs = compat_alloc_user_space(sizeof(struct i2c_msg) * nmsgs);
2870 if (tmsgs == NULL)
2871 return -ENOMEM;
2872 if (verify_area(VERIFY_WRITE, tmsgs, sizeof(struct i2c_msg) * nmsgs))
2873 return -EFAULT;
2874 if (__put_user(tmsgs, &tdata->msgs))
2875 return -ENOMEM;
2876 for (i = 0; i < nmsgs; i++) {
2877 if (__copy_in_user(&tmsgs[i].addr,
2878 &umsgs[i].addr,
2879 3 * sizeof(u16)))
2880 return -EFAULT;
2881 if (__get_user(datap, &umsgs[i].buf) ||
2882 __put_user(compat_ptr(datap), &tmsgs[i].buf))
2883 return -EFAULT;
2885 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2888 static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2890 struct i2c_smbus_ioctl_data __user *tdata;
2891 struct i2c_smbus_ioctl_data32 __user *udata;
2892 compat_caddr_t datap;
2894 tdata = compat_alloc_user_space(sizeof(*tdata));
2895 if (tdata == NULL)
2896 return -ENOMEM;
2897 if (verify_area(VERIFY_WRITE, tdata, sizeof(*tdata)))
2898 return -EFAULT;
2900 udata = compat_ptr(arg);
2901 if (verify_area(VERIFY_READ, udata, sizeof(*udata)))
2902 return -EFAULT;
2904 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2905 return -EFAULT;
2906 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2907 return -EFAULT;
2908 if (__get_user(datap, &udata->data) ||
2909 __put_user(compat_ptr(datap), &tdata->data))
2910 return -EFAULT;
2912 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2915 struct compat_iw_point {
2916 compat_caddr_t pointer;
2917 __u16 length;
2918 __u16 flags;
2921 static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2923 struct iwreq __user *iwr;
2924 struct iwreq __user *iwr_u;
2925 struct iw_point __user *iwp;
2926 struct compat_iw_point __user *iwp_u;
2927 compat_caddr_t pointer;
2928 __u16 length, flags;
2930 iwr_u = compat_ptr(arg);
2931 iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2932 iwr = compat_alloc_user_space(sizeof(*iwr));
2933 if (iwr == NULL)
2934 return -ENOMEM;
2936 iwp = &iwr->u.data;
2938 if (verify_area(VERIFY_WRITE, iwr, sizeof(*iwr)))
2939 return -EFAULT;
2941 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2942 &iwr_u->ifr_ifrn.ifrn_name[0],
2943 sizeof(iwr->ifr_ifrn.ifrn_name)))
2944 return -EFAULT;
2946 if (__get_user(pointer, &iwp_u->pointer) ||
2947 __get_user(length, &iwp_u->length) ||
2948 __get_user(flags, &iwp_u->flags))
2949 return -EFAULT;
2951 if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
2952 __put_user(length, &iwp->length) ||
2953 __put_user(flags, &iwp->flags))
2954 return -EFAULT;
2956 return sys_ioctl(fd, cmd, (unsigned long) iwr);
2959 /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2960 * for some operations; this forces use of the newer bridge-utils that
2961 * use compatiable ioctls
2963 static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2965 u32 tmp;
2967 if (get_user(tmp, (u32 __user *) arg))
2968 return -EFAULT;
2969 if (tmp == BRCTL_GET_VERSION)
2970 return BRCTL_VERSION + 1;
2971 return -EINVAL;
2974 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
2975 struct ncp_ioctl_request_32 {
2976 u32 function;
2977 u32 size;
2978 compat_caddr_t data;
2981 struct ncp_fs_info_v2_32 {
2982 s32 version;
2983 u32 mounted_uid;
2984 u32 connection;
2985 u32 buffer_size;
2987 u32 volume_number;
2988 u32 directory_id;
2990 u32 dummy1;
2991 u32 dummy2;
2992 u32 dummy3;
2995 struct ncp_objectname_ioctl_32
2997 s32 auth_type;
2998 u32 object_name_len;
2999 compat_caddr_t object_name; /* an userspace data, in most cases user name */
3002 struct ncp_privatedata_ioctl_32
3004 u32 len;
3005 compat_caddr_t data; /* ~1000 for NDS */
3008 #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
3009 #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32)
3010 #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
3011 #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
3012 #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
3013 #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
3014 #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
3016 static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
3018 struct ncp_ioctl_request_32 n32;
3019 struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p));
3021 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) ||
3022 put_user(n32.function, &p->function) ||
3023 put_user(n32.size, &p->size) ||
3024 put_user(compat_ptr(n32.data), &p->data))
3025 return -EFAULT;
3027 return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p);
3030 static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
3032 mm_segment_t old_fs = get_fs();
3033 __kernel_uid_t kuid;
3034 int err;
3036 cmd = NCP_IOC_GETMOUNTUID2;
3038 set_fs(KERNEL_DS);
3039 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
3040 set_fs(old_fs);
3042 if (!err)
3043 err = put_user(kuid,
3044 (unsigned int __user *) compat_ptr(arg));
3046 return err;
3049 static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
3051 mm_segment_t old_fs = get_fs();
3052 struct ncp_fs_info_v2_32 n32;
3053 struct ncp_fs_info_v2 n;
3054 int err;
3056 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)))
3057 return -EFAULT;
3058 if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
3059 return -EINVAL;
3060 n.version = NCP_GET_FS_INFO_VERSION_V2;
3062 set_fs(KERNEL_DS);
3063 err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
3064 set_fs(old_fs);
3066 if (!err) {
3067 n32.version = n.version;
3068 n32.mounted_uid = n.mounted_uid;
3069 n32.connection = n.connection;
3070 n32.buffer_size = n.buffer_size;
3071 n32.volume_number = n.volume_number;
3072 n32.directory_id = n.directory_id;
3073 n32.dummy1 = n.dummy1;
3074 n32.dummy2 = n.dummy2;
3075 n32.dummy3 = n.dummy3;
3076 err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0;
3078 return err;
3081 static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
3083 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
3084 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
3085 s32 auth_type;
3086 u32 name_len;
3087 int err;
3089 if (copy_from_user(&n32, p32, sizeof(n32)) ||
3090 put_user(n32.object_name_len, &p->object_name_len) ||
3091 put_user(compat_ptr(n32.object_name), &p->object_name))
3092 return -EFAULT;
3094 err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p);
3095 if (err)
3096 return err;
3098 if (get_user(auth_type, &p->auth_type) ||
3099 put_user(auth_type, &p32->auth_type) ||
3100 get_user(name_len, &p->object_name_len) ||
3101 put_user(name_len, &p32->object_name_len))
3102 return -EFAULT;
3104 return 0;
3107 static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
3109 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
3110 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
3112 if (copy_from_user(&n32, p32, sizeof(n32)) ||
3113 put_user(n32.auth_type, &p->auth_type) ||
3114 put_user(n32.object_name_len, &p->object_name_len) ||
3115 put_user(compat_ptr(n32.object_name), &p->object_name))
3116 return -EFAULT;
3118 return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p);
3121 static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
3123 struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg);
3124 struct ncp_privatedata_ioctl __user *p =
3125 compat_alloc_user_space(sizeof(*p));
3126 u32 len;
3127 int err;
3129 if (copy_from_user(&n32, p32, sizeof(n32)) ||
3130 put_user(n32.len, &p->len) ||
3131 put_user(compat_ptr(n32.data), &p->data))
3132 return -EFAULT;
3134 err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p);
3135 if (err)
3136 return err;
3138 if (get_user(len, &p->len) ||
3139 put_user(len, &p32->len))
3140 return -EFAULT;
3142 return 0;
3145 static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
3147 struct ncp_privatedata_ioctl_32 n32;
3148 struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg);
3149 struct ncp_privatedata_ioctl __user *p =
3150 compat_alloc_user_space(sizeof(*p));
3152 if (copy_from_user(&n32, p32, sizeof(n32)) ||
3153 put_user(n32.len, &p->len) ||
3154 put_user(compat_ptr(n32.data), &p->data))
3155 return -EFAULT;
3157 return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p);
3159 #endif
3161 #undef CODE
3162 #endif
3164 #ifdef DECLARES
3165 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
3166 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
3167 #ifdef CONFIG_NET
3168 HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
3169 HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
3170 HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
3171 HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
3172 HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
3173 HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
3174 HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
3175 HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
3176 HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
3177 HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
3178 HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
3179 HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
3180 HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
3181 HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
3182 HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
3183 HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
3184 HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
3185 HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
3186 HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
3187 HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
3188 HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
3189 HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
3190 HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
3191 HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
3192 HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
3193 HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
3194 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
3195 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
3196 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
3197 HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
3198 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
3199 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
3200 HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
3201 HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
3202 HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
3203 HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
3204 HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
3205 HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
3206 HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
3207 HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
3208 HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
3209 /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
3210 HANDLE_IOCTL(SIOCRTMSG, ret_einval)
3211 HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
3212 #endif
3213 HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
3214 HANDLE_IOCTL(BLKRAGET, w_long)
3215 HANDLE_IOCTL(BLKGETSIZE, w_long)
3216 HANDLE_IOCTL(0x1260, broken_blkgetsize)
3217 HANDLE_IOCTL(BLKFRAGET, w_long)
3218 HANDLE_IOCTL(BLKSECTGET, w_long)
3219 HANDLE_IOCTL(FBIOGET_FSCREENINFO, fb_ioctl_trans)
3220 HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
3221 HANDLE_IOCTL(FBIOGETCMAP, fb_ioctl_trans)
3222 HANDLE_IOCTL(FBIOPUTCMAP, fb_ioctl_trans)
3223 HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
3224 HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
3225 HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
3226 HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
3227 HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
3228 HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
3229 HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
3230 HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
3231 HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
3232 HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
3233 HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
3234 HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
3235 HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
3236 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
3237 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
3238 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
3239 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
3240 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
3241 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
3242 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
3243 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
3244 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
3245 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
3246 HANDLE_IOCTL(MTIOCGETCONFIG32, mt_ioctl_trans)
3247 HANDLE_IOCTL(MTIOCSETCONFIG32, mt_ioctl_trans)
3248 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
3249 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
3250 HANDLE_IOCTL(LOOP_SET_STATUS, loop_status)
3251 HANDLE_IOCTL(LOOP_GET_STATUS, loop_status)
3252 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
3253 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
3254 #ifdef CONFIG_VT
3255 HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
3256 HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
3257 HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
3258 HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
3259 HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
3260 #endif
3261 HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl)
3262 HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl)
3263 HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl)
3264 HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl)
3265 HANDLE_IOCTL(VIDIOCGTUNER32, do_video_ioctl)
3266 HANDLE_IOCTL(VIDIOCSTUNER32, do_video_ioctl)
3267 HANDLE_IOCTL(VIDIOCGWIN32, do_video_ioctl)
3268 HANDLE_IOCTL(VIDIOCSWIN32, do_set_window)
3269 HANDLE_IOCTL(VIDIOCGFBUF32, do_video_ioctl)
3270 HANDLE_IOCTL(VIDIOCSFBUF32, do_video_ioctl)
3271 HANDLE_IOCTL(VIDIOCGFREQ32, do_video_ioctl)
3272 HANDLE_IOCTL(VIDIOCSFREQ32, do_video_ioctl)
3273 /* One SMB ioctl needs translations. */
3274 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
3275 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
3276 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
3277 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
3278 HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
3279 HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
3280 HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
3281 HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
3282 HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
3283 HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
3284 HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
3285 HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
3286 HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
3287 HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
3288 HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
3289 HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
3290 HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
3291 HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
3292 HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
3293 HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
3294 HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
3295 HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
3296 HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
3297 HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
3298 HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
3299 HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
3300 HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
3301 /* block stuff */
3302 HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
3303 HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
3304 HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
3305 /* vfat */
3306 HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
3307 HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
3308 HANDLE_IOCTL(REISERFS_IOC_UNPACK32, reiserfs_ioctl32)
3309 /* Raw devices */
3310 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
3311 HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
3312 /* Serial */
3313 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
3314 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
3315 /* Usbdevfs */
3316 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
3317 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
3318 /*HANDLE_IOCTL(USBDEVFS_SUBMITURB32, do_usbdevfs_urb)*/
3319 HANDLE_IOCTL(USBDEVFS_REAPURB32, do_usbdevfs_reapurb)
3320 HANDLE_IOCTL(USBDEVFS_REAPURBNDELAY32, do_usbdevfs_reapurb)
3321 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
3322 /* i2c */
3323 HANDLE_IOCTL(I2C_FUNCS, w_long)
3324 HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
3325 HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
3326 /* wireless */
3327 HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
3328 HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
3329 HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
3330 HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
3331 HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
3332 HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
3333 HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
3334 HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
3335 HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
3336 HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
3337 HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
3338 HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
3339 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
3340 HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
3341 HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
3343 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
3344 HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest)
3345 HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2)
3346 HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2)
3347 HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname)
3348 HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname)
3349 HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata)
3350 HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata)
3351 #endif
3353 #undef DECLARES
3354 #endif