V4L/DVB (3320): Check if PLL-description is set
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / compat_ioctl.c
blob55d9a3a954cfe7fc35a5ccdc4eb7b6f1afbcff72
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/ext3_jbd.h>
53 #include <linux/ext3_fs.h>
54 #include <linux/videodev.h>
55 #include <linux/netdevice.h>
56 #include <linux/raw.h>
57 #include <linux/smb_fs.h>
58 #include <linux/blkpg.h>
59 #include <linux/blkdev.h>
60 #include <linux/elevator.h>
61 #include <linux/rtc.h>
62 #include <linux/pci.h>
63 #include <linux/module.h>
64 #include <linux/serial.h>
65 #include <linux/reiserfs_fs.h>
66 #include <linux/if_tun.h>
67 #include <linux/ctype.h>
68 #include <linux/ioctl32.h>
69 #include <linux/syscalls.h>
70 #include <linux/ncp_fs.h>
71 #include <linux/i2c.h>
72 #include <linux/i2c-dev.h>
73 #include <linux/wireless.h>
74 #include <linux/atalk.h>
76 #include <net/sock.h> /* siocdevprivate_ioctl */
77 #include <net/bluetooth/bluetooth.h>
78 #include <net/bluetooth/hci.h>
79 #include <net/bluetooth/rfcomm.h>
81 #include <linux/capi.h>
83 #include <scsi/scsi.h>
84 /* Ugly hack. */
85 #undef __KERNEL__
86 #include <scsi/scsi_ioctl.h>
87 #define __KERNEL__
88 #include <scsi/sg.h>
90 #include <asm/types.h>
91 #include <asm/uaccess.h>
92 #include <linux/ethtool.h>
93 #include <linux/mii.h>
94 #include <linux/if_bonding.h>
95 #include <linux/watchdog.h>
96 #include <linux/dm-ioctl.h>
98 #include <asm/module.h>
99 #include <linux/soundcard.h>
100 #include <linux/lp.h>
101 #include <linux/ppdev.h>
103 #include <linux/atm.h>
104 #include <linux/atmarp.h>
105 #include <linux/atmclip.h>
106 #include <linux/atmdev.h>
107 #include <linux/atmioc.h>
108 #include <linux/atmlec.h>
109 #include <linux/atmmpc.h>
110 #include <linux/atmsvc.h>
111 #include <linux/atm_tcp.h>
112 #include <linux/sonet.h>
113 #include <linux/atm_suni.h>
114 #include <linux/mtd/mtd.h>
116 #include <linux/usb.h>
117 #include <linux/usbdevice_fs.h>
118 #include <linux/nbd.h>
119 #include <linux/random.h>
120 #include <linux/filter.h>
121 #include <linux/msdos_fs.h>
122 #include <linux/pktcdvd.h>
124 #include <linux/hiddev.h>
126 #include <linux/dvb/audio.h>
127 #include <linux/dvb/dmx.h>
128 #include <linux/dvb/frontend.h>
129 #include <linux/dvb/video.h>
131 #undef INCLUDES
132 #endif
134 #ifdef CODE
136 /* Aiee. Someone does not find a difference between int and long */
137 #define EXT2_IOC32_GETFLAGS _IOR('f', 1, int)
138 #define EXT2_IOC32_SETFLAGS _IOW('f', 2, int)
139 #define EXT3_IOC32_GETVERSION _IOR('f', 3, int)
140 #define EXT3_IOC32_SETVERSION _IOW('f', 4, int)
141 #define EXT3_IOC32_GETRSVSZ _IOR('f', 5, int)
142 #define EXT3_IOC32_SETRSVSZ _IOW('f', 6, int)
143 #define EXT3_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
144 #ifdef CONFIG_JBD_DEBUG
145 #define EXT3_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
146 #endif
148 #define EXT2_IOC32_GETVERSION _IOR('v', 1, int)
149 #define EXT2_IOC32_SETVERSION _IOW('v', 2, int)
151 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
153 mm_segment_t old_fs = get_fs();
154 int err;
155 unsigned long val;
157 set_fs (KERNEL_DS);
158 err = sys_ioctl(fd, cmd, (unsigned long)&val);
159 set_fs (old_fs);
160 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
161 return -EFAULT;
162 return err;
165 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
167 mm_segment_t old_fs = get_fs();
168 u32 __user *argptr = compat_ptr(arg);
169 int err;
170 unsigned long val;
172 if(get_user(val, argptr))
173 return -EFAULT;
174 set_fs (KERNEL_DS);
175 err = sys_ioctl(fd, cmd, (unsigned long)&val);
176 set_fs (old_fs);
177 if (!err && put_user(val, argptr))
178 return -EFAULT;
179 return err;
182 static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
184 /* These are just misnamed, they actually get/put from/to user an int */
185 switch (cmd) {
186 case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
187 case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
188 case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
189 case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
191 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
194 static int do_ext3_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
196 /* These are just misnamed, they actually get/put from/to user an int */
197 switch (cmd) {
198 case EXT3_IOC32_GETVERSION: cmd = EXT3_IOC_GETVERSION; break;
199 case EXT3_IOC32_SETVERSION: cmd = EXT3_IOC_SETVERSION; break;
200 case EXT3_IOC32_GETRSVSZ: cmd = EXT3_IOC_GETRSVSZ; break;
201 case EXT3_IOC32_SETRSVSZ: cmd = EXT3_IOC_SETRSVSZ; break;
202 case EXT3_IOC32_GROUP_EXTEND: cmd = EXT3_IOC_GROUP_EXTEND; break;
203 #ifdef CONFIG_JBD_DEBUG
204 case EXT3_IOC32_WAIT_FOR_READONLY: cmd = EXT3_IOC_WAIT_FOR_READONLY; break;
205 #endif
207 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
210 struct compat_dmx_event {
211 dmx_event_t event;
212 compat_time_t timeStamp;
213 union
215 dmx_scrambling_status_t scrambling;
216 } u;
219 static int do_dmx_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
221 struct dmx_event kevent;
222 mm_segment_t old_fs = get_fs();
223 int err;
225 set_fs(KERNEL_DS);
226 err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
227 set_fs(old_fs);
229 if (!err) {
230 struct compat_dmx_event __user *up = compat_ptr(arg);
232 err = put_user(kevent.event, &up->event);
233 err |= put_user(kevent.timeStamp, &up->timeStamp);
234 err |= put_user(kevent.u.scrambling, &up->u.scrambling);
235 if (err)
236 err = -EFAULT;
239 return err;
242 struct compat_video_event {
243 int32_t type;
244 compat_time_t timestamp;
245 union {
246 video_size_t size;
247 unsigned int frame_rate;
248 } u;
251 static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
253 struct video_event kevent;
254 mm_segment_t old_fs = get_fs();
255 int err;
257 set_fs(KERNEL_DS);
258 err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
259 set_fs(old_fs);
261 if (!err) {
262 struct compat_video_event __user *up = compat_ptr(arg);
264 err = put_user(kevent.type, &up->type);
265 err |= put_user(kevent.timestamp, &up->timestamp);
266 err |= put_user(kevent.u.size.w, &up->u.size.w);
267 err |= put_user(kevent.u.size.h, &up->u.size.h);
268 err |= put_user(kevent.u.size.aspect_ratio,
269 &up->u.size.aspect_ratio);
270 if (err)
271 err = -EFAULT;
274 return err;
277 struct compat_video_still_picture {
278 compat_uptr_t iFrame;
279 int32_t size;
282 static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
284 struct compat_video_still_picture __user *up;
285 struct video_still_picture __user *up_native;
286 compat_uptr_t fp;
287 int32_t size;
288 int err;
290 up = (struct compat_video_still_picture __user *) arg;
291 err = get_user(fp, &up->iFrame);
292 err |= get_user(size, &up->size);
293 if (err)
294 return -EFAULT;
296 up_native =
297 compat_alloc_user_space(sizeof(struct video_still_picture));
299 put_user(compat_ptr(fp), &up_native->iFrame);
300 put_user(size, &up_native->size);
302 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
304 return err;
307 struct compat_video_spu_palette {
308 int length;
309 compat_uptr_t palette;
312 static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
314 struct compat_video_spu_palette __user *up;
315 struct video_spu_palette __user *up_native;
316 compat_uptr_t palp;
317 int length, err;
319 up = (struct compat_video_spu_palette __user *) arg;
320 err = get_user(palp, &up->palette);
321 err |= get_user(length, &up->length);
323 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
324 put_user(compat_ptr(palp), &up_native->palette);
325 put_user(length, &up_native->length);
327 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
329 return err;
332 #ifdef CONFIG_NET
333 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
335 struct compat_timeval __user *up = compat_ptr(arg);
336 struct timeval ktv;
337 mm_segment_t old_fs = get_fs();
338 int err;
340 set_fs(KERNEL_DS);
341 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
342 set_fs(old_fs);
343 if(!err) {
344 err = put_user(ktv.tv_sec, &up->tv_sec);
345 err |= __put_user(ktv.tv_usec, &up->tv_usec);
347 return err;
350 struct ifmap32 {
351 compat_ulong_t mem_start;
352 compat_ulong_t mem_end;
353 unsigned short base_addr;
354 unsigned char irq;
355 unsigned char dma;
356 unsigned char port;
359 struct ifreq32 {
360 #define IFHWADDRLEN 6
361 #define IFNAMSIZ 16
362 union {
363 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
364 } ifr_ifrn;
365 union {
366 struct sockaddr ifru_addr;
367 struct sockaddr ifru_dstaddr;
368 struct sockaddr ifru_broadaddr;
369 struct sockaddr ifru_netmask;
370 struct sockaddr ifru_hwaddr;
371 short ifru_flags;
372 compat_int_t ifru_ivalue;
373 compat_int_t ifru_mtu;
374 struct ifmap32 ifru_map;
375 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
376 char ifru_newname[IFNAMSIZ];
377 compat_caddr_t ifru_data;
378 /* XXXX? ifru_settings should be here */
379 } ifr_ifru;
382 struct ifconf32 {
383 compat_int_t ifc_len; /* size of buffer */
384 compat_caddr_t ifcbuf;
387 static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
389 struct net_device *dev;
390 struct ifreq32 ifr32;
391 int err;
393 if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
394 return -EFAULT;
396 dev = dev_get_by_index(ifr32.ifr_ifindex);
397 if (!dev)
398 return -ENODEV;
400 strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
401 dev_put(dev);
403 err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
404 return (err ? -EFAULT : 0);
407 static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
409 struct ifconf32 ifc32;
410 struct ifconf ifc;
411 struct ifconf __user *uifc;
412 struct ifreq32 __user *ifr32;
413 struct ifreq __user *ifr;
414 unsigned int i, j;
415 int err;
417 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
418 return -EFAULT;
420 if (ifc32.ifcbuf == 0) {
421 ifc32.ifc_len = 0;
422 ifc.ifc_len = 0;
423 ifc.ifc_req = NULL;
424 uifc = compat_alloc_user_space(sizeof(struct ifconf));
425 } else {
426 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
427 sizeof (struct ifreq);
428 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
429 ifc.ifc_len = len;
430 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
431 ifr32 = compat_ptr(ifc32.ifcbuf);
432 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
433 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
434 return -EFAULT;
435 ifr++;
436 ifr32++;
439 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
440 return -EFAULT;
442 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
443 if (err)
444 return err;
446 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
447 return -EFAULT;
449 ifr = ifc.ifc_req;
450 ifr32 = compat_ptr(ifc32.ifcbuf);
451 for (i = 0, j = 0;
452 i + sizeof (struct ifreq32) < ifc32.ifc_len && j < ifc.ifc_len;
453 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
454 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
455 return -EFAULT;
456 ifr32++;
457 ifr++;
460 if (ifc32.ifcbuf == 0) {
461 /* Translate from 64-bit structure multiple to
462 * a 32-bit one.
464 i = ifc.ifc_len;
465 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
466 ifc32.ifc_len = i;
467 } else {
468 ifc32.ifc_len = i;
470 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
471 return -EFAULT;
473 return 0;
476 static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
478 struct ifreq __user *ifr;
479 struct ifreq32 __user *ifr32;
480 u32 data;
481 void __user *datap;
483 ifr = compat_alloc_user_space(sizeof(*ifr));
484 ifr32 = compat_ptr(arg);
486 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
487 return -EFAULT;
489 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
490 return -EFAULT;
492 datap = compat_ptr(data);
493 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
494 return -EFAULT;
496 return sys_ioctl(fd, cmd, (unsigned long) ifr);
499 static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
501 struct ifreq kifr;
502 struct ifreq __user *uifr;
503 struct ifreq32 __user *ifr32 = compat_ptr(arg);
504 mm_segment_t old_fs;
505 int err;
506 u32 data;
507 void __user *datap;
509 switch (cmd) {
510 case SIOCBONDENSLAVE:
511 case SIOCBONDRELEASE:
512 case SIOCBONDSETHWADDR:
513 case SIOCBONDCHANGEACTIVE:
514 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
515 return -EFAULT;
517 old_fs = get_fs();
518 set_fs (KERNEL_DS);
519 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
520 set_fs (old_fs);
522 return err;
523 case SIOCBONDSLAVEINFOQUERY:
524 case SIOCBONDINFOQUERY:
525 uifr = compat_alloc_user_space(sizeof(*uifr));
526 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
527 return -EFAULT;
529 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
530 return -EFAULT;
532 datap = compat_ptr(data);
533 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
534 return -EFAULT;
536 return sys_ioctl (fd, cmd, (unsigned long)uifr);
537 default:
538 return -EINVAL;
542 int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
544 struct ifreq __user *u_ifreq64;
545 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
546 char tmp_buf[IFNAMSIZ];
547 void __user *data64;
548 u32 data32;
550 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
551 IFNAMSIZ))
552 return -EFAULT;
553 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
554 return -EFAULT;
555 data64 = compat_ptr(data32);
557 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
559 /* Don't check these user accesses, just let that get trapped
560 * in the ioctl handler instead.
562 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
563 IFNAMSIZ))
564 return -EFAULT;
565 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
566 return -EFAULT;
568 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
571 static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
573 struct ifreq ifr;
574 struct ifreq32 __user *uifr32;
575 struct ifmap32 __user *uifmap32;
576 mm_segment_t old_fs;
577 int err;
579 uifr32 = compat_ptr(arg);
580 uifmap32 = &uifr32->ifr_ifru.ifru_map;
581 switch (cmd) {
582 case SIOCSIFMAP:
583 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
584 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
585 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
586 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
587 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
588 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
589 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
590 if (err)
591 return -EFAULT;
592 break;
593 default:
594 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
595 return -EFAULT;
596 break;
598 old_fs = get_fs();
599 set_fs (KERNEL_DS);
600 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
601 set_fs (old_fs);
602 if (!err) {
603 switch (cmd) {
604 /* TUNSETIFF is defined as _IOW, it should be _IORW
605 * as the data is copied back to user space, but that
606 * cannot be fixed without breaking all existing apps.
608 case TUNSETIFF:
609 case SIOCGIFFLAGS:
610 case SIOCGIFMETRIC:
611 case SIOCGIFMTU:
612 case SIOCGIFMEM:
613 case SIOCGIFHWADDR:
614 case SIOCGIFINDEX:
615 case SIOCGIFADDR:
616 case SIOCGIFBRDADDR:
617 case SIOCGIFDSTADDR:
618 case SIOCGIFNETMASK:
619 case SIOCGIFTXQLEN:
620 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
621 return -EFAULT;
622 break;
623 case SIOCGIFMAP:
624 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
625 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
626 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
627 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
628 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
629 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
630 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
631 if (err)
632 err = -EFAULT;
633 break;
636 return err;
639 struct rtentry32 {
640 u32 rt_pad1;
641 struct sockaddr rt_dst; /* target address */
642 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
643 struct sockaddr rt_genmask; /* target network mask (IP) */
644 unsigned short rt_flags;
645 short rt_pad2;
646 u32 rt_pad3;
647 unsigned char rt_tos;
648 unsigned char rt_class;
649 short rt_pad4;
650 short rt_metric; /* +1 for binary compatibility! */
651 /* char * */ u32 rt_dev; /* forcing the device at add */
652 u32 rt_mtu; /* per route MTU/Window */
653 u32 rt_window; /* Window clamping */
654 unsigned short rt_irtt; /* Initial RTT */
658 struct in6_rtmsg32 {
659 struct in6_addr rtmsg_dst;
660 struct in6_addr rtmsg_src;
661 struct in6_addr rtmsg_gateway;
662 u32 rtmsg_type;
663 u16 rtmsg_dst_len;
664 u16 rtmsg_src_len;
665 u32 rtmsg_metric;
666 u32 rtmsg_info;
667 u32 rtmsg_flags;
668 s32 rtmsg_ifindex;
671 static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
673 int ret;
674 void *r = NULL;
675 struct in6_rtmsg r6;
676 struct rtentry r4;
677 char devname[16];
678 u32 rtdev;
679 mm_segment_t old_fs = get_fs();
681 struct socket *mysock = sockfd_lookup(fd, &ret);
683 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
684 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
685 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
686 3 * sizeof(struct in6_addr));
687 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
688 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
689 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
690 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
691 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
692 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
693 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
695 r = (void *) &r6;
696 } else { /* ipv4 */
697 struct rtentry32 __user *ur4 = compat_ptr(arg);
698 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
699 3 * sizeof(struct sockaddr));
700 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
701 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
702 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
703 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
704 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
705 ret |= __get_user (rtdev, &(ur4->rt_dev));
706 if (rtdev) {
707 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
708 r4.rt_dev = devname; devname[15] = 0;
709 } else
710 r4.rt_dev = NULL;
712 r = (void *) &r4;
715 if (ret) {
716 ret = -EFAULT;
717 goto out;
720 set_fs (KERNEL_DS);
721 ret = sys_ioctl (fd, cmd, (unsigned long) r);
722 set_fs (old_fs);
724 out:
725 if (mysock)
726 sockfd_put(mysock);
728 return ret;
730 #endif
732 struct hd_geometry32 {
733 unsigned char heads;
734 unsigned char sectors;
735 unsigned short cylinders;
736 u32 start;
739 static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
741 mm_segment_t old_fs = get_fs();
742 struct hd_geometry geo;
743 struct hd_geometry32 __user *ugeo;
744 int err;
746 set_fs (KERNEL_DS);
747 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
748 set_fs (old_fs);
749 ugeo = compat_ptr(arg);
750 if (!err) {
751 err = copy_to_user (ugeo, &geo, 4);
752 err |= __put_user (geo.start, &ugeo->start);
754 return err ? -EFAULT : 0;
757 static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
759 mm_segment_t old_fs = get_fs();
760 unsigned long kval;
761 unsigned int __user *uvp;
762 int error;
764 set_fs(KERNEL_DS);
765 error = sys_ioctl(fd, cmd, (long)&kval);
766 set_fs(old_fs);
768 if(error == 0) {
769 uvp = compat_ptr(arg);
770 if(put_user(kval, uvp))
771 error = -EFAULT;
773 return error;
777 typedef struct sg_io_hdr32 {
778 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
779 compat_int_t dxfer_direction; /* [i] data transfer direction */
780 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
781 unsigned char mx_sb_len; /* [i] max length to write to sbp */
782 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
783 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
784 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
785 or scatter gather list */
786 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
787 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
788 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
789 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
790 compat_int_t pack_id; /* [i->o] unused internally (normally) */
791 compat_uptr_t usr_ptr; /* [i->o] unused internally */
792 unsigned char status; /* [o] scsi status */
793 unsigned char masked_status; /* [o] shifted, masked scsi status */
794 unsigned char msg_status; /* [o] messaging level data (optional) */
795 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
796 unsigned short host_status; /* [o] errors from host adapter */
797 unsigned short driver_status; /* [o] errors from software driver */
798 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
799 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
800 compat_uint_t info; /* [o] auxiliary information */
801 } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
803 typedef struct sg_iovec32 {
804 compat_uint_t iov_base;
805 compat_uint_t iov_len;
806 } sg_iovec32_t;
808 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
810 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
811 sg_iovec32_t __user *iov32 = dxferp;
812 int i;
814 for (i = 0; i < iovec_count; i++) {
815 u32 base, len;
817 if (get_user(base, &iov32[i].iov_base) ||
818 get_user(len, &iov32[i].iov_len) ||
819 put_user(compat_ptr(base), &iov[i].iov_base) ||
820 put_user(len, &iov[i].iov_len))
821 return -EFAULT;
824 if (put_user(iov, &sgio->dxferp))
825 return -EFAULT;
826 return 0;
829 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
831 sg_io_hdr_t __user *sgio;
832 sg_io_hdr32_t __user *sgio32;
833 u16 iovec_count;
834 u32 data;
835 void __user *dxferp;
836 int err;
838 sgio32 = compat_ptr(arg);
839 if (get_user(iovec_count, &sgio32->iovec_count))
840 return -EFAULT;
843 void __user *top = compat_alloc_user_space(0);
844 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
845 (iovec_count * sizeof(sg_iovec_t)));
846 if (new > top)
847 return -EINVAL;
849 sgio = new;
852 /* Ok, now construct. */
853 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
854 (2 * sizeof(int)) +
855 (2 * sizeof(unsigned char)) +
856 (1 * sizeof(unsigned short)) +
857 (1 * sizeof(unsigned int))))
858 return -EFAULT;
860 if (get_user(data, &sgio32->dxferp))
861 return -EFAULT;
862 dxferp = compat_ptr(data);
863 if (iovec_count) {
864 if (sg_build_iovec(sgio, dxferp, iovec_count))
865 return -EFAULT;
866 } else {
867 if (put_user(dxferp, &sgio->dxferp))
868 return -EFAULT;
872 unsigned char __user *cmdp;
873 unsigned char __user *sbp;
875 if (get_user(data, &sgio32->cmdp))
876 return -EFAULT;
877 cmdp = compat_ptr(data);
879 if (get_user(data, &sgio32->sbp))
880 return -EFAULT;
881 sbp = compat_ptr(data);
883 if (put_user(cmdp, &sgio->cmdp) ||
884 put_user(sbp, &sgio->sbp))
885 return -EFAULT;
888 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
889 3 * sizeof(int)))
890 return -EFAULT;
892 if (get_user(data, &sgio32->usr_ptr))
893 return -EFAULT;
894 if (put_user(compat_ptr(data), &sgio->usr_ptr))
895 return -EFAULT;
897 if (copy_in_user(&sgio->status, &sgio32->status,
898 (4 * sizeof(unsigned char)) +
899 (2 * sizeof(unsigned (short))) +
900 (3 * sizeof(int))))
901 return -EFAULT;
903 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
905 if (err >= 0) {
906 void __user *datap;
908 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
909 sizeof(int)) ||
910 get_user(datap, &sgio->usr_ptr) ||
911 put_user((u32)(unsigned long)datap,
912 &sgio32->usr_ptr) ||
913 copy_in_user(&sgio32->status, &sgio->status,
914 (4 * sizeof(unsigned char)) +
915 (2 * sizeof(unsigned short)) +
916 (3 * sizeof(int))))
917 err = -EFAULT;
920 return err;
923 struct sock_fprog32 {
924 unsigned short len;
925 compat_caddr_t filter;
928 #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
929 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
931 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
933 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
934 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
935 void __user *fptr64;
936 u32 fptr32;
937 u16 flen;
939 if (get_user(flen, &u_fprog32->len) ||
940 get_user(fptr32, &u_fprog32->filter))
941 return -EFAULT;
943 fptr64 = compat_ptr(fptr32);
945 if (put_user(flen, &u_fprog64->len) ||
946 put_user(fptr64, &u_fprog64->filter))
947 return -EFAULT;
949 if (cmd == PPPIOCSPASS32)
950 cmd = PPPIOCSPASS;
951 else
952 cmd = PPPIOCSACTIVE;
954 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
957 struct ppp_option_data32 {
958 compat_caddr_t ptr;
959 u32 length;
960 compat_int_t transmit;
962 #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
964 struct ppp_idle32 {
965 compat_time_t xmit_idle;
966 compat_time_t recv_idle;
968 #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
970 static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
972 struct ppp_idle __user *idle;
973 struct ppp_idle32 __user *idle32;
974 __kernel_time_t xmit, recv;
975 int err;
977 idle = compat_alloc_user_space(sizeof(*idle));
978 idle32 = compat_ptr(arg);
980 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
982 if (!err) {
983 if (get_user(xmit, &idle->xmit_idle) ||
984 get_user(recv, &idle->recv_idle) ||
985 put_user(xmit, &idle32->xmit_idle) ||
986 put_user(recv, &idle32->recv_idle))
987 err = -EFAULT;
989 return err;
992 static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
994 struct ppp_option_data __user *odata;
995 struct ppp_option_data32 __user *odata32;
996 __u32 data;
997 void __user *datap;
999 odata = compat_alloc_user_space(sizeof(*odata));
1000 odata32 = compat_ptr(arg);
1002 if (get_user(data, &odata32->ptr))
1003 return -EFAULT;
1005 datap = compat_ptr(data);
1006 if (put_user(datap, &odata->ptr))
1007 return -EFAULT;
1009 if (copy_in_user(&odata->length, &odata32->length,
1010 sizeof(__u32) + sizeof(int)))
1011 return -EFAULT;
1013 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
1016 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1018 int err;
1020 switch (cmd) {
1021 case PPPIOCGIDLE32:
1022 err = ppp_gidle(fd, cmd, arg);
1023 break;
1025 case PPPIOCSCOMPRESS32:
1026 err = ppp_scompress(fd, cmd, arg);
1027 break;
1029 default:
1030 do {
1031 static int count;
1032 if (++count <= 20)
1033 printk("ppp_ioctl: Unknown cmd fd(%d) "
1034 "cmd(%08x) arg(%08x)\n",
1035 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1036 } while(0);
1037 err = -EINVAL;
1038 break;
1041 return err;
1045 struct mtget32 {
1046 compat_long_t mt_type;
1047 compat_long_t mt_resid;
1048 compat_long_t mt_dsreg;
1049 compat_long_t mt_gstat;
1050 compat_long_t mt_erreg;
1051 compat_daddr_t mt_fileno;
1052 compat_daddr_t mt_blkno;
1054 #define MTIOCGET32 _IOR('m', 2, struct mtget32)
1056 struct mtpos32 {
1057 compat_long_t mt_blkno;
1059 #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1061 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1063 mm_segment_t old_fs = get_fs();
1064 struct mtget get;
1065 struct mtget32 __user *umget32;
1066 struct mtpos pos;
1067 struct mtpos32 __user *upos32;
1068 unsigned long kcmd;
1069 void *karg;
1070 int err = 0;
1072 switch(cmd) {
1073 case MTIOCPOS32:
1074 kcmd = MTIOCPOS;
1075 karg = &pos;
1076 break;
1077 case MTIOCGET32:
1078 kcmd = MTIOCGET;
1079 karg = &get;
1080 break;
1081 default:
1082 do {
1083 static int count;
1084 if (++count <= 20)
1085 printk("mt_ioctl: Unknown cmd fd(%d) "
1086 "cmd(%08x) arg(%08x)\n",
1087 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1088 } while(0);
1089 return -EINVAL;
1091 set_fs (KERNEL_DS);
1092 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1093 set_fs (old_fs);
1094 if (err)
1095 return err;
1096 switch (cmd) {
1097 case MTIOCPOS32:
1098 upos32 = compat_ptr(arg);
1099 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1100 break;
1101 case MTIOCGET32:
1102 umget32 = compat_ptr(arg);
1103 err = __put_user(get.mt_type, &umget32->mt_type);
1104 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1105 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1106 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1107 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1108 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1109 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1110 break;
1112 return err ? -EFAULT: 0;
1115 struct cdrom_read_audio32 {
1116 union cdrom_addr addr;
1117 u8 addr_format;
1118 compat_int_t nframes;
1119 compat_caddr_t buf;
1122 struct cdrom_generic_command32 {
1123 unsigned char cmd[CDROM_PACKET_SIZE];
1124 compat_caddr_t buffer;
1125 compat_uint_t buflen;
1126 compat_int_t stat;
1127 compat_caddr_t sense;
1128 unsigned char data_direction;
1129 compat_int_t quiet;
1130 compat_int_t timeout;
1131 compat_caddr_t reserved[1];
1134 static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1136 struct cdrom_read_audio __user *cdread_audio;
1137 struct cdrom_read_audio32 __user *cdread_audio32;
1138 __u32 data;
1139 void __user *datap;
1141 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1142 cdread_audio32 = compat_ptr(arg);
1144 if (copy_in_user(&cdread_audio->addr,
1145 &cdread_audio32->addr,
1146 (sizeof(*cdread_audio32) -
1147 sizeof(compat_caddr_t))))
1148 return -EFAULT;
1150 if (get_user(data, &cdread_audio32->buf))
1151 return -EFAULT;
1152 datap = compat_ptr(data);
1153 if (put_user(datap, &cdread_audio->buf))
1154 return -EFAULT;
1156 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1159 static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1161 struct cdrom_generic_command __user *cgc;
1162 struct cdrom_generic_command32 __user *cgc32;
1163 u32 data;
1164 unsigned char dir;
1165 int itmp;
1167 cgc = compat_alloc_user_space(sizeof(*cgc));
1168 cgc32 = compat_ptr(arg);
1170 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1171 get_user(data, &cgc32->buffer) ||
1172 put_user(compat_ptr(data), &cgc->buffer) ||
1173 copy_in_user(&cgc->buflen, &cgc32->buflen,
1174 (sizeof(unsigned int) + sizeof(int))) ||
1175 get_user(data, &cgc32->sense) ||
1176 put_user(compat_ptr(data), &cgc->sense) ||
1177 get_user(dir, &cgc32->data_direction) ||
1178 put_user(dir, &cgc->data_direction) ||
1179 get_user(itmp, &cgc32->quiet) ||
1180 put_user(itmp, &cgc->quiet) ||
1181 get_user(itmp, &cgc32->timeout) ||
1182 put_user(itmp, &cgc->timeout) ||
1183 get_user(data, &cgc32->reserved[0]) ||
1184 put_user(compat_ptr(data), &cgc->reserved[0]))
1185 return -EFAULT;
1187 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1190 static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1192 int err;
1194 switch(cmd) {
1195 case CDROMREADAUDIO:
1196 err = cdrom_do_read_audio(fd, cmd, arg);
1197 break;
1199 case CDROM_SEND_PACKET:
1200 err = cdrom_do_generic_command(fd, cmd, arg);
1201 break;
1203 default:
1204 do {
1205 static int count;
1206 if (++count <= 20)
1207 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1208 "cmd(%08x) arg(%08x)\n",
1209 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1210 } while(0);
1211 err = -EINVAL;
1212 break;
1215 return err;
1218 struct loop_info32 {
1219 compat_int_t lo_number; /* ioctl r/o */
1220 compat_dev_t lo_device; /* ioctl r/o */
1221 compat_ulong_t lo_inode; /* ioctl r/o */
1222 compat_dev_t lo_rdevice; /* ioctl r/o */
1223 compat_int_t lo_offset;
1224 compat_int_t lo_encrypt_type;
1225 compat_int_t lo_encrypt_key_size; /* ioctl w/o */
1226 compat_int_t lo_flags; /* ioctl r/o */
1227 char lo_name[LO_NAME_SIZE];
1228 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
1229 compat_ulong_t lo_init[2];
1230 char reserved[4];
1233 static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg)
1235 mm_segment_t old_fs = get_fs();
1236 struct loop_info l;
1237 struct loop_info32 __user *ul;
1238 int err = -EINVAL;
1240 ul = compat_ptr(arg);
1241 switch(cmd) {
1242 case LOOP_SET_STATUS:
1243 err = get_user(l.lo_number, &ul->lo_number);
1244 err |= __get_user(l.lo_device, &ul->lo_device);
1245 err |= __get_user(l.lo_inode, &ul->lo_inode);
1246 err |= __get_user(l.lo_rdevice, &ul->lo_rdevice);
1247 err |= __copy_from_user(&l.lo_offset, &ul->lo_offset,
1248 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1249 if (err) {
1250 err = -EFAULT;
1251 } else {
1252 set_fs (KERNEL_DS);
1253 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1254 set_fs (old_fs);
1256 break;
1257 case LOOP_GET_STATUS:
1258 set_fs (KERNEL_DS);
1259 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1260 set_fs (old_fs);
1261 if (!err) {
1262 err = put_user(l.lo_number, &ul->lo_number);
1263 err |= __put_user(l.lo_device, &ul->lo_device);
1264 err |= __put_user(l.lo_inode, &ul->lo_inode);
1265 err |= __put_user(l.lo_rdevice, &ul->lo_rdevice);
1266 err |= __copy_to_user(&ul->lo_offset, &l.lo_offset,
1267 (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1268 if (err)
1269 err = -EFAULT;
1271 break;
1272 default: {
1273 static int count;
1274 if (++count <= 20)
1275 printk("%s: Unknown loop ioctl cmd, fd(%d) "
1276 "cmd(%08x) arg(%08lx)\n",
1277 __FUNCTION__, fd, cmd, arg);
1280 return err;
1283 extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);
1285 #ifdef CONFIG_VT
1287 static int vt_check(struct file *file)
1289 struct tty_struct *tty;
1290 struct inode *inode = file->f_dentry->d_inode;
1292 if (file->f_op->ioctl != tty_ioctl)
1293 return -EINVAL;
1295 tty = (struct tty_struct *)file->private_data;
1296 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1297 return -EINVAL;
1299 if (tty->driver->ioctl != vt_ioctl)
1300 return -EINVAL;
1303 * To have permissions to do most of the vt ioctls, we either have
1304 * to be the owner of the tty, or super-user.
1306 if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
1307 return 1;
1308 return 0;
1311 struct consolefontdesc32 {
1312 unsigned short charcount; /* characters in font (256 or 512) */
1313 unsigned short charheight; /* scan lines per character (1-32) */
1314 compat_caddr_t chardata; /* font data in expanded form */
1317 static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1319 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1320 struct console_font_op op;
1321 compat_caddr_t data;
1322 int i, perm;
1324 perm = vt_check(file);
1325 if (perm < 0) return perm;
1327 switch (cmd) {
1328 case PIO_FONTX:
1329 if (!perm)
1330 return -EPERM;
1331 op.op = KD_FONT_OP_SET;
1332 op.flags = 0;
1333 op.width = 8;
1334 if (get_user(op.height, &user_cfd->charheight) ||
1335 get_user(op.charcount, &user_cfd->charcount) ||
1336 get_user(data, &user_cfd->chardata))
1337 return -EFAULT;
1338 op.data = compat_ptr(data);
1339 return con_font_op(vc_cons[fg_console].d, &op);
1340 case GIO_FONTX:
1341 op.op = KD_FONT_OP_GET;
1342 op.flags = 0;
1343 op.width = 8;
1344 if (get_user(op.height, &user_cfd->charheight) ||
1345 get_user(op.charcount, &user_cfd->charcount) ||
1346 get_user(data, &user_cfd->chardata))
1347 return -EFAULT;
1348 if (!data)
1349 return 0;
1350 op.data = compat_ptr(data);
1351 i = con_font_op(vc_cons[fg_console].d, &op);
1352 if (i)
1353 return i;
1354 if (put_user(op.height, &user_cfd->charheight) ||
1355 put_user(op.charcount, &user_cfd->charcount) ||
1356 put_user((compat_caddr_t)(unsigned long)op.data,
1357 &user_cfd->chardata))
1358 return -EFAULT;
1359 return 0;
1361 return -EINVAL;
1364 struct console_font_op32 {
1365 compat_uint_t op; /* operation code KD_FONT_OP_* */
1366 compat_uint_t flags; /* KD_FONT_FLAG_* */
1367 compat_uint_t width, height; /* font size */
1368 compat_uint_t charcount;
1369 compat_caddr_t data; /* font data with height fixed to 32 */
1372 static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1374 struct console_font_op op;
1375 struct console_font_op32 __user *fontop = compat_ptr(arg);
1376 int perm = vt_check(file), i;
1377 struct vc_data *vc;
1379 if (perm < 0) return perm;
1381 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1382 return -EFAULT;
1383 if (!perm && op.op != KD_FONT_OP_GET)
1384 return -EPERM;
1385 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1386 op.flags |= KD_FONT_FLAG_OLD;
1387 vc = ((struct tty_struct *)file->private_data)->driver_data;
1388 i = con_font_op(vc, &op);
1389 if (i)
1390 return i;
1391 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1392 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1393 return -EFAULT;
1394 return 0;
1397 struct unimapdesc32 {
1398 unsigned short entry_ct;
1399 compat_caddr_t entries;
1402 static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1404 struct unimapdesc32 tmp;
1405 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1406 int perm = vt_check(file);
1408 if (perm < 0) return perm;
1409 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1410 return -EFAULT;
1411 switch (cmd) {
1412 case PIO_UNIMAP:
1413 if (!perm) return -EPERM;
1414 return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries));
1415 case GIO_UNIMAP:
1416 return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
1418 return 0;
1421 #endif /* CONFIG_VT */
1423 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1425 mm_segment_t old_fs = get_fs();
1426 __kernel_uid_t kuid;
1427 int err;
1429 cmd = SMB_IOC_GETMOUNTUID;
1431 set_fs(KERNEL_DS);
1432 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1433 set_fs(old_fs);
1435 if (err >= 0)
1436 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1438 return err;
1441 struct atmif_sioc32 {
1442 compat_int_t number;
1443 compat_int_t length;
1444 compat_caddr_t arg;
1447 struct atm_iobuf32 {
1448 compat_int_t length;
1449 compat_caddr_t buffer;
1452 #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1453 #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1454 #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1455 #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1456 #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1457 #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1458 #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1459 #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1460 #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1461 #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1462 #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1463 #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1464 #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1465 #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1466 #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1467 #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1468 #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1470 static struct {
1471 unsigned int cmd32;
1472 unsigned int cmd;
1473 } atm_ioctl_map[] = {
1474 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1475 { ATM_GETNAMES32, ATM_GETNAMES },
1476 { ATM_GETTYPE32, ATM_GETTYPE },
1477 { ATM_GETESI32, ATM_GETESI },
1478 { ATM_GETADDR32, ATM_GETADDR },
1479 { ATM_RSTADDR32, ATM_RSTADDR },
1480 { ATM_ADDADDR32, ATM_ADDADDR },
1481 { ATM_DELADDR32, ATM_DELADDR },
1482 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1483 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1484 { ATM_SETESI32, ATM_SETESI },
1485 { ATM_SETESIF32, ATM_SETESIF },
1486 { ATM_GETSTAT32, ATM_GETSTAT },
1487 { ATM_GETSTATZ32, ATM_GETSTATZ },
1488 { ATM_GETLOOP32, ATM_GETLOOP },
1489 { ATM_SETLOOP32, ATM_SETLOOP },
1490 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1493 #define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
1496 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1498 struct atm_iobuf __user *iobuf;
1499 struct atm_iobuf32 __user *iobuf32;
1500 u32 data;
1501 void __user *datap;
1502 int len, err;
1504 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1505 iobuf32 = compat_ptr(arg);
1507 if (get_user(len, &iobuf32->length) ||
1508 get_user(data, &iobuf32->buffer))
1509 return -EFAULT;
1510 datap = compat_ptr(data);
1511 if (put_user(len, &iobuf->length) ||
1512 put_user(datap, &iobuf->buffer))
1513 return -EFAULT;
1515 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1517 if (!err) {
1518 if (copy_in_user(&iobuf32->length, &iobuf->length,
1519 sizeof(int)))
1520 err = -EFAULT;
1523 return err;
1526 static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1528 struct atmif_sioc __user *sioc;
1529 struct atmif_sioc32 __user *sioc32;
1530 u32 data;
1531 void __user *datap;
1532 int err;
1534 sioc = compat_alloc_user_space(sizeof(*sioc));
1535 sioc32 = compat_ptr(arg);
1537 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1538 get_user(data, &sioc32->arg))
1539 return -EFAULT;
1540 datap = compat_ptr(data);
1541 if (put_user(datap, &sioc->arg))
1542 return -EFAULT;
1544 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1546 if (!err) {
1547 if (copy_in_user(&sioc32->length, &sioc->length,
1548 sizeof(int)))
1549 err = -EFAULT;
1551 return err;
1554 static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1556 int i;
1557 unsigned int cmd = 0;
1559 switch (cmd32) {
1560 case SONET_GETSTAT:
1561 case SONET_GETSTATZ:
1562 case SONET_GETDIAG:
1563 case SONET_SETDIAG:
1564 case SONET_CLRDIAG:
1565 case SONET_SETFRAMING:
1566 case SONET_GETFRAMING:
1567 case SONET_GETFRSENSE:
1568 return do_atmif_sioc(fd, cmd32, arg);
1571 for (i = 0; i < NR_ATM_IOCTL; i++) {
1572 if (cmd32 == atm_ioctl_map[i].cmd32) {
1573 cmd = atm_ioctl_map[i].cmd;
1574 break;
1577 if (i == NR_ATM_IOCTL)
1578 return -EINVAL;
1580 switch (cmd) {
1581 case ATM_GETNAMES:
1582 return do_atm_iobuf(fd, cmd, arg);
1584 case ATM_GETLINKRATE:
1585 case ATM_GETTYPE:
1586 case ATM_GETESI:
1587 case ATM_GETADDR:
1588 case ATM_RSTADDR:
1589 case ATM_ADDADDR:
1590 case ATM_DELADDR:
1591 case ATM_GETCIRANGE:
1592 case ATM_SETCIRANGE:
1593 case ATM_SETESI:
1594 case ATM_SETESIF:
1595 case ATM_GETSTAT:
1596 case ATM_GETSTATZ:
1597 case ATM_GETLOOP:
1598 case ATM_SETLOOP:
1599 case ATM_QUERYLOOP:
1600 return do_atmif_sioc(fd, cmd, arg);
1603 return -EINVAL;
1606 static __attribute_used__ int
1607 ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1609 return -EINVAL;
1612 static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1614 /* The mkswap binary hard codes it to Intel value :-((( */
1615 return w_long(fd, BLKGETSIZE, arg);
1618 struct blkpg_ioctl_arg32 {
1619 compat_int_t op;
1620 compat_int_t flags;
1621 compat_int_t datalen;
1622 compat_caddr_t data;
1625 static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1627 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1628 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1629 compat_caddr_t udata;
1630 compat_int_t n;
1631 int err;
1633 err = get_user(n, &ua32->op);
1634 err |= put_user(n, &a->op);
1635 err |= get_user(n, &ua32->flags);
1636 err |= put_user(n, &a->flags);
1637 err |= get_user(n, &ua32->datalen);
1638 err |= put_user(n, &a->datalen);
1639 err |= get_user(udata, &ua32->data);
1640 err |= put_user(compat_ptr(udata), &a->data);
1641 if (err)
1642 return err;
1644 return sys_ioctl(fd, cmd, (unsigned long)a);
1647 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1649 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1652 /* Fix sizeof(sizeof()) breakage */
1653 #define BLKBSZGET_32 _IOR(0x12,112,int)
1654 #define BLKBSZSET_32 _IOW(0x12,113,int)
1655 #define BLKGETSIZE64_32 _IOR(0x12,114,int)
1657 static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1659 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1662 static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1664 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1667 static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1668 unsigned long arg)
1670 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1673 /* Bluetooth ioctls */
1674 #define HCIUARTSETPROTO _IOW('U', 200, int)
1675 #define HCIUARTGETPROTO _IOR('U', 201, int)
1677 #define BNEPCONNADD _IOW('B', 200, int)
1678 #define BNEPCONNDEL _IOW('B', 201, int)
1679 #define BNEPGETCONNLIST _IOR('B', 210, int)
1680 #define BNEPGETCONNINFO _IOR('B', 211, int)
1682 #define CMTPCONNADD _IOW('C', 200, int)
1683 #define CMTPCONNDEL _IOW('C', 201, int)
1684 #define CMTPGETCONNLIST _IOR('C', 210, int)
1685 #define CMTPGETCONNINFO _IOR('C', 211, int)
1687 #define HIDPCONNADD _IOW('H', 200, int)
1688 #define HIDPCONNDEL _IOW('H', 201, int)
1689 #define HIDPGETCONNLIST _IOR('H', 210, int)
1690 #define HIDPGETCONNINFO _IOR('H', 211, int)
1692 struct floppy_struct32 {
1693 compat_uint_t size;
1694 compat_uint_t sect;
1695 compat_uint_t head;
1696 compat_uint_t track;
1697 compat_uint_t stretch;
1698 unsigned char gap;
1699 unsigned char rate;
1700 unsigned char spec1;
1701 unsigned char fmt_gap;
1702 const compat_caddr_t name;
1705 struct floppy_drive_params32 {
1706 char cmos;
1707 compat_ulong_t max_dtr;
1708 compat_ulong_t hlt;
1709 compat_ulong_t hut;
1710 compat_ulong_t srt;
1711 compat_ulong_t spinup;
1712 compat_ulong_t spindown;
1713 unsigned char spindown_offset;
1714 unsigned char select_delay;
1715 unsigned char rps;
1716 unsigned char tracks;
1717 compat_ulong_t timeout;
1718 unsigned char interleave_sect;
1719 struct floppy_max_errors max_errors;
1720 char flags;
1721 char read_track;
1722 short autodetect[8];
1723 compat_int_t checkfreq;
1724 compat_int_t native_format;
1727 struct floppy_drive_struct32 {
1728 signed char flags;
1729 compat_ulong_t spinup_date;
1730 compat_ulong_t select_date;
1731 compat_ulong_t first_read_date;
1732 short probed_format;
1733 short track;
1734 short maxblock;
1735 short maxtrack;
1736 compat_int_t generation;
1737 compat_int_t keep_data;
1738 compat_int_t fd_ref;
1739 compat_int_t fd_device;
1740 compat_int_t last_checked;
1741 compat_caddr_t dmabuf;
1742 compat_int_t bufblocks;
1745 struct floppy_fdc_state32 {
1746 compat_int_t spec1;
1747 compat_int_t spec2;
1748 compat_int_t dtr;
1749 unsigned char version;
1750 unsigned char dor;
1751 compat_ulong_t address;
1752 unsigned int rawcmd:2;
1753 unsigned int reset:1;
1754 unsigned int need_configure:1;
1755 unsigned int perp_mode:2;
1756 unsigned int has_fifo:1;
1757 unsigned int driver_version;
1758 unsigned char track[4];
1761 struct floppy_write_errors32 {
1762 unsigned int write_errors;
1763 compat_ulong_t first_error_sector;
1764 compat_int_t first_error_generation;
1765 compat_ulong_t last_error_sector;
1766 compat_int_t last_error_generation;
1767 compat_uint_t badness;
1770 #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1771 #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1772 #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1773 #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1774 #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1775 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1776 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1777 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1778 #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
1780 static struct {
1781 unsigned int cmd32;
1782 unsigned int cmd;
1783 } fd_ioctl_trans_table[] = {
1784 { FDSETPRM32, FDSETPRM },
1785 { FDDEFPRM32, FDDEFPRM },
1786 { FDGETPRM32, FDGETPRM },
1787 { FDSETDRVPRM32, FDSETDRVPRM },
1788 { FDGETDRVPRM32, FDGETDRVPRM },
1789 { FDGETDRVSTAT32, FDGETDRVSTAT },
1790 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1791 { FDGETFDCSTAT32, FDGETFDCSTAT },
1792 { FDWERRORGET32, FDWERRORGET }
1795 #define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
1797 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1799 mm_segment_t old_fs = get_fs();
1800 void *karg = NULL;
1801 unsigned int kcmd = 0;
1802 int i, err;
1804 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1805 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1806 kcmd = fd_ioctl_trans_table[i].cmd;
1807 break;
1809 if (!kcmd)
1810 return -EINVAL;
1812 switch (cmd) {
1813 case FDSETPRM32:
1814 case FDDEFPRM32:
1815 case FDGETPRM32:
1817 compat_uptr_t name;
1818 struct floppy_struct32 __user *uf;
1819 struct floppy_struct *f;
1821 uf = compat_ptr(arg);
1822 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1823 if (!karg)
1824 return -ENOMEM;
1825 if (cmd == FDGETPRM32)
1826 break;
1827 err = __get_user(f->size, &uf->size);
1828 err |= __get_user(f->sect, &uf->sect);
1829 err |= __get_user(f->head, &uf->head);
1830 err |= __get_user(f->track, &uf->track);
1831 err |= __get_user(f->stretch, &uf->stretch);
1832 err |= __get_user(f->gap, &uf->gap);
1833 err |= __get_user(f->rate, &uf->rate);
1834 err |= __get_user(f->spec1, &uf->spec1);
1835 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
1836 err |= __get_user(name, &uf->name);
1837 f->name = compat_ptr(name);
1838 if (err) {
1839 err = -EFAULT;
1840 goto out;
1842 break;
1844 case FDSETDRVPRM32:
1845 case FDGETDRVPRM32:
1847 struct floppy_drive_params32 __user *uf;
1848 struct floppy_drive_params *f;
1850 uf = compat_ptr(arg);
1851 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1852 if (!karg)
1853 return -ENOMEM;
1854 if (cmd == FDGETDRVPRM32)
1855 break;
1856 err = __get_user(f->cmos, &uf->cmos);
1857 err |= __get_user(f->max_dtr, &uf->max_dtr);
1858 err |= __get_user(f->hlt, &uf->hlt);
1859 err |= __get_user(f->hut, &uf->hut);
1860 err |= __get_user(f->srt, &uf->srt);
1861 err |= __get_user(f->spinup, &uf->spinup);
1862 err |= __get_user(f->spindown, &uf->spindown);
1863 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
1864 err |= __get_user(f->select_delay, &uf->select_delay);
1865 err |= __get_user(f->rps, &uf->rps);
1866 err |= __get_user(f->tracks, &uf->tracks);
1867 err |= __get_user(f->timeout, &uf->timeout);
1868 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
1869 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
1870 err |= __get_user(f->flags, &uf->flags);
1871 err |= __get_user(f->read_track, &uf->read_track);
1872 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
1873 err |= __get_user(f->checkfreq, &uf->checkfreq);
1874 err |= __get_user(f->native_format, &uf->native_format);
1875 if (err) {
1876 err = -EFAULT;
1877 goto out;
1879 break;
1881 case FDGETDRVSTAT32:
1882 case FDPOLLDRVSTAT32:
1883 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1884 if (!karg)
1885 return -ENOMEM;
1886 break;
1887 case FDGETFDCSTAT32:
1888 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1889 if (!karg)
1890 return -ENOMEM;
1891 break;
1892 case FDWERRORGET32:
1893 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1894 if (!karg)
1895 return -ENOMEM;
1896 break;
1897 default:
1898 return -EINVAL;
1900 set_fs (KERNEL_DS);
1901 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1902 set_fs (old_fs);
1903 if (err)
1904 goto out;
1905 switch (cmd) {
1906 case FDGETPRM32:
1908 struct floppy_struct *f = karg;
1909 struct floppy_struct32 __user *uf = compat_ptr(arg);
1911 err = __put_user(f->size, &uf->size);
1912 err |= __put_user(f->sect, &uf->sect);
1913 err |= __put_user(f->head, &uf->head);
1914 err |= __put_user(f->track, &uf->track);
1915 err |= __put_user(f->stretch, &uf->stretch);
1916 err |= __put_user(f->gap, &uf->gap);
1917 err |= __put_user(f->rate, &uf->rate);
1918 err |= __put_user(f->spec1, &uf->spec1);
1919 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
1920 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
1921 break;
1923 case FDGETDRVPRM32:
1925 struct floppy_drive_params32 __user *uf;
1926 struct floppy_drive_params *f = karg;
1928 uf = compat_ptr(arg);
1929 err = __put_user(f->cmos, &uf->cmos);
1930 err |= __put_user(f->max_dtr, &uf->max_dtr);
1931 err |= __put_user(f->hlt, &uf->hlt);
1932 err |= __put_user(f->hut, &uf->hut);
1933 err |= __put_user(f->srt, &uf->srt);
1934 err |= __put_user(f->spinup, &uf->spinup);
1935 err |= __put_user(f->spindown, &uf->spindown);
1936 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
1937 err |= __put_user(f->select_delay, &uf->select_delay);
1938 err |= __put_user(f->rps, &uf->rps);
1939 err |= __put_user(f->tracks, &uf->tracks);
1940 err |= __put_user(f->timeout, &uf->timeout);
1941 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
1942 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
1943 err |= __put_user(f->flags, &uf->flags);
1944 err |= __put_user(f->read_track, &uf->read_track);
1945 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
1946 err |= __put_user(f->checkfreq, &uf->checkfreq);
1947 err |= __put_user(f->native_format, &uf->native_format);
1948 break;
1950 case FDGETDRVSTAT32:
1951 case FDPOLLDRVSTAT32:
1953 struct floppy_drive_struct32 __user *uf;
1954 struct floppy_drive_struct *f = karg;
1956 uf = compat_ptr(arg);
1957 err = __put_user(f->flags, &uf->flags);
1958 err |= __put_user(f->spinup_date, &uf->spinup_date);
1959 err |= __put_user(f->select_date, &uf->select_date);
1960 err |= __put_user(f->first_read_date, &uf->first_read_date);
1961 err |= __put_user(f->probed_format, &uf->probed_format);
1962 err |= __put_user(f->track, &uf->track);
1963 err |= __put_user(f->maxblock, &uf->maxblock);
1964 err |= __put_user(f->maxtrack, &uf->maxtrack);
1965 err |= __put_user(f->generation, &uf->generation);
1966 err |= __put_user(f->keep_data, &uf->keep_data);
1967 err |= __put_user(f->fd_ref, &uf->fd_ref);
1968 err |= __put_user(f->fd_device, &uf->fd_device);
1969 err |= __put_user(f->last_checked, &uf->last_checked);
1970 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
1971 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
1972 break;
1974 case FDGETFDCSTAT32:
1976 struct floppy_fdc_state32 __user *uf;
1977 struct floppy_fdc_state *f = karg;
1979 uf = compat_ptr(arg);
1980 err = __put_user(f->spec1, &uf->spec1);
1981 err |= __put_user(f->spec2, &uf->spec2);
1982 err |= __put_user(f->dtr, &uf->dtr);
1983 err |= __put_user(f->version, &uf->version);
1984 err |= __put_user(f->dor, &uf->dor);
1985 err |= __put_user(f->address, &uf->address);
1986 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
1987 (char *)&f->address + sizeof(f->address), sizeof(int));
1988 err |= __put_user(f->driver_version, &uf->driver_version);
1989 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
1990 break;
1992 case FDWERRORGET32:
1994 struct floppy_write_errors32 __user *uf;
1995 struct floppy_write_errors *f = karg;
1997 uf = compat_ptr(arg);
1998 err = __put_user(f->write_errors, &uf->write_errors);
1999 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
2000 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
2001 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
2002 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
2003 err |= __put_user(f->badness, &uf->badness);
2004 break;
2006 default:
2007 break;
2009 if (err)
2010 err = -EFAULT;
2012 out:
2013 kfree(karg);
2014 return err;
2017 struct mtd_oob_buf32 {
2018 u_int32_t start;
2019 u_int32_t length;
2020 compat_caddr_t ptr; /* unsigned char* */
2023 #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
2024 #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
2026 static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
2028 struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
2029 struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
2030 u32 data;
2031 char __user *datap;
2032 unsigned int real_cmd;
2033 int err;
2035 real_cmd = (cmd == MEMREADOOB32) ?
2036 MEMREADOOB : MEMWRITEOOB;
2038 if (copy_in_user(&buf->start, &buf32->start,
2039 2 * sizeof(u32)) ||
2040 get_user(data, &buf32->ptr))
2041 return -EFAULT;
2042 datap = compat_ptr(data);
2043 if (put_user(datap, &buf->ptr))
2044 return -EFAULT;
2046 err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
2048 if (!err) {
2049 if (copy_in_user(&buf32->start, &buf->start,
2050 2 * sizeof(u32)))
2051 err = -EFAULT;
2054 return err;
2057 #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
2058 #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
2060 static long
2061 put_dirent32 (struct dirent *d, struct compat_dirent __user *d32)
2063 if (!access_ok(VERIFY_WRITE, d32, sizeof(struct compat_dirent)))
2064 return -EFAULT;
2066 __put_user(d->d_ino, &d32->d_ino);
2067 __put_user(d->d_off, &d32->d_off);
2068 __put_user(d->d_reclen, &d32->d_reclen);
2069 if (__copy_to_user(d32->d_name, d->d_name, d->d_reclen))
2070 return -EFAULT;
2072 return 0;
2075 static int vfat_ioctl32(unsigned fd, unsigned cmd, unsigned long arg)
2077 struct compat_dirent __user *p = compat_ptr(arg);
2078 int ret;
2079 mm_segment_t oldfs = get_fs();
2080 struct dirent d[2];
2082 switch(cmd)
2084 case VFAT_IOCTL_READDIR_BOTH32:
2085 cmd = VFAT_IOCTL_READDIR_BOTH;
2086 break;
2087 case VFAT_IOCTL_READDIR_SHORT32:
2088 cmd = VFAT_IOCTL_READDIR_SHORT;
2089 break;
2092 set_fs(KERNEL_DS);
2093 ret = sys_ioctl(fd,cmd,(unsigned long)&d);
2094 set_fs(oldfs);
2095 if (ret >= 0) {
2096 ret |= put_dirent32(&d[0], p);
2097 ret |= put_dirent32(&d[1], p + 1);
2099 return ret;
2102 #define REISERFS_IOC_UNPACK32 _IOW(0xCD,1,int)
2104 static int reiserfs_ioctl32(unsigned fd, unsigned cmd, unsigned long ptr)
2106 if (cmd == REISERFS_IOC_UNPACK32)
2107 cmd = REISERFS_IOC_UNPACK;
2109 return sys_ioctl(fd,cmd,ptr);
2112 struct raw32_config_request
2114 compat_int_t raw_minor;
2115 __u64 block_major;
2116 __u64 block_minor;
2117 } __attribute__((packed));
2119 static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2121 int ret;
2123 if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
2124 return -EFAULT;
2126 ret = __get_user(req->raw_minor, &user_req->raw_minor);
2127 ret |= __get_user(req->block_major, &user_req->block_major);
2128 ret |= __get_user(req->block_minor, &user_req->block_minor);
2130 return ret ? -EFAULT : 0;
2133 static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2135 int ret;
2137 if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
2138 return -EFAULT;
2140 ret = __put_user(req->raw_minor, &user_req->raw_minor);
2141 ret |= __put_user(req->block_major, &user_req->block_major);
2142 ret |= __put_user(req->block_minor, &user_req->block_minor);
2144 return ret ? -EFAULT : 0;
2147 static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2149 int ret;
2151 switch (cmd) {
2152 case RAW_SETBIND:
2153 case RAW_GETBIND: {
2154 struct raw_config_request req;
2155 struct raw32_config_request __user *user_req = compat_ptr(arg);
2156 mm_segment_t oldfs = get_fs();
2158 if ((ret = get_raw32_request(&req, user_req)))
2159 return ret;
2161 set_fs(KERNEL_DS);
2162 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2163 set_fs(oldfs);
2165 if ((!ret) && (cmd == RAW_GETBIND)) {
2166 ret = set_raw32_request(&req, user_req);
2168 break;
2170 default:
2171 ret = sys_ioctl(fd, cmd, arg);
2172 break;
2174 return ret;
2177 struct serial_struct32 {
2178 compat_int_t type;
2179 compat_int_t line;
2180 compat_uint_t port;
2181 compat_int_t irq;
2182 compat_int_t flags;
2183 compat_int_t xmit_fifo_size;
2184 compat_int_t custom_divisor;
2185 compat_int_t baud_base;
2186 unsigned short close_delay;
2187 char io_type;
2188 char reserved_char[1];
2189 compat_int_t hub6;
2190 unsigned short closing_wait; /* time to wait before closing */
2191 unsigned short closing_wait2; /* no longer used... */
2192 compat_uint_t iomem_base;
2193 unsigned short iomem_reg_shift;
2194 unsigned int port_high;
2195 /* compat_ulong_t iomap_base FIXME */
2196 compat_int_t reserved[1];
2199 static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2201 typedef struct serial_struct SS;
2202 typedef struct serial_struct32 SS32;
2203 struct serial_struct32 __user *ss32 = compat_ptr(arg);
2204 int err;
2205 struct serial_struct ss;
2206 mm_segment_t oldseg = get_fs();
2207 __u32 udata;
2209 if (cmd == TIOCSSERIAL) {
2210 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
2211 return -EFAULT;
2212 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
2213 return -EFAULT;
2214 __get_user(udata, &ss32->iomem_base);
2215 ss.iomem_base = compat_ptr(udata);
2216 __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2217 __get_user(ss.port_high, &ss32->port_high);
2218 ss.iomap_base = 0UL;
2220 set_fs(KERNEL_DS);
2221 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2222 set_fs(oldseg);
2223 if (cmd == TIOCGSERIAL && err >= 0) {
2224 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
2225 return -EFAULT;
2226 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
2227 return -EFAULT;
2228 __put_user((unsigned long)ss.iomem_base >> 32 ?
2229 0xffffffff : (unsigned)(unsigned long)ss.iomem_base,
2230 &ss32->iomem_base);
2231 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2232 __put_user(ss.port_high, &ss32->port_high);
2235 return err;
2238 struct usbdevfs_ctrltransfer32 {
2239 u8 bRequestType;
2240 u8 bRequest;
2241 u16 wValue;
2242 u16 wIndex;
2243 u16 wLength;
2244 u32 timeout; /* in milliseconds */
2245 compat_caddr_t data;
2248 #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2250 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2252 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2253 struct usbdevfs_ctrltransfer __user *p;
2254 __u32 udata;
2255 p = compat_alloc_user_space(sizeof(*p));
2256 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2257 get_user(udata, &p32->data) ||
2258 put_user(compat_ptr(udata), &p->data))
2259 return -EFAULT;
2260 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2264 struct usbdevfs_bulktransfer32 {
2265 compat_uint_t ep;
2266 compat_uint_t len;
2267 compat_uint_t timeout; /* in milliseconds */
2268 compat_caddr_t data;
2271 #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2273 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2275 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2276 struct usbdevfs_bulktransfer __user *p;
2277 compat_uint_t n;
2278 compat_caddr_t addr;
2280 p = compat_alloc_user_space(sizeof(*p));
2282 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2283 get_user(n, &p32->len) || put_user(n, &p->len) ||
2284 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2285 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2286 return -EFAULT;
2288 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2293 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
2294 * are handled in usbdevfs core. -Christopher Li
2297 struct usbdevfs_disconnectsignal32 {
2298 compat_int_t signr;
2299 compat_caddr_t context;
2302 #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2304 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2306 struct usbdevfs_disconnectsignal kdis;
2307 struct usbdevfs_disconnectsignal32 __user *udis;
2308 mm_segment_t old_fs;
2309 u32 uctx;
2310 int err;
2312 udis = compat_ptr(arg);
2314 if (get_user(kdis.signr, &udis->signr) ||
2315 __get_user(uctx, &udis->context))
2316 return -EFAULT;
2318 kdis.context = compat_ptr(uctx);
2320 old_fs = get_fs();
2321 set_fs(KERNEL_DS);
2322 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2323 set_fs(old_fs);
2325 return err;
2329 * I2C layer ioctls
2332 struct i2c_msg32 {
2333 u16 addr;
2334 u16 flags;
2335 u16 len;
2336 compat_caddr_t buf;
2339 struct i2c_rdwr_ioctl_data32 {
2340 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2341 u32 nmsgs;
2344 struct i2c_smbus_ioctl_data32 {
2345 u8 read_write;
2346 u8 command;
2347 u32 size;
2348 compat_caddr_t data; /* union i2c_smbus_data *data */
2351 struct i2c_rdwr_aligned {
2352 struct i2c_rdwr_ioctl_data cmd;
2353 struct i2c_msg msgs[0];
2356 static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2358 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
2359 struct i2c_rdwr_aligned __user *tdata;
2360 struct i2c_msg __user *tmsgs;
2361 struct i2c_msg32 __user *umsgs;
2362 compat_caddr_t datap;
2363 int nmsgs, i;
2365 if (get_user(nmsgs, &udata->nmsgs))
2366 return -EFAULT;
2367 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2368 return -EINVAL;
2370 if (get_user(datap, &udata->msgs))
2371 return -EFAULT;
2372 umsgs = compat_ptr(datap);
2374 tdata = compat_alloc_user_space(sizeof(*tdata) +
2375 nmsgs * sizeof(struct i2c_msg));
2376 tmsgs = &tdata->msgs[0];
2378 if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
2379 put_user(tmsgs, &tdata->cmd.msgs))
2380 return -EFAULT;
2382 for (i = 0; i < nmsgs; i++) {
2383 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
2384 return -EFAULT;
2385 if (get_user(datap, &umsgs[i].buf) ||
2386 put_user(compat_ptr(datap), &tmsgs[i].buf))
2387 return -EFAULT;
2389 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2392 static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2394 struct i2c_smbus_ioctl_data __user *tdata;
2395 struct i2c_smbus_ioctl_data32 __user *udata;
2396 compat_caddr_t datap;
2398 tdata = compat_alloc_user_space(sizeof(*tdata));
2399 if (tdata == NULL)
2400 return -ENOMEM;
2401 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
2402 return -EFAULT;
2404 udata = compat_ptr(arg);
2405 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
2406 return -EFAULT;
2408 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2409 return -EFAULT;
2410 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2411 return -EFAULT;
2412 if (__get_user(datap, &udata->data) ||
2413 __put_user(compat_ptr(datap), &tdata->data))
2414 return -EFAULT;
2416 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2419 struct compat_iw_point {
2420 compat_caddr_t pointer;
2421 __u16 length;
2422 __u16 flags;
2425 static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2427 struct iwreq __user *iwr;
2428 struct iwreq __user *iwr_u;
2429 struct iw_point __user *iwp;
2430 struct compat_iw_point __user *iwp_u;
2431 compat_caddr_t pointer;
2432 __u16 length, flags;
2434 iwr_u = compat_ptr(arg);
2435 iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2436 iwr = compat_alloc_user_space(sizeof(*iwr));
2437 if (iwr == NULL)
2438 return -ENOMEM;
2440 iwp = &iwr->u.data;
2442 if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
2443 return -EFAULT;
2445 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2446 &iwr_u->ifr_ifrn.ifrn_name[0],
2447 sizeof(iwr->ifr_ifrn.ifrn_name)))
2448 return -EFAULT;
2450 if (__get_user(pointer, &iwp_u->pointer) ||
2451 __get_user(length, &iwp_u->length) ||
2452 __get_user(flags, &iwp_u->flags))
2453 return -EFAULT;
2455 if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
2456 __put_user(length, &iwp->length) ||
2457 __put_user(flags, &iwp->flags))
2458 return -EFAULT;
2460 return sys_ioctl(fd, cmd, (unsigned long) iwr);
2463 /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2464 * for some operations; this forces use of the newer bridge-utils that
2465 * use compatiable ioctls
2467 static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2469 u32 tmp;
2471 if (get_user(tmp, (u32 __user *) arg))
2472 return -EFAULT;
2473 if (tmp == BRCTL_GET_VERSION)
2474 return BRCTL_VERSION + 1;
2475 return -EINVAL;
2478 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
2479 struct ncp_ioctl_request_32 {
2480 u32 function;
2481 u32 size;
2482 compat_caddr_t data;
2485 struct ncp_fs_info_v2_32 {
2486 s32 version;
2487 u32 mounted_uid;
2488 u32 connection;
2489 u32 buffer_size;
2491 u32 volume_number;
2492 u32 directory_id;
2494 u32 dummy1;
2495 u32 dummy2;
2496 u32 dummy3;
2499 struct ncp_objectname_ioctl_32
2501 s32 auth_type;
2502 u32 object_name_len;
2503 compat_caddr_t object_name; /* an userspace data, in most cases user name */
2506 struct ncp_privatedata_ioctl_32
2508 u32 len;
2509 compat_caddr_t data; /* ~1000 for NDS */
2512 #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
2513 #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32)
2514 #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
2515 #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
2516 #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
2517 #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
2518 #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
2520 static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
2522 struct ncp_ioctl_request_32 n32;
2523 struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p));
2525 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) ||
2526 put_user(n32.function, &p->function) ||
2527 put_user(n32.size, &p->size) ||
2528 put_user(compat_ptr(n32.data), &p->data))
2529 return -EFAULT;
2531 return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p);
2534 static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
2536 mm_segment_t old_fs = get_fs();
2537 __kernel_uid_t kuid;
2538 int err;
2540 cmd = NCP_IOC_GETMOUNTUID2;
2542 set_fs(KERNEL_DS);
2543 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
2544 set_fs(old_fs);
2546 if (!err)
2547 err = put_user(kuid,
2548 (unsigned int __user *) compat_ptr(arg));
2550 return err;
2553 static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
2555 mm_segment_t old_fs = get_fs();
2556 struct ncp_fs_info_v2_32 n32;
2557 struct ncp_fs_info_v2 n;
2558 int err;
2560 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)))
2561 return -EFAULT;
2562 if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
2563 return -EINVAL;
2564 n.version = NCP_GET_FS_INFO_VERSION_V2;
2566 set_fs(KERNEL_DS);
2567 err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
2568 set_fs(old_fs);
2570 if (!err) {
2571 n32.version = n.version;
2572 n32.mounted_uid = n.mounted_uid;
2573 n32.connection = n.connection;
2574 n32.buffer_size = n.buffer_size;
2575 n32.volume_number = n.volume_number;
2576 n32.directory_id = n.directory_id;
2577 n32.dummy1 = n.dummy1;
2578 n32.dummy2 = n.dummy2;
2579 n32.dummy3 = n.dummy3;
2580 err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0;
2582 return err;
2585 static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
2587 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2588 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
2589 s32 auth_type;
2590 u32 name_len;
2591 int err;
2593 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2594 put_user(n32.object_name_len, &p->object_name_len) ||
2595 put_user(compat_ptr(n32.object_name), &p->object_name))
2596 return -EFAULT;
2598 err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p);
2599 if (err)
2600 return err;
2602 if (get_user(auth_type, &p->auth_type) ||
2603 put_user(auth_type, &p32->auth_type) ||
2604 get_user(name_len, &p->object_name_len) ||
2605 put_user(name_len, &p32->object_name_len))
2606 return -EFAULT;
2608 return 0;
2611 static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
2613 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2614 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
2616 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2617 put_user(n32.auth_type, &p->auth_type) ||
2618 put_user(n32.object_name_len, &p->object_name_len) ||
2619 put_user(compat_ptr(n32.object_name), &p->object_name))
2620 return -EFAULT;
2622 return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p);
2625 static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
2627 struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2628 struct ncp_privatedata_ioctl __user *p =
2629 compat_alloc_user_space(sizeof(*p));
2630 u32 len;
2631 int err;
2633 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2634 put_user(n32.len, &p->len) ||
2635 put_user(compat_ptr(n32.data), &p->data))
2636 return -EFAULT;
2638 err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p);
2639 if (err)
2640 return err;
2642 if (get_user(len, &p->len) ||
2643 put_user(len, &p32->len))
2644 return -EFAULT;
2646 return 0;
2649 static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
2651 struct ncp_privatedata_ioctl_32 n32;
2652 struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg);
2653 struct ncp_privatedata_ioctl __user *p =
2654 compat_alloc_user_space(sizeof(*p));
2656 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2657 put_user(n32.len, &p->len) ||
2658 put_user(compat_ptr(n32.data), &p->data))
2659 return -EFAULT;
2661 return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p);
2663 #endif
2665 #undef CODE
2666 #endif
2668 #ifdef DECLARES
2669 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
2670 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
2671 #ifdef CONFIG_NET
2672 HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
2673 HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
2674 HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
2675 HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
2676 HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
2677 HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
2678 HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
2679 HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
2680 HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
2681 HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
2682 HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
2683 HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
2684 HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
2685 HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
2686 HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
2687 HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
2688 HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2689 HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2690 HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
2692 /* ioctls used by appletalk ddp.c */
2693 HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
2694 HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
2695 HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
2696 HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
2698 HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
2699 HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
2700 HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
2701 HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
2702 HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
2703 HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
2704 HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
2705 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
2706 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
2707 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
2708 HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
2709 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
2710 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
2711 HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
2712 HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
2713 HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
2714 HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
2715 HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
2716 HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
2717 HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
2718 HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
2719 HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
2720 /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
2721 HANDLE_IOCTL(SIOCRTMSG, ret_einval)
2722 HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
2723 #endif
2724 HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
2725 HANDLE_IOCTL(BLKRAGET, w_long)
2726 HANDLE_IOCTL(BLKGETSIZE, w_long)
2727 HANDLE_IOCTL(0x1260, broken_blkgetsize)
2728 HANDLE_IOCTL(BLKFRAGET, w_long)
2729 HANDLE_IOCTL(BLKSECTGET, w_long)
2730 HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
2731 HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
2732 HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
2733 HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
2734 HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
2735 HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
2736 HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
2737 HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
2738 HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
2739 HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
2740 HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
2741 HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
2742 HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
2743 HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
2744 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
2745 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
2746 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
2747 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
2748 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
2749 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
2750 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
2751 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
2752 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
2753 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
2754 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
2755 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
2756 HANDLE_IOCTL(LOOP_SET_STATUS, loop_status)
2757 HANDLE_IOCTL(LOOP_GET_STATUS, loop_status)
2758 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
2759 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
2760 #ifdef CONFIG_VT
2761 HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
2762 HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
2763 HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
2764 HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
2765 HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
2766 #endif
2767 HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl)
2768 HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl)
2769 HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl)
2770 HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl)
2771 HANDLE_IOCTL(EXT3_IOC32_GETVERSION, do_ext3_ioctl)
2772 HANDLE_IOCTL(EXT3_IOC32_SETVERSION, do_ext3_ioctl)
2773 HANDLE_IOCTL(EXT3_IOC32_GETRSVSZ, do_ext3_ioctl)
2774 HANDLE_IOCTL(EXT3_IOC32_SETRSVSZ, do_ext3_ioctl)
2775 HANDLE_IOCTL(EXT3_IOC32_GROUP_EXTEND, do_ext3_ioctl)
2776 COMPATIBLE_IOCTL(EXT3_IOC_GROUP_ADD)
2777 #ifdef CONFIG_JBD_DEBUG
2778 HANDLE_IOCTL(EXT3_IOC32_WAIT_FOR_READONLY, do_ext3_ioctl)
2779 #endif
2780 /* One SMB ioctl needs translations. */
2781 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
2782 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
2783 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
2784 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
2785 HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
2786 HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
2787 HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
2788 HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
2789 HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
2790 HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
2791 HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
2792 HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
2793 HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
2794 HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
2795 HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
2796 HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
2797 HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
2798 HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
2799 HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
2800 HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
2801 HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
2802 HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
2803 HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
2804 HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
2805 HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
2806 HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
2807 HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
2808 /* block stuff */
2809 HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
2810 HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
2811 HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
2812 /* vfat */
2813 HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
2814 HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
2815 HANDLE_IOCTL(REISERFS_IOC_UNPACK32, reiserfs_ioctl32)
2816 /* Raw devices */
2817 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
2818 HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
2819 /* Serial */
2820 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
2821 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
2822 #ifdef TIOCGLTC
2823 COMPATIBLE_IOCTL(TIOCGLTC)
2824 COMPATIBLE_IOCTL(TIOCSLTC)
2825 #endif
2826 #ifdef TIOCSTART
2828 * For these two we have defintions in ioctls.h and/or termios.h on
2829 * some architectures but no actual implemention. Some applications
2830 * like bash call them if they are defined in the headers, so we provide
2831 * entries here to avoid syslog message spew.
2833 COMPATIBLE_IOCTL(TIOCSTART)
2834 COMPATIBLE_IOCTL(TIOCSTOP)
2835 #endif
2836 /* Usbdevfs */
2837 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
2838 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
2839 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
2840 COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
2841 /* i2c */
2842 HANDLE_IOCTL(I2C_FUNCS, w_long)
2843 HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
2844 HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
2845 /* wireless */
2846 HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
2847 HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
2848 HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
2849 HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
2850 HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
2851 HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
2852 HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
2853 HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
2854 HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
2855 HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
2856 HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
2857 HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
2858 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
2859 HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
2860 HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
2862 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
2863 HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest)
2864 HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2)
2865 HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2)
2866 HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname)
2867 HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname)
2868 HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata)
2869 HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata)
2870 #endif
2872 /* dvb */
2873 HANDLE_IOCTL(DMX_GET_EVENT, do_dmx_get_event)
2874 HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
2875 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
2876 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
2878 #undef DECLARES
2879 #endif