blob: 71c9d45c062453894bd260af8e1e8d7a9b286ef0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3 *
4 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
5 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
7 * Copyright (C) 2003 Pavel Machek (pavel@suse.cz)
8 *
9 * These routines maintain argument size conversion between 32bit and 64bit
10 * ioctls.
11 */
12
13#ifdef INCLUDES
14#include <linux/config.h>
15#include <linux/types.h>
16#include <linux/compat.h>
17#include <linux/kernel.h>
18#include <linux/compiler.h>
19#include <linux/sched.h>
20#include <linux/smp.h>
21#include <linux/smp_lock.h>
22#include <linux/ioctl.h>
23#include <linux/if.h>
24#include <linux/if_bridge.h>
25#include <linux/slab.h>
26#include <linux/hdreg.h>
27#include <linux/raid/md.h>
28#include <linux/kd.h>
29#include <linux/dirent.h>
30#include <linux/route.h>
31#include <linux/in6.h>
32#include <linux/ipv6_route.h>
33#include <linux/skbuff.h>
34#include <linux/netlink.h>
35#include <linux/vt.h>
36#include <linux/fs.h>
37#include <linux/file.h>
38#include <linux/fd.h>
39#include <linux/ppp_defs.h>
40#include <linux/if_ppp.h>
41#include <linux/if_pppox.h>
42#include <linux/mtio.h>
43#include <linux/cdrom.h>
44#include <linux/loop.h>
45#include <linux/auto_fs.h>
46#include <linux/auto_fs4.h>
47#include <linux/devfs_fs.h>
48#include <linux/tty.h>
49#include <linux/vt_kern.h>
50#include <linux/fb.h>
51#include <linux/ext2_fs.h>
52#include <linux/videodev.h>
53#include <linux/netdevice.h>
54#include <linux/raw.h>
55#include <linux/smb_fs.h>
56#include <linux/blkpg.h>
57#include <linux/blkdev.h>
58#include <linux/elevator.h>
59#include <linux/rtc.h>
60#include <linux/pci.h>
61#include <linux/module.h>
62#include <linux/serial.h>
63#include <linux/reiserfs_fs.h>
64#include <linux/if_tun.h>
65#include <linux/ctype.h>
66#include <linux/ioctl32.h>
67#include <linux/syscalls.h>
68#include <linux/ncp_fs.h>
69#include <linux/i2c.h>
70#include <linux/i2c-dev.h>
71#include <linux/wireless.h>
72#include <linux/atalk.h>
73
74#include <net/sock.h> /* siocdevprivate_ioctl */
75#include <net/bluetooth/bluetooth.h>
76#include <net/bluetooth/hci.h>
77#include <net/bluetooth/rfcomm.h>
78
79#include <linux/capi.h>
80
81#include <scsi/scsi.h>
82/* Ugly hack. */
83#undef __KERNEL__
84#include <scsi/scsi_ioctl.h>
85#define __KERNEL__
86#include <scsi/sg.h>
87
88#include <asm/types.h>
89#include <asm/uaccess.h>
90#include <linux/ethtool.h>
91#include <linux/mii.h>
92#include <linux/if_bonding.h>
93#include <linux/watchdog.h>
94#include <linux/dm-ioctl.h>
95
96#include <asm/module.h>
97#include <linux/soundcard.h>
98#include <linux/lp.h>
99#include <linux/ppdev.h>
100
101#include <linux/atm.h>
102#include <linux/atmarp.h>
103#include <linux/atmclip.h>
104#include <linux/atmdev.h>
105#include <linux/atmioc.h>
106#include <linux/atmlec.h>
107#include <linux/atmmpc.h>
108#include <linux/atmsvc.h>
109#include <linux/atm_tcp.h>
110#include <linux/sonet.h>
111#include <linux/atm_suni.h>
112#include <linux/mtd/mtd.h>
113
114#include <linux/usb.h>
115#include <linux/usbdevice_fs.h>
116#include <linux/nbd.h>
117#include <linux/random.h>
118#include <linux/filter.h>
119#include <linux/msdos_fs.h>
120#include <linux/pktcdvd.h>
121
122#include <linux/hiddev.h>
123
124#undef INCLUDES
125#endif
126
127#ifdef CODE
128
129/* Aiee. Someone does not find a difference between int and long */
130#define EXT2_IOC32_GETFLAGS _IOR('f', 1, int)
131#define EXT2_IOC32_SETFLAGS _IOW('f', 2, int)
132#define EXT2_IOC32_GETVERSION _IOR('v', 1, int)
133#define EXT2_IOC32_SETVERSION _IOW('v', 2, int)
134
135static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
136{
137 mm_segment_t old_fs = get_fs();
138 int err;
139 unsigned long val;
140
141 set_fs (KERNEL_DS);
142 err = sys_ioctl(fd, cmd, (unsigned long)&val);
143 set_fs (old_fs);
144 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
145 return -EFAULT;
146 return err;
147}
148
149static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
150{
151 mm_segment_t old_fs = get_fs();
152 u32 __user *argptr = compat_ptr(arg);
153 int err;
154 unsigned long val;
155
156 if(get_user(val, argptr))
157 return -EFAULT;
158 set_fs (KERNEL_DS);
159 err = sys_ioctl(fd, cmd, (unsigned long)&val);
160 set_fs (old_fs);
161 if (!err && put_user(val, argptr))
162 return -EFAULT;
163 return err;
164}
165
166static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
167{
168 /* These are just misnamed, they actually get/put from/to user an int */
169 switch (cmd) {
170 case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
171 case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
172 case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
173 case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
174 }
175 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
176}
177
178struct video_tuner32 {
179 compat_int_t tuner;
180 char name[32];
181 compat_ulong_t rangelow, rangehigh;
182 u32 flags; /* It is really u32 in videodev.h */
183 u16 mode, signal;
184};
185
186static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
187{
188 int i;
189
190 if(get_user(kp->tuner, &up->tuner))
191 return -EFAULT;
192 for(i = 0; i < 32; i++)
193 __get_user(kp->name[i], &up->name[i]);
194 __get_user(kp->rangelow, &up->rangelow);
195 __get_user(kp->rangehigh, &up->rangehigh);
196 __get_user(kp->flags, &up->flags);
197 __get_user(kp->mode, &up->mode);
198 __get_user(kp->signal, &up->signal);
199 return 0;
200}
201
202static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
203{
204 int i;
205
206 if(put_user(kp->tuner, &up->tuner))
207 return -EFAULT;
208 for(i = 0; i < 32; i++)
209 __put_user(kp->name[i], &up->name[i]);
210 __put_user(kp->rangelow, &up->rangelow);
211 __put_user(kp->rangehigh, &up->rangehigh);
212 __put_user(kp->flags, &up->flags);
213 __put_user(kp->mode, &up->mode);
214 __put_user(kp->signal, &up->signal);
215 return 0;
216}
217
218struct video_buffer32 {
219 compat_caddr_t base;
220 compat_int_t height, width, depth, bytesperline;
221};
222
223static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
224{
225 u32 tmp;
226
227 if (get_user(tmp, &up->base))
228 return -EFAULT;
229
230 /* This is actually a physical address stored
231 * as a void pointer.
232 */
233 kp->base = (void *)(unsigned long) tmp;
234
235 __get_user(kp->height, &up->height);
236 __get_user(kp->width, &up->width);
237 __get_user(kp->depth, &up->depth);
238 __get_user(kp->bytesperline, &up->bytesperline);
239 return 0;
240}
241
242static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
243{
244 u32 tmp = (u32)((unsigned long)kp->base);
245
246 if(put_user(tmp, &up->base))
247 return -EFAULT;
248 __put_user(kp->height, &up->height);
249 __put_user(kp->width, &up->width);
250 __put_user(kp->depth, &up->depth);
251 __put_user(kp->bytesperline, &up->bytesperline);
252 return 0;
253}
254
255struct video_clip32 {
256 s32 x, y, width, height; /* Its really s32 in videodev.h */
257 compat_caddr_t next;
258};
259
260struct video_window32 {
261 u32 x, y, width, height, chromakey, flags;
262 compat_caddr_t clips;
263 compat_int_t clipcount;
264};
265
266/* You get back everything except the clips... */
267static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
268{
269 if(put_user(kp->x, &up->x))
270 return -EFAULT;
271 __put_user(kp->y, &up->y);
272 __put_user(kp->width, &up->width);
273 __put_user(kp->height, &up->height);
274 __put_user(kp->chromakey, &up->chromakey);
275 __put_user(kp->flags, &up->flags);
276 __put_user(kp->clipcount, &up->clipcount);
277 return 0;
278}
279
280#define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
281#define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
282#define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
283#define VIDIOCSWIN32 _IOW('v',10, struct video_window32)
284#define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32)
285#define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
286#define VIDIOCGFREQ32 _IOR('v',14, u32)
287#define VIDIOCSFREQ32 _IOW('v',15, u32)
288
289enum {
290 MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip)
291};
292
293static int do_set_window(unsigned int fd, unsigned int cmd, unsigned long arg)
294{
295 struct video_window32 __user *up = compat_ptr(arg);
296 struct video_window __user *vw;
297 struct video_clip __user *p;
298 int nclips;
299 u32 n;
300
301 if (get_user(nclips, &up->clipcount))
302 return -EFAULT;
303
304 /* Peculiar interface... */
305 if (nclips < 0)
306 nclips = VIDEO_CLIPMAP_SIZE;
307
308 if (nclips > MaxClips)
309 return -ENOMEM;
310
311 vw = compat_alloc_user_space(sizeof(struct video_window) +
312 nclips * sizeof(struct video_clip));
313
314 p = nclips ? (struct video_clip __user *)(vw + 1) : NULL;
315
316 if (get_user(n, &up->x) || put_user(n, &vw->x) ||
317 get_user(n, &up->y) || put_user(n, &vw->y) ||
318 get_user(n, &up->width) || put_user(n, &vw->width) ||
319 get_user(n, &up->height) || put_user(n, &vw->height) ||
320 get_user(n, &up->chromakey) || put_user(n, &vw->chromakey) ||
321 get_user(n, &up->flags) || put_user(n, &vw->flags) ||
322 get_user(n, &up->clipcount) || put_user(n, &vw->clipcount) ||
323 get_user(n, &up->clips) || put_user(p, &vw->clips))
324 return -EFAULT;
325
326 if (nclips) {
327 struct video_clip32 __user *u = compat_ptr(n);
328 int i;
329 if (!u)
330 return -EINVAL;
331 for (i = 0; i < nclips; i++, u++, p++) {
332 s32 v;
333 if (get_user(v, &u->x) ||
334 put_user(v, &p->x) ||
335 get_user(v, &u->y) ||
336 put_user(v, &p->y) ||
337 get_user(v, &u->width) ||
338 put_user(v, &p->width) ||
339 get_user(v, &u->height) ||
340 put_user(v, &p->height) ||
341 put_user(NULL, &p->next))
342 return -EFAULT;
343 }
344 }
345
346 return sys_ioctl(fd, VIDIOCSWIN, (unsigned long)p);
347}
348
349static int do_video_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
350{
351 union {
352 struct video_tuner vt;
353 struct video_buffer vb;
354 struct video_window vw;
355 unsigned long vx;
356 } karg;
357 mm_segment_t old_fs = get_fs();
358 void __user *up = compat_ptr(arg);
359 int err = 0;
360
361 /* First, convert the command. */
362 switch(cmd) {
363 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
364 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
365 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
366 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
367 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
368 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
369 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
370 };
371
372 switch(cmd) {
373 case VIDIOCSTUNER:
374 case VIDIOCGTUNER:
375 err = get_video_tuner32(&karg.vt, up);
376 break;
377
378 case VIDIOCSFBUF:
379 err = get_video_buffer32(&karg.vb, up);
380 break;
381
382 case VIDIOCSFREQ:
383 err = get_user(karg.vx, (u32 __user *)up);
384 break;
385 };
386 if(err)
387 goto out;
388
389 set_fs(KERNEL_DS);
390 err = sys_ioctl(fd, cmd, (unsigned long)&karg);
391 set_fs(old_fs);
392
393 if(err == 0) {
394 switch(cmd) {
395 case VIDIOCGTUNER:
396 err = put_video_tuner32(&karg.vt, up);
397 break;
398
399 case VIDIOCGWIN:
400 err = put_video_window32(&karg.vw, up);
401 break;
402
403 case VIDIOCGFBUF:
404 err = put_video_buffer32(&karg.vb, up);
405 break;
406
407 case VIDIOCGFREQ:
408 err = put_user(((u32)karg.vx), (u32 __user *)up);
409 break;
410 };
411 }
412out:
413 return err;
414}
415
416#ifdef CONFIG_NET
417static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
418{
419 struct compat_timeval __user *up = compat_ptr(arg);
420 struct timeval ktv;
421 mm_segment_t old_fs = get_fs();
422 int err;
423
424 set_fs(KERNEL_DS);
425 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
426 set_fs(old_fs);
427 if(!err) {
428 err = put_user(ktv.tv_sec, &up->tv_sec);
429 err |= __put_user(ktv.tv_usec, &up->tv_usec);
430 }
431 return err;
432}
433
434struct ifmap32 {
435 compat_ulong_t mem_start;
436 compat_ulong_t mem_end;
437 unsigned short base_addr;
438 unsigned char irq;
439 unsigned char dma;
440 unsigned char port;
441};
442
443struct ifreq32 {
444#define IFHWADDRLEN 6
445#define IFNAMSIZ 16
446 union {
447 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
448 } ifr_ifrn;
449 union {
450 struct sockaddr ifru_addr;
451 struct sockaddr ifru_dstaddr;
452 struct sockaddr ifru_broadaddr;
453 struct sockaddr ifru_netmask;
454 struct sockaddr ifru_hwaddr;
455 short ifru_flags;
456 compat_int_t ifru_ivalue;
457 compat_int_t ifru_mtu;
458 struct ifmap32 ifru_map;
459 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
460 char ifru_newname[IFNAMSIZ];
461 compat_caddr_t ifru_data;
462 /* XXXX? ifru_settings should be here */
463 } ifr_ifru;
464};
465
466struct ifconf32 {
467 compat_int_t ifc_len; /* size of buffer */
468 compat_caddr_t ifcbuf;
469};
470
471static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
472{
473 struct net_device *dev;
474 struct ifreq32 ifr32;
475 int err;
476
477 if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
478 return -EFAULT;
479
480 dev = dev_get_by_index(ifr32.ifr_ifindex);
481 if (!dev)
482 return -ENODEV;
483
484 strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
485 dev_put(dev);
486
487 err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
488 return (err ? -EFAULT : 0);
489}
490
491static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
492{
493 struct ifconf32 ifc32;
494 struct ifconf ifc;
495 struct ifconf __user *uifc;
496 struct ifreq32 __user *ifr32;
497 struct ifreq __user *ifr;
498 unsigned int i, j;
499 int err;
500
501 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
502 return -EFAULT;
503
504 if (ifc32.ifcbuf == 0) {
505 ifc32.ifc_len = 0;
506 ifc.ifc_len = 0;
507 ifc.ifc_req = NULL;
508 uifc = compat_alloc_user_space(sizeof(struct ifconf));
509 } else {
510 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
511 sizeof (struct ifreq);
512 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
513 ifc.ifc_len = len;
514 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
515 ifr32 = compat_ptr(ifc32.ifcbuf);
516 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
517 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
518 return -EFAULT;
519 ifr++;
520 ifr32++;
521 }
522 }
523 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
524 return -EFAULT;
525
526 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
527 if (err)
528 return err;
529
530 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
531 return -EFAULT;
532
533 ifr = ifc.ifc_req;
534 ifr32 = compat_ptr(ifc32.ifcbuf);
535 for (i = 0, j = 0; i < ifc32.ifc_len && j < ifc.ifc_len;
536 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
537 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
538 return -EFAULT;
539 ifr32++;
540 ifr++;
541 }
542
543 if (ifc32.ifcbuf == 0) {
544 /* Translate from 64-bit structure multiple to
545 * a 32-bit one.
546 */
547 i = ifc.ifc_len;
548 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
549 ifc32.ifc_len = i;
550 } else {
551 if (i <= ifc32.ifc_len)
552 ifc32.ifc_len = i;
553 else
554 ifc32.ifc_len = i - sizeof (struct ifreq32);
555 }
556 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
557 return -EFAULT;
558
559 return 0;
560}
561
562static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
563{
564 struct ifreq __user *ifr;
565 struct ifreq32 __user *ifr32;
566 u32 data;
567 void __user *datap;
568
569 ifr = compat_alloc_user_space(sizeof(*ifr));
570 ifr32 = compat_ptr(arg);
571
572 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
573 return -EFAULT;
574
575 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
576 return -EFAULT;
577
578 datap = compat_ptr(data);
579 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
580 return -EFAULT;
581
582 return sys_ioctl(fd, cmd, (unsigned long) ifr);
583}
584
585static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
586{
587 struct ifreq kifr;
588 struct ifreq __user *uifr;
589 struct ifreq32 __user *ifr32 = compat_ptr(arg);
590 mm_segment_t old_fs;
591 int err;
592 u32 data;
593 void __user *datap;
594
595 switch (cmd) {
596 case SIOCBONDENSLAVE:
597 case SIOCBONDRELEASE:
598 case SIOCBONDSETHWADDR:
599 case SIOCBONDCHANGEACTIVE:
600 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
601 return -EFAULT;
602
603 old_fs = get_fs();
604 set_fs (KERNEL_DS);
605 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
606 set_fs (old_fs);
607
608 return err;
609 case SIOCBONDSLAVEINFOQUERY:
610 case SIOCBONDINFOQUERY:
611 uifr = compat_alloc_user_space(sizeof(*uifr));
612 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
613 return -EFAULT;
614
615 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
616 return -EFAULT;
617
618 datap = compat_ptr(data);
619 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
620 return -EFAULT;
621
622 return sys_ioctl (fd, cmd, (unsigned long)uifr);
623 default:
624 return -EINVAL;
625 };
626}
627
628int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
629{
630 struct ifreq __user *u_ifreq64;
631 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
632 char tmp_buf[IFNAMSIZ];
633 void __user *data64;
634 u32 data32;
635
636 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
637 IFNAMSIZ))
638 return -EFAULT;
639 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
640 return -EFAULT;
641 data64 = compat_ptr(data32);
642
643 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
644
645 /* Don't check these user accesses, just let that get trapped
646 * in the ioctl handler instead.
647 */
648 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
649 IFNAMSIZ))
650 return -EFAULT;
651 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
652 return -EFAULT;
653
654 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
655}
656
657static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
658{
659 struct ifreq ifr;
660 struct ifreq32 __user *uifr32;
661 struct ifmap32 __user *uifmap32;
662 mm_segment_t old_fs;
663 int err;
664
665 uifr32 = compat_ptr(arg);
666 uifmap32 = &uifr32->ifr_ifru.ifru_map;
667 switch (cmd) {
668 case SIOCSIFMAP:
669 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
670 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
671 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
672 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
673 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
674 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
675 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
676 if (err)
677 return -EFAULT;
678 break;
679 default:
680 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
681 return -EFAULT;
682 break;
683 }
684 old_fs = get_fs();
685 set_fs (KERNEL_DS);
686 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
687 set_fs (old_fs);
688 if (!err) {
689 switch (cmd) {
690 /* TUNSETIFF is defined as _IOW, it should be _IORW
691 * as the data is copied back to user space, but that
692 * cannot be fixed without breaking all existing apps.
693 */
694 case TUNSETIFF:
695 case SIOCGIFFLAGS:
696 case SIOCGIFMETRIC:
697 case SIOCGIFMTU:
698 case SIOCGIFMEM:
699 case SIOCGIFHWADDR:
700 case SIOCGIFINDEX:
701 case SIOCGIFADDR:
702 case SIOCGIFBRDADDR:
703 case SIOCGIFDSTADDR:
704 case SIOCGIFNETMASK:
705 case SIOCGIFTXQLEN:
706 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
707 return -EFAULT;
708 break;
709 case SIOCGIFMAP:
710 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
711 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
712 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
713 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
714 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
715 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
716 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
717 if (err)
718 err = -EFAULT;
719 break;
720 }
721 }
722 return err;
723}
724
725struct rtentry32 {
726 u32 rt_pad1;
727 struct sockaddr rt_dst; /* target address */
728 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
729 struct sockaddr rt_genmask; /* target network mask (IP) */
730 unsigned short rt_flags;
731 short rt_pad2;
732 u32 rt_pad3;
733 unsigned char rt_tos;
734 unsigned char rt_class;
735 short rt_pad4;
736 short rt_metric; /* +1 for binary compatibility! */
737 /* char * */ u32 rt_dev; /* forcing the device at add */
738 u32 rt_mtu; /* per route MTU/Window */
739 u32 rt_window; /* Window clamping */
740 unsigned short rt_irtt; /* Initial RTT */
741
742};
743
744struct in6_rtmsg32 {
745 struct in6_addr rtmsg_dst;
746 struct in6_addr rtmsg_src;
747 struct in6_addr rtmsg_gateway;
748 u32 rtmsg_type;
749 u16 rtmsg_dst_len;
750 u16 rtmsg_src_len;
751 u32 rtmsg_metric;
752 u32 rtmsg_info;
753 u32 rtmsg_flags;
754 s32 rtmsg_ifindex;
755};
756
757static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
758{
759 int ret;
760 void *r = NULL;
761 struct in6_rtmsg r6;
762 struct rtentry r4;
763 char devname[16];
764 u32 rtdev;
765 mm_segment_t old_fs = get_fs();
766
767 struct socket *mysock = sockfd_lookup(fd, &ret);
768
769 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
770 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
771 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
772 3 * sizeof(struct in6_addr));
773 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
774 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
775 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
776 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
777 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
778 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
779 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
780
781 r = (void *) &r6;
782 } else { /* ipv4 */
783 struct rtentry32 __user *ur4 = compat_ptr(arg);
784 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
785 3 * sizeof(struct sockaddr));
786 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
787 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
788 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
789 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
790 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
791 ret |= __get_user (rtdev, &(ur4->rt_dev));
792 if (rtdev) {
793 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
794 r4.rt_dev = devname; devname[15] = 0;
795 } else
796 r4.rt_dev = NULL;
797
798 r = (void *) &r4;
799 }
800
Kirill Korotaevd99901d2005-09-09 13:59:48 +0400801 if (ret) {
802 ret = -EFAULT;
803 goto out;
804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 set_fs (KERNEL_DS);
807 ret = sys_ioctl (fd, cmd, (unsigned long) r);
808 set_fs (old_fs);
809
Kirill Korotaevd99901d2005-09-09 13:59:48 +0400810out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 if (mysock)
812 sockfd_put(mysock);
813
814 return ret;
815}
816#endif
817
818struct hd_geometry32 {
819 unsigned char heads;
820 unsigned char sectors;
821 unsigned short cylinders;
822 u32 start;
823};
824
825static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
826{
827 mm_segment_t old_fs = get_fs();
828 struct hd_geometry geo;
829 struct hd_geometry32 __user *ugeo;
830 int err;
831
832 set_fs (KERNEL_DS);
833 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
834 set_fs (old_fs);
835 ugeo = compat_ptr(arg);
836 if (!err) {
837 err = copy_to_user (ugeo, &geo, 4);
838 err |= __put_user (geo.start, &ugeo->start);
839 }
840 return err ? -EFAULT : 0;
841}
842
843struct fb_fix_screeninfo32 {
844 char id[16];
845 compat_caddr_t smem_start;
846 u32 smem_len;
847 u32 type;
848 u32 type_aux;
849 u32 visual;
850 u16 xpanstep;
851 u16 ypanstep;
852 u16 ywrapstep;
853 u32 line_length;
854 compat_caddr_t mmio_start;
855 u32 mmio_len;
856 u32 accel;
857 u16 reserved[3];
858};
859
860struct fb_cmap32 {
861 u32 start;
862 u32 len;
863 compat_caddr_t red;
864 compat_caddr_t green;
865 compat_caddr_t blue;
866 compat_caddr_t transp;
867};
868
869static int fb_getput_cmap(unsigned int fd, unsigned int cmd, unsigned long arg)
870{
871 struct fb_cmap_user __user *cmap;
872 struct fb_cmap32 __user *cmap32;
873 __u32 data;
874 int err;
875
876 cmap = compat_alloc_user_space(sizeof(*cmap));
877 cmap32 = compat_ptr(arg);
878
879 if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32)))
880 return -EFAULT;
881
882 if (get_user(data, &cmap32->red) ||
883 put_user(compat_ptr(data), &cmap->red) ||
884 get_user(data, &cmap32->green) ||
885 put_user(compat_ptr(data), &cmap->green) ||
886 get_user(data, &cmap32->blue) ||
887 put_user(compat_ptr(data), &cmap->blue) ||
888 get_user(data, &cmap32->transp) ||
889 put_user(compat_ptr(data), &cmap->transp))
890 return -EFAULT;
891
892 err = sys_ioctl(fd, cmd, (unsigned long) cmap);
893
894 if (!err) {
895 if (copy_in_user(&cmap32->start,
896 &cmap->start,
897 2 * sizeof(__u32)))
898 err = -EFAULT;
899 }
900 return err;
901}
902
903static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
904 struct fb_fix_screeninfo32 __user *fix32)
905{
906 __u32 data;
907 int err;
908
909 err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
910
911 data = (__u32) (unsigned long) fix->smem_start;
912 err |= put_user(data, &fix32->smem_start);
913
914 err |= put_user(fix->smem_len, &fix32->smem_len);
915 err |= put_user(fix->type, &fix32->type);
916 err |= put_user(fix->type_aux, &fix32->type_aux);
917 err |= put_user(fix->visual, &fix32->visual);
918 err |= put_user(fix->xpanstep, &fix32->xpanstep);
919 err |= put_user(fix->ypanstep, &fix32->ypanstep);
920 err |= put_user(fix->ywrapstep, &fix32->ywrapstep);
921 err |= put_user(fix->line_length, &fix32->line_length);
922
923 data = (__u32) (unsigned long) fix->mmio_start;
924 err |= put_user(data, &fix32->mmio_start);
925
926 err |= put_user(fix->mmio_len, &fix32->mmio_len);
927 err |= put_user(fix->accel, &fix32->accel);
928 err |= copy_to_user(fix32->reserved, fix->reserved,
929 sizeof(fix->reserved));
930
931 return err;
932}
933
934static int fb_get_fscreeninfo(unsigned int fd, unsigned int cmd, unsigned long arg)
935{
936 mm_segment_t old_fs;
937 struct fb_fix_screeninfo fix;
938 struct fb_fix_screeninfo32 __user *fix32;
939 int err;
940
941 fix32 = compat_ptr(arg);
942
943 old_fs = get_fs();
944 set_fs(KERNEL_DS);
945 err = sys_ioctl(fd, cmd, (unsigned long) &fix);
946 set_fs(old_fs);
947
948 if (!err)
949 err = do_fscreeninfo_to_user(&fix, fix32);
950
951 return err;
952}
953
954static int fb_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
955{
956 int err;
957
958 switch (cmd) {
959 case FBIOGET_FSCREENINFO:
960 err = fb_get_fscreeninfo(fd,cmd, arg);
961 break;
962
963 case FBIOGETCMAP:
964 case FBIOPUTCMAP:
965 err = fb_getput_cmap(fd, cmd, arg);
966 break;
967
968 default:
969 do {
970 static int count;
971 if (++count <= 20)
972 printk("%s: Unknown fb ioctl cmd fd(%d) "
973 "cmd(%08x) arg(%08lx)\n",
974 __FUNCTION__, fd, cmd, arg);
975 } while(0);
976 err = -ENOSYS;
977 break;
978 };
979
980 return err;
981}
982
983static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
984{
985 mm_segment_t old_fs = get_fs();
986 unsigned long kval;
987 unsigned int __user *uvp;
988 int error;
989
990 set_fs(KERNEL_DS);
991 error = sys_ioctl(fd, cmd, (long)&kval);
992 set_fs(old_fs);
993
994 if(error == 0) {
995 uvp = compat_ptr(arg);
996 if(put_user(kval, uvp))
997 error = -EFAULT;
998 }
999 return error;
1000}
1001
1002
1003typedef struct sg_io_hdr32 {
1004 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
1005 compat_int_t dxfer_direction; /* [i] data transfer direction */
1006 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
1007 unsigned char mx_sb_len; /* [i] max length to write to sbp */
1008 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
1009 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
1010 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
1011 or scatter gather list */
1012 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
1013 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
1014 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
1015 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
1016 compat_int_t pack_id; /* [i->o] unused internally (normally) */
1017 compat_uptr_t usr_ptr; /* [i->o] unused internally */
1018 unsigned char status; /* [o] scsi status */
1019 unsigned char masked_status; /* [o] shifted, masked scsi status */
1020 unsigned char msg_status; /* [o] messaging level data (optional) */
1021 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
1022 unsigned short host_status; /* [o] errors from host adapter */
1023 unsigned short driver_status; /* [o] errors from software driver */
1024 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
1025 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
1026 compat_uint_t info; /* [o] auxiliary information */
1027} sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
1028
1029typedef struct sg_iovec32 {
1030 compat_uint_t iov_base;
1031 compat_uint_t iov_len;
1032} sg_iovec32_t;
1033
1034static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
1035{
1036 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
1037 sg_iovec32_t __user *iov32 = dxferp;
1038 int i;
1039
1040 for (i = 0; i < iovec_count; i++) {
1041 u32 base, len;
1042
1043 if (get_user(base, &iov32[i].iov_base) ||
1044 get_user(len, &iov32[i].iov_len) ||
1045 put_user(compat_ptr(base), &iov[i].iov_base) ||
1046 put_user(len, &iov[i].iov_len))
1047 return -EFAULT;
1048 }
1049
1050 if (put_user(iov, &sgio->dxferp))
1051 return -EFAULT;
1052 return 0;
1053}
1054
1055static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1056{
1057 sg_io_hdr_t __user *sgio;
1058 sg_io_hdr32_t __user *sgio32;
1059 u16 iovec_count;
1060 u32 data;
1061 void __user *dxferp;
1062 int err;
1063
1064 sgio32 = compat_ptr(arg);
1065 if (get_user(iovec_count, &sgio32->iovec_count))
1066 return -EFAULT;
1067
1068 {
1069 void __user *top = compat_alloc_user_space(0);
1070 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
1071 (iovec_count * sizeof(sg_iovec_t)));
1072 if (new > top)
1073 return -EINVAL;
1074
1075 sgio = new;
1076 }
1077
1078 /* Ok, now construct. */
1079 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
1080 (2 * sizeof(int)) +
1081 (2 * sizeof(unsigned char)) +
1082 (1 * sizeof(unsigned short)) +
1083 (1 * sizeof(unsigned int))))
1084 return -EFAULT;
1085
1086 if (get_user(data, &sgio32->dxferp))
1087 return -EFAULT;
1088 dxferp = compat_ptr(data);
1089 if (iovec_count) {
1090 if (sg_build_iovec(sgio, dxferp, iovec_count))
1091 return -EFAULT;
1092 } else {
1093 if (put_user(dxferp, &sgio->dxferp))
1094 return -EFAULT;
1095 }
1096
1097 {
1098 unsigned char __user *cmdp;
1099 unsigned char __user *sbp;
1100
1101 if (get_user(data, &sgio32->cmdp))
1102 return -EFAULT;
1103 cmdp = compat_ptr(data);
1104
1105 if (get_user(data, &sgio32->sbp))
1106 return -EFAULT;
1107 sbp = compat_ptr(data);
1108
1109 if (put_user(cmdp, &sgio->cmdp) ||
1110 put_user(sbp, &sgio->sbp))
1111 return -EFAULT;
1112 }
1113
1114 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
1115 3 * sizeof(int)))
1116 return -EFAULT;
1117
1118 if (get_user(data, &sgio32->usr_ptr))
1119 return -EFAULT;
1120 if (put_user(compat_ptr(data), &sgio->usr_ptr))
1121 return -EFAULT;
1122
1123 if (copy_in_user(&sgio->status, &sgio32->status,
1124 (4 * sizeof(unsigned char)) +
1125 (2 * sizeof(unsigned (short))) +
1126 (3 * sizeof(int))))
1127 return -EFAULT;
1128
1129 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
1130
1131 if (err >= 0) {
1132 void __user *datap;
1133
1134 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
1135 sizeof(int)) ||
1136 get_user(datap, &sgio->usr_ptr) ||
1137 put_user((u32)(unsigned long)datap,
1138 &sgio32->usr_ptr) ||
1139 copy_in_user(&sgio32->status, &sgio->status,
1140 (4 * sizeof(unsigned char)) +
1141 (2 * sizeof(unsigned short)) +
1142 (3 * sizeof(int))))
1143 err = -EFAULT;
1144 }
1145
1146 return err;
1147}
1148
1149struct sock_fprog32 {
1150 unsigned short len;
1151 compat_caddr_t filter;
1152};
1153
1154#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
1155#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
1156
1157static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1158{
1159 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
1160 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
1161 void __user *fptr64;
1162 u32 fptr32;
1163 u16 flen;
1164
1165 if (get_user(flen, &u_fprog32->len) ||
1166 get_user(fptr32, &u_fprog32->filter))
1167 return -EFAULT;
1168
1169 fptr64 = compat_ptr(fptr32);
1170
1171 if (put_user(flen, &u_fprog64->len) ||
1172 put_user(fptr64, &u_fprog64->filter))
1173 return -EFAULT;
1174
1175 if (cmd == PPPIOCSPASS32)
1176 cmd = PPPIOCSPASS;
1177 else
1178 cmd = PPPIOCSACTIVE;
1179
1180 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
1181}
1182
1183struct ppp_option_data32 {
1184 compat_caddr_t ptr;
1185 u32 length;
1186 compat_int_t transmit;
1187};
1188#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
1189
1190struct ppp_idle32 {
1191 compat_time_t xmit_idle;
1192 compat_time_t recv_idle;
1193};
1194#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
1195
1196static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
1197{
1198 struct ppp_idle __user *idle;
1199 struct ppp_idle32 __user *idle32;
1200 __kernel_time_t xmit, recv;
1201 int err;
1202
1203 idle = compat_alloc_user_space(sizeof(*idle));
1204 idle32 = compat_ptr(arg);
1205
1206 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
1207
1208 if (!err) {
1209 if (get_user(xmit, &idle->xmit_idle) ||
1210 get_user(recv, &idle->recv_idle) ||
1211 put_user(xmit, &idle32->xmit_idle) ||
1212 put_user(recv, &idle32->recv_idle))
1213 err = -EFAULT;
1214 }
1215 return err;
1216}
1217
1218static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
1219{
1220 struct ppp_option_data __user *odata;
1221 struct ppp_option_data32 __user *odata32;
1222 __u32 data;
1223 void __user *datap;
1224
1225 odata = compat_alloc_user_space(sizeof(*odata));
1226 odata32 = compat_ptr(arg);
1227
1228 if (get_user(data, &odata32->ptr))
1229 return -EFAULT;
1230
1231 datap = compat_ptr(data);
1232 if (put_user(datap, &odata->ptr))
1233 return -EFAULT;
1234
1235 if (copy_in_user(&odata->length, &odata32->length,
1236 sizeof(__u32) + sizeof(int)))
1237 return -EFAULT;
1238
1239 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
1240}
1241
1242static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1243{
1244 int err;
1245
1246 switch (cmd) {
1247 case PPPIOCGIDLE32:
1248 err = ppp_gidle(fd, cmd, arg);
1249 break;
1250
1251 case PPPIOCSCOMPRESS32:
1252 err = ppp_scompress(fd, cmd, arg);
1253 break;
1254
1255 default:
1256 do {
1257 static int count;
1258 if (++count <= 20)
1259 printk("ppp_ioctl: Unknown cmd fd(%d) "
1260 "cmd(%08x) arg(%08x)\n",
1261 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1262 } while(0);
1263 err = -EINVAL;
1264 break;
1265 };
1266
1267 return err;
1268}
1269
1270
1271struct mtget32 {
1272 compat_long_t mt_type;
1273 compat_long_t mt_resid;
1274 compat_long_t mt_dsreg;
1275 compat_long_t mt_gstat;
1276 compat_long_t mt_erreg;
1277 compat_daddr_t mt_fileno;
1278 compat_daddr_t mt_blkno;
1279};
1280#define MTIOCGET32 _IOR('m', 2, struct mtget32)
1281
1282struct mtpos32 {
1283 compat_long_t mt_blkno;
1284};
1285#define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1286
1287static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1288{
1289 mm_segment_t old_fs = get_fs();
1290 struct mtget get;
1291 struct mtget32 __user *umget32;
1292 struct mtpos pos;
1293 struct mtpos32 __user *upos32;
1294 unsigned long kcmd;
1295 void *karg;
1296 int err = 0;
1297
1298 switch(cmd) {
1299 case MTIOCPOS32:
1300 kcmd = MTIOCPOS;
1301 karg = &pos;
1302 break;
1303 case MTIOCGET32:
1304 kcmd = MTIOCGET;
1305 karg = &get;
1306 break;
1307 default:
1308 do {
1309 static int count;
1310 if (++count <= 20)
1311 printk("mt_ioctl: Unknown cmd fd(%d) "
1312 "cmd(%08x) arg(%08x)\n",
1313 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1314 } while(0);
1315 return -EINVAL;
1316 }
1317 set_fs (KERNEL_DS);
1318 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1319 set_fs (old_fs);
1320 if (err)
1321 return err;
1322 switch (cmd) {
1323 case MTIOCPOS32:
1324 upos32 = compat_ptr(arg);
1325 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1326 break;
1327 case MTIOCGET32:
1328 umget32 = compat_ptr(arg);
1329 err = __put_user(get.mt_type, &umget32->mt_type);
1330 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1331 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1332 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1333 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1334 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1335 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1336 break;
1337 }
1338 return err ? -EFAULT: 0;
1339}
1340
1341struct cdrom_read_audio32 {
1342 union cdrom_addr addr;
1343 u8 addr_format;
1344 compat_int_t nframes;
1345 compat_caddr_t buf;
1346};
1347
1348struct cdrom_generic_command32 {
1349 unsigned char cmd[CDROM_PACKET_SIZE];
1350 compat_caddr_t buffer;
1351 compat_uint_t buflen;
1352 compat_int_t stat;
1353 compat_caddr_t sense;
1354 unsigned char data_direction;
1355 compat_int_t quiet;
1356 compat_int_t timeout;
1357 compat_caddr_t reserved[1];
1358};
1359
1360static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1361{
1362 struct cdrom_read_audio __user *cdread_audio;
1363 struct cdrom_read_audio32 __user *cdread_audio32;
1364 __u32 data;
1365 void __user *datap;
1366
1367 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1368 cdread_audio32 = compat_ptr(arg);
1369
1370 if (copy_in_user(&cdread_audio->addr,
1371 &cdread_audio32->addr,
1372 (sizeof(*cdread_audio32) -
1373 sizeof(compat_caddr_t))))
1374 return -EFAULT;
1375
1376 if (get_user(data, &cdread_audio32->buf))
1377 return -EFAULT;
1378 datap = compat_ptr(data);
1379 if (put_user(datap, &cdread_audio->buf))
1380 return -EFAULT;
1381
1382 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1383}
1384
1385static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1386{
1387 struct cdrom_generic_command __user *cgc;
1388 struct cdrom_generic_command32 __user *cgc32;
1389 u32 data;
1390 unsigned char dir;
1391 int itmp;
1392
1393 cgc = compat_alloc_user_space(sizeof(*cgc));
1394 cgc32 = compat_ptr(arg);
1395
1396 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1397 get_user(data, &cgc32->buffer) ||
1398 put_user(compat_ptr(data), &cgc->buffer) ||
1399 copy_in_user(&cgc->buflen, &cgc32->buflen,
1400 (sizeof(unsigned int) + sizeof(int))) ||
1401 get_user(data, &cgc32->sense) ||
1402 put_user(compat_ptr(data), &cgc->sense) ||
1403 get_user(dir, &cgc32->data_direction) ||
1404 put_user(dir, &cgc->data_direction) ||
1405 get_user(itmp, &cgc32->quiet) ||
1406 put_user(itmp, &cgc->quiet) ||
1407 get_user(itmp, &cgc32->timeout) ||
1408 put_user(itmp, &cgc->timeout) ||
1409 get_user(data, &cgc32->reserved[0]) ||
1410 put_user(compat_ptr(data), &cgc->reserved[0]))
1411 return -EFAULT;
1412
1413 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1414}
1415
1416static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1417{
1418 int err;
1419
1420 switch(cmd) {
1421 case CDROMREADAUDIO:
1422 err = cdrom_do_read_audio(fd, cmd, arg);
1423 break;
1424
1425 case CDROM_SEND_PACKET:
1426 err = cdrom_do_generic_command(fd, cmd, arg);
1427 break;
1428
1429 default:
1430 do {
1431 static int count;
1432 if (++count <= 20)
1433 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1434 "cmd(%08x) arg(%08x)\n",
1435 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1436 } while(0);
1437 err = -EINVAL;
1438 break;
1439 };
1440
1441 return err;
1442}
1443
1444struct loop_info32 {
1445 compat_int_t lo_number; /* ioctl r/o */
1446 compat_dev_t lo_device; /* ioctl r/o */
1447 compat_ulong_t lo_inode; /* ioctl r/o */
1448 compat_dev_t lo_rdevice; /* ioctl r/o */
1449 compat_int_t lo_offset;
1450 compat_int_t lo_encrypt_type;
1451 compat_int_t lo_encrypt_key_size; /* ioctl w/o */
1452 compat_int_t lo_flags; /* ioctl r/o */
1453 char lo_name[LO_NAME_SIZE];
1454 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
1455 compat_ulong_t lo_init[2];
1456 char reserved[4];
1457};
1458
1459static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg)
1460{
1461 mm_segment_t old_fs = get_fs();
1462 struct loop_info l;
1463 struct loop_info32 __user *ul;
1464 int err = -EINVAL;
1465
1466 ul = compat_ptr(arg);
1467 switch(cmd) {
1468 case LOOP_SET_STATUS:
1469 err = get_user(l.lo_number, &ul->lo_number);
1470 err |= __get_user(l.lo_device, &ul->lo_device);
1471 err |= __get_user(l.lo_inode, &ul->lo_inode);
1472 err |= __get_user(l.lo_rdevice, &ul->lo_rdevice);
1473 err |= __copy_from_user(&l.lo_offset, &ul->lo_offset,
1474 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1475 if (err) {
1476 err = -EFAULT;
1477 } else {
1478 set_fs (KERNEL_DS);
1479 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1480 set_fs (old_fs);
1481 }
1482 break;
1483 case LOOP_GET_STATUS:
1484 set_fs (KERNEL_DS);
1485 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1486 set_fs (old_fs);
1487 if (!err) {
1488 err = put_user(l.lo_number, &ul->lo_number);
1489 err |= __put_user(l.lo_device, &ul->lo_device);
1490 err |= __put_user(l.lo_inode, &ul->lo_inode);
1491 err |= __put_user(l.lo_rdevice, &ul->lo_rdevice);
1492 err |= __copy_to_user(&ul->lo_offset, &l.lo_offset,
1493 (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1494 if (err)
1495 err = -EFAULT;
1496 }
1497 break;
1498 default: {
1499 static int count;
1500 if (++count <= 20)
1501 printk("%s: Unknown loop ioctl cmd, fd(%d) "
1502 "cmd(%08x) arg(%08lx)\n",
1503 __FUNCTION__, fd, cmd, arg);
1504 }
1505 }
1506 return err;
1507}
1508
1509extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);
1510
1511#ifdef CONFIG_VT
1512
1513static int vt_check(struct file *file)
1514{
1515 struct tty_struct *tty;
1516 struct inode *inode = file->f_dentry->d_inode;
1517
1518 if (file->f_op->ioctl != tty_ioctl)
1519 return -EINVAL;
1520
1521 tty = (struct tty_struct *)file->private_data;
1522 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1523 return -EINVAL;
1524
1525 if (tty->driver->ioctl != vt_ioctl)
1526 return -EINVAL;
1527
1528 /*
1529 * To have permissions to do most of the vt ioctls, we either have
1530 * to be the owner of the tty, or super-user.
1531 */
1532 if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
1533 return 1;
1534 return 0;
1535}
1536
1537struct consolefontdesc32 {
1538 unsigned short charcount; /* characters in font (256 or 512) */
1539 unsigned short charheight; /* scan lines per character (1-32) */
1540 compat_caddr_t chardata; /* font data in expanded form */
1541};
1542
1543static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1544{
1545 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1546 struct console_font_op op;
1547 compat_caddr_t data;
1548 int i, perm;
1549
1550 perm = vt_check(file);
1551 if (perm < 0) return perm;
1552
1553 switch (cmd) {
1554 case PIO_FONTX:
1555 if (!perm)
1556 return -EPERM;
1557 op.op = KD_FONT_OP_SET;
1558 op.flags = 0;
1559 op.width = 8;
1560 if (get_user(op.height, &user_cfd->charheight) ||
1561 get_user(op.charcount, &user_cfd->charcount) ||
1562 get_user(data, &user_cfd->chardata))
1563 return -EFAULT;
1564 op.data = compat_ptr(data);
1565 return con_font_op(vc_cons[fg_console].d, &op);
1566 case GIO_FONTX:
1567 op.op = KD_FONT_OP_GET;
1568 op.flags = 0;
1569 op.width = 8;
1570 if (get_user(op.height, &user_cfd->charheight) ||
1571 get_user(op.charcount, &user_cfd->charcount) ||
1572 get_user(data, &user_cfd->chardata))
1573 return -EFAULT;
1574 if (!data)
1575 return 0;
1576 op.data = compat_ptr(data);
1577 i = con_font_op(vc_cons[fg_console].d, &op);
1578 if (i)
1579 return i;
1580 if (put_user(op.height, &user_cfd->charheight) ||
1581 put_user(op.charcount, &user_cfd->charcount) ||
1582 put_user((compat_caddr_t)(unsigned long)op.data,
1583 &user_cfd->chardata))
1584 return -EFAULT;
1585 return 0;
1586 }
1587 return -EINVAL;
1588}
1589
1590struct console_font_op32 {
1591 compat_uint_t op; /* operation code KD_FONT_OP_* */
1592 compat_uint_t flags; /* KD_FONT_FLAG_* */
1593 compat_uint_t width, height; /* font size */
1594 compat_uint_t charcount;
1595 compat_caddr_t data; /* font data with height fixed to 32 */
1596};
1597
1598static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1599{
1600 struct console_font_op op;
1601 struct console_font_op32 __user *fontop = compat_ptr(arg);
1602 int perm = vt_check(file), i;
1603 struct vc_data *vc;
1604
1605 if (perm < 0) return perm;
1606
1607 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1608 return -EFAULT;
1609 if (!perm && op.op != KD_FONT_OP_GET)
1610 return -EPERM;
1611 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1612 op.flags |= KD_FONT_FLAG_OLD;
1613 vc = ((struct tty_struct *)file->private_data)->driver_data;
1614 i = con_font_op(vc, &op);
1615 if (i)
1616 return i;
1617 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1618 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1619 return -EFAULT;
1620 return 0;
1621}
1622
1623struct unimapdesc32 {
1624 unsigned short entry_ct;
1625 compat_caddr_t entries;
1626};
1627
1628static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1629{
1630 struct unimapdesc32 tmp;
1631 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1632 int perm = vt_check(file);
1633
1634 if (perm < 0) return perm;
1635 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1636 return -EFAULT;
1637 switch (cmd) {
1638 case PIO_UNIMAP:
1639 if (!perm) return -EPERM;
1640 return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries));
1641 case GIO_UNIMAP:
1642 return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
1643 }
1644 return 0;
1645}
1646
1647#endif /* CONFIG_VT */
1648
1649static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1650{
1651 mm_segment_t old_fs = get_fs();
1652 __kernel_uid_t kuid;
1653 int err;
1654
1655 cmd = SMB_IOC_GETMOUNTUID;
1656
1657 set_fs(KERNEL_DS);
1658 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1659 set_fs(old_fs);
1660
1661 if (err >= 0)
1662 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1663
1664 return err;
1665}
1666
1667struct atmif_sioc32 {
1668 compat_int_t number;
1669 compat_int_t length;
1670 compat_caddr_t arg;
1671};
1672
1673struct atm_iobuf32 {
1674 compat_int_t length;
1675 compat_caddr_t buffer;
1676};
1677
1678#define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1679#define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1680#define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1681#define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1682#define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1683#define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1684#define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1685#define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1686#define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1687#define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1688#define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1689#define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1690#define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1691#define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1692#define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1693#define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1694#define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1695
1696static struct {
1697 unsigned int cmd32;
1698 unsigned int cmd;
1699} atm_ioctl_map[] = {
1700 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1701 { ATM_GETNAMES32, ATM_GETNAMES },
1702 { ATM_GETTYPE32, ATM_GETTYPE },
1703 { ATM_GETESI32, ATM_GETESI },
1704 { ATM_GETADDR32, ATM_GETADDR },
1705 { ATM_RSTADDR32, ATM_RSTADDR },
1706 { ATM_ADDADDR32, ATM_ADDADDR },
1707 { ATM_DELADDR32, ATM_DELADDR },
1708 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1709 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1710 { ATM_SETESI32, ATM_SETESI },
1711 { ATM_SETESIF32, ATM_SETESIF },
1712 { ATM_GETSTAT32, ATM_GETSTAT },
1713 { ATM_GETSTATZ32, ATM_GETSTATZ },
1714 { ATM_GETLOOP32, ATM_GETLOOP },
1715 { ATM_SETLOOP32, ATM_SETLOOP },
1716 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1717};
1718
1719#define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
1720
1721
1722static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1723{
1724 struct atm_iobuf __user *iobuf;
1725 struct atm_iobuf32 __user *iobuf32;
1726 u32 data;
1727 void __user *datap;
1728 int len, err;
1729
1730 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1731 iobuf32 = compat_ptr(arg);
1732
1733 if (get_user(len, &iobuf32->length) ||
1734 get_user(data, &iobuf32->buffer))
1735 return -EFAULT;
1736 datap = compat_ptr(data);
1737 if (put_user(len, &iobuf->length) ||
1738 put_user(datap, &iobuf->buffer))
1739 return -EFAULT;
1740
1741 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1742
1743 if (!err) {
1744 if (copy_in_user(&iobuf32->length, &iobuf->length,
1745 sizeof(int)))
1746 err = -EFAULT;
1747 }
1748
1749 return err;
1750}
1751
1752static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1753{
1754 struct atmif_sioc __user *sioc;
1755 struct atmif_sioc32 __user *sioc32;
1756 u32 data;
1757 void __user *datap;
1758 int err;
1759
1760 sioc = compat_alloc_user_space(sizeof(*sioc));
1761 sioc32 = compat_ptr(arg);
1762
1763 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1764 get_user(data, &sioc32->arg))
1765 return -EFAULT;
1766 datap = compat_ptr(data);
1767 if (put_user(datap, &sioc->arg))
1768 return -EFAULT;
1769
1770 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1771
1772 if (!err) {
1773 if (copy_in_user(&sioc32->length, &sioc->length,
1774 sizeof(int)))
1775 err = -EFAULT;
1776 }
1777 return err;
1778}
1779
1780static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1781{
1782 int i;
1783 unsigned int cmd = 0;
1784
1785 switch (cmd32) {
1786 case SONET_GETSTAT:
1787 case SONET_GETSTATZ:
1788 case SONET_GETDIAG:
1789 case SONET_SETDIAG:
1790 case SONET_CLRDIAG:
1791 case SONET_SETFRAMING:
1792 case SONET_GETFRAMING:
1793 case SONET_GETFRSENSE:
1794 return do_atmif_sioc(fd, cmd32, arg);
1795 }
1796
1797 for (i = 0; i < NR_ATM_IOCTL; i++) {
1798 if (cmd32 == atm_ioctl_map[i].cmd32) {
1799 cmd = atm_ioctl_map[i].cmd;
1800 break;
1801 }
1802 }
1803 if (i == NR_ATM_IOCTL)
1804 return -EINVAL;
1805
1806 switch (cmd) {
1807 case ATM_GETNAMES:
1808 return do_atm_iobuf(fd, cmd, arg);
1809
1810 case ATM_GETLINKRATE:
1811 case ATM_GETTYPE:
1812 case ATM_GETESI:
1813 case ATM_GETADDR:
1814 case ATM_RSTADDR:
1815 case ATM_ADDADDR:
1816 case ATM_DELADDR:
1817 case ATM_GETCIRANGE:
1818 case ATM_SETCIRANGE:
1819 case ATM_SETESI:
1820 case ATM_SETESIF:
1821 case ATM_GETSTAT:
1822 case ATM_GETSTATZ:
1823 case ATM_GETLOOP:
1824 case ATM_SETLOOP:
1825 case ATM_QUERYLOOP:
1826 return do_atmif_sioc(fd, cmd, arg);
1827 }
1828
1829 return -EINVAL;
1830}
1831
1832static __attribute_used__ int
1833ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1834{
1835 return -EINVAL;
1836}
1837
1838static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1839{
1840 /* The mkswap binary hard codes it to Intel value :-((( */
1841 return w_long(fd, BLKGETSIZE, arg);
1842}
1843
1844struct blkpg_ioctl_arg32 {
1845 compat_int_t op;
1846 compat_int_t flags;
1847 compat_int_t datalen;
1848 compat_caddr_t data;
1849};
1850
1851static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1852{
1853 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1854 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1855 compat_caddr_t udata;
1856 compat_int_t n;
1857 int err;
1858
1859 err = get_user(n, &ua32->op);
1860 err |= put_user(n, &a->op);
1861 err |= get_user(n, &ua32->flags);
1862 err |= put_user(n, &a->flags);
1863 err |= get_user(n, &ua32->datalen);
1864 err |= put_user(n, &a->datalen);
1865 err |= get_user(udata, &ua32->data);
1866 err |= put_user(compat_ptr(udata), &a->data);
1867 if (err)
1868 return err;
1869
1870 return sys_ioctl(fd, cmd, (unsigned long)a);
1871}
1872
1873static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1874{
1875 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1876}
1877
1878/* Fix sizeof(sizeof()) breakage */
1879#define BLKBSZGET_32 _IOR(0x12,112,int)
1880#define BLKBSZSET_32 _IOW(0x12,113,int)
1881#define BLKGETSIZE64_32 _IOR(0x12,114,int)
1882
1883static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1884{
1885 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1886}
1887
1888static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1889{
1890 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1891}
1892
1893static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1894 unsigned long arg)
1895{
1896 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1897}
1898
1899/* Bluetooth ioctls */
1900#define HCIUARTSETPROTO _IOW('U', 200, int)
1901#define HCIUARTGETPROTO _IOR('U', 201, int)
1902
1903#define BNEPCONNADD _IOW('B', 200, int)
1904#define BNEPCONNDEL _IOW('B', 201, int)
1905#define BNEPGETCONNLIST _IOR('B', 210, int)
1906#define BNEPGETCONNINFO _IOR('B', 211, int)
1907
1908#define CMTPCONNADD _IOW('C', 200, int)
1909#define CMTPCONNDEL _IOW('C', 201, int)
1910#define CMTPGETCONNLIST _IOR('C', 210, int)
1911#define CMTPGETCONNINFO _IOR('C', 211, int)
1912
1913#define HIDPCONNADD _IOW('H', 200, int)
1914#define HIDPCONNDEL _IOW('H', 201, int)
1915#define HIDPGETCONNLIST _IOR('H', 210, int)
1916#define HIDPGETCONNINFO _IOR('H', 211, int)
1917
1918struct floppy_struct32 {
1919 compat_uint_t size;
1920 compat_uint_t sect;
1921 compat_uint_t head;
1922 compat_uint_t track;
1923 compat_uint_t stretch;
1924 unsigned char gap;
1925 unsigned char rate;
1926 unsigned char spec1;
1927 unsigned char fmt_gap;
1928 const compat_caddr_t name;
1929};
1930
1931struct floppy_drive_params32 {
1932 char cmos;
1933 compat_ulong_t max_dtr;
1934 compat_ulong_t hlt;
1935 compat_ulong_t hut;
1936 compat_ulong_t srt;
1937 compat_ulong_t spinup;
1938 compat_ulong_t spindown;
1939 unsigned char spindown_offset;
1940 unsigned char select_delay;
1941 unsigned char rps;
1942 unsigned char tracks;
1943 compat_ulong_t timeout;
1944 unsigned char interleave_sect;
1945 struct floppy_max_errors max_errors;
1946 char flags;
1947 char read_track;
1948 short autodetect[8];
1949 compat_int_t checkfreq;
1950 compat_int_t native_format;
1951};
1952
1953struct floppy_drive_struct32 {
1954 signed char flags;
1955 compat_ulong_t spinup_date;
1956 compat_ulong_t select_date;
1957 compat_ulong_t first_read_date;
1958 short probed_format;
1959 short track;
1960 short maxblock;
1961 short maxtrack;
1962 compat_int_t generation;
1963 compat_int_t keep_data;
1964 compat_int_t fd_ref;
1965 compat_int_t fd_device;
1966 compat_int_t last_checked;
1967 compat_caddr_t dmabuf;
1968 compat_int_t bufblocks;
1969};
1970
1971struct floppy_fdc_state32 {
1972 compat_int_t spec1;
1973 compat_int_t spec2;
1974 compat_int_t dtr;
1975 unsigned char version;
1976 unsigned char dor;
1977 compat_ulong_t address;
1978 unsigned int rawcmd:2;
1979 unsigned int reset:1;
1980 unsigned int need_configure:1;
1981 unsigned int perp_mode:2;
1982 unsigned int has_fifo:1;
1983 unsigned int driver_version;
1984 unsigned char track[4];
1985};
1986
1987struct floppy_write_errors32 {
1988 unsigned int write_errors;
1989 compat_ulong_t first_error_sector;
1990 compat_int_t first_error_generation;
1991 compat_ulong_t last_error_sector;
1992 compat_int_t last_error_generation;
1993 compat_uint_t badness;
1994};
1995
1996#define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1997#define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1998#define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1999#define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
2000#define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
2001#define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
2002#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
2003#define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
2004#define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
2005
2006static struct {
2007 unsigned int cmd32;
2008 unsigned int cmd;
2009} fd_ioctl_trans_table[] = {
2010 { FDSETPRM32, FDSETPRM },
2011 { FDDEFPRM32, FDDEFPRM },
2012 { FDGETPRM32, FDGETPRM },
2013 { FDSETDRVPRM32, FDSETDRVPRM },
2014 { FDGETDRVPRM32, FDGETDRVPRM },
2015 { FDGETDRVSTAT32, FDGETDRVSTAT },
2016 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
2017 { FDGETFDCSTAT32, FDGETFDCSTAT },
2018 { FDWERRORGET32, FDWERRORGET }
2019};
2020
2021#define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
2022
2023static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2024{
2025 mm_segment_t old_fs = get_fs();
2026 void *karg = NULL;
2027 unsigned int kcmd = 0;
2028 int i, err;
2029
2030 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
2031 if (cmd == fd_ioctl_trans_table[i].cmd32) {
2032 kcmd = fd_ioctl_trans_table[i].cmd;
2033 break;
2034 }
2035 if (!kcmd)
2036 return -EINVAL;
2037
2038 switch (cmd) {
2039 case FDSETPRM32:
2040 case FDDEFPRM32:
2041 case FDGETPRM32:
2042 {
2043 compat_uptr_t name;
2044 struct floppy_struct32 __user *uf;
2045 struct floppy_struct *f;
2046
2047 uf = compat_ptr(arg);
2048 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
2049 if (!karg)
2050 return -ENOMEM;
2051 if (cmd == FDGETPRM32)
2052 break;
2053 err = __get_user(f->size, &uf->size);
2054 err |= __get_user(f->sect, &uf->sect);
2055 err |= __get_user(f->head, &uf->head);
2056 err |= __get_user(f->track, &uf->track);
2057 err |= __get_user(f->stretch, &uf->stretch);
2058 err |= __get_user(f->gap, &uf->gap);
2059 err |= __get_user(f->rate, &uf->rate);
2060 err |= __get_user(f->spec1, &uf->spec1);
2061 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
2062 err |= __get_user(name, &uf->name);
2063 f->name = compat_ptr(name);
2064 if (err) {
2065 err = -EFAULT;
2066 goto out;
2067 }
2068 break;
2069 }
2070 case FDSETDRVPRM32:
2071 case FDGETDRVPRM32:
2072 {
2073 struct floppy_drive_params32 __user *uf;
2074 struct floppy_drive_params *f;
2075
2076 uf = compat_ptr(arg);
2077 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
2078 if (!karg)
2079 return -ENOMEM;
2080 if (cmd == FDGETDRVPRM32)
2081 break;
2082 err = __get_user(f->cmos, &uf->cmos);
2083 err |= __get_user(f->max_dtr, &uf->max_dtr);
2084 err |= __get_user(f->hlt, &uf->hlt);
2085 err |= __get_user(f->hut, &uf->hut);
2086 err |= __get_user(f->srt, &uf->srt);
2087 err |= __get_user(f->spinup, &uf->spinup);
2088 err |= __get_user(f->spindown, &uf->spindown);
2089 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
2090 err |= __get_user(f->select_delay, &uf->select_delay);
2091 err |= __get_user(f->rps, &uf->rps);
2092 err |= __get_user(f->tracks, &uf->tracks);
2093 err |= __get_user(f->timeout, &uf->timeout);
2094 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
2095 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
2096 err |= __get_user(f->flags, &uf->flags);
2097 err |= __get_user(f->read_track, &uf->read_track);
2098 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
2099 err |= __get_user(f->checkfreq, &uf->checkfreq);
2100 err |= __get_user(f->native_format, &uf->native_format);
2101 if (err) {
2102 err = -EFAULT;
2103 goto out;
2104 }
2105 break;
2106 }
2107 case FDGETDRVSTAT32:
2108 case FDPOLLDRVSTAT32:
2109 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
2110 if (!karg)
2111 return -ENOMEM;
2112 break;
2113 case FDGETFDCSTAT32:
2114 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
2115 if (!karg)
2116 return -ENOMEM;
2117 break;
2118 case FDWERRORGET32:
2119 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
2120 if (!karg)
2121 return -ENOMEM;
2122 break;
2123 default:
2124 return -EINVAL;
2125 }
2126 set_fs (KERNEL_DS);
2127 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
2128 set_fs (old_fs);
2129 if (err)
2130 goto out;
2131 switch (cmd) {
2132 case FDGETPRM32:
2133 {
2134 struct floppy_struct *f = karg;
2135 struct floppy_struct32 __user *uf = compat_ptr(arg);
2136
2137 err = __put_user(f->size, &uf->size);
2138 err |= __put_user(f->sect, &uf->sect);
2139 err |= __put_user(f->head, &uf->head);
2140 err |= __put_user(f->track, &uf->track);
2141 err |= __put_user(f->stretch, &uf->stretch);
2142 err |= __put_user(f->gap, &uf->gap);
2143 err |= __put_user(f->rate, &uf->rate);
2144 err |= __put_user(f->spec1, &uf->spec1);
2145 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
2146 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
2147 break;
2148 }
2149 case FDGETDRVPRM32:
2150 {
2151 struct floppy_drive_params32 __user *uf;
2152 struct floppy_drive_params *f = karg;
2153
2154 uf = compat_ptr(arg);
2155 err = __put_user(f->cmos, &uf->cmos);
2156 err |= __put_user(f->max_dtr, &uf->max_dtr);
2157 err |= __put_user(f->hlt, &uf->hlt);
2158 err |= __put_user(f->hut, &uf->hut);
2159 err |= __put_user(f->srt, &uf->srt);
2160 err |= __put_user(f->spinup, &uf->spinup);
2161 err |= __put_user(f->spindown, &uf->spindown);
2162 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
2163 err |= __put_user(f->select_delay, &uf->select_delay);
2164 err |= __put_user(f->rps, &uf->rps);
2165 err |= __put_user(f->tracks, &uf->tracks);
2166 err |= __put_user(f->timeout, &uf->timeout);
2167 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
2168 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
2169 err |= __put_user(f->flags, &uf->flags);
2170 err |= __put_user(f->read_track, &uf->read_track);
2171 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
2172 err |= __put_user(f->checkfreq, &uf->checkfreq);
2173 err |= __put_user(f->native_format, &uf->native_format);
2174 break;
2175 }
2176 case FDGETDRVSTAT32:
2177 case FDPOLLDRVSTAT32:
2178 {
2179 struct floppy_drive_struct32 __user *uf;
2180 struct floppy_drive_struct *f = karg;
2181
2182 uf = compat_ptr(arg);
2183 err = __put_user(f->flags, &uf->flags);
2184 err |= __put_user(f->spinup_date, &uf->spinup_date);
2185 err |= __put_user(f->select_date, &uf->select_date);
2186 err |= __put_user(f->first_read_date, &uf->first_read_date);
2187 err |= __put_user(f->probed_format, &uf->probed_format);
2188 err |= __put_user(f->track, &uf->track);
2189 err |= __put_user(f->maxblock, &uf->maxblock);
2190 err |= __put_user(f->maxtrack, &uf->maxtrack);
2191 err |= __put_user(f->generation, &uf->generation);
2192 err |= __put_user(f->keep_data, &uf->keep_data);
2193 err |= __put_user(f->fd_ref, &uf->fd_ref);
2194 err |= __put_user(f->fd_device, &uf->fd_device);
2195 err |= __put_user(f->last_checked, &uf->last_checked);
2196 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
2197 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
2198 break;
2199 }
2200 case FDGETFDCSTAT32:
2201 {
2202 struct floppy_fdc_state32 __user *uf;
2203 struct floppy_fdc_state *f = karg;
2204
2205 uf = compat_ptr(arg);
2206 err = __put_user(f->spec1, &uf->spec1);
2207 err |= __put_user(f->spec2, &uf->spec2);
2208 err |= __put_user(f->dtr, &uf->dtr);
2209 err |= __put_user(f->version, &uf->version);
2210 err |= __put_user(f->dor, &uf->dor);
2211 err |= __put_user(f->address, &uf->address);
2212 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
2213 (char *)&f->address + sizeof(f->address), sizeof(int));
2214 err |= __put_user(f->driver_version, &uf->driver_version);
2215 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
2216 break;
2217 }
2218 case FDWERRORGET32:
2219 {
2220 struct floppy_write_errors32 __user *uf;
2221 struct floppy_write_errors *f = karg;
2222
2223 uf = compat_ptr(arg);
2224 err = __put_user(f->write_errors, &uf->write_errors);
2225 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
2226 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
2227 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
2228 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
2229 err |= __put_user(f->badness, &uf->badness);
2230 break;
2231 }
2232 default:
2233 break;
2234 }
2235 if (err)
2236 err = -EFAULT;
2237
Jesper Juhlf99d49a2005-11-07 01:01:34 -08002238out:
2239 kfree(karg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 return err;
2241}
2242
2243struct mtd_oob_buf32 {
2244 u_int32_t start;
2245 u_int32_t length;
2246 compat_caddr_t ptr; /* unsigned char* */
2247};
2248
2249#define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
2250#define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
2251
2252static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
2253{
2254 struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
2255 struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
2256 u32 data;
2257 char __user *datap;
2258 unsigned int real_cmd;
2259 int err;
2260
2261 real_cmd = (cmd == MEMREADOOB32) ?
2262 MEMREADOOB : MEMWRITEOOB;
2263
2264 if (copy_in_user(&buf->start, &buf32->start,
2265 2 * sizeof(u32)) ||
2266 get_user(data, &buf32->ptr))
2267 return -EFAULT;
2268 datap = compat_ptr(data);
2269 if (put_user(datap, &buf->ptr))
2270 return -EFAULT;
2271
2272 err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
2273
2274 if (!err) {
2275 if (copy_in_user(&buf32->start, &buf->start,
2276 2 * sizeof(u32)))
2277 err = -EFAULT;
2278 }
2279
2280 return err;
2281}
2282
2283#define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
2284#define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
2285
2286static long
2287put_dirent32 (struct dirent *d, struct compat_dirent __user *d32)
2288{
2289 if (!access_ok(VERIFY_WRITE, d32, sizeof(struct compat_dirent)))
2290 return -EFAULT;
2291
2292 __put_user(d->d_ino, &d32->d_ino);
2293 __put_user(d->d_off, &d32->d_off);
2294 __put_user(d->d_reclen, &d32->d_reclen);
2295 if (__copy_to_user(d32->d_name, d->d_name, d->d_reclen))
2296 return -EFAULT;
2297
2298 return 0;
2299}
2300
2301static int vfat_ioctl32(unsigned fd, unsigned cmd, unsigned long arg)
2302{
2303 struct compat_dirent __user *p = compat_ptr(arg);
2304 int ret;
2305 mm_segment_t oldfs = get_fs();
2306 struct dirent d[2];
2307
2308 switch(cmd)
2309 {
2310 case VFAT_IOCTL_READDIR_BOTH32:
2311 cmd = VFAT_IOCTL_READDIR_BOTH;
2312 break;
2313 case VFAT_IOCTL_READDIR_SHORT32:
2314 cmd = VFAT_IOCTL_READDIR_SHORT;
2315 break;
2316 }
2317
2318 set_fs(KERNEL_DS);
2319 ret = sys_ioctl(fd,cmd,(unsigned long)&d);
2320 set_fs(oldfs);
2321 if (ret >= 0) {
2322 ret |= put_dirent32(&d[0], p);
2323 ret |= put_dirent32(&d[1], p + 1);
2324 }
2325 return ret;
2326}
2327
2328#define REISERFS_IOC_UNPACK32 _IOW(0xCD,1,int)
2329
2330static int reiserfs_ioctl32(unsigned fd, unsigned cmd, unsigned long ptr)
2331{
2332 if (cmd == REISERFS_IOC_UNPACK32)
2333 cmd = REISERFS_IOC_UNPACK;
2334
2335 return sys_ioctl(fd,cmd,ptr);
2336}
2337
2338struct raw32_config_request
2339{
2340 compat_int_t raw_minor;
2341 __u64 block_major;
2342 __u64 block_minor;
2343} __attribute__((packed));
2344
2345static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2346{
2347 int ret;
2348
2349 if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
2350 return -EFAULT;
2351
2352 ret = __get_user(req->raw_minor, &user_req->raw_minor);
2353 ret |= __get_user(req->block_major, &user_req->block_major);
2354 ret |= __get_user(req->block_minor, &user_req->block_minor);
2355
2356 return ret ? -EFAULT : 0;
2357}
2358
2359static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2360{
2361 int ret;
2362
2363 if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
2364 return -EFAULT;
2365
2366 ret = __put_user(req->raw_minor, &user_req->raw_minor);
2367 ret |= __put_user(req->block_major, &user_req->block_major);
2368 ret |= __put_user(req->block_minor, &user_req->block_minor);
2369
2370 return ret ? -EFAULT : 0;
2371}
2372
2373static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2374{
2375 int ret;
2376
2377 switch (cmd) {
2378 case RAW_SETBIND:
2379 case RAW_GETBIND: {
2380 struct raw_config_request req;
2381 struct raw32_config_request __user *user_req = compat_ptr(arg);
2382 mm_segment_t oldfs = get_fs();
2383
2384 if ((ret = get_raw32_request(&req, user_req)))
2385 return ret;
2386
2387 set_fs(KERNEL_DS);
2388 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2389 set_fs(oldfs);
2390
2391 if ((!ret) && (cmd == RAW_GETBIND)) {
2392 ret = set_raw32_request(&req, user_req);
2393 }
2394 break;
2395 }
2396 default:
2397 ret = sys_ioctl(fd, cmd, arg);
2398 break;
2399 }
2400 return ret;
2401}
2402
2403struct serial_struct32 {
2404 compat_int_t type;
2405 compat_int_t line;
2406 compat_uint_t port;
2407 compat_int_t irq;
2408 compat_int_t flags;
2409 compat_int_t xmit_fifo_size;
2410 compat_int_t custom_divisor;
2411 compat_int_t baud_base;
2412 unsigned short close_delay;
2413 char io_type;
2414 char reserved_char[1];
2415 compat_int_t hub6;
2416 unsigned short closing_wait; /* time to wait before closing */
2417 unsigned short closing_wait2; /* no longer used... */
2418 compat_uint_t iomem_base;
2419 unsigned short iomem_reg_shift;
2420 unsigned int port_high;
2421 /* compat_ulong_t iomap_base FIXME */
2422 compat_int_t reserved[1];
2423};
2424
2425static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2426{
2427 typedef struct serial_struct SS;
2428 typedef struct serial_struct32 SS32;
2429 struct serial_struct32 __user *ss32 = compat_ptr(arg);
2430 int err;
2431 struct serial_struct ss;
2432 mm_segment_t oldseg = get_fs();
2433 __u32 udata;
2434
2435 if (cmd == TIOCSSERIAL) {
2436 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
2437 return -EFAULT;
2438 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
2439 return -EFAULT;
2440 __get_user(udata, &ss32->iomem_base);
2441 ss.iomem_base = compat_ptr(udata);
2442 __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2443 __get_user(ss.port_high, &ss32->port_high);
2444 ss.iomap_base = 0UL;
2445 }
2446 set_fs(KERNEL_DS);
2447 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2448 set_fs(oldseg);
2449 if (cmd == TIOCGSERIAL && err >= 0) {
2450 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
2451 return -EFAULT;
2452 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
2453 return -EFAULT;
2454 __put_user((unsigned long)ss.iomem_base >> 32 ?
2455 0xffffffff : (unsigned)(unsigned long)ss.iomem_base,
2456 &ss32->iomem_base);
2457 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
2458 __put_user(ss.port_high, &ss32->port_high);
2459
2460 }
2461 return err;
2462}
2463
2464struct usbdevfs_ctrltransfer32 {
2465 u8 bRequestType;
2466 u8 bRequest;
2467 u16 wValue;
2468 u16 wIndex;
2469 u16 wLength;
2470 u32 timeout; /* in milliseconds */
2471 compat_caddr_t data;
2472};
2473
2474#define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2475
2476static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2477{
2478 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2479 struct usbdevfs_ctrltransfer __user *p;
2480 __u32 udata;
2481 p = compat_alloc_user_space(sizeof(*p));
2482 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2483 get_user(udata, &p32->data) ||
2484 put_user(compat_ptr(udata), &p->data))
2485 return -EFAULT;
2486 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2487}
2488
2489
2490struct usbdevfs_bulktransfer32 {
2491 compat_uint_t ep;
2492 compat_uint_t len;
2493 compat_uint_t timeout; /* in milliseconds */
2494 compat_caddr_t data;
2495};
2496
2497#define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2498
2499static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2500{
2501 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2502 struct usbdevfs_bulktransfer __user *p;
2503 compat_uint_t n;
2504 compat_caddr_t addr;
2505
2506 p = compat_alloc_user_space(sizeof(*p));
2507
2508 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2509 get_user(n, &p32->len) || put_user(n, &p->len) ||
2510 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2511 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2512 return -EFAULT;
2513
2514 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2515}
2516
2517
2518/*
2519 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
2520 * are handled in usbdevfs core. -Christopher Li
2521 */
2522
2523struct usbdevfs_disconnectsignal32 {
2524 compat_int_t signr;
2525 compat_caddr_t context;
2526};
2527
2528#define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2529
2530static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2531{
2532 struct usbdevfs_disconnectsignal kdis;
2533 struct usbdevfs_disconnectsignal32 __user *udis;
2534 mm_segment_t old_fs;
2535 u32 uctx;
2536 int err;
2537
2538 udis = compat_ptr(arg);
2539
2540 if (get_user(kdis.signr, &udis->signr) ||
2541 __get_user(uctx, &udis->context))
2542 return -EFAULT;
2543
2544 kdis.context = compat_ptr(uctx);
2545
2546 old_fs = get_fs();
2547 set_fs(KERNEL_DS);
2548 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2549 set_fs(old_fs);
2550
2551 return err;
2552}
2553
2554/*
2555 * I2C layer ioctls
2556 */
2557
2558struct i2c_msg32 {
2559 u16 addr;
2560 u16 flags;
2561 u16 len;
2562 compat_caddr_t buf;
2563};
2564
2565struct i2c_rdwr_ioctl_data32 {
2566 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2567 u32 nmsgs;
2568};
2569
2570struct i2c_smbus_ioctl_data32 {
2571 u8 read_write;
2572 u8 command;
2573 u32 size;
2574 compat_caddr_t data; /* union i2c_smbus_data *data */
2575};
2576
2577struct i2c_rdwr_aligned {
2578 struct i2c_rdwr_ioctl_data cmd;
2579 struct i2c_msg msgs[0];
2580};
2581
2582static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2583{
2584 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
2585 struct i2c_rdwr_aligned __user *tdata;
2586 struct i2c_msg __user *tmsgs;
2587 struct i2c_msg32 __user *umsgs;
2588 compat_caddr_t datap;
2589 int nmsgs, i;
2590
2591 if (get_user(nmsgs, &udata->nmsgs))
2592 return -EFAULT;
2593 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2594 return -EINVAL;
2595
2596 if (get_user(datap, &udata->msgs))
2597 return -EFAULT;
2598 umsgs = compat_ptr(datap);
2599
2600 tdata = compat_alloc_user_space(sizeof(*tdata) +
2601 nmsgs * sizeof(struct i2c_msg));
2602 tmsgs = &tdata->msgs[0];
2603
2604 if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
2605 put_user(tmsgs, &tdata->cmd.msgs))
2606 return -EFAULT;
2607
2608 for (i = 0; i < nmsgs; i++) {
2609 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
2610 return -EFAULT;
2611 if (get_user(datap, &umsgs[i].buf) ||
2612 put_user(compat_ptr(datap), &tmsgs[i].buf))
2613 return -EFAULT;
2614 }
2615 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2616}
2617
2618static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2619{
2620 struct i2c_smbus_ioctl_data __user *tdata;
2621 struct i2c_smbus_ioctl_data32 __user *udata;
2622 compat_caddr_t datap;
2623
2624 tdata = compat_alloc_user_space(sizeof(*tdata));
2625 if (tdata == NULL)
2626 return -ENOMEM;
2627 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
2628 return -EFAULT;
2629
2630 udata = compat_ptr(arg);
2631 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
2632 return -EFAULT;
2633
2634 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2635 return -EFAULT;
2636 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2637 return -EFAULT;
2638 if (__get_user(datap, &udata->data) ||
2639 __put_user(compat_ptr(datap), &tdata->data))
2640 return -EFAULT;
2641
2642 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2643}
2644
2645struct compat_iw_point {
2646 compat_caddr_t pointer;
2647 __u16 length;
2648 __u16 flags;
2649};
2650
2651static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2652{
2653 struct iwreq __user *iwr;
2654 struct iwreq __user *iwr_u;
2655 struct iw_point __user *iwp;
2656 struct compat_iw_point __user *iwp_u;
2657 compat_caddr_t pointer;
2658 __u16 length, flags;
2659
2660 iwr_u = compat_ptr(arg);
2661 iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2662 iwr = compat_alloc_user_space(sizeof(*iwr));
2663 if (iwr == NULL)
2664 return -ENOMEM;
2665
2666 iwp = &iwr->u.data;
2667
2668 if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
2669 return -EFAULT;
2670
2671 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2672 &iwr_u->ifr_ifrn.ifrn_name[0],
2673 sizeof(iwr->ifr_ifrn.ifrn_name)))
2674 return -EFAULT;
2675
2676 if (__get_user(pointer, &iwp_u->pointer) ||
2677 __get_user(length, &iwp_u->length) ||
2678 __get_user(flags, &iwp_u->flags))
2679 return -EFAULT;
2680
2681 if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
2682 __put_user(length, &iwp->length) ||
2683 __put_user(flags, &iwp->flags))
2684 return -EFAULT;
2685
2686 return sys_ioctl(fd, cmd, (unsigned long) iwr);
2687}
2688
2689/* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2690 * for some operations; this forces use of the newer bridge-utils that
2691 * use compatiable ioctls
2692 */
2693static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2694{
2695 u32 tmp;
2696
2697 if (get_user(tmp, (u32 __user *) arg))
2698 return -EFAULT;
2699 if (tmp == BRCTL_GET_VERSION)
2700 return BRCTL_VERSION + 1;
2701 return -EINVAL;
2702}
2703
2704#if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
2705struct ncp_ioctl_request_32 {
2706 u32 function;
2707 u32 size;
2708 compat_caddr_t data;
2709};
2710
2711struct ncp_fs_info_v2_32 {
2712 s32 version;
2713 u32 mounted_uid;
2714 u32 connection;
2715 u32 buffer_size;
2716
2717 u32 volume_number;
2718 u32 directory_id;
2719
2720 u32 dummy1;
2721 u32 dummy2;
2722 u32 dummy3;
2723};
2724
2725struct ncp_objectname_ioctl_32
2726{
2727 s32 auth_type;
2728 u32 object_name_len;
2729 compat_caddr_t object_name; /* an userspace data, in most cases user name */
2730};
2731
2732struct ncp_privatedata_ioctl_32
2733{
2734 u32 len;
2735 compat_caddr_t data; /* ~1000 for NDS */
2736};
2737
2738#define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
2739#define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32)
2740#define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
2741#define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
2742#define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
2743#define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
2744#define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
2745
2746static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
2747{
2748 struct ncp_ioctl_request_32 n32;
2749 struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p));
2750
2751 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) ||
2752 put_user(n32.function, &p->function) ||
2753 put_user(n32.size, &p->size) ||
2754 put_user(compat_ptr(n32.data), &p->data))
2755 return -EFAULT;
2756
2757 return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p);
2758}
2759
2760static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
2761{
2762 mm_segment_t old_fs = get_fs();
2763 __kernel_uid_t kuid;
2764 int err;
2765
2766 cmd = NCP_IOC_GETMOUNTUID2;
2767
2768 set_fs(KERNEL_DS);
2769 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
2770 set_fs(old_fs);
2771
2772 if (!err)
2773 err = put_user(kuid,
2774 (unsigned int __user *) compat_ptr(arg));
2775
2776 return err;
2777}
2778
2779static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
2780{
2781 mm_segment_t old_fs = get_fs();
2782 struct ncp_fs_info_v2_32 n32;
2783 struct ncp_fs_info_v2 n;
2784 int err;
2785
2786 if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)))
2787 return -EFAULT;
2788 if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
2789 return -EINVAL;
2790 n.version = NCP_GET_FS_INFO_VERSION_V2;
2791
2792 set_fs(KERNEL_DS);
2793 err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
2794 set_fs(old_fs);
2795
2796 if (!err) {
2797 n32.version = n.version;
2798 n32.mounted_uid = n.mounted_uid;
2799 n32.connection = n.connection;
2800 n32.buffer_size = n.buffer_size;
2801 n32.volume_number = n.volume_number;
2802 n32.directory_id = n.directory_id;
2803 n32.dummy1 = n.dummy1;
2804 n32.dummy2 = n.dummy2;
2805 n32.dummy3 = n.dummy3;
2806 err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0;
2807 }
2808 return err;
2809}
2810
2811static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
2812{
2813 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2814 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
2815 s32 auth_type;
2816 u32 name_len;
2817 int err;
2818
2819 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2820 put_user(n32.object_name_len, &p->object_name_len) ||
2821 put_user(compat_ptr(n32.object_name), &p->object_name))
2822 return -EFAULT;
2823
2824 err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p);
2825 if (err)
2826 return err;
2827
2828 if (get_user(auth_type, &p->auth_type) ||
2829 put_user(auth_type, &p32->auth_type) ||
2830 get_user(name_len, &p->object_name_len) ||
2831 put_user(name_len, &p32->object_name_len))
2832 return -EFAULT;
2833
2834 return 0;
2835}
2836
2837static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
2838{
2839 struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2840 struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
2841
2842 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2843 put_user(n32.auth_type, &p->auth_type) ||
2844 put_user(n32.object_name_len, &p->object_name_len) ||
2845 put_user(compat_ptr(n32.object_name), &p->object_name))
2846 return -EFAULT;
2847
2848 return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p);
2849}
2850
2851static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
2852{
2853 struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg);
2854 struct ncp_privatedata_ioctl __user *p =
2855 compat_alloc_user_space(sizeof(*p));
2856 u32 len;
2857 int err;
2858
2859 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2860 put_user(n32.len, &p->len) ||
2861 put_user(compat_ptr(n32.data), &p->data))
2862 return -EFAULT;
2863
2864 err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p);
2865 if (err)
2866 return err;
2867
2868 if (get_user(len, &p->len) ||
2869 put_user(len, &p32->len))
2870 return -EFAULT;
2871
2872 return 0;
2873}
2874
2875static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
2876{
2877 struct ncp_privatedata_ioctl_32 n32;
2878 struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg);
2879 struct ncp_privatedata_ioctl __user *p =
2880 compat_alloc_user_space(sizeof(*p));
2881
2882 if (copy_from_user(&n32, p32, sizeof(n32)) ||
2883 put_user(n32.len, &p->len) ||
2884 put_user(compat_ptr(n32.data), &p->data))
2885 return -EFAULT;
2886
2887 return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p);
2888}
2889#endif
2890
2891#undef CODE
2892#endif
2893
2894#ifdef DECLARES
2895HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
2896HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
2897#ifdef CONFIG_NET
2898HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
2899HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
2900HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
2901HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
2902HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
2903HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
2904HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
2905HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
2906HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
2907HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
2908HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
2909HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
2910HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
2911HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
2912HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
2913HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
2914HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2915HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2916HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
2917
2918/* ioctls used by appletalk ddp.c */
2919HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
2920HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
2921HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
2922HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
2923
2924HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
2925HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
2926HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
2927HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
2928HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
2929HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
2930HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
2931HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
2932HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
2933HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
2934HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
2935HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
2936HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
2937HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
2938HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
2939HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
2940HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
2941HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
2942HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
2943HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
2944HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
2945HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
2946/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
2947HANDLE_IOCTL(SIOCRTMSG, ret_einval)
2948HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
2949#endif
2950HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
2951HANDLE_IOCTL(BLKRAGET, w_long)
2952HANDLE_IOCTL(BLKGETSIZE, w_long)
2953HANDLE_IOCTL(0x1260, broken_blkgetsize)
2954HANDLE_IOCTL(BLKFRAGET, w_long)
2955HANDLE_IOCTL(BLKSECTGET, w_long)
2956HANDLE_IOCTL(FBIOGET_FSCREENINFO, fb_ioctl_trans)
2957HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
2958HANDLE_IOCTL(FBIOGETCMAP, fb_ioctl_trans)
2959HANDLE_IOCTL(FBIOPUTCMAP, fb_ioctl_trans)
2960HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
2961HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
2962HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
2963HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
2964HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
2965HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
2966HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
2967HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
2968HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
2969HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
2970HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
2971HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
2972HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
2973HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
2974HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
2975HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
2976HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
2977HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
2978HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
2979HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
2980HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
2981HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
2982HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
2983HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
2984HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
2985HANDLE_IOCTL(LOOP_SET_STATUS, loop_status)
2986HANDLE_IOCTL(LOOP_GET_STATUS, loop_status)
2987#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
2988HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
2989#ifdef CONFIG_VT
2990HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
2991HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
2992HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
2993HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
2994HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
2995#endif
2996HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl)
2997HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl)
2998HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl)
2999HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl)
3000HANDLE_IOCTL(VIDIOCGTUNER32, do_video_ioctl)
3001HANDLE_IOCTL(VIDIOCSTUNER32, do_video_ioctl)
3002HANDLE_IOCTL(VIDIOCGWIN32, do_video_ioctl)
3003HANDLE_IOCTL(VIDIOCSWIN32, do_set_window)
3004HANDLE_IOCTL(VIDIOCGFBUF32, do_video_ioctl)
3005HANDLE_IOCTL(VIDIOCSFBUF32, do_video_ioctl)
3006HANDLE_IOCTL(VIDIOCGFREQ32, do_video_ioctl)
3007HANDLE_IOCTL(VIDIOCSFREQ32, do_video_ioctl)
3008/* One SMB ioctl needs translations. */
3009#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
3010HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
3011HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
3012HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
3013HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
3014HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
3015HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
3016HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
3017HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
3018HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
3019HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
3020HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
3021HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
3022HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
3023HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
3024HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
3025HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
3026HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
3027HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
3028HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
3029HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
3030HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
3031HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
3032HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
3033HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
3034HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
3035HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
3036/* block stuff */
3037HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
3038HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
3039HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
3040/* vfat */
3041HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
3042HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
3043HANDLE_IOCTL(REISERFS_IOC_UNPACK32, reiserfs_ioctl32)
3044/* Raw devices */
3045HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
3046HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
3047/* Serial */
3048HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
3049HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
Christoph Hellwig9c0cbd52005-10-30 15:01:41 -08003050#ifdef TIOCGLTC
3051COMPATIBLE_IOCTL(TIOCGLTC)
3052COMPATIBLE_IOCTL(TIOCSLTC)
3053#endif
Christoph Hellwig7a81e312005-11-08 21:35:07 -08003054#ifdef TIOCSTART
3055/*
3056 * For these two we have defintions in ioctls.h and/or termios.h on
3057 * some architectures but no actual implemention. Some applications
3058 * like bash call them if they are defined in the headers, so we provide
3059 * entries here to avoid syslog message spew.
3060 */
3061COMPATIBLE_IOCTL(TIOCSTART)
3062COMPATIBLE_IOCTL(TIOCSTOP)
3063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064/* Usbdevfs */
3065HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
3066HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
3067HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
Pete Zaitcevc36fc882005-10-17 18:15:54 -07003068COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069/* i2c */
3070HANDLE_IOCTL(I2C_FUNCS, w_long)
3071HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
3072HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
3073/* wireless */
3074HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
3075HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
3076HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
3077HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
3078HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
3079HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
3080HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
3081HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
3082HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
3083HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
3084HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
3085HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
3086HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
3087HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
3088HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
3089
3090#if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
3091HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest)
3092HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2)
3093HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2)
3094HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname)
3095HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname)
3096HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata)
3097HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata)
3098#endif
3099
3100#undef DECLARES
3101#endif