[PATCH] BLOCK: Move the ReiserFS device ioctl compat stuff to the ReiserFS driver...
[linux-2.6/mini2440.git] / fs / compat_ioctl.c
blob0346f2ab57c49dc6bf3cfd54ba26632ab5264a25
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/ext2_fs.h>
49 #include <linux/ext3_jbd.h>
50 #include <linux/ext3_fs.h>
51 #include <linux/videodev.h>
52 #include <linux/netdevice.h>
53 #include <linux/raw.h>
54 #include <linux/smb_fs.h>
55 #include <linux/blkpg.h>
56 #include <linux/blkdev.h>
57 #include <linux/elevator.h>
58 #include <linux/rtc.h>
59 #include <linux/pci.h>
60 #include <linux/module.h>
61 #include <linux/serial.h>
62 #include <linux/if_tun.h>
63 #include <linux/ctype.h>
64 #include <linux/ioctl32.h>
65 #include <linux/syscalls.h>
66 #include <linux/ncp_fs.h>
67 #include <linux/i2c.h>
68 #include <linux/i2c-dev.h>
69 #include <linux/wireless.h>
70 #include <linux/atalk.h>
71 #include <linux/blktrace_api.h>
73 #include <net/sock.h> /* siocdevprivate_ioctl */
74 #include <net/bluetooth/bluetooth.h>
75 #include <net/bluetooth/hci.h>
76 #include <net/bluetooth/rfcomm.h>
78 #include <linux/capi.h>
79 #include <linux/gigaset_dev.h>
81 #include <scsi/scsi.h>
82 #include <scsi/scsi_ioctl.h>
83 #include <scsi/sg.h>
85 #include <asm/uaccess.h>
86 #include <linux/ethtool.h>
87 #include <linux/mii.h>
88 #include <linux/if_bonding.h>
89 #include <linux/watchdog.h>
90 #include <linux/dm-ioctl.h>
92 #include <linux/soundcard.h>
93 #include <linux/lp.h>
94 #include <linux/ppdev.h>
96 #include <linux/atm.h>
97 #include <linux/atmarp.h>
98 #include <linux/atmclip.h>
99 #include <linux/atmdev.h>
100 #include <linux/atmioc.h>
101 #include <linux/atmlec.h>
102 #include <linux/atmmpc.h>
103 #include <linux/atmsvc.h>
104 #include <linux/atm_tcp.h>
105 #include <linux/sonet.h>
106 #include <linux/atm_suni.h>
107 #include <linux/mtd/mtd.h>
109 #include <linux/usb.h>
110 #include <linux/usbdevice_fs.h>
111 #include <linux/nbd.h>
112 #include <linux/random.h>
113 #include <linux/filter.h>
114 #include <linux/msdos_fs.h>
115 #include <linux/pktcdvd.h>
117 #include <linux/hiddev.h>
119 #include <linux/dvb/audio.h>
120 #include <linux/dvb/dmx.h>
121 #include <linux/dvb/frontend.h>
122 #include <linux/dvb/video.h>
123 #include <linux/lp.h>
125 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
126 unsigned long arg, struct file *f)
128 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
131 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
133 mm_segment_t old_fs = get_fs();
134 int err;
135 unsigned long val;
137 set_fs (KERNEL_DS);
138 err = sys_ioctl(fd, cmd, (unsigned long)&val);
139 set_fs (old_fs);
140 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
141 return -EFAULT;
142 return err;
145 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
147 mm_segment_t old_fs = get_fs();
148 u32 __user *argptr = compat_ptr(arg);
149 int err;
150 unsigned long val;
152 if(get_user(val, argptr))
153 return -EFAULT;
154 set_fs (KERNEL_DS);
155 err = sys_ioctl(fd, cmd, (unsigned long)&val);
156 set_fs (old_fs);
157 if (!err && put_user(val, argptr))
158 return -EFAULT;
159 return err;
162 static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
164 /* These are just misnamed, they actually get/put from/to user an int */
165 switch (cmd) {
166 case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
167 case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
168 case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
169 case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
171 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
174 static int do_ext3_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
176 /* These are just misnamed, they actually get/put from/to user an int */
177 switch (cmd) {
178 case EXT3_IOC32_GETVERSION: cmd = EXT3_IOC_GETVERSION; break;
179 case EXT3_IOC32_SETVERSION: cmd = EXT3_IOC_SETVERSION; break;
180 case EXT3_IOC32_GETRSVSZ: cmd = EXT3_IOC_GETRSVSZ; break;
181 case EXT3_IOC32_SETRSVSZ: cmd = EXT3_IOC_SETRSVSZ; break;
182 case EXT3_IOC32_GROUP_EXTEND: cmd = EXT3_IOC_GROUP_EXTEND; break;
183 #ifdef CONFIG_JBD_DEBUG
184 case EXT3_IOC32_WAIT_FOR_READONLY: cmd = EXT3_IOC_WAIT_FOR_READONLY; break;
185 #endif
187 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
190 struct compat_video_event {
191 int32_t type;
192 compat_time_t timestamp;
193 union {
194 video_size_t size;
195 unsigned int frame_rate;
196 } u;
199 static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
201 struct video_event kevent;
202 mm_segment_t old_fs = get_fs();
203 int err;
205 set_fs(KERNEL_DS);
206 err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
207 set_fs(old_fs);
209 if (!err) {
210 struct compat_video_event __user *up = compat_ptr(arg);
212 err = put_user(kevent.type, &up->type);
213 err |= put_user(kevent.timestamp, &up->timestamp);
214 err |= put_user(kevent.u.size.w, &up->u.size.w);
215 err |= put_user(kevent.u.size.h, &up->u.size.h);
216 err |= put_user(kevent.u.size.aspect_ratio,
217 &up->u.size.aspect_ratio);
218 if (err)
219 err = -EFAULT;
222 return err;
225 struct compat_video_still_picture {
226 compat_uptr_t iFrame;
227 int32_t size;
230 static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
232 struct compat_video_still_picture __user *up;
233 struct video_still_picture __user *up_native;
234 compat_uptr_t fp;
235 int32_t size;
236 int err;
238 up = (struct compat_video_still_picture __user *) arg;
239 err = get_user(fp, &up->iFrame);
240 err |= get_user(size, &up->size);
241 if (err)
242 return -EFAULT;
244 up_native =
245 compat_alloc_user_space(sizeof(struct video_still_picture));
247 put_user(compat_ptr(fp), &up_native->iFrame);
248 put_user(size, &up_native->size);
250 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
252 return err;
255 struct compat_video_spu_palette {
256 int length;
257 compat_uptr_t palette;
260 static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
262 struct compat_video_spu_palette __user *up;
263 struct video_spu_palette __user *up_native;
264 compat_uptr_t palp;
265 int length, err;
267 up = (struct compat_video_spu_palette __user *) arg;
268 err = get_user(palp, &up->palette);
269 err |= get_user(length, &up->length);
271 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
272 put_user(compat_ptr(palp), &up_native->palette);
273 put_user(length, &up_native->length);
275 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
277 return err;
280 #ifdef CONFIG_NET
281 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
283 struct compat_timeval __user *up = compat_ptr(arg);
284 struct timeval ktv;
285 mm_segment_t old_fs = get_fs();
286 int err;
288 set_fs(KERNEL_DS);
289 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
290 set_fs(old_fs);
291 if(!err) {
292 err = put_user(ktv.tv_sec, &up->tv_sec);
293 err |= __put_user(ktv.tv_usec, &up->tv_usec);
295 return err;
298 struct ifmap32 {
299 compat_ulong_t mem_start;
300 compat_ulong_t mem_end;
301 unsigned short base_addr;
302 unsigned char irq;
303 unsigned char dma;
304 unsigned char port;
307 struct ifreq32 {
308 #define IFHWADDRLEN 6
309 #define IFNAMSIZ 16
310 union {
311 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
312 } ifr_ifrn;
313 union {
314 struct sockaddr ifru_addr;
315 struct sockaddr ifru_dstaddr;
316 struct sockaddr ifru_broadaddr;
317 struct sockaddr ifru_netmask;
318 struct sockaddr ifru_hwaddr;
319 short ifru_flags;
320 compat_int_t ifru_ivalue;
321 compat_int_t ifru_mtu;
322 struct ifmap32 ifru_map;
323 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
324 char ifru_newname[IFNAMSIZ];
325 compat_caddr_t ifru_data;
326 /* XXXX? ifru_settings should be here */
327 } ifr_ifru;
330 struct ifconf32 {
331 compat_int_t ifc_len; /* size of buffer */
332 compat_caddr_t ifcbuf;
335 static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
337 struct net_device *dev;
338 struct ifreq32 ifr32;
339 int err;
341 if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
342 return -EFAULT;
344 dev = dev_get_by_index(ifr32.ifr_ifindex);
345 if (!dev)
346 return -ENODEV;
348 strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
349 dev_put(dev);
351 err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
352 return (err ? -EFAULT : 0);
355 static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
357 struct ifconf32 ifc32;
358 struct ifconf ifc;
359 struct ifconf __user *uifc;
360 struct ifreq32 __user *ifr32;
361 struct ifreq __user *ifr;
362 unsigned int i, j;
363 int err;
365 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
366 return -EFAULT;
368 if (ifc32.ifcbuf == 0) {
369 ifc32.ifc_len = 0;
370 ifc.ifc_len = 0;
371 ifc.ifc_req = NULL;
372 uifc = compat_alloc_user_space(sizeof(struct ifconf));
373 } else {
374 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
375 sizeof (struct ifreq);
376 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
377 ifc.ifc_len = len;
378 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
379 ifr32 = compat_ptr(ifc32.ifcbuf);
380 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
381 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
382 return -EFAULT;
383 ifr++;
384 ifr32++;
387 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
388 return -EFAULT;
390 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
391 if (err)
392 return err;
394 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
395 return -EFAULT;
397 ifr = ifc.ifc_req;
398 ifr32 = compat_ptr(ifc32.ifcbuf);
399 for (i = 0, j = 0;
400 i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
401 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
402 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
403 return -EFAULT;
404 ifr32++;
405 ifr++;
408 if (ifc32.ifcbuf == 0) {
409 /* Translate from 64-bit structure multiple to
410 * a 32-bit one.
412 i = ifc.ifc_len;
413 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
414 ifc32.ifc_len = i;
415 } else {
416 ifc32.ifc_len = i;
418 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
419 return -EFAULT;
421 return 0;
424 static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
426 struct ifreq __user *ifr;
427 struct ifreq32 __user *ifr32;
428 u32 data;
429 void __user *datap;
431 ifr = compat_alloc_user_space(sizeof(*ifr));
432 ifr32 = compat_ptr(arg);
434 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
435 return -EFAULT;
437 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
438 return -EFAULT;
440 datap = compat_ptr(data);
441 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
442 return -EFAULT;
444 return sys_ioctl(fd, cmd, (unsigned long) ifr);
447 static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
449 struct ifreq kifr;
450 struct ifreq __user *uifr;
451 struct ifreq32 __user *ifr32 = compat_ptr(arg);
452 mm_segment_t old_fs;
453 int err;
454 u32 data;
455 void __user *datap;
457 switch (cmd) {
458 case SIOCBONDENSLAVE:
459 case SIOCBONDRELEASE:
460 case SIOCBONDSETHWADDR:
461 case SIOCBONDCHANGEACTIVE:
462 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
463 return -EFAULT;
465 old_fs = get_fs();
466 set_fs (KERNEL_DS);
467 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
468 set_fs (old_fs);
470 return err;
471 case SIOCBONDSLAVEINFOQUERY:
472 case SIOCBONDINFOQUERY:
473 uifr = compat_alloc_user_space(sizeof(*uifr));
474 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
475 return -EFAULT;
477 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
478 return -EFAULT;
480 datap = compat_ptr(data);
481 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
482 return -EFAULT;
484 return sys_ioctl (fd, cmd, (unsigned long)uifr);
485 default:
486 return -EINVAL;
490 int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
492 struct ifreq __user *u_ifreq64;
493 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
494 char tmp_buf[IFNAMSIZ];
495 void __user *data64;
496 u32 data32;
498 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
499 IFNAMSIZ))
500 return -EFAULT;
501 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
502 return -EFAULT;
503 data64 = compat_ptr(data32);
505 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
507 /* Don't check these user accesses, just let that get trapped
508 * in the ioctl handler instead.
510 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
511 IFNAMSIZ))
512 return -EFAULT;
513 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
514 return -EFAULT;
516 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
519 static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
521 struct ifreq ifr;
522 struct ifreq32 __user *uifr32;
523 struct ifmap32 __user *uifmap32;
524 mm_segment_t old_fs;
525 int err;
527 uifr32 = compat_ptr(arg);
528 uifmap32 = &uifr32->ifr_ifru.ifru_map;
529 switch (cmd) {
530 case SIOCSIFMAP:
531 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
532 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
533 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
534 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
535 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
536 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
537 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
538 if (err)
539 return -EFAULT;
540 break;
541 default:
542 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
543 return -EFAULT;
544 break;
546 old_fs = get_fs();
547 set_fs (KERNEL_DS);
548 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
549 set_fs (old_fs);
550 if (!err) {
551 switch (cmd) {
552 /* TUNSETIFF is defined as _IOW, it should be _IORW
553 * as the data is copied back to user space, but that
554 * cannot be fixed without breaking all existing apps.
556 case TUNSETIFF:
557 case SIOCGIFFLAGS:
558 case SIOCGIFMETRIC:
559 case SIOCGIFMTU:
560 case SIOCGIFMEM:
561 case SIOCGIFHWADDR:
562 case SIOCGIFINDEX:
563 case SIOCGIFADDR:
564 case SIOCGIFBRDADDR:
565 case SIOCGIFDSTADDR:
566 case SIOCGIFNETMASK:
567 case SIOCGIFTXQLEN:
568 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
569 return -EFAULT;
570 break;
571 case SIOCGIFMAP:
572 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
573 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
574 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
575 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
576 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
577 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
578 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
579 if (err)
580 err = -EFAULT;
581 break;
584 return err;
587 struct rtentry32 {
588 u32 rt_pad1;
589 struct sockaddr rt_dst; /* target address */
590 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
591 struct sockaddr rt_genmask; /* target network mask (IP) */
592 unsigned short rt_flags;
593 short rt_pad2;
594 u32 rt_pad3;
595 unsigned char rt_tos;
596 unsigned char rt_class;
597 short rt_pad4;
598 short rt_metric; /* +1 for binary compatibility! */
599 /* char * */ u32 rt_dev; /* forcing the device at add */
600 u32 rt_mtu; /* per route MTU/Window */
601 u32 rt_window; /* Window clamping */
602 unsigned short rt_irtt; /* Initial RTT */
606 struct in6_rtmsg32 {
607 struct in6_addr rtmsg_dst;
608 struct in6_addr rtmsg_src;
609 struct in6_addr rtmsg_gateway;
610 u32 rtmsg_type;
611 u16 rtmsg_dst_len;
612 u16 rtmsg_src_len;
613 u32 rtmsg_metric;
614 u32 rtmsg_info;
615 u32 rtmsg_flags;
616 s32 rtmsg_ifindex;
619 static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
621 int ret;
622 void *r = NULL;
623 struct in6_rtmsg r6;
624 struct rtentry r4;
625 char devname[16];
626 u32 rtdev;
627 mm_segment_t old_fs = get_fs();
629 struct socket *mysock = sockfd_lookup(fd, &ret);
631 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
632 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
633 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
634 3 * sizeof(struct in6_addr));
635 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
636 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
637 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
638 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
639 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
640 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
641 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
643 r = (void *) &r6;
644 } else { /* ipv4 */
645 struct rtentry32 __user *ur4 = compat_ptr(arg);
646 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
647 3 * sizeof(struct sockaddr));
648 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
649 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
650 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
651 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
652 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
653 ret |= __get_user (rtdev, &(ur4->rt_dev));
654 if (rtdev) {
655 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
656 r4.rt_dev = devname; devname[15] = 0;
657 } else
658 r4.rt_dev = NULL;
660 r = (void *) &r4;
663 if (ret) {
664 ret = -EFAULT;
665 goto out;
668 set_fs (KERNEL_DS);
669 ret = sys_ioctl (fd, cmd, (unsigned long) r);
670 set_fs (old_fs);
672 out:
673 if (mysock)
674 sockfd_put(mysock);
676 return ret;
678 #endif
680 struct hd_geometry32 {
681 unsigned char heads;
682 unsigned char sectors;
683 unsigned short cylinders;
684 u32 start;
687 static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
689 mm_segment_t old_fs = get_fs();
690 struct hd_geometry geo;
691 struct hd_geometry32 __user *ugeo;
692 int err;
694 set_fs (KERNEL_DS);
695 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
696 set_fs (old_fs);
697 ugeo = compat_ptr(arg);
698 if (!err) {
699 err = copy_to_user (ugeo, &geo, 4);
700 err |= __put_user (geo.start, &ugeo->start);
702 return err ? -EFAULT : 0;
705 static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
707 mm_segment_t old_fs = get_fs();
708 unsigned long kval;
709 unsigned int __user *uvp;
710 int error;
712 set_fs(KERNEL_DS);
713 error = sys_ioctl(fd, cmd, (long)&kval);
714 set_fs(old_fs);
716 if(error == 0) {
717 uvp = compat_ptr(arg);
718 if(put_user(kval, uvp))
719 error = -EFAULT;
721 return error;
725 typedef struct sg_io_hdr32 {
726 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
727 compat_int_t dxfer_direction; /* [i] data transfer direction */
728 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
729 unsigned char mx_sb_len; /* [i] max length to write to sbp */
730 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
731 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
732 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
733 or scatter gather list */
734 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
735 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
736 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
737 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
738 compat_int_t pack_id; /* [i->o] unused internally (normally) */
739 compat_uptr_t usr_ptr; /* [i->o] unused internally */
740 unsigned char status; /* [o] scsi status */
741 unsigned char masked_status; /* [o] shifted, masked scsi status */
742 unsigned char msg_status; /* [o] messaging level data (optional) */
743 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
744 unsigned short host_status; /* [o] errors from host adapter */
745 unsigned short driver_status; /* [o] errors from software driver */
746 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
747 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
748 compat_uint_t info; /* [o] auxiliary information */
749 } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
751 typedef struct sg_iovec32 {
752 compat_uint_t iov_base;
753 compat_uint_t iov_len;
754 } sg_iovec32_t;
756 static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
758 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
759 sg_iovec32_t __user *iov32 = dxferp;
760 int i;
762 for (i = 0; i < iovec_count; i++) {
763 u32 base, len;
765 if (get_user(base, &iov32[i].iov_base) ||
766 get_user(len, &iov32[i].iov_len) ||
767 put_user(compat_ptr(base), &iov[i].iov_base) ||
768 put_user(len, &iov[i].iov_len))
769 return -EFAULT;
772 if (put_user(iov, &sgio->dxferp))
773 return -EFAULT;
774 return 0;
777 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
779 sg_io_hdr_t __user *sgio;
780 sg_io_hdr32_t __user *sgio32;
781 u16 iovec_count;
782 u32 data;
783 void __user *dxferp;
784 int err;
786 sgio32 = compat_ptr(arg);
787 if (get_user(iovec_count, &sgio32->iovec_count))
788 return -EFAULT;
791 void __user *top = compat_alloc_user_space(0);
792 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
793 (iovec_count * sizeof(sg_iovec_t)));
794 if (new > top)
795 return -EINVAL;
797 sgio = new;
800 /* Ok, now construct. */
801 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
802 (2 * sizeof(int)) +
803 (2 * sizeof(unsigned char)) +
804 (1 * sizeof(unsigned short)) +
805 (1 * sizeof(unsigned int))))
806 return -EFAULT;
808 if (get_user(data, &sgio32->dxferp))
809 return -EFAULT;
810 dxferp = compat_ptr(data);
811 if (iovec_count) {
812 if (sg_build_iovec(sgio, dxferp, iovec_count))
813 return -EFAULT;
814 } else {
815 if (put_user(dxferp, &sgio->dxferp))
816 return -EFAULT;
820 unsigned char __user *cmdp;
821 unsigned char __user *sbp;
823 if (get_user(data, &sgio32->cmdp))
824 return -EFAULT;
825 cmdp = compat_ptr(data);
827 if (get_user(data, &sgio32->sbp))
828 return -EFAULT;
829 sbp = compat_ptr(data);
831 if (put_user(cmdp, &sgio->cmdp) ||
832 put_user(sbp, &sgio->sbp))
833 return -EFAULT;
836 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
837 3 * sizeof(int)))
838 return -EFAULT;
840 if (get_user(data, &sgio32->usr_ptr))
841 return -EFAULT;
842 if (put_user(compat_ptr(data), &sgio->usr_ptr))
843 return -EFAULT;
845 if (copy_in_user(&sgio->status, &sgio32->status,
846 (4 * sizeof(unsigned char)) +
847 (2 * sizeof(unsigned (short))) +
848 (3 * sizeof(int))))
849 return -EFAULT;
851 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
853 if (err >= 0) {
854 void __user *datap;
856 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
857 sizeof(int)) ||
858 get_user(datap, &sgio->usr_ptr) ||
859 put_user((u32)(unsigned long)datap,
860 &sgio32->usr_ptr) ||
861 copy_in_user(&sgio32->status, &sgio->status,
862 (4 * sizeof(unsigned char)) +
863 (2 * sizeof(unsigned short)) +
864 (3 * sizeof(int))))
865 err = -EFAULT;
868 return err;
871 struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
872 char req_state;
873 char orphan;
874 char sg_io_owned;
875 char problem;
876 int pack_id;
877 compat_uptr_t usr_ptr;
878 unsigned int duration;
879 int unused;
882 static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
884 int err, i;
885 sg_req_info_t __user *r;
886 struct compat_sg_req_info __user *o = (void __user *)arg;
887 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
888 err = sys_ioctl(fd,cmd,(unsigned long)r);
889 if (err < 0)
890 return err;
891 for (i = 0; i < SG_MAX_QUEUE; i++) {
892 void __user *ptr;
893 int d;
895 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
896 get_user(ptr, &r[i].usr_ptr) ||
897 get_user(d, &r[i].duration) ||
898 put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
899 put_user(d, &o[i].duration))
900 return -EFAULT;
902 return err;
905 struct sock_fprog32 {
906 unsigned short len;
907 compat_caddr_t filter;
910 #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
911 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
913 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
915 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
916 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
917 void __user *fptr64;
918 u32 fptr32;
919 u16 flen;
921 if (get_user(flen, &u_fprog32->len) ||
922 get_user(fptr32, &u_fprog32->filter))
923 return -EFAULT;
925 fptr64 = compat_ptr(fptr32);
927 if (put_user(flen, &u_fprog64->len) ||
928 put_user(fptr64, &u_fprog64->filter))
929 return -EFAULT;
931 if (cmd == PPPIOCSPASS32)
932 cmd = PPPIOCSPASS;
933 else
934 cmd = PPPIOCSACTIVE;
936 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
939 struct ppp_option_data32 {
940 compat_caddr_t ptr;
941 u32 length;
942 compat_int_t transmit;
944 #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
946 struct ppp_idle32 {
947 compat_time_t xmit_idle;
948 compat_time_t recv_idle;
950 #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
952 static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
954 struct ppp_idle __user *idle;
955 struct ppp_idle32 __user *idle32;
956 __kernel_time_t xmit, recv;
957 int err;
959 idle = compat_alloc_user_space(sizeof(*idle));
960 idle32 = compat_ptr(arg);
962 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
964 if (!err) {
965 if (get_user(xmit, &idle->xmit_idle) ||
966 get_user(recv, &idle->recv_idle) ||
967 put_user(xmit, &idle32->xmit_idle) ||
968 put_user(recv, &idle32->recv_idle))
969 err = -EFAULT;
971 return err;
974 static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
976 struct ppp_option_data __user *odata;
977 struct ppp_option_data32 __user *odata32;
978 __u32 data;
979 void __user *datap;
981 odata = compat_alloc_user_space(sizeof(*odata));
982 odata32 = compat_ptr(arg);
984 if (get_user(data, &odata32->ptr))
985 return -EFAULT;
987 datap = compat_ptr(data);
988 if (put_user(datap, &odata->ptr))
989 return -EFAULT;
991 if (copy_in_user(&odata->length, &odata32->length,
992 sizeof(__u32) + sizeof(int)))
993 return -EFAULT;
995 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
998 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1000 int err;
1002 switch (cmd) {
1003 case PPPIOCGIDLE32:
1004 err = ppp_gidle(fd, cmd, arg);
1005 break;
1007 case PPPIOCSCOMPRESS32:
1008 err = ppp_scompress(fd, cmd, arg);
1009 break;
1011 default:
1012 do {
1013 static int count;
1014 if (++count <= 20)
1015 printk("ppp_ioctl: Unknown cmd fd(%d) "
1016 "cmd(%08x) arg(%08x)\n",
1017 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1018 } while(0);
1019 err = -EINVAL;
1020 break;
1023 return err;
1027 struct mtget32 {
1028 compat_long_t mt_type;
1029 compat_long_t mt_resid;
1030 compat_long_t mt_dsreg;
1031 compat_long_t mt_gstat;
1032 compat_long_t mt_erreg;
1033 compat_daddr_t mt_fileno;
1034 compat_daddr_t mt_blkno;
1036 #define MTIOCGET32 _IOR('m', 2, struct mtget32)
1038 struct mtpos32 {
1039 compat_long_t mt_blkno;
1041 #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1043 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1045 mm_segment_t old_fs = get_fs();
1046 struct mtget get;
1047 struct mtget32 __user *umget32;
1048 struct mtpos pos;
1049 struct mtpos32 __user *upos32;
1050 unsigned long kcmd;
1051 void *karg;
1052 int err = 0;
1054 switch(cmd) {
1055 case MTIOCPOS32:
1056 kcmd = MTIOCPOS;
1057 karg = &pos;
1058 break;
1059 case MTIOCGET32:
1060 kcmd = MTIOCGET;
1061 karg = &get;
1062 break;
1063 default:
1064 do {
1065 static int count;
1066 if (++count <= 20)
1067 printk("mt_ioctl: Unknown cmd fd(%d) "
1068 "cmd(%08x) arg(%08x)\n",
1069 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1070 } while(0);
1071 return -EINVAL;
1073 set_fs (KERNEL_DS);
1074 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1075 set_fs (old_fs);
1076 if (err)
1077 return err;
1078 switch (cmd) {
1079 case MTIOCPOS32:
1080 upos32 = compat_ptr(arg);
1081 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1082 break;
1083 case MTIOCGET32:
1084 umget32 = compat_ptr(arg);
1085 err = __put_user(get.mt_type, &umget32->mt_type);
1086 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1087 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1088 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1089 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1090 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1091 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1092 break;
1094 return err ? -EFAULT: 0;
1097 struct cdrom_read_audio32 {
1098 union cdrom_addr addr;
1099 u8 addr_format;
1100 compat_int_t nframes;
1101 compat_caddr_t buf;
1104 struct cdrom_generic_command32 {
1105 unsigned char cmd[CDROM_PACKET_SIZE];
1106 compat_caddr_t buffer;
1107 compat_uint_t buflen;
1108 compat_int_t stat;
1109 compat_caddr_t sense;
1110 unsigned char data_direction;
1111 compat_int_t quiet;
1112 compat_int_t timeout;
1113 compat_caddr_t reserved[1];
1116 static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1118 struct cdrom_read_audio __user *cdread_audio;
1119 struct cdrom_read_audio32 __user *cdread_audio32;
1120 __u32 data;
1121 void __user *datap;
1123 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1124 cdread_audio32 = compat_ptr(arg);
1126 if (copy_in_user(&cdread_audio->addr,
1127 &cdread_audio32->addr,
1128 (sizeof(*cdread_audio32) -
1129 sizeof(compat_caddr_t))))
1130 return -EFAULT;
1132 if (get_user(data, &cdread_audio32->buf))
1133 return -EFAULT;
1134 datap = compat_ptr(data);
1135 if (put_user(datap, &cdread_audio->buf))
1136 return -EFAULT;
1138 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1141 static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1143 struct cdrom_generic_command __user *cgc;
1144 struct cdrom_generic_command32 __user *cgc32;
1145 u32 data;
1146 unsigned char dir;
1147 int itmp;
1149 cgc = compat_alloc_user_space(sizeof(*cgc));
1150 cgc32 = compat_ptr(arg);
1152 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1153 get_user(data, &cgc32->buffer) ||
1154 put_user(compat_ptr(data), &cgc->buffer) ||
1155 copy_in_user(&cgc->buflen, &cgc32->buflen,
1156 (sizeof(unsigned int) + sizeof(int))) ||
1157 get_user(data, &cgc32->sense) ||
1158 put_user(compat_ptr(data), &cgc->sense) ||
1159 get_user(dir, &cgc32->data_direction) ||
1160 put_user(dir, &cgc->data_direction) ||
1161 get_user(itmp, &cgc32->quiet) ||
1162 put_user(itmp, &cgc->quiet) ||
1163 get_user(itmp, &cgc32->timeout) ||
1164 put_user(itmp, &cgc->timeout) ||
1165 get_user(data, &cgc32->reserved[0]) ||
1166 put_user(compat_ptr(data), &cgc->reserved[0]))
1167 return -EFAULT;
1169 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1172 static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1174 int err;
1176 switch(cmd) {
1177 case CDROMREADAUDIO:
1178 err = cdrom_do_read_audio(fd, cmd, arg);
1179 break;
1181 case CDROM_SEND_PACKET:
1182 err = cdrom_do_generic_command(fd, cmd, arg);
1183 break;
1185 default:
1186 do {
1187 static int count;
1188 if (++count <= 20)
1189 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1190 "cmd(%08x) arg(%08x)\n",
1191 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1192 } while(0);
1193 err = -EINVAL;
1194 break;
1197 return err;
1200 #ifdef CONFIG_VT
1202 static int vt_check(struct file *file)
1204 struct tty_struct *tty;
1205 struct inode *inode = file->f_dentry->d_inode;
1207 if (file->f_op->ioctl != tty_ioctl)
1208 return -EINVAL;
1210 tty = (struct tty_struct *)file->private_data;
1211 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1212 return -EINVAL;
1214 if (tty->driver->ioctl != vt_ioctl)
1215 return -EINVAL;
1218 * To have permissions to do most of the vt ioctls, we either have
1219 * to be the owner of the tty, or super-user.
1221 if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
1222 return 1;
1223 return 0;
1226 struct consolefontdesc32 {
1227 unsigned short charcount; /* characters in font (256 or 512) */
1228 unsigned short charheight; /* scan lines per character (1-32) */
1229 compat_caddr_t chardata; /* font data in expanded form */
1232 static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1234 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1235 struct console_font_op op;
1236 compat_caddr_t data;
1237 int i, perm;
1239 perm = vt_check(file);
1240 if (perm < 0) return perm;
1242 switch (cmd) {
1243 case PIO_FONTX:
1244 if (!perm)
1245 return -EPERM;
1246 op.op = KD_FONT_OP_SET;
1247 op.flags = 0;
1248 op.width = 8;
1249 if (get_user(op.height, &user_cfd->charheight) ||
1250 get_user(op.charcount, &user_cfd->charcount) ||
1251 get_user(data, &user_cfd->chardata))
1252 return -EFAULT;
1253 op.data = compat_ptr(data);
1254 return con_font_op(vc_cons[fg_console].d, &op);
1255 case GIO_FONTX:
1256 op.op = KD_FONT_OP_GET;
1257 op.flags = 0;
1258 op.width = 8;
1259 if (get_user(op.height, &user_cfd->charheight) ||
1260 get_user(op.charcount, &user_cfd->charcount) ||
1261 get_user(data, &user_cfd->chardata))
1262 return -EFAULT;
1263 if (!data)
1264 return 0;
1265 op.data = compat_ptr(data);
1266 i = con_font_op(vc_cons[fg_console].d, &op);
1267 if (i)
1268 return i;
1269 if (put_user(op.height, &user_cfd->charheight) ||
1270 put_user(op.charcount, &user_cfd->charcount) ||
1271 put_user((compat_caddr_t)(unsigned long)op.data,
1272 &user_cfd->chardata))
1273 return -EFAULT;
1274 return 0;
1276 return -EINVAL;
1279 struct console_font_op32 {
1280 compat_uint_t op; /* operation code KD_FONT_OP_* */
1281 compat_uint_t flags; /* KD_FONT_FLAG_* */
1282 compat_uint_t width, height; /* font size */
1283 compat_uint_t charcount;
1284 compat_caddr_t data; /* font data with height fixed to 32 */
1287 static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1289 struct console_font_op op;
1290 struct console_font_op32 __user *fontop = compat_ptr(arg);
1291 int perm = vt_check(file), i;
1292 struct vc_data *vc;
1294 if (perm < 0) return perm;
1296 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1297 return -EFAULT;
1298 if (!perm && op.op != KD_FONT_OP_GET)
1299 return -EPERM;
1300 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1301 op.flags |= KD_FONT_FLAG_OLD;
1302 vc = ((struct tty_struct *)file->private_data)->driver_data;
1303 i = con_font_op(vc, &op);
1304 if (i)
1305 return i;
1306 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1307 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1308 return -EFAULT;
1309 return 0;
1312 struct unimapdesc32 {
1313 unsigned short entry_ct;
1314 compat_caddr_t entries;
1317 static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1319 struct unimapdesc32 tmp;
1320 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1321 int perm = vt_check(file);
1323 if (perm < 0) return perm;
1324 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1325 return -EFAULT;
1326 switch (cmd) {
1327 case PIO_UNIMAP:
1328 if (!perm) return -EPERM;
1329 return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries));
1330 case GIO_UNIMAP:
1331 return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
1333 return 0;
1336 #endif /* CONFIG_VT */
1338 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1340 mm_segment_t old_fs = get_fs();
1341 __kernel_uid_t kuid;
1342 int err;
1344 cmd = SMB_IOC_GETMOUNTUID;
1346 set_fs(KERNEL_DS);
1347 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1348 set_fs(old_fs);
1350 if (err >= 0)
1351 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1353 return err;
1356 struct atmif_sioc32 {
1357 compat_int_t number;
1358 compat_int_t length;
1359 compat_caddr_t arg;
1362 struct atm_iobuf32 {
1363 compat_int_t length;
1364 compat_caddr_t buffer;
1367 #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1368 #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1369 #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1370 #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1371 #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1372 #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1373 #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1374 #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1375 #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1376 #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1377 #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1378 #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1379 #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1380 #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1381 #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1382 #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1383 #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1385 static struct {
1386 unsigned int cmd32;
1387 unsigned int cmd;
1388 } atm_ioctl_map[] = {
1389 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1390 { ATM_GETNAMES32, ATM_GETNAMES },
1391 { ATM_GETTYPE32, ATM_GETTYPE },
1392 { ATM_GETESI32, ATM_GETESI },
1393 { ATM_GETADDR32, ATM_GETADDR },
1394 { ATM_RSTADDR32, ATM_RSTADDR },
1395 { ATM_ADDADDR32, ATM_ADDADDR },
1396 { ATM_DELADDR32, ATM_DELADDR },
1397 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1398 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1399 { ATM_SETESI32, ATM_SETESI },
1400 { ATM_SETESIF32, ATM_SETESIF },
1401 { ATM_GETSTAT32, ATM_GETSTAT },
1402 { ATM_GETSTATZ32, ATM_GETSTATZ },
1403 { ATM_GETLOOP32, ATM_GETLOOP },
1404 { ATM_SETLOOP32, ATM_SETLOOP },
1405 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1408 #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
1410 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1412 struct atm_iobuf __user *iobuf;
1413 struct atm_iobuf32 __user *iobuf32;
1414 u32 data;
1415 void __user *datap;
1416 int len, err;
1418 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1419 iobuf32 = compat_ptr(arg);
1421 if (get_user(len, &iobuf32->length) ||
1422 get_user(data, &iobuf32->buffer))
1423 return -EFAULT;
1424 datap = compat_ptr(data);
1425 if (put_user(len, &iobuf->length) ||
1426 put_user(datap, &iobuf->buffer))
1427 return -EFAULT;
1429 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1431 if (!err) {
1432 if (copy_in_user(&iobuf32->length, &iobuf->length,
1433 sizeof(int)))
1434 err = -EFAULT;
1437 return err;
1440 static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1442 struct atmif_sioc __user *sioc;
1443 struct atmif_sioc32 __user *sioc32;
1444 u32 data;
1445 void __user *datap;
1446 int err;
1448 sioc = compat_alloc_user_space(sizeof(*sioc));
1449 sioc32 = compat_ptr(arg);
1451 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1452 get_user(data, &sioc32->arg))
1453 return -EFAULT;
1454 datap = compat_ptr(data);
1455 if (put_user(datap, &sioc->arg))
1456 return -EFAULT;
1458 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1460 if (!err) {
1461 if (copy_in_user(&sioc32->length, &sioc->length,
1462 sizeof(int)))
1463 err = -EFAULT;
1465 return err;
1468 static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1470 int i;
1471 unsigned int cmd = 0;
1473 switch (cmd32) {
1474 case SONET_GETSTAT:
1475 case SONET_GETSTATZ:
1476 case SONET_GETDIAG:
1477 case SONET_SETDIAG:
1478 case SONET_CLRDIAG:
1479 case SONET_SETFRAMING:
1480 case SONET_GETFRAMING:
1481 case SONET_GETFRSENSE:
1482 return do_atmif_sioc(fd, cmd32, arg);
1485 for (i = 0; i < NR_ATM_IOCTL; i++) {
1486 if (cmd32 == atm_ioctl_map[i].cmd32) {
1487 cmd = atm_ioctl_map[i].cmd;
1488 break;
1491 if (i == NR_ATM_IOCTL)
1492 return -EINVAL;
1494 switch (cmd) {
1495 case ATM_GETNAMES:
1496 return do_atm_iobuf(fd, cmd, arg);
1498 case ATM_GETLINKRATE:
1499 case ATM_GETTYPE:
1500 case ATM_GETESI:
1501 case ATM_GETADDR:
1502 case ATM_RSTADDR:
1503 case ATM_ADDADDR:
1504 case ATM_DELADDR:
1505 case ATM_GETCIRANGE:
1506 case ATM_SETCIRANGE:
1507 case ATM_SETESI:
1508 case ATM_SETESIF:
1509 case ATM_GETSTAT:
1510 case ATM_GETSTATZ:
1511 case ATM_GETLOOP:
1512 case ATM_SETLOOP:
1513 case ATM_QUERYLOOP:
1514 return do_atmif_sioc(fd, cmd, arg);
1517 return -EINVAL;
1520 static __attribute_used__ int
1521 ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1523 return -EINVAL;
1526 static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1528 /* The mkswap binary hard codes it to Intel value :-((( */
1529 return w_long(fd, BLKGETSIZE, arg);
1532 struct blkpg_ioctl_arg32 {
1533 compat_int_t op;
1534 compat_int_t flags;
1535 compat_int_t datalen;
1536 compat_caddr_t data;
1539 static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1541 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1542 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1543 compat_caddr_t udata;
1544 compat_int_t n;
1545 int err;
1547 err = get_user(n, &ua32->op);
1548 err |= put_user(n, &a->op);
1549 err |= get_user(n, &ua32->flags);
1550 err |= put_user(n, &a->flags);
1551 err |= get_user(n, &ua32->datalen);
1552 err |= put_user(n, &a->datalen);
1553 err |= get_user(udata, &ua32->data);
1554 err |= put_user(compat_ptr(udata), &a->data);
1555 if (err)
1556 return err;
1558 return sys_ioctl(fd, cmd, (unsigned long)a);
1561 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1563 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1566 /* Fix sizeof(sizeof()) breakage */
1567 #define BLKBSZGET_32 _IOR(0x12,112,int)
1568 #define BLKBSZSET_32 _IOW(0x12,113,int)
1569 #define BLKGETSIZE64_32 _IOR(0x12,114,int)
1571 static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1573 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1576 static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1578 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1581 static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1582 unsigned long arg)
1584 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1587 /* Bluetooth ioctls */
1588 #define HCIUARTSETPROTO _IOW('U', 200, int)
1589 #define HCIUARTGETPROTO _IOR('U', 201, int)
1591 #define BNEPCONNADD _IOW('B', 200, int)
1592 #define BNEPCONNDEL _IOW('B', 201, int)
1593 #define BNEPGETCONNLIST _IOR('B', 210, int)
1594 #define BNEPGETCONNINFO _IOR('B', 211, int)
1596 #define CMTPCONNADD _IOW('C', 200, int)
1597 #define CMTPCONNDEL _IOW('C', 201, int)
1598 #define CMTPGETCONNLIST _IOR('C', 210, int)
1599 #define CMTPGETCONNINFO _IOR('C', 211, int)
1601 #define HIDPCONNADD _IOW('H', 200, int)
1602 #define HIDPCONNDEL _IOW('H', 201, int)
1603 #define HIDPGETCONNLIST _IOR('H', 210, int)
1604 #define HIDPGETCONNINFO _IOR('H', 211, int)
1606 struct floppy_struct32 {
1607 compat_uint_t size;
1608 compat_uint_t sect;
1609 compat_uint_t head;
1610 compat_uint_t track;
1611 compat_uint_t stretch;
1612 unsigned char gap;
1613 unsigned char rate;
1614 unsigned char spec1;
1615 unsigned char fmt_gap;
1616 const compat_caddr_t name;
1619 struct floppy_drive_params32 {
1620 char cmos;
1621 compat_ulong_t max_dtr;
1622 compat_ulong_t hlt;
1623 compat_ulong_t hut;
1624 compat_ulong_t srt;
1625 compat_ulong_t spinup;
1626 compat_ulong_t spindown;
1627 unsigned char spindown_offset;
1628 unsigned char select_delay;
1629 unsigned char rps;
1630 unsigned char tracks;
1631 compat_ulong_t timeout;
1632 unsigned char interleave_sect;
1633 struct floppy_max_errors max_errors;
1634 char flags;
1635 char read_track;
1636 short autodetect[8];
1637 compat_int_t checkfreq;
1638 compat_int_t native_format;
1641 struct floppy_drive_struct32 {
1642 signed char flags;
1643 compat_ulong_t spinup_date;
1644 compat_ulong_t select_date;
1645 compat_ulong_t first_read_date;
1646 short probed_format;
1647 short track;
1648 short maxblock;
1649 short maxtrack;
1650 compat_int_t generation;
1651 compat_int_t keep_data;
1652 compat_int_t fd_ref;
1653 compat_int_t fd_device;
1654 compat_int_t last_checked;
1655 compat_caddr_t dmabuf;
1656 compat_int_t bufblocks;
1659 struct floppy_fdc_state32 {
1660 compat_int_t spec1;
1661 compat_int_t spec2;
1662 compat_int_t dtr;
1663 unsigned char version;
1664 unsigned char dor;
1665 compat_ulong_t address;
1666 unsigned int rawcmd:2;
1667 unsigned int reset:1;
1668 unsigned int need_configure:1;
1669 unsigned int perp_mode:2;
1670 unsigned int has_fifo:1;
1671 unsigned int driver_version;
1672 unsigned char track[4];
1675 struct floppy_write_errors32 {
1676 unsigned int write_errors;
1677 compat_ulong_t first_error_sector;
1678 compat_int_t first_error_generation;
1679 compat_ulong_t last_error_sector;
1680 compat_int_t last_error_generation;
1681 compat_uint_t badness;
1684 #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1685 #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1686 #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1687 #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1688 #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1689 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1690 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1691 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1692 #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
1694 static struct {
1695 unsigned int cmd32;
1696 unsigned int cmd;
1697 } fd_ioctl_trans_table[] = {
1698 { FDSETPRM32, FDSETPRM },
1699 { FDDEFPRM32, FDDEFPRM },
1700 { FDGETPRM32, FDGETPRM },
1701 { FDSETDRVPRM32, FDSETDRVPRM },
1702 { FDGETDRVPRM32, FDGETDRVPRM },
1703 { FDGETDRVSTAT32, FDGETDRVSTAT },
1704 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1705 { FDGETFDCSTAT32, FDGETFDCSTAT },
1706 { FDWERRORGET32, FDWERRORGET }
1709 #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
1711 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1713 mm_segment_t old_fs = get_fs();
1714 void *karg = NULL;
1715 unsigned int kcmd = 0;
1716 int i, err;
1718 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1719 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1720 kcmd = fd_ioctl_trans_table[i].cmd;
1721 break;
1723 if (!kcmd)
1724 return -EINVAL;
1726 switch (cmd) {
1727 case FDSETPRM32:
1728 case FDDEFPRM32:
1729 case FDGETPRM32:
1731 compat_uptr_t name;
1732 struct floppy_struct32 __user *uf;
1733 struct floppy_struct *f;
1735 uf = compat_ptr(arg);
1736 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1737 if (!karg)
1738 return -ENOMEM;
1739 if (cmd == FDGETPRM32)
1740 break;
1741 err = __get_user(f->size, &uf->size);
1742 err |= __get_user(f->sect, &uf->sect);
1743 err |= __get_user(f->head, &uf->head);
1744 err |= __get_user(f->track, &uf->track);
1745 err |= __get_user(f->stretch, &uf->stretch);
1746 err |= __get_user(f->gap, &uf->gap);
1747 err |= __get_user(f->rate, &uf->rate);
1748 err |= __get_user(f->spec1, &uf->spec1);
1749 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
1750 err |= __get_user(name, &uf->name);
1751 f->name = compat_ptr(name);
1752 if (err) {
1753 err = -EFAULT;
1754 goto out;
1756 break;
1758 case FDSETDRVPRM32:
1759 case FDGETDRVPRM32:
1761 struct floppy_drive_params32 __user *uf;
1762 struct floppy_drive_params *f;
1764 uf = compat_ptr(arg);
1765 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1766 if (!karg)
1767 return -ENOMEM;
1768 if (cmd == FDGETDRVPRM32)
1769 break;
1770 err = __get_user(f->cmos, &uf->cmos);
1771 err |= __get_user(f->max_dtr, &uf->max_dtr);
1772 err |= __get_user(f->hlt, &uf->hlt);
1773 err |= __get_user(f->hut, &uf->hut);
1774 err |= __get_user(f->srt, &uf->srt);
1775 err |= __get_user(f->spinup, &uf->spinup);
1776 err |= __get_user(f->spindown, &uf->spindown);
1777 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
1778 err |= __get_user(f->select_delay, &uf->select_delay);
1779 err |= __get_user(f->rps, &uf->rps);
1780 err |= __get_user(f->tracks, &uf->tracks);
1781 err |= __get_user(f->timeout, &uf->timeout);
1782 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
1783 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
1784 err |= __get_user(f->flags, &uf->flags);
1785 err |= __get_user(f->read_track, &uf->read_track);
1786 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
1787 err |= __get_user(f->checkfreq, &uf->checkfreq);
1788 err |= __get_user(f->native_format, &uf->native_format);
1789 if (err) {
1790 err = -EFAULT;
1791 goto out;
1793 break;
1795 case FDGETDRVSTAT32:
1796 case FDPOLLDRVSTAT32:
1797 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1798 if (!karg)
1799 return -ENOMEM;
1800 break;
1801 case FDGETFDCSTAT32:
1802 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1803 if (!karg)
1804 return -ENOMEM;
1805 break;
1806 case FDWERRORGET32:
1807 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1808 if (!karg)
1809 return -ENOMEM;
1810 break;
1811 default:
1812 return -EINVAL;
1814 set_fs (KERNEL_DS);
1815 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1816 set_fs (old_fs);
1817 if (err)
1818 goto out;
1819 switch (cmd) {
1820 case FDGETPRM32:
1822 struct floppy_struct *f = karg;
1823 struct floppy_struct32 __user *uf = compat_ptr(arg);
1825 err = __put_user(f->size, &uf->size);
1826 err |= __put_user(f->sect, &uf->sect);
1827 err |= __put_user(f->head, &uf->head);
1828 err |= __put_user(f->track, &uf->track);
1829 err |= __put_user(f->stretch, &uf->stretch);
1830 err |= __put_user(f->gap, &uf->gap);
1831 err |= __put_user(f->rate, &uf->rate);
1832 err |= __put_user(f->spec1, &uf->spec1);
1833 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
1834 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
1835 break;
1837 case FDGETDRVPRM32:
1839 struct floppy_drive_params32 __user *uf;
1840 struct floppy_drive_params *f = karg;
1842 uf = compat_ptr(arg);
1843 err = __put_user(f->cmos, &uf->cmos);
1844 err |= __put_user(f->max_dtr, &uf->max_dtr);
1845 err |= __put_user(f->hlt, &uf->hlt);
1846 err |= __put_user(f->hut, &uf->hut);
1847 err |= __put_user(f->srt, &uf->srt);
1848 err |= __put_user(f->spinup, &uf->spinup);
1849 err |= __put_user(f->spindown, &uf->spindown);
1850 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
1851 err |= __put_user(f->select_delay, &uf->select_delay);
1852 err |= __put_user(f->rps, &uf->rps);
1853 err |= __put_user(f->tracks, &uf->tracks);
1854 err |= __put_user(f->timeout, &uf->timeout);
1855 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
1856 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
1857 err |= __put_user(f->flags, &uf->flags);
1858 err |= __put_user(f->read_track, &uf->read_track);
1859 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
1860 err |= __put_user(f->checkfreq, &uf->checkfreq);
1861 err |= __put_user(f->native_format, &uf->native_format);
1862 break;
1864 case FDGETDRVSTAT32:
1865 case FDPOLLDRVSTAT32:
1867 struct floppy_drive_struct32 __user *uf;
1868 struct floppy_drive_struct *f = karg;
1870 uf = compat_ptr(arg);
1871 err = __put_user(f->flags, &uf->flags);
1872 err |= __put_user(f->spinup_date, &uf->spinup_date);
1873 err |= __put_user(f->select_date, &uf->select_date);
1874 err |= __put_user(f->first_read_date, &uf->first_read_date);
1875 err |= __put_user(f->probed_format, &uf->probed_format);
1876 err |= __put_user(f->track, &uf->track);
1877 err |= __put_user(f->maxblock, &uf->maxblock);
1878 err |= __put_user(f->maxtrack, &uf->maxtrack);
1879 err |= __put_user(f->generation, &uf->generation);
1880 err |= __put_user(f->keep_data, &uf->keep_data);
1881 err |= __put_user(f->fd_ref, &uf->fd_ref);
1882 err |= __put_user(f->fd_device, &uf->fd_device);
1883 err |= __put_user(f->last_checked, &uf->last_checked);
1884 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
1885 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
1886 break;
1888 case FDGETFDCSTAT32:
1890 struct floppy_fdc_state32 __user *uf;
1891 struct floppy_fdc_state *f = karg;
1893 uf = compat_ptr(arg);
1894 err = __put_user(f->spec1, &uf->spec1);
1895 err |= __put_user(f->spec2, &uf->spec2);
1896 err |= __put_user(f->dtr, &uf->dtr);
1897 err |= __put_user(f->version, &uf->version);
1898 err |= __put_user(f->dor, &uf->dor);
1899 err |= __put_user(f->address, &uf->address);
1900 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
1901 (char *)&f->address + sizeof(f->address), sizeof(int));
1902 err |= __put_user(f->driver_version, &uf->driver_version);
1903 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
1904 break;
1906 case FDWERRORGET32:
1908 struct floppy_write_errors32 __user *uf;
1909 struct floppy_write_errors *f = karg;
1911 uf = compat_ptr(arg);
1912 err = __put_user(f->write_errors, &uf->write_errors);
1913 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
1914 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
1915 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
1916 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
1917 err |= __put_user(f->badness, &uf->badness);
1918 break;
1920 default:
1921 break;
1923 if (err)
1924 err = -EFAULT;
1926 out:
1927 kfree(karg);
1928 return err;
1931 struct mtd_oob_buf32 {
1932 u_int32_t start;
1933 u_int32_t length;
1934 compat_caddr_t ptr; /* unsigned char* */
1937 #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
1938 #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
1940 static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
1942 struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
1943 struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
1944 u32 data;
1945 char __user *datap;
1946 unsigned int real_cmd;
1947 int err;
1949 real_cmd = (cmd == MEMREADOOB32) ?
1950 MEMREADOOB : MEMWRITEOOB;
1952 if (copy_in_user(&buf->start, &buf32->start,
1953 2 * sizeof(u32)) ||
1954 get_user(data, &buf32->ptr))
1955 return -EFAULT;
1956 datap = compat_ptr(data);
1957 if (put_user(datap, &buf->ptr))
1958 return -EFAULT;
1960 err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
1962 if (!err) {
1963 if (copy_in_user(&buf32->start, &buf->start,
1964 2 * sizeof(u32)))
1965 err = -EFAULT;
1968 return err;
1971 #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
1972 #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
1974 static long
1975 put_dirent32 (struct dirent *d, struct compat_dirent __user *d32)
1977 if (!access_ok(VERIFY_WRITE, d32, sizeof(struct compat_dirent)))
1978 return -EFAULT;
1980 __put_user(d->d_ino, &d32->d_ino);
1981 __put_user(d->d_off, &d32->d_off);
1982 __put_user(d->d_reclen, &d32->d_reclen);
1983 if (__copy_to_user(d32->d_name, d->d_name, d->d_reclen))
1984 return -EFAULT;
1986 return 0;
1989 static int vfat_ioctl32(unsigned fd, unsigned cmd, unsigned long arg)
1991 struct compat_dirent __user *p = compat_ptr(arg);
1992 int ret;
1993 mm_segment_t oldfs = get_fs();
1994 struct dirent d[2];
1996 switch(cmd)
1998 case VFAT_IOCTL_READDIR_BOTH32:
1999 cmd = VFAT_IOCTL_READDIR_BOTH;
2000 break;
2001 case VFAT_IOCTL_READDIR_SHORT32:
2002 cmd = VFAT_IOCTL_READDIR_SHORT;
2003 break;
2006 set_fs(KERNEL_DS);
2007 ret = sys_ioctl(fd,cmd,(unsigned long)&d);
2008 set_fs(oldfs);
2009 if (ret >= 0) {
2010 ret |= put_dirent32(&d[0], p);
2011 ret |= put_dirent32(&d[1], p + 1);
2013 return ret;
2016 struct raw32_config_request
2018 compat_int_t raw_minor;
2019 __u64 block_major;
2020 __u64 block_minor;
2021 } __attribute__((packed));
2023 static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2025 int ret;
2027 if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
2028 return -EFAULT;
2030 ret = __get_user(req->raw_minor, &user_req->raw_minor);
2031 ret |= __get_user(req->block_major, &user_req->block_major);
2032 ret |= __get_user(req->block_minor, &user_req->block_minor);
2034 return ret ? -EFAULT : 0;
2037 static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2039 int ret;
2041 if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
2042 return -EFAULT;
2044 ret = __put_user(req->raw_minor, &user_req->raw_minor);
2045 ret |= __put_user(req->block_major, &user_req->block_major);
2046 ret |= __put_user(req->block_minor, &user_req->block_minor);
2048 return ret ? -EFAULT : 0;
2051 static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2053 int ret;
2055 switch (cmd) {
2056 case RAW_SETBIND:
2057 case RAW_GETBIND: {
2058 struct raw_config_request req;
2059 struct raw32_config_request __user *user_req = compat_ptr(arg);
2060 mm_segment_t oldfs = get_fs();
2062 if ((ret = get_raw32_request(&req, user_req)))
2063 return ret;
2065 set_fs(KERNEL_DS);
2066 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2067 set_fs(oldfs);
2069 if ((!ret) && (cmd == RAW_GETBIND)) {
2070 ret = set_raw32_request(&req, user_req);
2072 break;
2074 default:
2075 ret = sys_ioctl(fd, cmd, arg);
2076 break;
2078 return ret;
2081 struct serial_struct32 {
2082 compat_int_t type;
2083 compat_int_t line;
2084 compat_uint_t port;
2085 compat_int_t irq;
2086 compat_int_t flags;
2087 compat_int_t xmit_fifo_size;
2088 compat_int_t custom_divisor;
2089 compat_int_t baud_base;
2090 unsigned short close_delay;
2091 char io_type;
2092 char reserved_char[1];
2093 compat_int_t hub6;
2094 unsigned short closing_wait; /* time to wait before closing */
2095 unsigned short closing_wait2; /* no longer used... */
2096 compat_uint_t iomem_base;
2097 unsigned short iomem_reg_shift;
2098 unsigned int port_high;
2099 /* compat_ulong_t iomap_base FIXME */
2100 compat_int_t reserved[1];
2103 static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2105 typedef struct serial_struct SS;
2106 typedef struct serial_struct32 SS32;
2107 struct serial_struct32 __user *ss32 = compat_ptr(arg);
2108 int err;
2109 struct serial_struct ss;
2110 mm_segment_t oldseg = get_fs();
2111 __u32 udata;
2113 if (cmd == TIOCSSERIAL) {
2114 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
2115 return -EFAULT;
2116 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
2117 return -EFAULT;
2118 __get_user(udata, &ss32->iomem_base);
2119 ss.iomem_base = compat_ptr(udata);
2120 __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2121 __get_user(ss.port_high, &ss32->port_high);
2122 ss.iomap_base = 0UL;
2124 set_fs(KERNEL_DS);
2125 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2126 set_fs(oldseg);
2127 if (cmd == TIOCGSERIAL && err >= 0) {
2128 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
2129 return -EFAULT;
2130 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
2131 return -EFAULT;
2132 __put_user((unsigned long)ss.iomem_base >> 32 ?
2133 0xffffffff : (unsigned)(unsigned long)ss.iomem_base,
2134 &ss32->iomem_base);
2135 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2136 __put_user(ss.port_high, &ss32->port_high);
2139 return err;
2142 struct usbdevfs_ctrltransfer32 {
2143 u8 bRequestType;
2144 u8 bRequest;
2145 u16 wValue;
2146 u16 wIndex;
2147 u16 wLength;
2148 u32 timeout; /* in milliseconds */
2149 compat_caddr_t data;
2152 #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2154 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2156 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2157 struct usbdevfs_ctrltransfer __user *p;
2158 __u32 udata;
2159 p = compat_alloc_user_space(sizeof(*p));
2160 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2161 get_user(udata, &p32->data) ||
2162 put_user(compat_ptr(udata), &p->data))
2163 return -EFAULT;
2164 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2168 struct usbdevfs_bulktransfer32 {
2169 compat_uint_t ep;
2170 compat_uint_t len;
2171 compat_uint_t timeout; /* in milliseconds */
2172 compat_caddr_t data;
2175 #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2177 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2179 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2180 struct usbdevfs_bulktransfer __user *p;
2181 compat_uint_t n;
2182 compat_caddr_t addr;
2184 p = compat_alloc_user_space(sizeof(*p));
2186 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2187 get_user(n, &p32->len) || put_user(n, &p->len) ||
2188 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2189 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2190 return -EFAULT;
2192 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2197 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
2198 * are handled in usbdevfs core. -Christopher Li
2201 struct usbdevfs_disconnectsignal32 {
2202 compat_int_t signr;
2203 compat_caddr_t context;
2206 #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2208 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2210 struct usbdevfs_disconnectsignal kdis;
2211 struct usbdevfs_disconnectsignal32 __user *udis;
2212 mm_segment_t old_fs;
2213 u32 uctx;
2214 int err;
2216 udis = compat_ptr(arg);
2218 if (get_user(kdis.signr, &udis->signr) ||
2219 __get_user(uctx, &udis->context))
2220 return -EFAULT;
2222 kdis.context = compat_ptr(uctx);
2224 old_fs = get_fs();
2225 set_fs(KERNEL_DS);
2226 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2227 set_fs(old_fs);
2229 return err;
2233 * I2C layer ioctls
2236 struct i2c_msg32 {
2237 u16 addr;
2238 u16 flags;
2239 u16 len;
2240 compat_caddr_t buf;
2243 struct i2c_rdwr_ioctl_data32 {
2244 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2245 u32 nmsgs;
2248 struct i2c_smbus_ioctl_data32 {
2249 u8 read_write;
2250 u8 command;
2251 u32 size;
2252 compat_caddr_t data; /* union i2c_smbus_data *data */
2255 struct i2c_rdwr_aligned {
2256 struct i2c_rdwr_ioctl_data cmd;
2257 struct i2c_msg msgs[0];
2260 static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2262 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
2263 struct i2c_rdwr_aligned __user *tdata;
2264 struct i2c_msg __user *tmsgs;
2265 struct i2c_msg32 __user *umsgs;
2266 compat_caddr_t datap;
2267 int nmsgs, i;
2269 if (get_user(nmsgs, &udata->nmsgs))
2270 return -EFAULT;
2271 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2272 return -EINVAL;
2274 if (get_user(datap, &udata->msgs))
2275 return -EFAULT;
2276 umsgs = compat_ptr(datap);
2278 tdata = compat_alloc_user_space(sizeof(*tdata) +
2279 nmsgs * sizeof(struct i2c_msg));
2280 tmsgs = &tdata->msgs[0];
2282 if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
2283 put_user(tmsgs, &tdata->cmd.msgs))
2284 return -EFAULT;
2286 for (i = 0; i < nmsgs; i++) {
2287 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
2288 return -EFAULT;
2289 if (get_user(datap, &umsgs[i].buf) ||
2290 put_user(compat_ptr(datap), &tmsgs[i].buf))
2291 return -EFAULT;
2293 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2296 static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2298 struct i2c_smbus_ioctl_data __user *tdata;
2299 struct i2c_smbus_ioctl_data32 __user *udata;
2300 compat_caddr_t datap;
2302 tdata = compat_alloc_user_space(sizeof(*tdata));
2303 if (tdata == NULL)
2304 return -ENOMEM;
2305 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
2306 return -EFAULT;
2308 udata = compat_ptr(arg);
2309 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
2310 return -EFAULT;
2312 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2313 return -EFAULT;
2314 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2315 return -EFAULT;
2316 if (__get_user(datap, &udata->data) ||
2317 __put_user(compat_ptr(datap), &tdata->data))
2318 return -EFAULT;
2320 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2323 struct compat_iw_point {
2324 compat_caddr_t pointer;
2325 __u16 length;
2326 __u16 flags;
2329 static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2331 struct iwreq __user *iwr;
2332 struct iwreq __user *iwr_u;
2333 struct iw_point __user *iwp;
2334 struct compat_iw_point __user *iwp_u;
2335 compat_caddr_t pointer;
2336 __u16 length, flags;
2338 iwr_u = compat_ptr(arg);
2339 iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2340 iwr = compat_alloc_user_space(sizeof(*iwr));
2341 if (iwr == NULL)
2342 return -ENOMEM;
2344 iwp = &iwr->u.data;
2346 if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
2347 return -EFAULT;
2349 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2350 &iwr_u->ifr_ifrn.ifrn_name[0],
2351 sizeof(iwr->ifr_ifrn.ifrn_name)))
2352 return -EFAULT;
2354 if (__get_user(pointer, &iwp_u->pointer) ||
2355 __get_user(length, &iwp_u->length) ||
2356 __get_user(flags, &iwp_u->flags))
2357 return -EFAULT;
2359 if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
2360 __put_user(length, &iwp->length) ||
2361 __put_user(flags, &iwp->flags))
2362 return -EFAULT;
2364 return sys_ioctl(fd, cmd, (unsigned long) iwr);
2367 /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2368 * for some operations; this forces use of the newer bridge-utils that
2369 * use compatiable ioctls
2371 static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2373 u32 tmp;
2375 if (get_user(tmp, (u32 __user *) arg))
2376 return -EFAULT;
2377 if (tmp == BRCTL_GET_VERSION)
2378 return BRCTL_VERSION + 1;
2379 return -EINVAL;
2382 #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
2383 #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
2384 #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
2385 #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
2387 static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2389 mm_segment_t oldfs = get_fs();
2390 compat_ulong_t val32;
2391 unsigned long kval;
2392 int ret;
2394 switch (cmd) {
2395 case RTC_IRQP_READ32:
2396 case RTC_EPOCH_READ32:
2397 set_fs(KERNEL_DS);
2398 ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
2399 RTC_IRQP_READ : RTC_EPOCH_READ,
2400 (unsigned long)&kval);
2401 set_fs(oldfs);
2402 if (ret)
2403 return ret;
2404 val32 = kval;
2405 return put_user(val32, (unsigned int __user *)arg);
2406 case RTC_IRQP_SET32:
2407 return sys_ioctl(fd, RTC_IRQP_SET, arg);
2408 case RTC_EPOCH_SET32:
2409 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
2410 default:
2411 /* unreached */
2412 return -ENOIOCTLCMD;
2416 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
2417 struct ncp_ioctl_request_32 {
2418 u32 function;
2419 u32 size;
2420 compat_caddr_t data;
2423 struct ncp_fs_info_v2_32 {
2424 s32 version;
2425 u32 mounted_uid;
2426 u32 connection;
2427 u32 buffer_size;
2429 u32 volume_number;
2430 u32 directory_id;
2432 u32 dummy1;
2433 u32 dummy2;
2434 u32 dummy3;
2437 struct ncp_objectname_ioctl_32
2439 s32 auth_type;
2440 u32 object_name_len;
2441 compat_caddr_t object_name; /* an userspace data, in most cases user name */
2444 struct ncp_privatedata_ioctl_32
2446 u32 len;
2447 compat_caddr_t data; /* ~1000 for NDS */
2450 #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
2451 #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32)
2452 #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
2453 #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
2454 #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
2455 #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
2456 #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
2458 static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
2460 struct ncp_ioctl_request_32 n32;
2461 struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p));
2463 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) ||
2464 put_user(n32.function, &p->function) ||
2465 put_user(n32.size, &p->size) ||
2466 put_user(compat_ptr(n32.data), &p->data))
2467 return -EFAULT;
2469 return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p);
2472 static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
2474 mm_segment_t old_fs = get_fs();
2475 __kernel_uid_t kuid;
2476 int err;
2478 cmd = NCP_IOC_GETMOUNTUID2;
2480 set_fs(KERNEL_DS);
2481 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
2482 set_fs(old_fs);
2484 if (!err)
2485 err = put_user(kuid,
2486 (unsigned int __user *) compat_ptr(arg));
2488 return err;
2491 static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
2493 mm_segment_t old_fs = get_fs();
2494 struct ncp_fs_info_v2_32 n32;
2495 struct ncp_fs_info_v2 n;
2496 int err;
2498 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)))
2499 return -EFAULT;
2500 if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
2501 return -EINVAL;
2502 n.version = NCP_GET_FS_INFO_VERSION_V2;
2504 set_fs(KERNEL_DS);
2505 err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
2506 set_fs(old_fs);
2508 if (!err) {
2509 n32.version = n.version;
2510 n32.mounted_uid = n.mounted_uid;
2511 n32.connection = n.connection;
2512 n32.buffer_size = n.buffer_size;
2513 n32.volume_number = n.volume_number;
2514 n32.directory_id = n.directory_id;
2515 n32.dummy1 = n.dummy1;
2516 n32.dummy2 = n.dummy2;
2517 n32.dummy3 = n.dummy3;
2518 err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0;
2520 return err;
2523 static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
2525 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2526 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
2527 s32 auth_type;
2528 u32 name_len;
2529 int err;
2531 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2532 put_user(n32.object_name_len, &p->object_name_len) ||
2533 put_user(compat_ptr(n32.object_name), &p->object_name))
2534 return -EFAULT;
2536 err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p);
2537 if (err)
2538 return err;
2540 if (get_user(auth_type, &p->auth_type) ||
2541 put_user(auth_type, &p32->auth_type) ||
2542 get_user(name_len, &p->object_name_len) ||
2543 put_user(name_len, &p32->object_name_len))
2544 return -EFAULT;
2546 return 0;
2549 static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
2551 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2552 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
2554 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2555 put_user(n32.auth_type, &p->auth_type) ||
2556 put_user(n32.object_name_len, &p->object_name_len) ||
2557 put_user(compat_ptr(n32.object_name), &p->object_name))
2558 return -EFAULT;
2560 return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p);
2563 static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
2565 struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2566 struct ncp_privatedata_ioctl __user *p =
2567 compat_alloc_user_space(sizeof(*p));
2568 u32 len;
2569 int err;
2571 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2572 put_user(n32.len, &p->len) ||
2573 put_user(compat_ptr(n32.data), &p->data))
2574 return -EFAULT;
2576 err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p);
2577 if (err)
2578 return err;
2580 if (get_user(len, &p->len) ||
2581 put_user(len, &p32->len))
2582 return -EFAULT;
2584 return 0;
2587 static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
2589 struct ncp_privatedata_ioctl_32 n32;
2590 struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg);
2591 struct ncp_privatedata_ioctl __user *p =
2592 compat_alloc_user_space(sizeof(*p));
2594 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2595 put_user(n32.len, &p->len) ||
2596 put_user(compat_ptr(n32.data), &p->data))
2597 return -EFAULT;
2599 return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p);
2601 #endif
2603 static int
2604 lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2606 struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
2607 struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
2608 struct timeval ts;
2609 if (get_user(ts.tv_sec, &tc->tv_sec) ||
2610 get_user(ts.tv_usec, &tc->tv_usec) ||
2611 put_user(ts.tv_sec, &tn->tv_sec) ||
2612 put_user(ts.tv_usec, &tn->tv_usec))
2613 return -EFAULT;
2614 return sys_ioctl(fd, cmd, (unsigned long)tn);
2617 #define HANDLE_IOCTL(cmd,handler) \
2618 { (cmd), (ioctl_trans_handler_t)(handler) },
2620 /* pointer to compatible structure or no argument */
2621 #define COMPATIBLE_IOCTL(cmd) \
2622 { (cmd), do_ioctl32_pointer },
2624 /* argument is an unsigned long integer, not a pointer */
2625 #define ULONG_IOCTL(cmd) \
2626 { (cmd), (ioctl_trans_handler_t)sys_ioctl },
2629 struct ioctl_trans ioctl_start[] = {
2630 #include <linux/compat_ioctl.h>
2631 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
2632 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
2633 #ifdef CONFIG_NET
2634 HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
2635 HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
2636 HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
2637 HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
2638 HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
2639 HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
2640 HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
2641 HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
2642 HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
2643 HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
2644 HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
2645 HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
2646 HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
2647 HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
2648 HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
2649 HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
2650 HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2651 HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2652 HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
2654 /* ioctls used by appletalk ddp.c */
2655 HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
2656 HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
2657 HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
2658 HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
2660 HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
2661 HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
2662 HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
2663 HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
2664 HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
2665 HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
2666 HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
2667 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
2668 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
2669 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
2670 HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
2671 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
2672 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
2673 HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
2674 HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
2675 HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
2676 HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
2677 HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
2678 HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
2679 HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
2680 HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
2681 HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
2682 /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
2683 HANDLE_IOCTL(SIOCRTMSG, ret_einval)
2684 HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
2685 #endif
2686 HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
2687 HANDLE_IOCTL(BLKRAGET, w_long)
2688 HANDLE_IOCTL(BLKGETSIZE, w_long)
2689 HANDLE_IOCTL(0x1260, broken_blkgetsize)
2690 HANDLE_IOCTL(BLKFRAGET, w_long)
2691 HANDLE_IOCTL(BLKSECTGET, w_long)
2692 HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
2693 HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
2694 HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
2695 HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
2696 HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
2697 HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
2698 HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
2699 HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
2700 HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
2701 HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
2702 HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
2703 HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
2704 HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
2705 HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
2706 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
2707 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
2708 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
2709 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
2710 HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
2711 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
2712 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
2713 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
2714 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
2715 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
2716 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
2717 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
2718 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
2719 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
2720 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
2721 #ifdef CONFIG_VT
2722 HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
2723 HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
2724 HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
2725 HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
2726 HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
2727 #endif
2728 HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl)
2729 HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl)
2730 HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl)
2731 HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl)
2732 HANDLE_IOCTL(EXT3_IOC32_GETVERSION, do_ext3_ioctl)
2733 HANDLE_IOCTL(EXT3_IOC32_SETVERSION, do_ext3_ioctl)
2734 HANDLE_IOCTL(EXT3_IOC32_GETRSVSZ, do_ext3_ioctl)
2735 HANDLE_IOCTL(EXT3_IOC32_SETRSVSZ, do_ext3_ioctl)
2736 HANDLE_IOCTL(EXT3_IOC32_GROUP_EXTEND, do_ext3_ioctl)
2737 COMPATIBLE_IOCTL(EXT3_IOC_GROUP_ADD)
2738 #ifdef CONFIG_JBD_DEBUG
2739 HANDLE_IOCTL(EXT3_IOC32_WAIT_FOR_READONLY, do_ext3_ioctl)
2740 #endif
2741 /* One SMB ioctl needs translations. */
2742 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
2743 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
2744 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
2745 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
2746 HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
2747 HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
2748 HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
2749 HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
2750 HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
2751 HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
2752 HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
2753 HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
2754 HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
2755 HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
2756 HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
2757 HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
2758 HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
2759 HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
2760 HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
2761 HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
2762 HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
2763 HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
2764 HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
2765 HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
2766 HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
2767 HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
2768 HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
2769 /* block stuff */
2770 HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
2771 HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
2772 HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
2773 /* vfat */
2774 HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
2775 HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
2776 /* Raw devices */
2777 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
2778 HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
2779 /* Serial */
2780 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
2781 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
2782 #ifdef TIOCGLTC
2783 COMPATIBLE_IOCTL(TIOCGLTC)
2784 COMPATIBLE_IOCTL(TIOCSLTC)
2785 #endif
2786 #ifdef TIOCSTART
2788 * For these two we have defintions in ioctls.h and/or termios.h on
2789 * some architectures but no actual implemention. Some applications
2790 * like bash call them if they are defined in the headers, so we provide
2791 * entries here to avoid syslog message spew.
2793 COMPATIBLE_IOCTL(TIOCSTART)
2794 COMPATIBLE_IOCTL(TIOCSTOP)
2795 #endif
2796 /* Usbdevfs */
2797 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
2798 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
2799 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
2800 COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
2801 /* i2c */
2802 HANDLE_IOCTL(I2C_FUNCS, w_long)
2803 HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
2804 HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
2805 /* wireless */
2806 HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
2807 HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
2808 HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
2809 HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
2810 HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
2811 HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
2812 HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
2813 HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
2814 HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
2815 HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
2816 HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
2817 HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
2818 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
2819 HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
2820 HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
2821 HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
2822 HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
2823 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
2824 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
2826 #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
2827 HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest)
2828 HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2)
2829 HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2)
2830 HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname)
2831 HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname)
2832 HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata)
2833 HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata)
2834 #endif
2836 /* dvb */
2837 HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
2838 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
2839 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
2841 /* parport */
2842 COMPATIBLE_IOCTL(LPTIME)
2843 COMPATIBLE_IOCTL(LPCHAR)
2844 COMPATIBLE_IOCTL(LPABORTOPEN)
2845 COMPATIBLE_IOCTL(LPCAREFUL)
2846 COMPATIBLE_IOCTL(LPWAIT)
2847 COMPATIBLE_IOCTL(LPSETIRQ)
2848 COMPATIBLE_IOCTL(LPGETSTATUS)
2849 COMPATIBLE_IOCTL(LPGETSTATUS)
2850 COMPATIBLE_IOCTL(LPRESET)
2851 /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
2852 COMPATIBLE_IOCTL(LPGETFLAGS)
2853 HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
2856 int ioctl_table_size = ARRAY_SIZE(ioctl_start);