[PATCH] CPUFREQ: Support rev H AMD64s in powernow-k8
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / compat_ioctl.c
blob8b1c5d8bf4effc57a2d54e40e54bea5081f9f18d
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 #include <linux/types.h>
14 #include <linux/compat.h>
15 #include <linux/kernel.h>
16 #include <linux/capability.h>
17 #include <linux/compiler.h>
18 #include <linux/sched.h>
19 #include <linux/smp.h>
20 #include <linux/smp_lock.h>
21 #include <linux/ioctl.h>
22 #include <linux/if.h>
23 #include <linux/if_bridge.h>
24 #include <linux/slab.h>
25 #include <linux/hdreg.h>
26 #include <linux/raid/md.h>
27 #include <linux/kd.h>
28 #include <linux/dirent.h>
29 #include <linux/route.h>
30 #include <linux/in6.h>
31 #include <linux/ipv6_route.h>
32 #include <linux/skbuff.h>
33 #include <linux/netlink.h>
34 #include <linux/vt.h>
35 #include <linux/fs.h>
36 #include <linux/file.h>
37 #include <linux/fd.h>
38 #include <linux/ppp_defs.h>
39 #include <linux/if_ppp.h>
40 #include <linux/if_pppox.h>
41 #include <linux/mtio.h>
42 #include <linux/cdrom.h>
43 #include <linux/auto_fs.h>
44 #include <linux/auto_fs4.h>
45 #include <linux/tty.h>
46 #include <linux/vt_kern.h>
47 #include <linux/fb.h>
48 #include <linux/videodev.h>
49 #include <linux/netdevice.h>
50 #include <linux/raw.h>
51 #include <linux/smb_fs.h>
52 #include <linux/blkpg.h>
53 #include <linux/blkdev.h>
54 #include <linux/elevator.h>
55 #include <linux/rtc.h>
56 #include <linux/pci.h>
57 #include <linux/module.h>
58 #include <linux/serial.h>
59 #include <linux/if_tun.h>
60 #include <linux/ctype.h>
61 #include <linux/ioctl32.h>
62 #include <linux/syscalls.h>
63 #include <linux/i2c.h>
64 #include <linux/i2c-dev.h>
65 #include <linux/wireless.h>
66 #include <linux/atalk.h>
67 #include <linux/blktrace_api.h>
69 #include <net/sock.h> /* siocdevprivate_ioctl */
70 #include <net/bluetooth/bluetooth.h>
71 #include <net/bluetooth/hci.h>
72 #include <net/bluetooth/rfcomm.h>
74 #include <linux/capi.h>
75 #include <linux/gigaset_dev.h>
77 #include <scsi/scsi.h>
78 #include <scsi/scsi_ioctl.h>
79 #include <scsi/sg.h>
81 #include <asm/uaccess.h>
82 #include <linux/ethtool.h>
83 #include <linux/mii.h>
84 #include <linux/if_bonding.h>
85 #include <linux/watchdog.h>
86 #include <linux/dm-ioctl.h>
88 #include <linux/soundcard.h>
89 #include <linux/lp.h>
90 #include <linux/ppdev.h>
92 #include <linux/atm.h>
93 #include <linux/atmarp.h>
94 #include <linux/atmclip.h>
95 #include <linux/atmdev.h>
96 #include <linux/atmioc.h>
97 #include <linux/atmlec.h>
98 #include <linux/atmmpc.h>
99 #include <linux/atmsvc.h>
100 #include <linux/atm_tcp.h>
101 #include <linux/sonet.h>
102 #include <linux/atm_suni.h>
103 #include <linux/mtd/mtd.h>
105 #include <linux/usb.h>
106 #include <linux/usbdevice_fs.h>
107 #include <linux/nbd.h>
108 #include <linux/random.h>
109 #include <linux/filter.h>
110 #include <linux/pktcdvd.h>
112 #include <linux/hiddev.h>
114 #include <linux/dvb/audio.h>
115 #include <linux/dvb/dmx.h>
116 #include <linux/dvb/frontend.h>
117 #include <linux/dvb/video.h>
118 #include <linux/lp.h>
120 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
121 unsigned long arg, struct file *f)
123 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
126 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
128 mm_segment_t old_fs = get_fs();
129 int err;
130 unsigned long val;
132 set_fs (KERNEL_DS);
133 err = sys_ioctl(fd, cmd, (unsigned long)&val);
134 set_fs (old_fs);
135 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
136 return -EFAULT;
137 return err;
140 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
142 mm_segment_t old_fs = get_fs();
143 u32 __user *argptr = compat_ptr(arg);
144 int err;
145 unsigned long val;
147 if(get_user(val, argptr))
148 return -EFAULT;
149 set_fs (KERNEL_DS);
150 err = sys_ioctl(fd, cmd, (unsigned long)&val);
151 set_fs (old_fs);
152 if (!err && put_user(val, argptr))
153 return -EFAULT;
154 return err;
157 struct compat_video_event {
158 int32_t type;
159 compat_time_t timestamp;
160 union {
161 video_size_t size;
162 unsigned int frame_rate;
163 } u;
166 static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
168 struct video_event kevent;
169 mm_segment_t old_fs = get_fs();
170 int err;
172 set_fs(KERNEL_DS);
173 err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
174 set_fs(old_fs);
176 if (!err) {
177 struct compat_video_event __user *up = compat_ptr(arg);
179 err = put_user(kevent.type, &up->type);
180 err |= put_user(kevent.timestamp, &up->timestamp);
181 err |= put_user(kevent.u.size.w, &up->u.size.w);
182 err |= put_user(kevent.u.size.h, &up->u.size.h);
183 err |= put_user(kevent.u.size.aspect_ratio,
184 &up->u.size.aspect_ratio);
185 if (err)
186 err = -EFAULT;
189 return err;
192 struct compat_video_still_picture {
193 compat_uptr_t iFrame;
194 int32_t size;
197 static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
199 struct compat_video_still_picture __user *up;
200 struct video_still_picture __user *up_native;
201 compat_uptr_t fp;
202 int32_t size;
203 int err;
205 up = (struct compat_video_still_picture __user *) arg;
206 err = get_user(fp, &up->iFrame);
207 err |= get_user(size, &up->size);
208 if (err)
209 return -EFAULT;
211 up_native =
212 compat_alloc_user_space(sizeof(struct video_still_picture));
214 err = put_user(compat_ptr(fp), &up_native->iFrame);
215 err |= put_user(size, &up_native->size);
216 if (err)
217 return -EFAULT;
219 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
221 return err;
224 struct compat_video_spu_palette {
225 int length;
226 compat_uptr_t palette;
229 static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
231 struct compat_video_spu_palette __user *up;
232 struct video_spu_palette __user *up_native;
233 compat_uptr_t palp;
234 int length, err;
236 up = (struct compat_video_spu_palette __user *) arg;
237 err = get_user(palp, &up->palette);
238 err |= get_user(length, &up->length);
240 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
241 err = put_user(compat_ptr(palp), &up_native->palette);
242 err |= put_user(length, &up_native->length);
243 if (err)
244 return -EFAULT;
246 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
248 return err;
251 #ifdef CONFIG_NET
252 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
254 struct compat_timeval __user *up = compat_ptr(arg);
255 struct timeval ktv;
256 mm_segment_t old_fs = get_fs();
257 int err;
259 set_fs(KERNEL_DS);
260 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
261 set_fs(old_fs);
262 if(!err) {
263 err = put_user(ktv.tv_sec, &up->tv_sec);
264 err |= __put_user(ktv.tv_usec, &up->tv_usec);
266 return err;
269 struct ifmap32 {
270 compat_ulong_t mem_start;
271 compat_ulong_t mem_end;
272 unsigned short base_addr;
273 unsigned char irq;
274 unsigned char dma;
275 unsigned char port;
278 struct ifreq32 {
279 #define IFHWADDRLEN 6
280 #define IFNAMSIZ 16
281 union {
282 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
283 } ifr_ifrn;
284 union {
285 struct sockaddr ifru_addr;
286 struct sockaddr ifru_dstaddr;
287 struct sockaddr ifru_broadaddr;
288 struct sockaddr ifru_netmask;
289 struct sockaddr ifru_hwaddr;
290 short ifru_flags;
291 compat_int_t ifru_ivalue;
292 compat_int_t ifru_mtu;
293 struct ifmap32 ifru_map;
294 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
295 char ifru_newname[IFNAMSIZ];
296 compat_caddr_t ifru_data;
297 /* XXXX? ifru_settings should be here */
298 } ifr_ifru;
301 struct ifconf32 {
302 compat_int_t ifc_len; /* size of buffer */
303 compat_caddr_t ifcbuf;
306 static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
308 struct net_device *dev;
309 struct ifreq32 ifr32;
310 int err;
312 if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
313 return -EFAULT;
315 dev = dev_get_by_index(ifr32.ifr_ifindex);
316 if (!dev)
317 return -ENODEV;
319 strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
320 dev_put(dev);
322 err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
323 return (err ? -EFAULT : 0);
326 static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
328 struct ifconf32 ifc32;
329 struct ifconf ifc;
330 struct ifconf __user *uifc;
331 struct ifreq32 __user *ifr32;
332 struct ifreq __user *ifr;
333 unsigned int i, j;
334 int err;
336 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
337 return -EFAULT;
339 if (ifc32.ifcbuf == 0) {
340 ifc32.ifc_len = 0;
341 ifc.ifc_len = 0;
342 ifc.ifc_req = NULL;
343 uifc = compat_alloc_user_space(sizeof(struct ifconf));
344 } else {
345 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
346 sizeof (struct ifreq);
347 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
348 ifc.ifc_len = len;
349 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
350 ifr32 = compat_ptr(ifc32.ifcbuf);
351 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
352 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
353 return -EFAULT;
354 ifr++;
355 ifr32++;
358 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
359 return -EFAULT;
361 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
362 if (err)
363 return err;
365 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
366 return -EFAULT;
368 ifr = ifc.ifc_req;
369 ifr32 = compat_ptr(ifc32.ifcbuf);
370 for (i = 0, j = 0;
371 i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
372 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
373 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
374 return -EFAULT;
375 ifr32++;
376 ifr++;
379 if (ifc32.ifcbuf == 0) {
380 /* Translate from 64-bit structure multiple to
381 * a 32-bit one.
383 i = ifc.ifc_len;
384 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
385 ifc32.ifc_len = i;
386 } else {
387 ifc32.ifc_len = i;
389 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
390 return -EFAULT;
392 return 0;
395 static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
397 struct ifreq __user *ifr;
398 struct ifreq32 __user *ifr32;
399 u32 data;
400 void __user *datap;
402 ifr = compat_alloc_user_space(sizeof(*ifr));
403 ifr32 = compat_ptr(arg);
405 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
406 return -EFAULT;
408 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
409 return -EFAULT;
411 datap = compat_ptr(data);
412 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
413 return -EFAULT;
415 return sys_ioctl(fd, cmd, (unsigned long) ifr);
418 static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
420 struct ifreq kifr;
421 struct ifreq __user *uifr;
422 struct ifreq32 __user *ifr32 = compat_ptr(arg);
423 mm_segment_t old_fs;
424 int err;
425 u32 data;
426 void __user *datap;
428 switch (cmd) {
429 case SIOCBONDENSLAVE:
430 case SIOCBONDRELEASE:
431 case SIOCBONDSETHWADDR:
432 case SIOCBONDCHANGEACTIVE:
433 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
434 return -EFAULT;
436 old_fs = get_fs();
437 set_fs (KERNEL_DS);
438 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
439 set_fs (old_fs);
441 return err;
442 case SIOCBONDSLAVEINFOQUERY:
443 case SIOCBONDINFOQUERY:
444 uifr = compat_alloc_user_space(sizeof(*uifr));
445 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
446 return -EFAULT;
448 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
449 return -EFAULT;
451 datap = compat_ptr(data);
452 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
453 return -EFAULT;
455 return sys_ioctl (fd, cmd, (unsigned long)uifr);
456 default:
457 return -EINVAL;
461 int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
463 struct ifreq __user *u_ifreq64;
464 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
465 char tmp_buf[IFNAMSIZ];
466 void __user *data64;
467 u32 data32;
469 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
470 IFNAMSIZ))
471 return -EFAULT;
472 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
473 return -EFAULT;
474 data64 = compat_ptr(data32);
476 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
478 /* Don't check these user accesses, just let that get trapped
479 * in the ioctl handler instead.
481 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
482 IFNAMSIZ))
483 return -EFAULT;
484 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
485 return -EFAULT;
487 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
490 static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
492 struct ifreq ifr;
493 struct ifreq32 __user *uifr32;
494 struct ifmap32 __user *uifmap32;
495 mm_segment_t old_fs;
496 int err;
498 uifr32 = compat_ptr(arg);
499 uifmap32 = &uifr32->ifr_ifru.ifru_map;
500 switch (cmd) {
501 case SIOCSIFMAP:
502 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
503 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
504 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
505 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
506 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
507 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
508 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
509 if (err)
510 return -EFAULT;
511 break;
512 default:
513 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
514 return -EFAULT;
515 break;
517 old_fs = get_fs();
518 set_fs (KERNEL_DS);
519 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
520 set_fs (old_fs);
521 if (!err) {
522 switch (cmd) {
523 /* TUNSETIFF is defined as _IOW, it should be _IORW
524 * as the data is copied back to user space, but that
525 * cannot be fixed without breaking all existing apps.
527 case TUNSETIFF:
528 case SIOCGIFFLAGS:
529 case SIOCGIFMETRIC:
530 case SIOCGIFMTU:
531 case SIOCGIFMEM:
532 case SIOCGIFHWADDR:
533 case SIOCGIFINDEX:
534 case SIOCGIFADDR:
535 case SIOCGIFBRDADDR:
536 case SIOCGIFDSTADDR:
537 case SIOCGIFNETMASK:
538 case SIOCGIFTXQLEN:
539 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
540 return -EFAULT;
541 break;
542 case SIOCGIFMAP:
543 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
544 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
545 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
546 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
547 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
548 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
549 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
550 if (err)
551 err = -EFAULT;
552 break;
555 return err;
558 struct rtentry32 {
559 u32 rt_pad1;
560 struct sockaddr rt_dst; /* target address */
561 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
562 struct sockaddr rt_genmask; /* target network mask (IP) */
563 unsigned short rt_flags;
564 short rt_pad2;
565 u32 rt_pad3;
566 unsigned char rt_tos;
567 unsigned char rt_class;
568 short rt_pad4;
569 short rt_metric; /* +1 for binary compatibility! */
570 /* char * */ u32 rt_dev; /* forcing the device at add */
571 u32 rt_mtu; /* per route MTU/Window */
572 u32 rt_window; /* Window clamping */
573 unsigned short rt_irtt; /* Initial RTT */
577 struct in6_rtmsg32 {
578 struct in6_addr rtmsg_dst;
579 struct in6_addr rtmsg_src;
580 struct in6_addr rtmsg_gateway;
581 u32 rtmsg_type;
582 u16 rtmsg_dst_len;
583 u16 rtmsg_src_len;
584 u32 rtmsg_metric;
585 u32 rtmsg_info;
586 u32 rtmsg_flags;
587 s32 rtmsg_ifindex;
590 static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
592 int ret;
593 void *r = NULL;
594 struct in6_rtmsg r6;
595 struct rtentry r4;
596 char devname[16];
597 u32 rtdev;
598 mm_segment_t old_fs = get_fs();
600 struct socket *mysock = sockfd_lookup(fd, &ret);
602 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
603 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
604 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
605 3 * sizeof(struct in6_addr));
606 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
607 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
608 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
609 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
610 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
611 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
612 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
614 r = (void *) &r6;
615 } else { /* ipv4 */
616 struct rtentry32 __user *ur4 = compat_ptr(arg);
617 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
618 3 * sizeof(struct sockaddr));
619 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
620 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
621 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
622 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
623 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
624 ret |= __get_user (rtdev, &(ur4->rt_dev));
625 if (rtdev) {
626 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
627 r4.rt_dev = devname; devname[15] = 0;
628 } else
629 r4.rt_dev = NULL;
631 r = (void *) &r4;
634 if (ret) {
635 ret = -EFAULT;
636 goto out;
639 set_fs (KERNEL_DS);
640 ret = sys_ioctl (fd, cmd, (unsigned long) r);
641 set_fs (old_fs);
643 out:
644 if (mysock)
645 sockfd_put(mysock);
647 return ret;
649 #endif
651 #ifdef CONFIG_BLOCK
652 struct hd_geometry32 {
653 unsigned char heads;
654 unsigned char sectors;
655 unsigned short cylinders;
656 u32 start;
659 static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
661 mm_segment_t old_fs = get_fs();
662 struct hd_geometry geo;
663 struct hd_geometry32 __user *ugeo;
664 int err;
666 set_fs (KERNEL_DS);
667 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
668 set_fs (old_fs);
669 ugeo = compat_ptr(arg);
670 if (!err) {
671 err = copy_to_user (ugeo, &geo, 4);
672 err |= __put_user (geo.start, &ugeo->start);
674 return err ? -EFAULT : 0;
677 static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
679 mm_segment_t old_fs = get_fs();
680 unsigned long kval;
681 unsigned int __user *uvp;
682 int error;
684 set_fs(KERNEL_DS);
685 error = sys_ioctl(fd, cmd, (long)&kval);
686 set_fs(old_fs);
688 if(error == 0) {
689 uvp = compat_ptr(arg);
690 if(put_user(kval, uvp))
691 error = -EFAULT;
693 return error;
697 typedef struct sg_io_hdr32 {
698 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
699 compat_int_t dxfer_direction; /* [i] data transfer direction */
700 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
701 unsigned char mx_sb_len; /* [i] max length to write to sbp */
702 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
703 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
704 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
705 or scatter gather list */
706 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
707 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
708 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
709 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
710 compat_int_t pack_id; /* [i->o] unused internally (normally) */
711 compat_uptr_t usr_ptr; /* [i->o] unused internally */
712 unsigned char status; /* [o] scsi status */
713 unsigned char masked_status; /* [o] shifted, masked scsi status */
714 unsigned char msg_status; /* [o] messaging level data (optional) */
715 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
716 unsigned short host_status; /* [o] errors from host adapter */
717 unsigned short driver_status; /* [o] errors from software driver */
718 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
719 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
720 compat_uint_t info; /* [o] auxiliary information */
721 } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
723 typedef struct sg_iovec32 {
724 compat_uint_t iov_base;
725 compat_uint_t iov_len;
726 } sg_iovec32_t;
728 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
730 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
731 sg_iovec32_t __user *iov32 = dxferp;
732 int i;
734 for (i = 0; i < iovec_count; i++) {
735 u32 base, len;
737 if (get_user(base, &iov32[i].iov_base) ||
738 get_user(len, &iov32[i].iov_len) ||
739 put_user(compat_ptr(base), &iov[i].iov_base) ||
740 put_user(len, &iov[i].iov_len))
741 return -EFAULT;
744 if (put_user(iov, &sgio->dxferp))
745 return -EFAULT;
746 return 0;
749 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
751 sg_io_hdr_t __user *sgio;
752 sg_io_hdr32_t __user *sgio32;
753 u16 iovec_count;
754 u32 data;
755 void __user *dxferp;
756 int err;
758 sgio32 = compat_ptr(arg);
759 if (get_user(iovec_count, &sgio32->iovec_count))
760 return -EFAULT;
763 void __user *top = compat_alloc_user_space(0);
764 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
765 (iovec_count * sizeof(sg_iovec_t)));
766 if (new > top)
767 return -EINVAL;
769 sgio = new;
772 /* Ok, now construct. */
773 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
774 (2 * sizeof(int)) +
775 (2 * sizeof(unsigned char)) +
776 (1 * sizeof(unsigned short)) +
777 (1 * sizeof(unsigned int))))
778 return -EFAULT;
780 if (get_user(data, &sgio32->dxferp))
781 return -EFAULT;
782 dxferp = compat_ptr(data);
783 if (iovec_count) {
784 if (sg_build_iovec(sgio, dxferp, iovec_count))
785 return -EFAULT;
786 } else {
787 if (put_user(dxferp, &sgio->dxferp))
788 return -EFAULT;
792 unsigned char __user *cmdp;
793 unsigned char __user *sbp;
795 if (get_user(data, &sgio32->cmdp))
796 return -EFAULT;
797 cmdp = compat_ptr(data);
799 if (get_user(data, &sgio32->sbp))
800 return -EFAULT;
801 sbp = compat_ptr(data);
803 if (put_user(cmdp, &sgio->cmdp) ||
804 put_user(sbp, &sgio->sbp))
805 return -EFAULT;
808 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
809 3 * sizeof(int)))
810 return -EFAULT;
812 if (get_user(data, &sgio32->usr_ptr))
813 return -EFAULT;
814 if (put_user(compat_ptr(data), &sgio->usr_ptr))
815 return -EFAULT;
817 if (copy_in_user(&sgio->status, &sgio32->status,
818 (4 * sizeof(unsigned char)) +
819 (2 * sizeof(unsigned (short))) +
820 (3 * sizeof(int))))
821 return -EFAULT;
823 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
825 if (err >= 0) {
826 void __user *datap;
828 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
829 sizeof(int)) ||
830 get_user(datap, &sgio->usr_ptr) ||
831 put_user((u32)(unsigned long)datap,
832 &sgio32->usr_ptr) ||
833 copy_in_user(&sgio32->status, &sgio->status,
834 (4 * sizeof(unsigned char)) +
835 (2 * sizeof(unsigned short)) +
836 (3 * sizeof(int))))
837 err = -EFAULT;
840 return err;
843 struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
844 char req_state;
845 char orphan;
846 char sg_io_owned;
847 char problem;
848 int pack_id;
849 compat_uptr_t usr_ptr;
850 unsigned int duration;
851 int unused;
854 static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
856 int err, i;
857 sg_req_info_t __user *r;
858 struct compat_sg_req_info __user *o = (void __user *)arg;
859 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
860 err = sys_ioctl(fd,cmd,(unsigned long)r);
861 if (err < 0)
862 return err;
863 for (i = 0; i < SG_MAX_QUEUE; i++) {
864 void __user *ptr;
865 int d;
867 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
868 get_user(ptr, &r[i].usr_ptr) ||
869 get_user(d, &r[i].duration) ||
870 put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
871 put_user(d, &o[i].duration))
872 return -EFAULT;
874 return err;
876 #endif /* CONFIG_BLOCK */
878 struct sock_fprog32 {
879 unsigned short len;
880 compat_caddr_t filter;
883 #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
884 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
886 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
888 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
889 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
890 void __user *fptr64;
891 u32 fptr32;
892 u16 flen;
894 if (get_user(flen, &u_fprog32->len) ||
895 get_user(fptr32, &u_fprog32->filter))
896 return -EFAULT;
898 fptr64 = compat_ptr(fptr32);
900 if (put_user(flen, &u_fprog64->len) ||
901 put_user(fptr64, &u_fprog64->filter))
902 return -EFAULT;
904 if (cmd == PPPIOCSPASS32)
905 cmd = PPPIOCSPASS;
906 else
907 cmd = PPPIOCSACTIVE;
909 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
912 struct ppp_option_data32 {
913 compat_caddr_t ptr;
914 u32 length;
915 compat_int_t transmit;
917 #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
919 struct ppp_idle32 {
920 compat_time_t xmit_idle;
921 compat_time_t recv_idle;
923 #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
925 static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
927 struct ppp_idle __user *idle;
928 struct ppp_idle32 __user *idle32;
929 __kernel_time_t xmit, recv;
930 int err;
932 idle = compat_alloc_user_space(sizeof(*idle));
933 idle32 = compat_ptr(arg);
935 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
937 if (!err) {
938 if (get_user(xmit, &idle->xmit_idle) ||
939 get_user(recv, &idle->recv_idle) ||
940 put_user(xmit, &idle32->xmit_idle) ||
941 put_user(recv, &idle32->recv_idle))
942 err = -EFAULT;
944 return err;
947 static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
949 struct ppp_option_data __user *odata;
950 struct ppp_option_data32 __user *odata32;
951 __u32 data;
952 void __user *datap;
954 odata = compat_alloc_user_space(sizeof(*odata));
955 odata32 = compat_ptr(arg);
957 if (get_user(data, &odata32->ptr))
958 return -EFAULT;
960 datap = compat_ptr(data);
961 if (put_user(datap, &odata->ptr))
962 return -EFAULT;
964 if (copy_in_user(&odata->length, &odata32->length,
965 sizeof(__u32) + sizeof(int)))
966 return -EFAULT;
968 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
971 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
973 int err;
975 switch (cmd) {
976 case PPPIOCGIDLE32:
977 err = ppp_gidle(fd, cmd, arg);
978 break;
980 case PPPIOCSCOMPRESS32:
981 err = ppp_scompress(fd, cmd, arg);
982 break;
984 default:
985 do {
986 static int count;
987 if (++count <= 20)
988 printk("ppp_ioctl: Unknown cmd fd(%d) "
989 "cmd(%08x) arg(%08x)\n",
990 (int)fd, (unsigned int)cmd, (unsigned int)arg);
991 } while(0);
992 err = -EINVAL;
993 break;
996 return err;
1000 #ifdef CONFIG_BLOCK
1001 struct mtget32 {
1002 compat_long_t mt_type;
1003 compat_long_t mt_resid;
1004 compat_long_t mt_dsreg;
1005 compat_long_t mt_gstat;
1006 compat_long_t mt_erreg;
1007 compat_daddr_t mt_fileno;
1008 compat_daddr_t mt_blkno;
1010 #define MTIOCGET32 _IOR('m', 2, struct mtget32)
1012 struct mtpos32 {
1013 compat_long_t mt_blkno;
1015 #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1017 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1019 mm_segment_t old_fs = get_fs();
1020 struct mtget get;
1021 struct mtget32 __user *umget32;
1022 struct mtpos pos;
1023 struct mtpos32 __user *upos32;
1024 unsigned long kcmd;
1025 void *karg;
1026 int err = 0;
1028 switch(cmd) {
1029 case MTIOCPOS32:
1030 kcmd = MTIOCPOS;
1031 karg = &pos;
1032 break;
1033 case MTIOCGET32:
1034 kcmd = MTIOCGET;
1035 karg = &get;
1036 break;
1037 default:
1038 do {
1039 static int count;
1040 if (++count <= 20)
1041 printk("mt_ioctl: Unknown cmd fd(%d) "
1042 "cmd(%08x) arg(%08x)\n",
1043 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1044 } while(0);
1045 return -EINVAL;
1047 set_fs (KERNEL_DS);
1048 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1049 set_fs (old_fs);
1050 if (err)
1051 return err;
1052 switch (cmd) {
1053 case MTIOCPOS32:
1054 upos32 = compat_ptr(arg);
1055 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1056 break;
1057 case MTIOCGET32:
1058 umget32 = compat_ptr(arg);
1059 err = __put_user(get.mt_type, &umget32->mt_type);
1060 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1061 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1062 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1063 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1064 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1065 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1066 break;
1068 return err ? -EFAULT: 0;
1071 struct cdrom_read_audio32 {
1072 union cdrom_addr addr;
1073 u8 addr_format;
1074 compat_int_t nframes;
1075 compat_caddr_t buf;
1078 struct cdrom_generic_command32 {
1079 unsigned char cmd[CDROM_PACKET_SIZE];
1080 compat_caddr_t buffer;
1081 compat_uint_t buflen;
1082 compat_int_t stat;
1083 compat_caddr_t sense;
1084 unsigned char data_direction;
1085 compat_int_t quiet;
1086 compat_int_t timeout;
1087 compat_caddr_t reserved[1];
1090 static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1092 struct cdrom_read_audio __user *cdread_audio;
1093 struct cdrom_read_audio32 __user *cdread_audio32;
1094 __u32 data;
1095 void __user *datap;
1097 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1098 cdread_audio32 = compat_ptr(arg);
1100 if (copy_in_user(&cdread_audio->addr,
1101 &cdread_audio32->addr,
1102 (sizeof(*cdread_audio32) -
1103 sizeof(compat_caddr_t))))
1104 return -EFAULT;
1106 if (get_user(data, &cdread_audio32->buf))
1107 return -EFAULT;
1108 datap = compat_ptr(data);
1109 if (put_user(datap, &cdread_audio->buf))
1110 return -EFAULT;
1112 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1115 static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1117 struct cdrom_generic_command __user *cgc;
1118 struct cdrom_generic_command32 __user *cgc32;
1119 u32 data;
1120 unsigned char dir;
1121 int itmp;
1123 cgc = compat_alloc_user_space(sizeof(*cgc));
1124 cgc32 = compat_ptr(arg);
1126 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1127 get_user(data, &cgc32->buffer) ||
1128 put_user(compat_ptr(data), &cgc->buffer) ||
1129 copy_in_user(&cgc->buflen, &cgc32->buflen,
1130 (sizeof(unsigned int) + sizeof(int))) ||
1131 get_user(data, &cgc32->sense) ||
1132 put_user(compat_ptr(data), &cgc->sense) ||
1133 get_user(dir, &cgc32->data_direction) ||
1134 put_user(dir, &cgc->data_direction) ||
1135 get_user(itmp, &cgc32->quiet) ||
1136 put_user(itmp, &cgc->quiet) ||
1137 get_user(itmp, &cgc32->timeout) ||
1138 put_user(itmp, &cgc->timeout) ||
1139 get_user(data, &cgc32->reserved[0]) ||
1140 put_user(compat_ptr(data), &cgc->reserved[0]))
1141 return -EFAULT;
1143 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1146 static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1148 int err;
1150 switch(cmd) {
1151 case CDROMREADAUDIO:
1152 err = cdrom_do_read_audio(fd, cmd, arg);
1153 break;
1155 case CDROM_SEND_PACKET:
1156 err = cdrom_do_generic_command(fd, cmd, arg);
1157 break;
1159 default:
1160 do {
1161 static int count;
1162 if (++count <= 20)
1163 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1164 "cmd(%08x) arg(%08x)\n",
1165 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1166 } while(0);
1167 err = -EINVAL;
1168 break;
1171 return err;
1173 #endif /* CONFIG_BLOCK */
1175 #ifdef CONFIG_VT
1177 static int vt_check(struct file *file)
1179 struct tty_struct *tty;
1180 struct inode *inode = file->f_path.dentry->d_inode;
1182 if (file->f_op->ioctl != tty_ioctl)
1183 return -EINVAL;
1185 tty = (struct tty_struct *)file->private_data;
1186 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1187 return -EINVAL;
1189 if (tty->driver->ioctl != vt_ioctl)
1190 return -EINVAL;
1193 * To have permissions to do most of the vt ioctls, we either have
1194 * to be the owner of the tty, or super-user.
1196 if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
1197 return 1;
1198 return 0;
1201 struct consolefontdesc32 {
1202 unsigned short charcount; /* characters in font (256 or 512) */
1203 unsigned short charheight; /* scan lines per character (1-32) */
1204 compat_caddr_t chardata; /* font data in expanded form */
1207 static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1209 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1210 struct console_font_op op;
1211 compat_caddr_t data;
1212 int i, perm;
1214 perm = vt_check(file);
1215 if (perm < 0) return perm;
1217 switch (cmd) {
1218 case PIO_FONTX:
1219 if (!perm)
1220 return -EPERM;
1221 op.op = KD_FONT_OP_SET;
1222 op.flags = 0;
1223 op.width = 8;
1224 if (get_user(op.height, &user_cfd->charheight) ||
1225 get_user(op.charcount, &user_cfd->charcount) ||
1226 get_user(data, &user_cfd->chardata))
1227 return -EFAULT;
1228 op.data = compat_ptr(data);
1229 return con_font_op(vc_cons[fg_console].d, &op);
1230 case GIO_FONTX:
1231 op.op = KD_FONT_OP_GET;
1232 op.flags = 0;
1233 op.width = 8;
1234 if (get_user(op.height, &user_cfd->charheight) ||
1235 get_user(op.charcount, &user_cfd->charcount) ||
1236 get_user(data, &user_cfd->chardata))
1237 return -EFAULT;
1238 if (!data)
1239 return 0;
1240 op.data = compat_ptr(data);
1241 i = con_font_op(vc_cons[fg_console].d, &op);
1242 if (i)
1243 return i;
1244 if (put_user(op.height, &user_cfd->charheight) ||
1245 put_user(op.charcount, &user_cfd->charcount) ||
1246 put_user((compat_caddr_t)(unsigned long)op.data,
1247 &user_cfd->chardata))
1248 return -EFAULT;
1249 return 0;
1251 return -EINVAL;
1254 struct console_font_op32 {
1255 compat_uint_t op; /* operation code KD_FONT_OP_* */
1256 compat_uint_t flags; /* KD_FONT_FLAG_* */
1257 compat_uint_t width, height; /* font size */
1258 compat_uint_t charcount;
1259 compat_caddr_t data; /* font data with height fixed to 32 */
1262 static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1264 struct console_font_op op;
1265 struct console_font_op32 __user *fontop = compat_ptr(arg);
1266 int perm = vt_check(file), i;
1267 struct vc_data *vc;
1269 if (perm < 0) return perm;
1271 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1272 return -EFAULT;
1273 if (!perm && op.op != KD_FONT_OP_GET)
1274 return -EPERM;
1275 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1276 op.flags |= KD_FONT_FLAG_OLD;
1277 vc = ((struct tty_struct *)file->private_data)->driver_data;
1278 i = con_font_op(vc, &op);
1279 if (i)
1280 return i;
1281 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1282 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1283 return -EFAULT;
1284 return 0;
1287 struct unimapdesc32 {
1288 unsigned short entry_ct;
1289 compat_caddr_t entries;
1292 static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1294 struct unimapdesc32 tmp;
1295 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1296 int perm = vt_check(file);
1298 if (perm < 0) return perm;
1299 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1300 return -EFAULT;
1301 switch (cmd) {
1302 case PIO_UNIMAP:
1303 if (!perm) return -EPERM;
1304 return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries));
1305 case GIO_UNIMAP:
1306 return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
1308 return 0;
1311 #endif /* CONFIG_VT */
1313 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1315 mm_segment_t old_fs = get_fs();
1316 __kernel_uid_t kuid;
1317 int err;
1319 cmd = SMB_IOC_GETMOUNTUID;
1321 set_fs(KERNEL_DS);
1322 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1323 set_fs(old_fs);
1325 if (err >= 0)
1326 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1328 return err;
1331 struct atmif_sioc32 {
1332 compat_int_t number;
1333 compat_int_t length;
1334 compat_caddr_t arg;
1337 struct atm_iobuf32 {
1338 compat_int_t length;
1339 compat_caddr_t buffer;
1342 #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1343 #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1344 #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1345 #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1346 #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1347 #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1348 #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1349 #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1350 #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1351 #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1352 #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1353 #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1354 #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1355 #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1356 #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1357 #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1358 #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1360 static struct {
1361 unsigned int cmd32;
1362 unsigned int cmd;
1363 } atm_ioctl_map[] = {
1364 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1365 { ATM_GETNAMES32, ATM_GETNAMES },
1366 { ATM_GETTYPE32, ATM_GETTYPE },
1367 { ATM_GETESI32, ATM_GETESI },
1368 { ATM_GETADDR32, ATM_GETADDR },
1369 { ATM_RSTADDR32, ATM_RSTADDR },
1370 { ATM_ADDADDR32, ATM_ADDADDR },
1371 { ATM_DELADDR32, ATM_DELADDR },
1372 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1373 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1374 { ATM_SETESI32, ATM_SETESI },
1375 { ATM_SETESIF32, ATM_SETESIF },
1376 { ATM_GETSTAT32, ATM_GETSTAT },
1377 { ATM_GETSTATZ32, ATM_GETSTATZ },
1378 { ATM_GETLOOP32, ATM_GETLOOP },
1379 { ATM_SETLOOP32, ATM_SETLOOP },
1380 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1383 #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
1385 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1387 struct atm_iobuf __user *iobuf;
1388 struct atm_iobuf32 __user *iobuf32;
1389 u32 data;
1390 void __user *datap;
1391 int len, err;
1393 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1394 iobuf32 = compat_ptr(arg);
1396 if (get_user(len, &iobuf32->length) ||
1397 get_user(data, &iobuf32->buffer))
1398 return -EFAULT;
1399 datap = compat_ptr(data);
1400 if (put_user(len, &iobuf->length) ||
1401 put_user(datap, &iobuf->buffer))
1402 return -EFAULT;
1404 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1406 if (!err) {
1407 if (copy_in_user(&iobuf32->length, &iobuf->length,
1408 sizeof(int)))
1409 err = -EFAULT;
1412 return err;
1415 static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1417 struct atmif_sioc __user *sioc;
1418 struct atmif_sioc32 __user *sioc32;
1419 u32 data;
1420 void __user *datap;
1421 int err;
1423 sioc = compat_alloc_user_space(sizeof(*sioc));
1424 sioc32 = compat_ptr(arg);
1426 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1427 get_user(data, &sioc32->arg))
1428 return -EFAULT;
1429 datap = compat_ptr(data);
1430 if (put_user(datap, &sioc->arg))
1431 return -EFAULT;
1433 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1435 if (!err) {
1436 if (copy_in_user(&sioc32->length, &sioc->length,
1437 sizeof(int)))
1438 err = -EFAULT;
1440 return err;
1443 static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1445 int i;
1446 unsigned int cmd = 0;
1448 switch (cmd32) {
1449 case SONET_GETSTAT:
1450 case SONET_GETSTATZ:
1451 case SONET_GETDIAG:
1452 case SONET_SETDIAG:
1453 case SONET_CLRDIAG:
1454 case SONET_SETFRAMING:
1455 case SONET_GETFRAMING:
1456 case SONET_GETFRSENSE:
1457 return do_atmif_sioc(fd, cmd32, arg);
1460 for (i = 0; i < NR_ATM_IOCTL; i++) {
1461 if (cmd32 == atm_ioctl_map[i].cmd32) {
1462 cmd = atm_ioctl_map[i].cmd;
1463 break;
1466 if (i == NR_ATM_IOCTL)
1467 return -EINVAL;
1469 switch (cmd) {
1470 case ATM_GETNAMES:
1471 return do_atm_iobuf(fd, cmd, arg);
1473 case ATM_GETLINKRATE:
1474 case ATM_GETTYPE:
1475 case ATM_GETESI:
1476 case ATM_GETADDR:
1477 case ATM_RSTADDR:
1478 case ATM_ADDADDR:
1479 case ATM_DELADDR:
1480 case ATM_GETCIRANGE:
1481 case ATM_SETCIRANGE:
1482 case ATM_SETESI:
1483 case ATM_SETESIF:
1484 case ATM_GETSTAT:
1485 case ATM_GETSTATZ:
1486 case ATM_GETLOOP:
1487 case ATM_SETLOOP:
1488 case ATM_QUERYLOOP:
1489 return do_atmif_sioc(fd, cmd, arg);
1492 return -EINVAL;
1495 static __attribute_used__ int
1496 ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1498 return -EINVAL;
1501 #ifdef CONFIG_BLOCK
1502 static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1504 /* The mkswap binary hard codes it to Intel value :-((( */
1505 return w_long(fd, BLKGETSIZE, arg);
1508 struct blkpg_ioctl_arg32 {
1509 compat_int_t op;
1510 compat_int_t flags;
1511 compat_int_t datalen;
1512 compat_caddr_t data;
1515 static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1517 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1518 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1519 compat_caddr_t udata;
1520 compat_int_t n;
1521 int err;
1523 err = get_user(n, &ua32->op);
1524 err |= put_user(n, &a->op);
1525 err |= get_user(n, &ua32->flags);
1526 err |= put_user(n, &a->flags);
1527 err |= get_user(n, &ua32->datalen);
1528 err |= put_user(n, &a->datalen);
1529 err |= get_user(udata, &ua32->data);
1530 err |= put_user(compat_ptr(udata), &a->data);
1531 if (err)
1532 return err;
1534 return sys_ioctl(fd, cmd, (unsigned long)a);
1536 #endif
1538 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1540 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1543 #ifdef CONFIG_BLOCK
1544 /* Fix sizeof(sizeof()) breakage */
1545 #define BLKBSZGET_32 _IOR(0x12,112,int)
1546 #define BLKBSZSET_32 _IOW(0x12,113,int)
1547 #define BLKGETSIZE64_32 _IOR(0x12,114,int)
1549 static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1551 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1554 static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1556 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1559 static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1560 unsigned long arg)
1562 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1564 #endif
1566 /* Bluetooth ioctls */
1567 #define HCIUARTSETPROTO _IOW('U', 200, int)
1568 #define HCIUARTGETPROTO _IOR('U', 201, int)
1570 #define BNEPCONNADD _IOW('B', 200, int)
1571 #define BNEPCONNDEL _IOW('B', 201, int)
1572 #define BNEPGETCONNLIST _IOR('B', 210, int)
1573 #define BNEPGETCONNINFO _IOR('B', 211, int)
1575 #define CMTPCONNADD _IOW('C', 200, int)
1576 #define CMTPCONNDEL _IOW('C', 201, int)
1577 #define CMTPGETCONNLIST _IOR('C', 210, int)
1578 #define CMTPGETCONNINFO _IOR('C', 211, int)
1580 #define HIDPCONNADD _IOW('H', 200, int)
1581 #define HIDPCONNDEL _IOW('H', 201, int)
1582 #define HIDPGETCONNLIST _IOR('H', 210, int)
1583 #define HIDPGETCONNINFO _IOR('H', 211, int)
1585 #ifdef CONFIG_BLOCK
1586 struct floppy_struct32 {
1587 compat_uint_t size;
1588 compat_uint_t sect;
1589 compat_uint_t head;
1590 compat_uint_t track;
1591 compat_uint_t stretch;
1592 unsigned char gap;
1593 unsigned char rate;
1594 unsigned char spec1;
1595 unsigned char fmt_gap;
1596 const compat_caddr_t name;
1599 struct floppy_drive_params32 {
1600 char cmos;
1601 compat_ulong_t max_dtr;
1602 compat_ulong_t hlt;
1603 compat_ulong_t hut;
1604 compat_ulong_t srt;
1605 compat_ulong_t spinup;
1606 compat_ulong_t spindown;
1607 unsigned char spindown_offset;
1608 unsigned char select_delay;
1609 unsigned char rps;
1610 unsigned char tracks;
1611 compat_ulong_t timeout;
1612 unsigned char interleave_sect;
1613 struct floppy_max_errors max_errors;
1614 char flags;
1615 char read_track;
1616 short autodetect[8];
1617 compat_int_t checkfreq;
1618 compat_int_t native_format;
1621 struct floppy_drive_struct32 {
1622 signed char flags;
1623 compat_ulong_t spinup_date;
1624 compat_ulong_t select_date;
1625 compat_ulong_t first_read_date;
1626 short probed_format;
1627 short track;
1628 short maxblock;
1629 short maxtrack;
1630 compat_int_t generation;
1631 compat_int_t keep_data;
1632 compat_int_t fd_ref;
1633 compat_int_t fd_device;
1634 compat_int_t last_checked;
1635 compat_caddr_t dmabuf;
1636 compat_int_t bufblocks;
1639 struct floppy_fdc_state32 {
1640 compat_int_t spec1;
1641 compat_int_t spec2;
1642 compat_int_t dtr;
1643 unsigned char version;
1644 unsigned char dor;
1645 compat_ulong_t address;
1646 unsigned int rawcmd:2;
1647 unsigned int reset:1;
1648 unsigned int need_configure:1;
1649 unsigned int perp_mode:2;
1650 unsigned int has_fifo:1;
1651 unsigned int driver_version;
1652 unsigned char track[4];
1655 struct floppy_write_errors32 {
1656 unsigned int write_errors;
1657 compat_ulong_t first_error_sector;
1658 compat_int_t first_error_generation;
1659 compat_ulong_t last_error_sector;
1660 compat_int_t last_error_generation;
1661 compat_uint_t badness;
1664 #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1665 #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1666 #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1667 #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1668 #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1669 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1670 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1671 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1672 #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
1674 static struct {
1675 unsigned int cmd32;
1676 unsigned int cmd;
1677 } fd_ioctl_trans_table[] = {
1678 { FDSETPRM32, FDSETPRM },
1679 { FDDEFPRM32, FDDEFPRM },
1680 { FDGETPRM32, FDGETPRM },
1681 { FDSETDRVPRM32, FDSETDRVPRM },
1682 { FDGETDRVPRM32, FDGETDRVPRM },
1683 { FDGETDRVSTAT32, FDGETDRVSTAT },
1684 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1685 { FDGETFDCSTAT32, FDGETFDCSTAT },
1686 { FDWERRORGET32, FDWERRORGET }
1689 #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
1691 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1693 mm_segment_t old_fs = get_fs();
1694 void *karg = NULL;
1695 unsigned int kcmd = 0;
1696 int i, err;
1698 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1699 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1700 kcmd = fd_ioctl_trans_table[i].cmd;
1701 break;
1703 if (!kcmd)
1704 return -EINVAL;
1706 switch (cmd) {
1707 case FDSETPRM32:
1708 case FDDEFPRM32:
1709 case FDGETPRM32:
1711 compat_uptr_t name;
1712 struct floppy_struct32 __user *uf;
1713 struct floppy_struct *f;
1715 uf = compat_ptr(arg);
1716 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1717 if (!karg)
1718 return -ENOMEM;
1719 if (cmd == FDGETPRM32)
1720 break;
1721 err = __get_user(f->size, &uf->size);
1722 err |= __get_user(f->sect, &uf->sect);
1723 err |= __get_user(f->head, &uf->head);
1724 err |= __get_user(f->track, &uf->track);
1725 err |= __get_user(f->stretch, &uf->stretch);
1726 err |= __get_user(f->gap, &uf->gap);
1727 err |= __get_user(f->rate, &uf->rate);
1728 err |= __get_user(f->spec1, &uf->spec1);
1729 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
1730 err |= __get_user(name, &uf->name);
1731 f->name = compat_ptr(name);
1732 if (err) {
1733 err = -EFAULT;
1734 goto out;
1736 break;
1738 case FDSETDRVPRM32:
1739 case FDGETDRVPRM32:
1741 struct floppy_drive_params32 __user *uf;
1742 struct floppy_drive_params *f;
1744 uf = compat_ptr(arg);
1745 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1746 if (!karg)
1747 return -ENOMEM;
1748 if (cmd == FDGETDRVPRM32)
1749 break;
1750 err = __get_user(f->cmos, &uf->cmos);
1751 err |= __get_user(f->max_dtr, &uf->max_dtr);
1752 err |= __get_user(f->hlt, &uf->hlt);
1753 err |= __get_user(f->hut, &uf->hut);
1754 err |= __get_user(f->srt, &uf->srt);
1755 err |= __get_user(f->spinup, &uf->spinup);
1756 err |= __get_user(f->spindown, &uf->spindown);
1757 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
1758 err |= __get_user(f->select_delay, &uf->select_delay);
1759 err |= __get_user(f->rps, &uf->rps);
1760 err |= __get_user(f->tracks, &uf->tracks);
1761 err |= __get_user(f->timeout, &uf->timeout);
1762 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
1763 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
1764 err |= __get_user(f->flags, &uf->flags);
1765 err |= __get_user(f->read_track, &uf->read_track);
1766 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
1767 err |= __get_user(f->checkfreq, &uf->checkfreq);
1768 err |= __get_user(f->native_format, &uf->native_format);
1769 if (err) {
1770 err = -EFAULT;
1771 goto out;
1773 break;
1775 case FDGETDRVSTAT32:
1776 case FDPOLLDRVSTAT32:
1777 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1778 if (!karg)
1779 return -ENOMEM;
1780 break;
1781 case FDGETFDCSTAT32:
1782 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1783 if (!karg)
1784 return -ENOMEM;
1785 break;
1786 case FDWERRORGET32:
1787 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1788 if (!karg)
1789 return -ENOMEM;
1790 break;
1791 default:
1792 return -EINVAL;
1794 set_fs (KERNEL_DS);
1795 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1796 set_fs (old_fs);
1797 if (err)
1798 goto out;
1799 switch (cmd) {
1800 case FDGETPRM32:
1802 struct floppy_struct *f = karg;
1803 struct floppy_struct32 __user *uf = compat_ptr(arg);
1805 err = __put_user(f->size, &uf->size);
1806 err |= __put_user(f->sect, &uf->sect);
1807 err |= __put_user(f->head, &uf->head);
1808 err |= __put_user(f->track, &uf->track);
1809 err |= __put_user(f->stretch, &uf->stretch);
1810 err |= __put_user(f->gap, &uf->gap);
1811 err |= __put_user(f->rate, &uf->rate);
1812 err |= __put_user(f->spec1, &uf->spec1);
1813 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
1814 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
1815 break;
1817 case FDGETDRVPRM32:
1819 struct floppy_drive_params32 __user *uf;
1820 struct floppy_drive_params *f = karg;
1822 uf = compat_ptr(arg);
1823 err = __put_user(f->cmos, &uf->cmos);
1824 err |= __put_user(f->max_dtr, &uf->max_dtr);
1825 err |= __put_user(f->hlt, &uf->hlt);
1826 err |= __put_user(f->hut, &uf->hut);
1827 err |= __put_user(f->srt, &uf->srt);
1828 err |= __put_user(f->spinup, &uf->spinup);
1829 err |= __put_user(f->spindown, &uf->spindown);
1830 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
1831 err |= __put_user(f->select_delay, &uf->select_delay);
1832 err |= __put_user(f->rps, &uf->rps);
1833 err |= __put_user(f->tracks, &uf->tracks);
1834 err |= __put_user(f->timeout, &uf->timeout);
1835 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
1836 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
1837 err |= __put_user(f->flags, &uf->flags);
1838 err |= __put_user(f->read_track, &uf->read_track);
1839 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
1840 err |= __put_user(f->checkfreq, &uf->checkfreq);
1841 err |= __put_user(f->native_format, &uf->native_format);
1842 break;
1844 case FDGETDRVSTAT32:
1845 case FDPOLLDRVSTAT32:
1847 struct floppy_drive_struct32 __user *uf;
1848 struct floppy_drive_struct *f = karg;
1850 uf = compat_ptr(arg);
1851 err = __put_user(f->flags, &uf->flags);
1852 err |= __put_user(f->spinup_date, &uf->spinup_date);
1853 err |= __put_user(f->select_date, &uf->select_date);
1854 err |= __put_user(f->first_read_date, &uf->first_read_date);
1855 err |= __put_user(f->probed_format, &uf->probed_format);
1856 err |= __put_user(f->track, &uf->track);
1857 err |= __put_user(f->maxblock, &uf->maxblock);
1858 err |= __put_user(f->maxtrack, &uf->maxtrack);
1859 err |= __put_user(f->generation, &uf->generation);
1860 err |= __put_user(f->keep_data, &uf->keep_data);
1861 err |= __put_user(f->fd_ref, &uf->fd_ref);
1862 err |= __put_user(f->fd_device, &uf->fd_device);
1863 err |= __put_user(f->last_checked, &uf->last_checked);
1864 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
1865 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
1866 break;
1868 case FDGETFDCSTAT32:
1870 struct floppy_fdc_state32 __user *uf;
1871 struct floppy_fdc_state *f = karg;
1873 uf = compat_ptr(arg);
1874 err = __put_user(f->spec1, &uf->spec1);
1875 err |= __put_user(f->spec2, &uf->spec2);
1876 err |= __put_user(f->dtr, &uf->dtr);
1877 err |= __put_user(f->version, &uf->version);
1878 err |= __put_user(f->dor, &uf->dor);
1879 err |= __put_user(f->address, &uf->address);
1880 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
1881 (char *)&f->address + sizeof(f->address), sizeof(int));
1882 err |= __put_user(f->driver_version, &uf->driver_version);
1883 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
1884 break;
1886 case FDWERRORGET32:
1888 struct floppy_write_errors32 __user *uf;
1889 struct floppy_write_errors *f = karg;
1891 uf = compat_ptr(arg);
1892 err = __put_user(f->write_errors, &uf->write_errors);
1893 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
1894 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
1895 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
1896 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
1897 err |= __put_user(f->badness, &uf->badness);
1898 break;
1900 default:
1901 break;
1903 if (err)
1904 err = -EFAULT;
1906 out:
1907 kfree(karg);
1908 return err;
1910 #endif
1912 struct mtd_oob_buf32 {
1913 u_int32_t start;
1914 u_int32_t length;
1915 compat_caddr_t ptr; /* unsigned char* */
1918 #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
1919 #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
1921 static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
1923 struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
1924 struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
1925 u32 data;
1926 char __user *datap;
1927 unsigned int real_cmd;
1928 int err;
1930 real_cmd = (cmd == MEMREADOOB32) ?
1931 MEMREADOOB : MEMWRITEOOB;
1933 if (copy_in_user(&buf->start, &buf32->start,
1934 2 * sizeof(u32)) ||
1935 get_user(data, &buf32->ptr))
1936 return -EFAULT;
1937 datap = compat_ptr(data);
1938 if (put_user(datap, &buf->ptr))
1939 return -EFAULT;
1941 err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
1943 if (!err) {
1944 if (copy_in_user(&buf32->start, &buf->start,
1945 2 * sizeof(u32)))
1946 err = -EFAULT;
1949 return err;
1952 #ifdef CONFIG_BLOCK
1953 struct raw32_config_request
1955 compat_int_t raw_minor;
1956 __u64 block_major;
1957 __u64 block_minor;
1958 } __attribute__((packed));
1960 static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1962 int ret;
1964 if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
1965 return -EFAULT;
1967 ret = __get_user(req->raw_minor, &user_req->raw_minor);
1968 ret |= __get_user(req->block_major, &user_req->block_major);
1969 ret |= __get_user(req->block_minor, &user_req->block_minor);
1971 return ret ? -EFAULT : 0;
1974 static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1976 int ret;
1978 if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
1979 return -EFAULT;
1981 ret = __put_user(req->raw_minor, &user_req->raw_minor);
1982 ret |= __put_user(req->block_major, &user_req->block_major);
1983 ret |= __put_user(req->block_minor, &user_req->block_minor);
1985 return ret ? -EFAULT : 0;
1988 static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1990 int ret;
1992 switch (cmd) {
1993 case RAW_SETBIND:
1994 case RAW_GETBIND: {
1995 struct raw_config_request req;
1996 struct raw32_config_request __user *user_req = compat_ptr(arg);
1997 mm_segment_t oldfs = get_fs();
1999 if ((ret = get_raw32_request(&req, user_req)))
2000 return ret;
2002 set_fs(KERNEL_DS);
2003 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2004 set_fs(oldfs);
2006 if ((!ret) && (cmd == RAW_GETBIND)) {
2007 ret = set_raw32_request(&req, user_req);
2009 break;
2011 default:
2012 ret = sys_ioctl(fd, cmd, arg);
2013 break;
2015 return ret;
2017 #endif /* CONFIG_BLOCK */
2019 struct serial_struct32 {
2020 compat_int_t type;
2021 compat_int_t line;
2022 compat_uint_t port;
2023 compat_int_t irq;
2024 compat_int_t flags;
2025 compat_int_t xmit_fifo_size;
2026 compat_int_t custom_divisor;
2027 compat_int_t baud_base;
2028 unsigned short close_delay;
2029 char io_type;
2030 char reserved_char[1];
2031 compat_int_t hub6;
2032 unsigned short closing_wait; /* time to wait before closing */
2033 unsigned short closing_wait2; /* no longer used... */
2034 compat_uint_t iomem_base;
2035 unsigned short iomem_reg_shift;
2036 unsigned int port_high;
2037 /* compat_ulong_t iomap_base FIXME */
2038 compat_int_t reserved[1];
2041 static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2043 typedef struct serial_struct SS;
2044 typedef struct serial_struct32 SS32;
2045 struct serial_struct32 __user *ss32 = compat_ptr(arg);
2046 int err;
2047 struct serial_struct ss;
2048 mm_segment_t oldseg = get_fs();
2049 __u32 udata;
2050 unsigned int base;
2052 if (cmd == TIOCSSERIAL) {
2053 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
2054 return -EFAULT;
2055 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
2056 return -EFAULT;
2057 if (__get_user(udata, &ss32->iomem_base))
2058 return -EFAULT;
2059 ss.iomem_base = compat_ptr(udata);
2060 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
2061 __get_user(ss.port_high, &ss32->port_high))
2062 return -EFAULT;
2063 ss.iomap_base = 0UL;
2065 set_fs(KERNEL_DS);
2066 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2067 set_fs(oldseg);
2068 if (cmd == TIOCGSERIAL && err >= 0) {
2069 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
2070 return -EFAULT;
2071 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
2072 return -EFAULT;
2073 base = (unsigned long)ss.iomem_base >> 32 ?
2074 0xffffffff : (unsigned)(unsigned long)ss.iomem_base;
2075 if (__put_user(base, &ss32->iomem_base) ||
2076 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
2077 __put_user(ss.port_high, &ss32->port_high))
2078 return -EFAULT;
2080 return err;
2083 struct usbdevfs_ctrltransfer32 {
2084 u8 bRequestType;
2085 u8 bRequest;
2086 u16 wValue;
2087 u16 wIndex;
2088 u16 wLength;
2089 u32 timeout; /* in milliseconds */
2090 compat_caddr_t data;
2093 #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2095 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2097 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2098 struct usbdevfs_ctrltransfer __user *p;
2099 __u32 udata;
2100 p = compat_alloc_user_space(sizeof(*p));
2101 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2102 get_user(udata, &p32->data) ||
2103 put_user(compat_ptr(udata), &p->data))
2104 return -EFAULT;
2105 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2109 struct usbdevfs_bulktransfer32 {
2110 compat_uint_t ep;
2111 compat_uint_t len;
2112 compat_uint_t timeout; /* in milliseconds */
2113 compat_caddr_t data;
2116 #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2118 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2120 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2121 struct usbdevfs_bulktransfer __user *p;
2122 compat_uint_t n;
2123 compat_caddr_t addr;
2125 p = compat_alloc_user_space(sizeof(*p));
2127 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2128 get_user(n, &p32->len) || put_user(n, &p->len) ||
2129 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2130 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2131 return -EFAULT;
2133 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2138 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
2139 * are handled in usbdevfs core. -Christopher Li
2142 struct usbdevfs_disconnectsignal32 {
2143 compat_int_t signr;
2144 compat_caddr_t context;
2147 #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2149 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2151 struct usbdevfs_disconnectsignal kdis;
2152 struct usbdevfs_disconnectsignal32 __user *udis;
2153 mm_segment_t old_fs;
2154 u32 uctx;
2155 int err;
2157 udis = compat_ptr(arg);
2159 if (get_user(kdis.signr, &udis->signr) ||
2160 __get_user(uctx, &udis->context))
2161 return -EFAULT;
2163 kdis.context = compat_ptr(uctx);
2165 old_fs = get_fs();
2166 set_fs(KERNEL_DS);
2167 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2168 set_fs(old_fs);
2170 return err;
2174 * I2C layer ioctls
2177 struct i2c_msg32 {
2178 u16 addr;
2179 u16 flags;
2180 u16 len;
2181 compat_caddr_t buf;
2184 struct i2c_rdwr_ioctl_data32 {
2185 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2186 u32 nmsgs;
2189 struct i2c_smbus_ioctl_data32 {
2190 u8 read_write;
2191 u8 command;
2192 u32 size;
2193 compat_caddr_t data; /* union i2c_smbus_data *data */
2196 struct i2c_rdwr_aligned {
2197 struct i2c_rdwr_ioctl_data cmd;
2198 struct i2c_msg msgs[0];
2201 static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2203 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
2204 struct i2c_rdwr_aligned __user *tdata;
2205 struct i2c_msg __user *tmsgs;
2206 struct i2c_msg32 __user *umsgs;
2207 compat_caddr_t datap;
2208 int nmsgs, i;
2210 if (get_user(nmsgs, &udata->nmsgs))
2211 return -EFAULT;
2212 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2213 return -EINVAL;
2215 if (get_user(datap, &udata->msgs))
2216 return -EFAULT;
2217 umsgs = compat_ptr(datap);
2219 tdata = compat_alloc_user_space(sizeof(*tdata) +
2220 nmsgs * sizeof(struct i2c_msg));
2221 tmsgs = &tdata->msgs[0];
2223 if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
2224 put_user(tmsgs, &tdata->cmd.msgs))
2225 return -EFAULT;
2227 for (i = 0; i < nmsgs; i++) {
2228 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
2229 return -EFAULT;
2230 if (get_user(datap, &umsgs[i].buf) ||
2231 put_user(compat_ptr(datap), &tmsgs[i].buf))
2232 return -EFAULT;
2234 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2237 static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2239 struct i2c_smbus_ioctl_data __user *tdata;
2240 struct i2c_smbus_ioctl_data32 __user *udata;
2241 compat_caddr_t datap;
2243 tdata = compat_alloc_user_space(sizeof(*tdata));
2244 if (tdata == NULL)
2245 return -ENOMEM;
2246 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
2247 return -EFAULT;
2249 udata = compat_ptr(arg);
2250 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
2251 return -EFAULT;
2253 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2254 return -EFAULT;
2255 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2256 return -EFAULT;
2257 if (__get_user(datap, &udata->data) ||
2258 __put_user(compat_ptr(datap), &tdata->data))
2259 return -EFAULT;
2261 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2264 struct compat_iw_point {
2265 compat_caddr_t pointer;
2266 __u16 length;
2267 __u16 flags;
2270 static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2272 struct iwreq __user *iwr;
2273 struct iwreq __user *iwr_u;
2274 struct iw_point __user *iwp;
2275 struct compat_iw_point __user *iwp_u;
2276 compat_caddr_t pointer;
2277 __u16 length, flags;
2279 iwr_u = compat_ptr(arg);
2280 iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2281 iwr = compat_alloc_user_space(sizeof(*iwr));
2282 if (iwr == NULL)
2283 return -ENOMEM;
2285 iwp = &iwr->u.data;
2287 if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
2288 return -EFAULT;
2290 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2291 &iwr_u->ifr_ifrn.ifrn_name[0],
2292 sizeof(iwr->ifr_ifrn.ifrn_name)))
2293 return -EFAULT;
2295 if (__get_user(pointer, &iwp_u->pointer) ||
2296 __get_user(length, &iwp_u->length) ||
2297 __get_user(flags, &iwp_u->flags))
2298 return -EFAULT;
2300 if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
2301 __put_user(length, &iwp->length) ||
2302 __put_user(flags, &iwp->flags))
2303 return -EFAULT;
2305 return sys_ioctl(fd, cmd, (unsigned long) iwr);
2308 /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2309 * for some operations; this forces use of the newer bridge-utils that
2310 * use compatiable ioctls
2312 static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2314 u32 tmp;
2316 if (get_user(tmp, (u32 __user *) arg))
2317 return -EFAULT;
2318 if (tmp == BRCTL_GET_VERSION)
2319 return BRCTL_VERSION + 1;
2320 return -EINVAL;
2323 #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
2324 #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
2325 #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
2326 #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
2328 static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2330 mm_segment_t oldfs = get_fs();
2331 compat_ulong_t val32;
2332 unsigned long kval;
2333 int ret;
2335 switch (cmd) {
2336 case RTC_IRQP_READ32:
2337 case RTC_EPOCH_READ32:
2338 set_fs(KERNEL_DS);
2339 ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
2340 RTC_IRQP_READ : RTC_EPOCH_READ,
2341 (unsigned long)&kval);
2342 set_fs(oldfs);
2343 if (ret)
2344 return ret;
2345 val32 = kval;
2346 return put_user(val32, (unsigned int __user *)arg);
2347 case RTC_IRQP_SET32:
2348 return sys_ioctl(fd, RTC_IRQP_SET, arg);
2349 case RTC_EPOCH_SET32:
2350 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
2351 default:
2352 /* unreached */
2353 return -ENOIOCTLCMD;
2357 static int
2358 lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2360 struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
2361 struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
2362 struct timeval ts;
2363 if (get_user(ts.tv_sec, &tc->tv_sec) ||
2364 get_user(ts.tv_usec, &tc->tv_usec) ||
2365 put_user(ts.tv_sec, &tn->tv_sec) ||
2366 put_user(ts.tv_usec, &tn->tv_usec))
2367 return -EFAULT;
2368 return sys_ioctl(fd, cmd, (unsigned long)tn);
2371 #define HANDLE_IOCTL(cmd,handler) \
2372 { (cmd), (ioctl_trans_handler_t)(handler) },
2374 /* pointer to compatible structure or no argument */
2375 #define COMPATIBLE_IOCTL(cmd) \
2376 { (cmd), do_ioctl32_pointer },
2378 /* argument is an unsigned long integer, not a pointer */
2379 #define ULONG_IOCTL(cmd) \
2380 { (cmd), (ioctl_trans_handler_t)sys_ioctl },
2383 struct ioctl_trans ioctl_start[] = {
2384 #include <linux/compat_ioctl.h>
2385 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
2386 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
2387 #ifdef CONFIG_NET
2388 HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
2389 HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
2390 HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
2391 HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
2392 HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
2393 HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
2394 HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
2395 HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
2396 HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
2397 HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
2398 HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
2399 HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
2400 HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
2401 HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
2402 HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
2403 HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
2404 HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2405 HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2406 HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
2407 HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
2409 /* ioctls used by appletalk ddp.c */
2410 HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
2411 HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
2412 HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
2413 HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
2415 HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
2416 HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
2417 HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
2418 HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
2419 HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
2420 HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
2421 HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
2422 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
2423 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
2424 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
2425 HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
2426 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
2427 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
2428 HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
2429 HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
2430 HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
2431 HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
2432 HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
2433 HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
2434 HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
2435 HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
2436 HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
2437 /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
2438 HANDLE_IOCTL(SIOCRTMSG, ret_einval)
2439 HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
2440 #endif
2441 #ifdef CONFIG_BLOCK
2442 HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
2443 HANDLE_IOCTL(BLKRAGET, w_long)
2444 HANDLE_IOCTL(BLKGETSIZE, w_long)
2445 HANDLE_IOCTL(0x1260, broken_blkgetsize)
2446 HANDLE_IOCTL(BLKFRAGET, w_long)
2447 HANDLE_IOCTL(BLKSECTGET, w_long)
2448 HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
2449 HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
2450 HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
2451 HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
2452 HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
2453 HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
2454 HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
2455 HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
2456 HANDLE_IOCTL(HDIO_GET_WCACHE, hdio_ioctl_trans)
2457 HANDLE_IOCTL(HDIO_GET_ACOUSTIC, hdio_ioctl_trans)
2458 HANDLE_IOCTL(HDIO_GET_ADDRESS, hdio_ioctl_trans)
2459 HANDLE_IOCTL(HDIO_GET_BUSSTATE, hdio_ioctl_trans)
2460 HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
2461 HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
2462 HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
2463 HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
2464 HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
2465 HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
2466 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
2467 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
2468 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
2469 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
2470 HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
2471 #endif
2472 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
2473 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
2474 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
2475 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
2476 #ifdef CONFIG_BLOCK
2477 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
2478 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
2479 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
2480 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
2481 #endif
2482 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
2483 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
2484 #ifdef CONFIG_VT
2485 HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
2486 HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
2487 HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
2488 HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
2489 HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
2490 #endif
2491 /* One SMB ioctl needs translations. */
2492 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
2493 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
2494 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
2495 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
2496 HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
2497 HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
2498 HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
2499 HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
2500 HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
2501 HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
2502 HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
2503 HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
2504 HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
2505 HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
2506 HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
2507 HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
2508 HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
2509 HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
2510 HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
2511 HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
2512 HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
2513 HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
2514 HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
2515 HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
2516 HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
2517 HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
2518 HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
2519 /* block stuff */
2520 #ifdef CONFIG_BLOCK
2521 HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
2522 HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
2523 HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
2524 /* Raw devices */
2525 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
2526 HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
2527 #endif
2528 /* Serial */
2529 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
2530 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
2531 #ifdef TIOCGLTC
2532 COMPATIBLE_IOCTL(TIOCGLTC)
2533 COMPATIBLE_IOCTL(TIOCSLTC)
2534 #endif
2535 #ifdef TIOCSTART
2537 * For these two we have defintions in ioctls.h and/or termios.h on
2538 * some architectures but no actual implemention. Some applications
2539 * like bash call them if they are defined in the headers, so we provide
2540 * entries here to avoid syslog message spew.
2542 COMPATIBLE_IOCTL(TIOCSTART)
2543 COMPATIBLE_IOCTL(TIOCSTOP)
2544 #endif
2545 /* Usbdevfs */
2546 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
2547 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
2548 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
2549 COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
2550 /* i2c */
2551 HANDLE_IOCTL(I2C_FUNCS, w_long)
2552 HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
2553 HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
2554 /* wireless */
2555 HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
2556 HANDLE_IOCTL(SIOCGIWPRIV, do_wireless_ioctl)
2557 HANDLE_IOCTL(SIOCGIWSTATS, do_wireless_ioctl)
2558 HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
2559 HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
2560 HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
2561 HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
2562 HANDLE_IOCTL(SIOCSIWMLME, do_wireless_ioctl)
2563 HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
2564 HANDLE_IOCTL(SIOCSIWSCAN, do_wireless_ioctl)
2565 HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
2566 HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
2567 HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
2568 HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
2569 HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
2570 HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
2571 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
2572 HANDLE_IOCTL(SIOCSIWGENIE, do_wireless_ioctl)
2573 HANDLE_IOCTL(SIOCGIWGENIE, do_wireless_ioctl)
2574 HANDLE_IOCTL(SIOCSIWENCODEEXT, do_wireless_ioctl)
2575 HANDLE_IOCTL(SIOCGIWENCODEEXT, do_wireless_ioctl)
2576 HANDLE_IOCTL(SIOCSIWPMKSA, do_wireless_ioctl)
2577 HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
2578 HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
2579 HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
2580 HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
2581 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
2582 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
2584 /* dvb */
2585 HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
2586 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
2587 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
2589 /* parport */
2590 COMPATIBLE_IOCTL(LPTIME)
2591 COMPATIBLE_IOCTL(LPCHAR)
2592 COMPATIBLE_IOCTL(LPABORTOPEN)
2593 COMPATIBLE_IOCTL(LPCAREFUL)
2594 COMPATIBLE_IOCTL(LPWAIT)
2595 COMPATIBLE_IOCTL(LPSETIRQ)
2596 COMPATIBLE_IOCTL(LPGETSTATUS)
2597 COMPATIBLE_IOCTL(LPGETSTATUS)
2598 COMPATIBLE_IOCTL(LPRESET)
2599 /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
2600 COMPATIBLE_IOCTL(LPGETFLAGS)
2601 HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
2604 int ioctl_table_size = ARRAY_SIZE(ioctl_start);