1 /* $Id: ia32_ioctl.c,v 1.44 2004/03/21 22:32:20 ak Exp $
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 *
8 * These routines maintain argument size conversion between 32bit and 64bit
9 * ioctls.
10 */
11
12 #include <linux/config.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.h>
18 #include <linux/ioctl.h>
19 #include <linux/if.h>
20 #include <linux/slab.h>
21 #include <linux/hdreg.h>
22 #include <linux/raid/md.h>
23 #include <linux/kd.h>
24 #include <linux/dirent.h>
25 #include <linux/route.h>
26 #include <linux/in6.h>
27 #include <linux/ipv6_route.h>
28 #include <linux/skbuff.h>
29 #include <linux/netlink.h>
30 #include <linux/vt.h>
31 #include <linux/fs.h>
32 #include <linux/file.h>
33 #include <linux/fd.h>
34 #include <linux/ppp_defs.h>
35 #include <linux/if_ppp.h>
36 #include <linux/if_pppox.h>
37 #include <linux/mtio.h>
38 #include <linux/cdrom.h>
39 #include <linux/loop.h>
40 #include <linux/auto_fs.h>
41 #include <linux/auto_fs4.h>
42 #include <linux/devfs_fs.h>
43 #include <linux/tty.h>
44 #include <linux/vt_kern.h>
45 #include <linux/fb.h>
46 #include <linux/ext2_fs.h>
47 #include <linux/videodev.h>
48 #include <linux/netdevice.h>
49 #include <linux/raw.h>
50 #include <linux/smb_fs.h>
51 #include <linux/blkpg.h>
52 #include <linux/blk.h>
53 #include <linux/elevator.h>
54 #include <linux/rtc.h>
55 #include <linux/pci.h>
56 #include <linux/rtc.h>
57 #include <linux/module.h>
58 #include <linux/serial.h>
59 #include <linux/reiserfs_fs.h>
60 #include <linux/if_tun.h>
61 #include <linux/ctype.h>
62 #include <linux/wireless.h>
63 #include <net/bluetooth/bluetooth.h>
64 #include <net/bluetooth/rfcomm.h>
65 #if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)
66 /* Ugh. This header really is not clean */
67 #define min min
68 #define max max
69 #include <linux/lvm.h>
70 #endif /* LVM */
71
72 #include <scsi/scsi.h>
73 /* Ugly hack. */
74 #undef __KERNEL__
75 #include <scsi/scsi_ioctl.h>
76 #define __KERNEL__
77 #include <scsi/sg.h>
78
79 #include <asm/types.h>
80 #include <asm/ia32.h>
81 #include <asm/uaccess.h>
82 #include <linux/ethtool.h>
83 #include <linux/mii.h>
84 #include <linux/if_bonding.h>
85 #include <linux/watchdog.h>
86
87 #include <asm/module.h>
88 #include <asm/ioctl32.h>
89 #include <linux/soundcard.h>
90 #include <linux/lp.h>
91
92 #include <linux/atm.h>
93 #include <linux/atmarp.h>
94 #include <linux/atmclip.h>
95 #include <linux/atmdev.h>
96 #include <linux/atmioc.h>
97 #include <linux/atmlec.h>
98 #include <linux/atmmpc.h>
99 #include <linux/atmsvc.h>
100 #include <linux/atm_tcp.h>
101 #include <linux/sonet.h>
102 #include <linux/atm_suni.h>
103 #include <linux/mtd/mtd.h>
104
105 #include <net/bluetooth/bluetooth.h>
106 #include <net/bluetooth/hci.h>
107
108 #include <linux/usb.h>
109 #include <linux/usbdevice_fs.h>
110 #include <linux/nbd.h>
111 #include <linux/random.h>
112 #include <linux/filter.h>
113
114 #include <asm/mtrr.h>
115
116 #define A(__x) ((void *)(unsigned long)(__x))
117 #define AA(__x) A(__x)
118
119 /* Allocate memory on the user stack */
compat_alloc_user_space(long len)120 static __inline__ void *compat_alloc_user_space(long len)
121 {
122 struct pt_regs *regs = (void *)current->thread.rsp0 - sizeof(struct pt_regs);
123 return (void *)regs->rsp - len;
124 }
125
126 /* Aiee. Someone does not find a difference between int and long */
127 #define EXT2_IOC32_GETFLAGS _IOR('f', 1, int)
128 #define EXT2_IOC32_SETFLAGS _IOW('f', 2, int)
129 #define EXT2_IOC32_GETVERSION _IOR('v', 1, int)
130 #define EXT2_IOC32_SETVERSION _IOW('v', 2, int)
131
132 extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
133
w_long(unsigned int fd,unsigned int cmd,unsigned long arg)134 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
135 {
136 mm_segment_t old_fs = get_fs();
137 int err;
138 unsigned long val;
139
140 set_fs (KERNEL_DS);
141 err = sys_ioctl(fd, cmd, (unsigned long)&val);
142 set_fs (old_fs);
143 if (!err && put_user(val, (u32 *)arg))
144 return -EFAULT;
145 return err;
146 }
147
rw_long(unsigned int fd,unsigned int cmd,unsigned long arg)148 static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
149 {
150 mm_segment_t old_fs = get_fs();
151 int err;
152 unsigned long val;
153
154 if(get_user(val, (u32 *)arg))
155 return -EFAULT;
156 set_fs (KERNEL_DS);
157 err = sys_ioctl(fd, cmd, (unsigned long)&val);
158 set_fs (old_fs);
159 if (!err && put_user(val, (u32 *)arg))
160 return -EFAULT;
161 return err;
162 }
163
do_ext2_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)164 static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
165 {
166 /* These are just misnamed, they actually get/put from/to user an int */
167 switch (cmd) {
168 case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
169 case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
170 case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
171 case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
172 }
173 return sys_ioctl(fd, cmd, arg);
174 }
175
176 struct video_tuner32 {
177 s32 tuner;
178 u8 name[32];
179 u32 rangelow, rangehigh;
180 u32 flags;
181 u16 mode, signal;
182 };
183
get_video_tuner32(struct video_tuner * kp,struct video_tuner32 * up)184 static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 *up)
185 {
186 int i;
187
188 if(get_user(kp->tuner, &up->tuner))
189 return -EFAULT;
190 for(i = 0; i < 32; i++)
191 __get_user(kp->name[i], &up->name[i]);
192 __get_user(kp->rangelow, &up->rangelow);
193 __get_user(kp->rangehigh, &up->rangehigh);
194 __get_user(kp->flags, &up->flags);
195 __get_user(kp->mode, &up->mode);
196 __get_user(kp->signal, &up->signal);
197 return 0;
198 }
199
put_video_tuner32(struct video_tuner * kp,struct video_tuner32 * up)200 static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 *up)
201 {
202 int i;
203
204 if(put_user(kp->tuner, &up->tuner))
205 return -EFAULT;
206 for(i = 0; i < 32; i++)
207 __put_user(kp->name[i], &up->name[i]);
208 __put_user(kp->rangelow, &up->rangelow);
209 __put_user(kp->rangehigh, &up->rangehigh);
210 __put_user(kp->flags, &up->flags);
211 __put_user(kp->mode, &up->mode);
212 __put_user(kp->signal, &up->signal);
213 return 0;
214 }
215
216 struct video_buffer32 {
217 /* void * */ u32 base;
218 s32 height, width, depth, bytesperline;
219 };
220
get_video_buffer32(struct video_buffer * kp,struct video_buffer32 * up)221 static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 *up)
222 {
223 u32 tmp;
224
225 if(get_user(tmp, &up->base))
226 return -EFAULT;
227 kp->base = (void *) ((unsigned long)tmp);
228 __get_user(kp->height, &up->height);
229 __get_user(kp->width, &up->width);
230 __get_user(kp->depth, &up->depth);
231 __get_user(kp->bytesperline, &up->bytesperline);
232 return 0;
233 }
234
put_video_buffer32(struct video_buffer * kp,struct video_buffer32 * up)235 static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 *up)
236 {
237 u32 tmp = (u32)((unsigned long)kp->base);
238
239 if(put_user(tmp, &up->base))
240 return -EFAULT;
241 __put_user(kp->height, &up->height);
242 __put_user(kp->width, &up->width);
243 __put_user(kp->depth, &up->depth);
244 __put_user(kp->bytesperline, &up->bytesperline);
245 return 0;
246 }
247
248 struct video_clip32 {
249 s32 x, y, width, height;
250 /* struct video_clip32 * */ u32 next;
251 };
252
253 struct video_window32 {
254 u32 x, y, width, height, chromakey, flags;
255 /* struct video_clip32 * */ u32 clips;
256 s32 clipcount;
257 };
258
free_kvideo_clips(struct video_window * kp)259 static void free_kvideo_clips(struct video_window *kp)
260 {
261 struct video_clip *cp;
262
263 cp = kp->clips;
264 if(cp != NULL)
265 kfree(cp);
266 }
267
get_video_window32(struct video_window * kp,struct video_window32 * up)268 static int get_video_window32(struct video_window *kp, struct video_window32 *up)
269 {
270 struct video_clip32 *ucp;
271 struct video_clip *kcp;
272 int nclips, err, i;
273 u32 tmp;
274
275 if(get_user(kp->x, &up->x))
276 return -EFAULT;
277 __get_user(kp->y, &up->y);
278 __get_user(kp->width, &up->width);
279 __get_user(kp->height, &up->height);
280 __get_user(kp->chromakey, &up->chromakey);
281 __get_user(kp->flags, &up->flags);
282 __get_user(kp->clipcount, &up->clipcount);
283 __get_user(tmp, &up->clips);
284 ucp = (struct video_clip32 *)A(tmp);
285 kp->clips = NULL;
286
287 nclips = kp->clipcount;
288 if(nclips == 0)
289 return 0;
290
291 if(ucp == 0)
292 return -EINVAL;
293
294 /* Peculiar interface... */
295 if(nclips < 0)
296 nclips = VIDEO_CLIPMAP_SIZE;
297
298 kcp = kmalloc(nclips * sizeof(struct video_clip), GFP_KERNEL);
299 err = -ENOMEM;
300 if(kcp == NULL)
301 goto cleanup_and_err;
302
303 kp->clips = kcp;
304 for(i = 0; i < nclips; i++) {
305 __get_user(kcp[i].x, &ucp[i].x);
306 __get_user(kcp[i].y, &ucp[i].y);
307 __get_user(kcp[i].width, &ucp[i].width);
308 __get_user(kcp[i].height, &ucp[i].height);
309 kcp[nclips].next = NULL;
310 }
311
312 return 0;
313
314 cleanup_and_err:
315 free_kvideo_clips(kp);
316 return err;
317 }
318
319 /* You get back everything except the clips... */
put_video_window32(struct video_window * kp,struct video_window32 * up)320 static int put_video_window32(struct video_window *kp, struct video_window32 *up)
321 {
322 if(put_user(kp->x, &up->x))
323 return -EFAULT;
324 __put_user(kp->y, &up->y);
325 __put_user(kp->width, &up->width);
326 __put_user(kp->height, &up->height);
327 __put_user(kp->chromakey, &up->chromakey);
328 __put_user(kp->flags, &up->flags);
329 __put_user(kp->clipcount, &up->clipcount);
330 return 0;
331 }
332
333 #define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
334 #define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
335 #define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
336 #define VIDIOCSWIN32 _IOW('v',10, struct video_window32)
337 #define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32)
338 #define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
339 #define VIDIOCGFREQ32 _IOR('v',14, u32)
340 #define VIDIOCSFREQ32 _IOW('v',15, u32)
341
do_video_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)342 static int do_video_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
343 {
344 union {
345 struct video_tuner vt;
346 struct video_buffer vb;
347 struct video_window vw;
348 unsigned long vx;
349 } karg;
350 mm_segment_t old_fs = get_fs();
351 void *up = (void *)arg;
352 int err = 0;
353
354 /* First, convert the command. */
355 switch(cmd) {
356 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
357 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
358 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
359 case VIDIOCSWIN32: cmd = VIDIOCSWIN; break;
360 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
361 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
362 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
363 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
364 };
365
366 switch(cmd) {
367 case VIDIOCSTUNER:
368 case VIDIOCGTUNER:
369 err = get_video_tuner32(&karg.vt, up);
370 break;
371
372 case VIDIOCSWIN:
373 err = get_video_window32(&karg.vw, up);
374 break;
375
376 case VIDIOCSFBUF:
377 err = get_video_buffer32(&karg.vb, up);
378 break;
379
380 case VIDIOCSFREQ:
381 err = get_user(karg.vx, (u32 *)up);
382 break;
383 };
384 if(err)
385 goto out;
386
387 set_fs(KERNEL_DS);
388 err = sys_ioctl(fd, cmd, (unsigned long)&karg);
389 set_fs(old_fs);
390
391 if(cmd == VIDIOCSWIN)
392 free_kvideo_clips(&karg.vw);
393
394 if(err == 0) {
395 switch(cmd) {
396 case VIDIOCGTUNER:
397 err = put_video_tuner32(&karg.vt, up);
398 break;
399
400 case VIDIOCGWIN:
401 err = put_video_window32(&karg.vw, up);
402 break;
403
404 case VIDIOCGFBUF:
405 err = put_video_buffer32(&karg.vb, up);
406 break;
407
408 case VIDIOCGFREQ:
409 err = put_user(((u32)karg.vx), (u32 *)up);
410 break;
411 };
412 }
413 out:
414 return err;
415 }
416
417 struct timeval32 {
418 int tv_sec;
419 int tv_usec;
420 };
421
do_siocgstamp(unsigned int fd,unsigned int cmd,unsigned long arg)422 static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
423 {
424 struct timeval32 *up = (struct timeval32 *)arg;
425 struct timeval ktv;
426 mm_segment_t old_fs = get_fs();
427 int err;
428
429 set_fs(KERNEL_DS);
430 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
431 set_fs(old_fs);
432 if(!err) {
433 err = put_user(ktv.tv_sec, &up->tv_sec);
434 err |= __put_user(ktv.tv_usec, &up->tv_usec);
435 }
436 return err;
437 }
438
439 struct ifmap32 {
440 u32 mem_start;
441 u32 mem_end;
442 unsigned short base_addr;
443 unsigned char irq;
444 unsigned char dma;
445 unsigned char port;
446 };
447
448 struct ifreq32 {
449 #define IFHWADDRLEN 6
450 #define IFNAMSIZ 16
451 union {
452 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
453 } ifr_ifrn;
454 union {
455 struct sockaddr ifru_addr;
456 struct sockaddr ifru_dstaddr;
457 struct sockaddr ifru_broadaddr;
458 struct sockaddr ifru_netmask;
459 struct sockaddr ifru_hwaddr;
460 short ifru_flags;
461 int ifru_ivalue;
462 int ifru_mtu;
463 struct ifmap32 ifru_map;
464 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
465 char ifru_newname[IFNAMSIZ];
466 __kernel_caddr_t32 ifru_data;
467 } ifr_ifru;
468 };
469
470 struct ifconf32 {
471 int ifc_len; /* size of buffer */
472 __kernel_caddr_t32 ifcbuf;
473 };
474
475 #ifdef CONFIG_NET
dev_ifname32(unsigned int fd,unsigned int cmd,unsigned long arg)476 static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
477 {
478 struct net_device *dev;
479 struct ifreq32 ifr32;
480 int err;
481
482 if (copy_from_user(&ifr32, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
483 return -EFAULT;
484
485 dev = dev_get_by_index(ifr32.ifr_ifindex);
486 if (!dev)
487 return -ENODEV;
488
489 strncpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name)-1);
490 ifr32.ifr_name[sizeof(ifr32.ifr_name)-1] = 0;
491 dev_put(dev);
492
493 err = copy_to_user((struct ifreq32 *)arg, &ifr32, sizeof(struct ifreq32));
494 return (err ? -EFAULT : 0);
495 }
496 #endif
497
dev_ifconf(unsigned int fd,unsigned int cmd,unsigned long arg)498 static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
499 {
500 struct ifconf32 ifc32;
501 struct ifconf ifc;
502 struct ifreq32 *ifr32;
503 struct ifreq *ifr;
504 mm_segment_t old_fs;
505 unsigned int i, j;
506 int err;
507
508 if (copy_from_user(&ifc32, (struct ifconf32 *)arg, sizeof(struct ifconf32)))
509 return -EFAULT;
510
511 if(ifc32.ifcbuf == 0) {
512 ifc32.ifc_len = 0;
513 ifc.ifc_len = 0;
514 ifc.ifc_buf = NULL;
515 } else {
516 ifc.ifc_len = ((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
517 sizeof (struct ifreq);
518 ifc.ifc_buf = kmalloc (ifc.ifc_len, GFP_KERNEL);
519 if (!ifc.ifc_buf)
520 return -ENOMEM;
521 }
522 ifr = ifc.ifc_req;
523 ifr32 = (struct ifreq32 *)A(ifc32.ifcbuf);
524 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
525 if (copy_from_user(ifr, ifr32, sizeof (struct ifreq32))) {
526 kfree (ifc.ifc_buf);
527 return -EFAULT;
528 }
529 ifr++;
530 ifr32++;
531 }
532 old_fs = get_fs(); set_fs (KERNEL_DS);
533 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)&ifc);
534 set_fs (old_fs);
535 if (!err) {
536 ifr = ifc.ifc_req;
537 ifr32 = (struct ifreq32 *)A(ifc32.ifcbuf);
538 for (i = 0, j = 0; i < ifc32.ifc_len && j < ifc.ifc_len;
539 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
540 int k = copy_to_user(ifr32, ifr, sizeof (struct ifreq32));
541 ifr32++;
542 ifr++;
543 if (k) {
544 err = -EFAULT;
545 break;
546 }
547
548 }
549 if (!err) {
550 if (ifc32.ifcbuf == 0) {
551 /* Translate from 64-bit structure multiple to
552 * a 32-bit one.
553 */
554 i = ifc.ifc_len;
555 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
556 ifc32.ifc_len = i;
557 } else {
558 if (i <= ifc32.ifc_len)
559 ifc32.ifc_len = i;
560 else
561 ifc32.ifc_len = i - sizeof (struct ifreq32);
562 }
563 if (copy_to_user((struct ifconf32 *)arg, &ifc32, sizeof(struct ifconf32)))
564 err = -EFAULT;
565 }
566 }
567 if(ifc.ifc_buf != NULL)
568 kfree (ifc.ifc_buf);
569 return err;
570 }
571
ethtool_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)572 static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
573 {
574 struct ifreq ifr;
575 mm_segment_t old_fs;
576 int err, len;
577 u32 data, ethcmd;
578
579 if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
580 return -EFAULT;
581 ifr.ifr_data = (__kernel_caddr_t)get_free_page(GFP_KERNEL);
582 if (!ifr.ifr_data)
583 return -EAGAIN;
584
585 __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
586
587 if (get_user(ethcmd, (u32 *)A(data))) {
588 err = -EFAULT;
589 goto out;
590 }
591 switch (ethcmd) {
592 case ETHTOOL_GDRVINFO: len = sizeof(struct ethtool_drvinfo); break;
593 case ETHTOOL_GMSGLVL:
594 case ETHTOOL_SMSGLVL:
595 case ETHTOOL_GLINK:
596 case ETHTOOL_NWAY_RST: len = sizeof(struct ethtool_value); break;
597 case ETHTOOL_GREGS: {
598 struct ethtool_regs *regaddr = (struct ethtool_regs *)A(data);
599 /* darned variable size arguments */
600 if (get_user(len, (u32 *)®addr->len)) {
601 err = -EFAULT;
602 goto out;
603 }
604 if (len > PAGE_SIZE - sizeof(struct ethtool_regs)) {
605 err = -EINVAL;
606 goto out;
607 }
608 len += sizeof(struct ethtool_regs);
609 break;
610 }
611 case ETHTOOL_GSET:
612 case ETHTOOL_SSET: len = sizeof(struct ethtool_cmd); break;
613 default:
614 err = -EOPNOTSUPP;
615 goto out;
616 }
617
618 if (copy_from_user(ifr.ifr_data, (char *)A(data), len)) {
619 err = -EFAULT;
620 goto out;
621 }
622
623 old_fs = get_fs();
624 set_fs (KERNEL_DS);
625 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
626 set_fs (old_fs);
627 if (!err) {
628 u32 data;
629
630 __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
631 len = copy_to_user((char *)A(data), ifr.ifr_data, len);
632 if (len)
633 err = -EFAULT;
634 }
635
636 out:
637 free_page((unsigned long)ifr.ifr_data);
638 return err;
639 }
640
641
bond_ioctl(unsigned long fd,unsigned int cmd,unsigned long arg)642 static int bond_ioctl(unsigned long fd, unsigned int cmd, unsigned long arg)
643 {
644 struct ifreq ifr;
645 mm_segment_t old_fs;
646 int err, len;
647 u32 data;
648
649 if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
650 return -EFAULT;
651 ifr.ifr_data = (__kernel_caddr_t)get_free_page(GFP_KERNEL);
652 if (!ifr.ifr_data)
653 return -EAGAIN;
654
655 switch (cmd) {
656 case SIOCBONDENSLAVE:
657 case SIOCBONDRELEASE:
658 case SIOCBONDSETHWADDR:
659 case SIOCBONDCHANGEACTIVE:
660 len = IFNAMSIZ * sizeof(char);
661 break;
662 case SIOCBONDSLAVEINFOQUERY:
663 len = sizeof(struct ifslave);
664 break;
665 case SIOCBONDINFOQUERY:
666 len = sizeof(struct ifbond);
667 break;
668 default:
669 err = -EINVAL;
670 goto out;
671 };
672
673 __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
674 if (copy_from_user(ifr.ifr_data, (char *)A(data), len)) {
675 err = -EFAULT;
676 goto out;
677 }
678
679 old_fs = get_fs();
680 set_fs (KERNEL_DS);
681 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
682 set_fs (old_fs);
683 if (!err) {
684 len = copy_to_user((char *)A(data), ifr.ifr_data, len);
685 if (len)
686 err = -EFAULT;
687 }
688
689 out:
690 free_page((unsigned long)ifr.ifr_data);
691 return err;
692 }
693
alloc_user_space(long len)694 static __inline__ void *alloc_user_space(long len)
695 {
696 struct pt_regs *regs = (void *)current->thread.rsp0 - sizeof(struct pt_regs);
697 return (void *)regs->rsp - len;
698 }
699
siocdevprivate_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)700 static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
701 {
702 struct ifreq *u_ifreq64;
703 struct ifreq32 *u_ifreq32 = (struct ifreq32 *) arg;
704 char tmp_buf[IFNAMSIZ];
705 void *data64;
706 u32 data32;
707
708 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
709 IFNAMSIZ))
710 return -EFAULT;
711 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
712 return -EFAULT;
713 data64 = (void *) A(data32);
714
715 u_ifreq64 = alloc_user_space(sizeof(*u_ifreq64));
716
717 /* Don't check these user accesses, just let that get trapped
718 * in the ioctl handler instead.
719 */
720 copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], IFNAMSIZ);
721 __put_user(data64, &u_ifreq64->ifr_ifru.ifru_data);
722
723 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
724 }
725
dev_ifsioc(unsigned int fd,unsigned int cmd,unsigned long arg)726 static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
727 {
728 struct ifreq ifr;
729 mm_segment_t old_fs;
730 int err;
731
732 switch (cmd) {
733 case SIOCSIFMAP:
734 err = copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(ifr.ifr_name));
735 err |= __get_user(ifr.ifr_map.mem_start, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_start));
736 err |= __get_user(ifr.ifr_map.mem_end, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_end));
737 err |= __get_user(ifr.ifr_map.base_addr, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.base_addr));
738 err |= __get_user(ifr.ifr_map.irq, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.irq));
739 err |= __get_user(ifr.ifr_map.dma, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.dma));
740 err |= __get_user(ifr.ifr_map.port, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.port));
741 if (err)
742 return -EFAULT;
743 break;
744 default:
745 if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
746 return -EFAULT;
747 break;
748 }
749 old_fs = get_fs();
750 set_fs (KERNEL_DS);
751 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
752 set_fs (old_fs);
753 if (!err) {
754 switch (cmd) {
755 case SIOCGIFFLAGS:
756 case SIOCGIFMETRIC:
757 case SIOCGIFMTU:
758 case SIOCGIFMEM:
759 case SIOCGIFHWADDR:
760 case SIOCGIFINDEX:
761 case SIOCGIFADDR:
762 case SIOCGIFBRDADDR:
763 case SIOCGIFDSTADDR:
764 case SIOCGIFNETMASK:
765 case SIOCGIFTXQLEN:
766 if (copy_to_user((struct ifreq32 *)arg, &ifr, sizeof(struct ifreq32)))
767 return -EFAULT;
768 break;
769 case SIOCGIFMAP:
770 err = copy_to_user((struct ifreq32 *)arg, &ifr, sizeof(ifr.ifr_name));
771 err |= __put_user(ifr.ifr_map.mem_start, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_start));
772 err |= __put_user(ifr.ifr_map.mem_end, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_end));
773 err |= __put_user(ifr.ifr_map.base_addr, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.base_addr));
774 err |= __put_user(ifr.ifr_map.irq, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.irq));
775 err |= __put_user(ifr.ifr_map.dma, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.dma));
776 err |= __put_user(ifr.ifr_map.port, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.port));
777 if (err)
778 err = -EFAULT;
779 break;
780 }
781 }
782 return err;
783 }
784
785 struct rtentry32 {
786 u32 rt_pad1;
787 struct sockaddr rt_dst; /* target address */
788 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
789 struct sockaddr rt_genmask; /* target network mask (IP) */
790 unsigned short rt_flags;
791 short rt_pad2;
792 u32 rt_pad3;
793 unsigned char rt_tos;
794 unsigned char rt_class;
795 short rt_pad4;
796 short rt_metric; /* +1 for binary compatibility! */
797 /* char * */ u32 rt_dev; /* forcing the device at add */
798 u32 rt_mtu; /* per route MTU/Window */
799 u32 rt_window; /* Window clamping */
800 unsigned short rt_irtt; /* Initial RTT */
801
802 };
803
804 struct in6_rtmsg32 {
805 struct in6_addr rtmsg_dst;
806 struct in6_addr rtmsg_src;
807 struct in6_addr rtmsg_gateway;
808 u32 rtmsg_type;
809 u16 rtmsg_dst_len;
810 u16 rtmsg_src_len;
811 u32 rtmsg_metric;
812 u32 rtmsg_info;
813 u32 rtmsg_flags;
814 s32 rtmsg_ifindex;
815 };
816
817 extern struct socket *sockfd_lookup(int fd, int *err);
818
sockfd_put(struct socket * sock)819 extern __inline__ void sockfd_put(struct socket *sock)
820 {
821 fput(sock->file);
822 }
823
routing_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)824 static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
825 {
826 int ret;
827 void *r = NULL;
828 struct in6_rtmsg r6;
829 struct rtentry r4;
830 char devname[16];
831 u32 rtdev;
832 mm_segment_t old_fs = get_fs();
833
834 struct socket *mysock = sockfd_lookup(fd, &ret);
835
836 if (mysock && mysock->sk && mysock->sk->family == AF_INET6) { /* ipv6 */
837 ret = copy_from_user (&r6.rtmsg_dst, &(((struct in6_rtmsg32 *)arg)->rtmsg_dst),
838 3 * sizeof(struct in6_addr));
839 ret |= __get_user (r6.rtmsg_type, &(((struct in6_rtmsg32 *)arg)->rtmsg_type));
840 ret |= __get_user (r6.rtmsg_dst_len, &(((struct in6_rtmsg32 *)arg)->rtmsg_dst_len));
841 ret |= __get_user (r6.rtmsg_src_len, &(((struct in6_rtmsg32 *)arg)->rtmsg_src_len));
842 ret |= __get_user (r6.rtmsg_metric, &(((struct in6_rtmsg32 *)arg)->rtmsg_metric));
843 ret |= __get_user (r6.rtmsg_info, &(((struct in6_rtmsg32 *)arg)->rtmsg_info));
844 ret |= __get_user (r6.rtmsg_flags, &(((struct in6_rtmsg32 *)arg)->rtmsg_flags));
845 ret |= __get_user (r6.rtmsg_ifindex, &(((struct in6_rtmsg32 *)arg)->rtmsg_ifindex));
846
847 r = (void *) &r6;
848 } else { /* ipv4 */
849 ret = copy_from_user (&r4.rt_dst, &(((struct rtentry32 *)arg)->rt_dst), 3 * sizeof(struct sockaddr));
850 ret |= __get_user (r4.rt_flags, &(((struct rtentry32 *)arg)->rt_flags));
851 ret |= __get_user (r4.rt_metric, &(((struct rtentry32 *)arg)->rt_metric));
852 ret |= __get_user (r4.rt_mtu, &(((struct rtentry32 *)arg)->rt_mtu));
853 ret |= __get_user (r4.rt_window, &(((struct rtentry32 *)arg)->rt_window));
854 ret |= __get_user (r4.rt_irtt, &(((struct rtentry32 *)arg)->rt_irtt));
855 ret |= __get_user (rtdev, &(((struct rtentry32 *)arg)->rt_dev));
856 if (rtdev) {
857 ret |= copy_from_user (devname, (char *)A(rtdev), 15);
858 r4.rt_dev = devname; devname[15] = 0;
859 } else
860 r4.rt_dev = 0;
861
862 r = (void *) &r4;
863 }
864
865 if (ret) {
866 ret = -EFAULT;
867 goto out;
868 }
869
870 set_fs (KERNEL_DS);
871 ret = sys_ioctl (fd, cmd, (long) r);
872 set_fs (old_fs);
873 out:
874 if (mysock)
875 sockfd_put(mysock);
876
877 return ret;
878 }
879
880 struct hd_geometry32 {
881 unsigned char heads;
882 unsigned char sectors;
883 unsigned short cylinders;
884 u32 start;
885 };
886
hdio_getgeo(unsigned int fd,unsigned int cmd,unsigned long arg)887 static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
888 {
889 mm_segment_t old_fs = get_fs();
890 struct hd_geometry geo;
891 int err;
892
893 set_fs (KERNEL_DS);
894 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
895 set_fs (old_fs);
896 if (!err) {
897 err = copy_to_user ((struct hd_geometry32 *)arg, &geo, 4);
898 err |= __put_user (geo.start, &(((struct hd_geometry32 *)arg)->start));
899 }
900 return err ? -EFAULT : 0;
901 }
902
903 struct fb_fix_screeninfo32 {
904 char id[16];
905 __kernel_caddr_t32 smem_start;
906 __u32 smem_len;
907 __u32 type;
908 __u32 type_aux;
909 __u32 visual;
910 __u16 xpanstep;
911 __u16 ypanstep;
912 __u16 ywrapstep;
913 __u32 line_length;
914 __kernel_caddr_t32 mmio_start;
915 __u32 mmio_len;
916 __u32 accel;
917 __u16 reserved[3];
918 };
919
920 struct fb_cmap32 {
921 __u32 start;
922 __u32 len;
923 __kernel_caddr_t32 red;
924 __kernel_caddr_t32 green;
925 __kernel_caddr_t32 blue;
926 __kernel_caddr_t32 transp;
927 };
928
fb_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)929 static int fb_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
930 {
931 mm_segment_t old_fs = get_fs();
932 u32 red = 0, green = 0, blue = 0, transp = 0;
933 struct fb_fix_screeninfo fix;
934 struct fb_cmap cmap;
935 void *karg;
936 int err = 0;
937
938 memset(&cmap, 0, sizeof(cmap));
939 switch (cmd) {
940 case FBIOGET_FSCREENINFO:
941 karg = &fix;
942 break;
943 case FBIOGETCMAP:
944 case FBIOPUTCMAP:
945 karg = &cmap;
946 err = __get_user(cmap.start, &((struct fb_cmap32 *)arg)->start);
947 err |= __get_user(cmap.len, &((struct fb_cmap32 *)arg)->len);
948 err |= __get_user(red, &((struct fb_cmap32 *)arg)->red);
949 err |= __get_user(green, &((struct fb_cmap32 *)arg)->green);
950 err |= __get_user(blue, &((struct fb_cmap32 *)arg)->blue);
951 err |= __get_user(transp, &((struct fb_cmap32 *)arg)->transp);
952 if (err) {
953 err = -EFAULT;
954 goto out;
955 }
956 if (cmap.len > PAGE_SIZE/sizeof(u16)) {
957 err = -EINVAL;
958 goto out;
959 }
960 err = -ENOMEM;
961 cmap.red = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
962 if (!cmap.red)
963 goto out;
964 cmap.green = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
965 if (!cmap.green)
966 goto out;
967 cmap.blue = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
968 if (!cmap.blue)
969 goto out;
970 if (transp) {
971 cmap.transp = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
972 if (!cmap.transp)
973 goto out;
974 }
975
976 if (cmd == FBIOGETCMAP)
977 break;
978
979 err = __copy_from_user(cmap.red, (char *)A(red), cmap.len * sizeof(__u16));
980 err |= __copy_from_user(cmap.green, (char *)A(green), cmap.len * sizeof(__u16));
981 err |= __copy_from_user(cmap.blue, (char *)A(blue), cmap.len * sizeof(__u16));
982 if (cmap.transp) err |= __copy_from_user(cmap.transp, (char *)A(transp), cmap.len * sizeof(__u16));
983 if (err) {
984 err = -EFAULT;
985 goto out;
986 }
987 break;
988 default:
989 do {
990 static int count;
991 if (++count <= 20)
992 printk("%s: Unknown fb ioctl cmd fd(%d) "
993 "cmd(%08x) arg(%08lx)\n",
994 __FUNCTION__, fd, cmd, arg);
995 } while(0);
996 return -ENOSYS;
997 }
998 set_fs(KERNEL_DS);
999 err = sys_ioctl(fd, cmd, (unsigned long)karg);
1000 set_fs(old_fs);
1001 if (err)
1002 goto out;
1003 switch (cmd) {
1004 case FBIOGET_FSCREENINFO:
1005 err = __copy_to_user((char *)((struct fb_fix_screeninfo32 *)arg)->id, (char *)fix.id, sizeof(fix.id));
1006 err |= __put_user((__u32)(unsigned long)fix.smem_start, &((struct fb_fix_screeninfo32 *)arg)->smem_start);
1007 err |= __put_user(fix.smem_len, &((struct fb_fix_screeninfo32 *)arg)->smem_len);
1008 err |= __put_user(fix.type, &((struct fb_fix_screeninfo32 *)arg)->type);
1009 err |= __put_user(fix.type_aux, &((struct fb_fix_screeninfo32 *)arg)->type_aux);
1010 err |= __put_user(fix.visual, &((struct fb_fix_screeninfo32 *)arg)->visual);
1011 err |= __put_user(fix.xpanstep, &((struct fb_fix_screeninfo32 *)arg)->xpanstep);
1012 err |= __put_user(fix.ypanstep, &((struct fb_fix_screeninfo32 *)arg)->ypanstep);
1013 err |= __put_user(fix.ywrapstep, &((struct fb_fix_screeninfo32 *)arg)->ywrapstep);
1014 err |= __put_user(fix.line_length, &((struct fb_fix_screeninfo32 *)arg)->line_length);
1015 err |= __put_user((__u32)(unsigned long)fix.mmio_start, &((struct fb_fix_screeninfo32 *)arg)->mmio_start);
1016 err |= __put_user(fix.mmio_len, &((struct fb_fix_screeninfo32 *)arg)->mmio_len);
1017 err |= __put_user(fix.accel, &((struct fb_fix_screeninfo32 *)arg)->accel);
1018 err |= __copy_to_user((char *)((struct fb_fix_screeninfo32 *)arg)->reserved, (char *)fix.reserved, sizeof(fix.reserved));
1019 break;
1020 case FBIOGETCMAP:
1021 err = __copy_to_user((char *)A(red), cmap.red, cmap.len * sizeof(__u16));
1022 err |= __copy_to_user((char *)A(green), cmap.blue, cmap.len * sizeof(__u16));
1023 err |= __copy_to_user((char *)A(blue), cmap.blue, cmap.len * sizeof(__u16));
1024 if (cmap.transp)
1025 err |= __copy_to_user((char *)A(transp), cmap.transp, cmap.len * sizeof(__u16));
1026 break;
1027 case FBIOPUTCMAP:
1028 break;
1029 }
1030 if (err)
1031 err = -EFAULT;
1032
1033 out: if (cmap.red) kfree(cmap.red);
1034 if (cmap.green) kfree(cmap.green);
1035 if (cmap.blue) kfree(cmap.blue);
1036 if (cmap.transp) kfree(cmap.transp);
1037 return err;
1038 }
1039
hdio_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1040 static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1041 {
1042 mm_segment_t old_fs = get_fs();
1043 unsigned long kval;
1044 unsigned int *uvp;
1045 int error;
1046
1047 set_fs(KERNEL_DS);
1048 error = sys_ioctl(fd, cmd, (long)&kval);
1049 set_fs(old_fs);
1050
1051 if(error == 0) {
1052 uvp = (unsigned int *)arg;
1053 if(put_user(kval, uvp))
1054 error = -EFAULT;
1055 }
1056 return error;
1057 }
1058
1059 struct floppy_struct32 {
1060 unsigned int size;
1061 unsigned int sect;
1062 unsigned int head;
1063 unsigned int track;
1064 unsigned int stretch;
1065 unsigned char gap;
1066 unsigned char rate;
1067 unsigned char spec1;
1068 unsigned char fmt_gap;
1069 const __kernel_caddr_t32 name;
1070 };
1071
1072 struct floppy_drive_params32 {
1073 char cmos;
1074 u32 max_dtr;
1075 u32 hlt;
1076 u32 hut;
1077 u32 srt;
1078 u32 spinup;
1079 u32 spindown;
1080 unsigned char spindown_offset;
1081 unsigned char select_delay;
1082 unsigned char rps;
1083 unsigned char tracks;
1084 u32 timeout;
1085 unsigned char interleave_sect;
1086 struct floppy_max_errors max_errors;
1087 char flags;
1088 char read_track;
1089 short autodetect[8];
1090 int checkfreq;
1091 int native_format;
1092 };
1093
1094 struct floppy_drive_struct32 {
1095 signed char flags;
1096 u32 spinup_date;
1097 u32 select_date;
1098 u32 first_read_date;
1099 short probed_format;
1100 short track;
1101 short maxblock;
1102 short maxtrack;
1103 int generation;
1104 int keep_data;
1105 int fd_ref;
1106 int fd_device;
1107 int last_checked;
1108 __kernel_caddr_t32 dmabuf;
1109 int bufblocks;
1110 };
1111
1112 struct floppy_fdc_state32 {
1113 int spec1;
1114 int spec2;
1115 int dtr;
1116 unsigned char version;
1117 unsigned char dor;
1118 u32 address;
1119 unsigned int rawcmd:2;
1120 unsigned int reset:1;
1121 unsigned int need_configure:1;
1122 unsigned int perp_mode:2;
1123 unsigned int has_fifo:1;
1124 unsigned int driver_version;
1125 unsigned char track[4];
1126 };
1127
1128 struct floppy_write_errors32 {
1129 unsigned int write_errors;
1130 u32 first_error_sector;
1131 int first_error_generation;
1132 u32 last_error_sector;
1133 int last_error_generation;
1134 unsigned int badness;
1135 };
1136
1137 #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1138 #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1139 #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1140 #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1141 #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1142 #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1143 #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1144 #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1145 #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
1146
1147 static struct {
1148 unsigned int cmd32;
1149 unsigned int cmd;
1150 } fd_ioctl_trans_table[] = {
1151 { FDSETPRM32, FDSETPRM },
1152 { FDDEFPRM32, FDDEFPRM },
1153 { FDGETPRM32, FDGETPRM },
1154 { FDSETDRVPRM32, FDSETDRVPRM },
1155 { FDGETDRVPRM32, FDGETDRVPRM },
1156 { FDGETDRVSTAT32, FDGETDRVSTAT },
1157 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1158 { FDGETFDCSTAT32, FDGETFDCSTAT },
1159 { FDWERRORGET32, FDWERRORGET }
1160 };
1161
1162 #define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
1163
fd_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1164 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1165 {
1166 mm_segment_t old_fs = get_fs();
1167 void *karg = NULL;
1168 unsigned int kcmd = 0;
1169 int i, err;
1170
1171 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1172 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1173 kcmd = fd_ioctl_trans_table[i].cmd;
1174 break;
1175 }
1176 if (!kcmd)
1177 return -EINVAL;
1178
1179 switch (cmd) {
1180 case FDSETPRM32:
1181 case FDDEFPRM32:
1182 case FDGETPRM32:
1183 {
1184 u32 name;
1185 struct floppy_struct *f;
1186
1187 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1188 if (!karg)
1189 return -ENOMEM;
1190 if (cmd == FDGETPRM32)
1191 break;
1192 err = __get_user(f->size, &((struct floppy_struct32 *)arg)->size);
1193 err |= __get_user(f->sect, &((struct floppy_struct32 *)arg)->sect);
1194 err |= __get_user(f->head, &((struct floppy_struct32 *)arg)->head);
1195 err |= __get_user(f->track, &((struct floppy_struct32 *)arg)->track);
1196 err |= __get_user(f->stretch, &((struct floppy_struct32 *)arg)->stretch);
1197 err |= __get_user(f->gap, &((struct floppy_struct32 *)arg)->gap);
1198 err |= __get_user(f->rate, &((struct floppy_struct32 *)arg)->rate);
1199 err |= __get_user(f->spec1, &((struct floppy_struct32 *)arg)->spec1);
1200 err |= __get_user(f->fmt_gap, &((struct floppy_struct32 *)arg)->fmt_gap);
1201 err |= __get_user(name, &((struct floppy_struct32 *)arg)->name);
1202 f->name = (void*)(u64)name;
1203 if (err) {
1204 err = -EFAULT;
1205 goto out;
1206 }
1207 break;
1208 }
1209 case FDSETDRVPRM32:
1210 case FDGETDRVPRM32:
1211 {
1212 struct floppy_drive_params *f;
1213
1214 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1215 if (!karg)
1216 return -ENOMEM;
1217 if (cmd == FDGETDRVPRM32)
1218 break;
1219 err = __get_user(f->cmos, &((struct floppy_drive_params32 *)arg)->cmos);
1220 err |= __get_user(f->max_dtr, &((struct floppy_drive_params32 *)arg)->max_dtr);
1221 err |= __get_user(f->hlt, &((struct floppy_drive_params32 *)arg)->hlt);
1222 err |= __get_user(f->hut, &((struct floppy_drive_params32 *)arg)->hut);
1223 err |= __get_user(f->srt, &((struct floppy_drive_params32 *)arg)->srt);
1224 err |= __get_user(f->spinup, &((struct floppy_drive_params32 *)arg)->spinup);
1225 err |= __get_user(f->spindown, &((struct floppy_drive_params32 *)arg)->spindown);
1226 err |= __get_user(f->spindown_offset, &((struct floppy_drive_params32 *)arg)->spindown_offset);
1227 err |= __get_user(f->select_delay, &((struct floppy_drive_params32 *)arg)->select_delay);
1228 err |= __get_user(f->rps, &((struct floppy_drive_params32 *)arg)->rps);
1229 err |= __get_user(f->tracks, &((struct floppy_drive_params32 *)arg)->tracks);
1230 err |= __get_user(f->timeout, &((struct floppy_drive_params32 *)arg)->timeout);
1231 err |= __get_user(f->interleave_sect, &((struct floppy_drive_params32 *)arg)->interleave_sect);
1232 err |= __copy_from_user(&f->max_errors, &((struct floppy_drive_params32 *)arg)->max_errors, sizeof(f->max_errors));
1233 err |= __get_user(f->flags, &((struct floppy_drive_params32 *)arg)->flags);
1234 err |= __get_user(f->read_track, &((struct floppy_drive_params32 *)arg)->read_track);
1235 err |= __copy_from_user(f->autodetect, ((struct floppy_drive_params32 *)arg)->autodetect, sizeof(f->autodetect));
1236 err |= __get_user(f->checkfreq, &((struct floppy_drive_params32 *)arg)->checkfreq);
1237 err |= __get_user(f->native_format, &((struct floppy_drive_params32 *)arg)->native_format);
1238 if (err) {
1239 err = -EFAULT;
1240 goto out;
1241 }
1242 break;
1243 }
1244 case FDGETDRVSTAT32:
1245 case FDPOLLDRVSTAT32:
1246 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1247 if (!karg)
1248 return -ENOMEM;
1249 break;
1250 case FDGETFDCSTAT32:
1251 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1252 if (!karg)
1253 return -ENOMEM;
1254 break;
1255 case FDWERRORGET32:
1256 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1257 if (!karg)
1258 return -ENOMEM;
1259 break;
1260 default:
1261 return -EINVAL;
1262 }
1263 set_fs (KERNEL_DS);
1264 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1265 set_fs (old_fs);
1266 if (err)
1267 goto out;
1268 switch (cmd) {
1269 case FDGETPRM32:
1270 {
1271 struct floppy_struct *f = karg;
1272
1273 err = __put_user(f->size, &((struct floppy_struct32 *)arg)->size);
1274 err |= __put_user(f->sect, &((struct floppy_struct32 *)arg)->sect);
1275 err |= __put_user(f->head, &((struct floppy_struct32 *)arg)->head);
1276 err |= __put_user(f->track, &((struct floppy_struct32 *)arg)->track);
1277 err |= __put_user(f->stretch, &((struct floppy_struct32 *)arg)->stretch);
1278 err |= __put_user(f->gap, &((struct floppy_struct32 *)arg)->gap);
1279 err |= __put_user(f->rate, &((struct floppy_struct32 *)arg)->rate);
1280 err |= __put_user(f->spec1, &((struct floppy_struct32 *)arg)->spec1);
1281 err |= __put_user(f->fmt_gap, &((struct floppy_struct32 *)arg)->fmt_gap);
1282 err |= __put_user((u64)f->name, &((struct floppy_struct32 *)arg)->name);
1283 break;
1284 }
1285 case FDGETDRVPRM32:
1286 {
1287 struct floppy_drive_params *f = karg;
1288
1289 err = __put_user(f->cmos, &((struct floppy_drive_params32 *)arg)->cmos);
1290 err |= __put_user(f->max_dtr, &((struct floppy_drive_params32 *)arg)->max_dtr);
1291 err |= __put_user(f->hlt, &((struct floppy_drive_params32 *)arg)->hlt);
1292 err |= __put_user(f->hut, &((struct floppy_drive_params32 *)arg)->hut);
1293 err |= __put_user(f->srt, &((struct floppy_drive_params32 *)arg)->srt);
1294 err |= __put_user(f->spinup, &((struct floppy_drive_params32 *)arg)->spinup);
1295 err |= __put_user(f->spindown, &((struct floppy_drive_params32 *)arg)->spindown);
1296 err |= __put_user(f->spindown_offset, &((struct floppy_drive_params32 *)arg)->spindown_offset);
1297 err |= __put_user(f->select_delay, &((struct floppy_drive_params32 *)arg)->select_delay);
1298 err |= __put_user(f->rps, &((struct floppy_drive_params32 *)arg)->rps);
1299 err |= __put_user(f->tracks, &((struct floppy_drive_params32 *)arg)->tracks);
1300 err |= __put_user(f->timeout, &((struct floppy_drive_params32 *)arg)->timeout);
1301 err |= __put_user(f->interleave_sect, &((struct floppy_drive_params32 *)arg)->interleave_sect);
1302 err |= __copy_to_user(&((struct floppy_drive_params32 *)arg)->max_errors, &f->max_errors, sizeof(f->max_errors));
1303 err |= __put_user(f->flags, &((struct floppy_drive_params32 *)arg)->flags);
1304 err |= __put_user(f->read_track, &((struct floppy_drive_params32 *)arg)->read_track);
1305 err |= __copy_to_user(((struct floppy_drive_params32 *)arg)->autodetect, f->autodetect, sizeof(f->autodetect));
1306 err |= __put_user(f->checkfreq, &((struct floppy_drive_params32 *)arg)->checkfreq);
1307 err |= __put_user(f->native_format, &((struct floppy_drive_params32 *)arg)->native_format);
1308 break;
1309 }
1310 case FDGETDRVSTAT32:
1311 case FDPOLLDRVSTAT32:
1312 {
1313 struct floppy_drive_struct *f = karg;
1314
1315 err = __put_user(f->flags, &((struct floppy_drive_struct32 *)arg)->flags);
1316 err |= __put_user(f->spinup_date, &((struct floppy_drive_struct32 *)arg)->spinup_date);
1317 err |= __put_user(f->select_date, &((struct floppy_drive_struct32 *)arg)->select_date);
1318 err |= __put_user(f->first_read_date, &((struct floppy_drive_struct32 *)arg)->first_read_date);
1319 err |= __put_user(f->probed_format, &((struct floppy_drive_struct32 *)arg)->probed_format);
1320 err |= __put_user(f->track, &((struct floppy_drive_struct32 *)arg)->track);
1321 err |= __put_user(f->maxblock, &((struct floppy_drive_struct32 *)arg)->maxblock);
1322 err |= __put_user(f->maxtrack, &((struct floppy_drive_struct32 *)arg)->maxtrack);
1323 err |= __put_user(f->generation, &((struct floppy_drive_struct32 *)arg)->generation);
1324 err |= __put_user(f->keep_data, &((struct floppy_drive_struct32 *)arg)->keep_data);
1325 err |= __put_user(f->fd_ref, &((struct floppy_drive_struct32 *)arg)->fd_ref);
1326 err |= __put_user(f->fd_device, &((struct floppy_drive_struct32 *)arg)->fd_device);
1327 err |= __put_user(f->last_checked, &((struct floppy_drive_struct32 *)arg)->last_checked);
1328 err |= __put_user((u64)f->dmabuf, &((struct floppy_drive_struct32 *)arg)->dmabuf);
1329 err |= __put_user((u64)f->bufblocks, &((struct floppy_drive_struct32 *)arg)->bufblocks);
1330 break;
1331 }
1332 case FDGETFDCSTAT32:
1333 {
1334 struct floppy_fdc_state *f = karg;
1335
1336 err = __put_user(f->spec1, &((struct floppy_fdc_state32 *)arg)->spec1);
1337 err |= __put_user(f->spec2, &((struct floppy_fdc_state32 *)arg)->spec2);
1338 err |= __put_user(f->dtr, &((struct floppy_fdc_state32 *)arg)->dtr);
1339 err |= __put_user(f->version, &((struct floppy_fdc_state32 *)arg)->version);
1340 err |= __put_user(f->dor, &((struct floppy_fdc_state32 *)arg)->dor);
1341 err |= __put_user(f->address, &((struct floppy_fdc_state32 *)arg)->address);
1342 err |= __copy_to_user((char *)&((struct floppy_fdc_state32 *)arg)->address
1343 + sizeof(((struct floppy_fdc_state32 *)arg)->address),
1344 (char *)&f->address + sizeof(f->address), sizeof(int));
1345 err |= __put_user(f->driver_version, &((struct floppy_fdc_state32 *)arg)->driver_version);
1346 err |= __copy_to_user(((struct floppy_fdc_state32 *)arg)->track, f->track, sizeof(f->track));
1347 break;
1348 }
1349 case FDWERRORGET32:
1350 {
1351 struct floppy_write_errors *f = karg;
1352
1353 err = __put_user(f->write_errors, &((struct floppy_write_errors32 *)arg)->write_errors);
1354 err |= __put_user(f->first_error_sector, &((struct floppy_write_errors32 *)arg)->first_error_sector);
1355 err |= __put_user(f->first_error_generation, &((struct floppy_write_errors32 *)arg)->first_error_generation);
1356 err |= __put_user(f->last_error_sector, &((struct floppy_write_errors32 *)arg)->last_error_sector);
1357 err |= __put_user(f->last_error_generation, &((struct floppy_write_errors32 *)arg)->last_error_generation);
1358 err |= __put_user(f->badness, &((struct floppy_write_errors32 *)arg)->badness);
1359 break;
1360 }
1361 default:
1362 break;
1363 }
1364 if (err)
1365 err = -EFAULT;
1366
1367 out: if (karg) kfree(karg);
1368 return err;
1369 }
1370
1371
1372 typedef struct sg_io_hdr32 {
1373 s32 interface_id; /* [i] 'S' for SCSI generic (required) */
1374 s32 dxfer_direction; /* [i] data transfer direction */
1375 u8 cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
1376 u8 mx_sb_len; /* [i] max length to write to sbp */
1377 u16 iovec_count; /* [i] 0 implies no scatter gather */
1378 u32 dxfer_len; /* [i] byte count of data transfer */
1379 u32 dxferp; /* [i], [*io] points to data transfer memory
1380 or scatter gather list */
1381 u32 cmdp; /* [i], [*i] points to command to perform */
1382 u32 sbp; /* [i], [*o] points to sense_buffer memory */
1383 u32 timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
1384 u32 flags; /* [i] 0 -> default, see SG_FLAG... */
1385 s32 pack_id; /* [i->o] unused internally (normally) */
1386 u32 usr_ptr; /* [i->o] unused internally */
1387 u8 status; /* [o] scsi status */
1388 u8 masked_status; /* [o] shifted, masked scsi status */
1389 u8 msg_status; /* [o] messaging level data (optional) */
1390 u8 sb_len_wr; /* [o] byte count actually written to sbp */
1391 u16 host_status; /* [o] errors from host adapter */
1392 u16 driver_status; /* [o] errors from software driver */
1393 s32 resid; /* [o] dxfer_len - actual_transferred */
1394 u32 duration; /* [o] time taken by cmd (unit: millisec) */
1395 u32 info; /* [o] auxiliary information */
1396 } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
1397
1398 typedef struct sg_iovec32 {
1399 u32 iov_base;
1400 u32 iov_len;
1401 } sg_iovec32_t;
1402
1403 #define EMU_SG_MAX 128
1404
alloc_sg_iovec(sg_io_hdr_t * sgp,u32 uptr32)1405 static int alloc_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
1406 {
1407 sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
1408 sg_iovec_t *kiov;
1409 int i;
1410
1411 if (sgp->iovec_count > EMU_SG_MAX)
1412 return -EINVAL;
1413 sgp->dxferp = kmalloc(sgp->iovec_count *
1414 sizeof(sg_iovec_t), GFP_KERNEL);
1415 if (!sgp->dxferp)
1416 return -ENOMEM;
1417 memset(sgp->dxferp, 0,
1418 sgp->iovec_count * sizeof(sg_iovec_t));
1419
1420 kiov = (sg_iovec_t *) sgp->dxferp;
1421 for (i = 0; i < sgp->iovec_count; i++) {
1422 u32 iov_base32;
1423 if (__get_user(iov_base32, &uiov->iov_base) ||
1424 __get_user(kiov->iov_len, &uiov->iov_len))
1425 return -EFAULT;
1426 if (verify_area(VERIFY_WRITE, (void *)A(iov_base32), kiov->iov_len))
1427 return -EFAULT;
1428 kiov->iov_base = (void *)A(iov_base32);
1429 uiov++;
1430 kiov++;
1431 }
1432
1433 return 0;
1434 }
1435
free_sg_iovec(sg_io_hdr_t * sgp)1436 static void free_sg_iovec(sg_io_hdr_t *sgp)
1437 {
1438 kfree(sgp->dxferp);
1439 sgp->dxferp = NULL;
1440 }
1441
sg_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1442 static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1443 {
1444 sg_io_hdr32_t *sg_io32;
1445 sg_io_hdr_t sg_io64;
1446 u32 dxferp32, cmdp32, sbp32;
1447 mm_segment_t old_fs;
1448 int err = 0;
1449
1450 sg_io32 = (sg_io_hdr32_t *)arg;
1451 err = __get_user(sg_io64.interface_id, &sg_io32->interface_id);
1452 err |= __get_user(sg_io64.dxfer_direction, &sg_io32->dxfer_direction);
1453 err |= __get_user(sg_io64.cmd_len, &sg_io32->cmd_len);
1454 err |= __get_user(sg_io64.mx_sb_len, &sg_io32->mx_sb_len);
1455 err |= __get_user(sg_io64.iovec_count, &sg_io32->iovec_count);
1456 err |= __get_user(sg_io64.dxfer_len, &sg_io32->dxfer_len);
1457 err |= __get_user(sg_io64.timeout, &sg_io32->timeout);
1458 err |= __get_user(sg_io64.flags, &sg_io32->flags);
1459 err |= __get_user(sg_io64.pack_id, &sg_io32->pack_id);
1460
1461 sg_io64.dxferp = NULL;
1462 sg_io64.cmdp = NULL;
1463 sg_io64.sbp = NULL;
1464
1465 err |= __get_user(cmdp32, &sg_io32->cmdp);
1466
1467 sg_io64.cmdp = kmalloc(sg_io64.cmd_len, GFP_KERNEL);
1468 if (!sg_io64.cmdp) {
1469 err = -ENOMEM;
1470 goto out;
1471 }
1472 if (copy_from_user(sg_io64.cmdp,
1473 (void *) A(cmdp32),
1474 sg_io64.cmd_len)) {
1475 err = -EFAULT;
1476 goto out;
1477 }
1478
1479 err |= __get_user(sbp32, &sg_io32->sbp);
1480 sg_io64.sbp = kmalloc(sg_io64.mx_sb_len, GFP_KERNEL);
1481 if (!sg_io64.sbp) {
1482 err = -ENOMEM;
1483 goto out;
1484 }
1485 if (copy_from_user(sg_io64.sbp,
1486 (void *) A(sbp32),
1487 sg_io64.mx_sb_len)) {
1488 err = -EFAULT;
1489 goto out;
1490 }
1491
1492 err |= __get_user(dxferp32, &sg_io32->dxferp);
1493 if (sg_io64.iovec_count) {
1494 int ret;
1495
1496 if ((ret = alloc_sg_iovec(&sg_io64, dxferp32))) {
1497 err = ret;
1498 goto out;
1499 }
1500 } else {
1501 err = verify_area(VERIFY_WRITE, (void *)A(dxferp32), sg_io64.dxfer_len);
1502 if (err)
1503 goto out;
1504
1505 sg_io64.dxferp = A(dxferp32);
1506 }
1507
1508 /* Unused internally, do not even bother to copy it over. */
1509 sg_io64.usr_ptr = NULL;
1510
1511 if (err)
1512 return -EFAULT;
1513
1514 old_fs = get_fs();
1515 set_fs (KERNEL_DS);
1516 err = sys_ioctl (fd, cmd, (unsigned long) &sg_io64);
1517 set_fs (old_fs);
1518
1519 if (err < 0)
1520 goto out;
1521
1522 err = __put_user(sg_io64.pack_id, &sg_io32->pack_id);
1523 err |= __put_user(sg_io64.status, &sg_io32->status);
1524 err |= __put_user(sg_io64.masked_status, &sg_io32->masked_status);
1525 err |= __put_user(sg_io64.msg_status, &sg_io32->msg_status);
1526 err |= __put_user(sg_io64.sb_len_wr, &sg_io32->sb_len_wr);
1527 err |= __put_user(sg_io64.host_status, &sg_io32->host_status);
1528 err |= __put_user(sg_io64.driver_status, &sg_io32->driver_status);
1529 err |= __put_user(sg_io64.resid, &sg_io32->resid);
1530 err |= __put_user(sg_io64.duration, &sg_io32->duration);
1531 err |= __put_user(sg_io64.info, &sg_io32->info);
1532 err |= copy_to_user((void *)A(sbp32), sg_io64.sbp, sg_io64.mx_sb_len);
1533 if (err)
1534 err = -EFAULT;
1535
1536 out:
1537 if (sg_io64.cmdp)
1538 kfree(sg_io64.cmdp);
1539 if (sg_io64.sbp)
1540 kfree(sg_io64.sbp);
1541 if (sg_io64.dxferp && sg_io64.iovec_count)
1542 free_sg_iovec(&sg_io64);
1543 return err;
1544 }
1545
1546 struct sock_fprog32 {
1547 __u16 len;
1548 __u32 filter;
1549 };
1550
1551 #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
1552 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
1553
ppp_sock_fprog_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1554 static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1555 {
1556 struct sock_fprog32 *u_fprog32 = (struct sock_fprog32 *) arg;
1557 struct sock_fprog *u_fprog64 = alloc_user_space(sizeof(struct sock_fprog));
1558 void *fptr64;
1559 u32 fptr32;
1560 u16 flen;
1561
1562 if (get_user(flen, &u_fprog32->len) ||
1563 get_user(fptr32, &u_fprog32->filter))
1564 return -EFAULT;
1565
1566 fptr64 = (void *) A(fptr32);
1567
1568 if (put_user(flen, &u_fprog64->len) ||
1569 put_user(fptr64, &u_fprog64->filter))
1570 return -EFAULT;
1571
1572 if (cmd == PPPIOCSPASS32)
1573 cmd = PPPIOCSPASS;
1574 else
1575 cmd = PPPIOCSACTIVE;
1576
1577 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
1578 }
1579
1580 struct ppp_option_data32 {
1581 __kernel_caddr_t32 ptr;
1582 __u32 length;
1583 int transmit;
1584 };
1585 #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
1586
1587 struct ppp_idle32 {
1588 __kernel_time_t32 xmit_idle;
1589 __kernel_time_t32 recv_idle;
1590 };
1591 #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
1592
ppp_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1593 static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1594 {
1595 mm_segment_t old_fs = get_fs();
1596 struct ppp_option_data32 data32;
1597 struct ppp_option_data data;
1598 struct ppp_idle32 idle32;
1599 struct ppp_idle idle;
1600 unsigned int kcmd;
1601 void *karg;
1602 int err = 0;
1603
1604 switch (cmd) {
1605 case PPPIOCGIDLE32:
1606 kcmd = PPPIOCGIDLE;
1607 karg = &idle;
1608 break;
1609 case PPPIOCSCOMPRESS32:
1610 if (copy_from_user(&data32, (struct ppp_option_data32 *)arg, sizeof(struct ppp_option_data32)))
1611 return -EFAULT;
1612 if (data32.length > PAGE_SIZE)
1613 return -EINVAL;
1614 data.ptr = kmalloc (data32.length, GFP_KERNEL);
1615 if (!data.ptr)
1616 return -ENOMEM;
1617 if (copy_from_user(data.ptr, (__u8 *)A(data32.ptr), data32.length)) {
1618 kfree(data.ptr);
1619 return -EFAULT;
1620 }
1621 data.length = data32.length;
1622 data.transmit = data32.transmit;
1623 kcmd = PPPIOCSCOMPRESS;
1624 karg = &data;
1625 break;
1626 default:
1627 do {
1628 static int count;
1629 if (++count <= 20)
1630 printk("ppp_ioctl: Unknown cmd fd(%d) "
1631 "cmd(%08x) arg(%08x)\n",
1632 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1633 } while(0);
1634 return -EINVAL;
1635 }
1636 set_fs (KERNEL_DS);
1637 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1638 set_fs (old_fs);
1639 switch (cmd) {
1640 case PPPIOCGIDLE32:
1641 if (err)
1642 return err;
1643 idle32.xmit_idle = idle.xmit_idle;
1644 idle32.recv_idle = idle.recv_idle;
1645 if (copy_to_user((struct ppp_idle32 *)arg, &idle32, sizeof(struct ppp_idle32)))
1646 return -EFAULT;
1647 break;
1648 case PPPIOCSCOMPRESS32:
1649 kfree(data.ptr);
1650 break;
1651 default:
1652 break;
1653 }
1654 return err;
1655 }
1656
1657
1658 struct mtget32 {
1659 __u32 mt_type;
1660 __u32 mt_resid;
1661 __u32 mt_dsreg;
1662 __u32 mt_gstat;
1663 __u32 mt_erreg;
1664 __kernel_daddr_t32 mt_fileno;
1665 __kernel_daddr_t32 mt_blkno;
1666 };
1667 #define MTIOCGET32 _IOR('m', 2, struct mtget32)
1668
1669 struct mtpos32 {
1670 __u32 mt_blkno;
1671 };
1672 #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1673
1674 struct mtconfiginfo32 {
1675 __u32 mt_type;
1676 __u32 ifc_type;
1677 __u16 irqnr;
1678 __u16 dmanr;
1679 __u16 port;
1680 __u32 debug;
1681 __u32 have_dens:1;
1682 __u32 have_bsf:1;
1683 __u32 have_fsr:1;
1684 __u32 have_bsr:1;
1685 __u32 have_eod:1;
1686 __u32 have_seek:1;
1687 __u32 have_tell:1;
1688 __u32 have_ras1:1;
1689 __u32 have_ras2:1;
1690 __u32 have_ras3:1;
1691 __u32 have_qfa:1;
1692 __u32 pad1:5;
1693 char reserved[10];
1694 };
1695 #define MTIOCGETCONFIG32 _IOR('m', 4, struct mtconfiginfo32)
1696 #define MTIOCSETCONFIG32 _IOW('m', 5, struct mtconfiginfo32)
1697
mt_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1698 static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1699 {
1700 mm_segment_t old_fs = get_fs();
1701 struct mtconfiginfo info;
1702 struct mtget get;
1703 struct mtpos pos;
1704 unsigned long kcmd;
1705 void *karg;
1706 int err = 0;
1707
1708 switch(cmd) {
1709 case MTIOCPOS32:
1710 kcmd = MTIOCPOS;
1711 karg = &pos;
1712 break;
1713 case MTIOCGET32:
1714 kcmd = MTIOCGET;
1715 karg = &get;
1716 break;
1717 case MTIOCGETCONFIG32:
1718 kcmd = MTIOCGETCONFIG;
1719 karg = &info;
1720 break;
1721 case MTIOCSETCONFIG32:
1722 kcmd = MTIOCSETCONFIG;
1723 karg = &info;
1724 err = __get_user(info.mt_type, &((struct mtconfiginfo32 *)arg)->mt_type);
1725 err |= __get_user(info.ifc_type, &((struct mtconfiginfo32 *)arg)->ifc_type);
1726 err |= __get_user(info.irqnr, &((struct mtconfiginfo32 *)arg)->irqnr);
1727 err |= __get_user(info.dmanr, &((struct mtconfiginfo32 *)arg)->dmanr);
1728 err |= __get_user(info.port, &((struct mtconfiginfo32 *)arg)->port);
1729 err |= __get_user(info.debug, &((struct mtconfiginfo32 *)arg)->debug);
1730 err |= __copy_from_user((char *)&info.debug + sizeof(info.debug),
1731 (char *)&((struct mtconfiginfo32 *)arg)->debug
1732 + sizeof(((struct mtconfiginfo32 *)arg)->debug), sizeof(__u32));
1733 if (err)
1734 return -EFAULT;
1735 break;
1736 default:
1737 do {
1738 static int count;
1739 if (++count <= 20)
1740 printk("mt_ioctl: Unknown cmd fd(%d) "
1741 "cmd(%08x) arg(%08x)\n",
1742 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1743 } while(0);
1744 return -EINVAL;
1745 }
1746 set_fs (KERNEL_DS);
1747 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1748 set_fs (old_fs);
1749 if (err)
1750 return err;
1751 switch (cmd) {
1752 case MTIOCPOS32:
1753 err = __put_user(pos.mt_blkno, &((struct mtpos32 *)arg)->mt_blkno);
1754 break;
1755 case MTIOCGET32:
1756 err = __put_user(get.mt_type, &((struct mtget32 *)arg)->mt_type);
1757 err |= __put_user(get.mt_resid, &((struct mtget32 *)arg)->mt_resid);
1758 err |= __put_user(get.mt_dsreg, &((struct mtget32 *)arg)->mt_dsreg);
1759 err |= __put_user(get.mt_gstat, &((struct mtget32 *)arg)->mt_gstat);
1760 err |= __put_user(get.mt_erreg, &((struct mtget32 *)arg)->mt_erreg);
1761 err |= __put_user(get.mt_fileno, &((struct mtget32 *)arg)->mt_fileno);
1762 err |= __put_user(get.mt_blkno, &((struct mtget32 *)arg)->mt_blkno);
1763 break;
1764 case MTIOCGETCONFIG32:
1765 err = __put_user(info.mt_type, &((struct mtconfiginfo32 *)arg)->mt_type);
1766 err |= __put_user(info.ifc_type, &((struct mtconfiginfo32 *)arg)->ifc_type);
1767 err |= __put_user(info.irqnr, &((struct mtconfiginfo32 *)arg)->irqnr);
1768 err |= __put_user(info.dmanr, &((struct mtconfiginfo32 *)arg)->dmanr);
1769 err |= __put_user(info.port, &((struct mtconfiginfo32 *)arg)->port);
1770 err |= __put_user(info.debug, &((struct mtconfiginfo32 *)arg)->debug);
1771 err |= __copy_to_user((char *)&((struct mtconfiginfo32 *)arg)->debug
1772 + sizeof(((struct mtconfiginfo32 *)arg)->debug),
1773 (char *)&info.debug + sizeof(info.debug), sizeof(__u32));
1774 break;
1775 case MTIOCSETCONFIG32:
1776 break;
1777 }
1778 return err ? -EFAULT: 0;
1779 }
1780
1781 struct cdrom_read32 {
1782 int cdread_lba;
1783 __kernel_caddr_t32 cdread_bufaddr;
1784 int cdread_buflen;
1785 };
1786
1787 struct cdrom_read_audio32 {
1788 union cdrom_addr addr;
1789 u_char addr_format;
1790 int nframes;
1791 __kernel_caddr_t32 buf;
1792 };
1793
1794 struct cdrom_generic_command32 {
1795 unsigned char cmd[CDROM_PACKET_SIZE];
1796 __kernel_caddr_t32 buffer;
1797 unsigned int buflen;
1798 int stat;
1799 __kernel_caddr_t32 sense;
1800 unsigned char data_direction;
1801 int quiet;
1802 int timeout;
1803 __kernel_caddr_t32 reserved[1];
1804 };
1805
cdrom_ioctl_trans(unsigned int fd,unsigned int cmd,unsigned long arg)1806 static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1807 {
1808 mm_segment_t old_fs = get_fs();
1809 struct cdrom_read cdread;
1810 struct cdrom_read_audio cdreadaudio;
1811 struct cdrom_generic_command cgc;
1812 __kernel_caddr_t32 addr;
1813 void *karg;
1814 int err = 0;
1815
1816 switch(cmd) {
1817 case CDROMREADMODE2:
1818 case CDROMREADMODE1:
1819 case CDROMREADRAW:
1820 case CDROMREADCOOKED:
1821 karg = &cdread;
1822 err = __get_user(cdread.cdread_lba, &((struct cdrom_read32 *)arg)->cdread_lba);
1823 err |= __get_user(addr, &((struct cdrom_read32 *)arg)->cdread_bufaddr);
1824 err |= __get_user(cdread.cdread_buflen, &((struct cdrom_read32 *)arg)->cdread_buflen);
1825 if (err)
1826 return -EFAULT;
1827 if (verify_area(VERIFY_WRITE, (void *)A(addr), cdread.cdread_buflen))
1828 return -EFAULT;
1829 cdread.cdread_bufaddr = (void *)A(addr);
1830 break;
1831 case CDROMREADAUDIO:
1832 karg = &cdreadaudio;
1833 err = copy_from_user(&cdreadaudio.addr, &((struct cdrom_read_audio32 *)arg)->addr, sizeof(cdreadaudio.addr));
1834 err |= __get_user(cdreadaudio.addr_format, &((struct cdrom_read_audio32 *)arg)->addr_format);
1835 err |= __get_user(cdreadaudio.nframes, &((struct cdrom_read_audio32 *)arg)->nframes);
1836 err |= __get_user(addr, &((struct cdrom_read_audio32 *)arg)->buf);
1837 if (err)
1838 return -EFAULT;
1839
1840
1841 if (verify_area(VERIFY_WRITE, (void *)A(addr), cdreadaudio.nframes*2352))
1842 return -EFAULT;
1843 cdreadaudio.buf = (void *)A(addr);
1844 break;
1845 case CDROM_SEND_PACKET: {
1846 __kernel_caddr_t32 sense;
1847 karg = &cgc;
1848 err = copy_from_user(cgc.cmd, &((struct cdrom_generic_command32 *)arg)->cmd, sizeof(cgc.cmd));
1849 err |= __get_user(addr, &((struct cdrom_generic_command32 *)arg)->buffer);
1850 err |= __get_user(cgc.buflen, &((struct cdrom_generic_command32 *)arg)->buflen);
1851 err |= __get_user(sense, &((struct cdrom_generic_command32 *)arg)->sense);
1852 err |= __get_user(cgc.data_direction, &((struct cdrom_generic_command32 *)arg)->data_direction);
1853 err |= __get_user(cgc.timeout, &((struct cdrom_generic_command32 *)arg)->timeout);
1854 if (err)
1855 return -EFAULT;
1856 if (verify_area(VERIFY_WRITE, (void *)A(addr), cgc.buflen))
1857 return -EFAULT;
1858 if (sense && verify_area(VERIFY_WRITE, (void *)A(sense), sizeof(struct request_sense)))
1859 return -EFAULT;
1860 cgc.buffer = (void *)A(addr);
1861 cgc.sense = (void *)A(sense);
1862 break;
1863 }
1864 default:
1865 do {
1866 static int count;
1867 if (++count <= 20)
1868 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1869 "cmd(%08x) arg(%08x)\n",
1870 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1871 } while(0);
1872 return -EINVAL;
1873 }
1874 set_fs (KERNEL_DS);
1875 err = sys_ioctl (fd, cmd, (unsigned long)karg);
1876 set_fs (old_fs);
1877 return err ? -EFAULT : 0;
1878 }
1879
1880 struct loop_info32 {
1881 int lo_number; /* ioctl r/o */
1882 __kernel_dev_t32 lo_device; /* ioctl r/o */
1883 unsigned int lo_inode; /* ioctl r/o */
1884 __kernel_dev_t32 lo_rdevice; /* ioctl r/o */
1885 int lo_offset;
1886 int lo_encrypt_type;
1887 int lo_encrypt_key_size; /* ioctl w/o */
1888 int lo_flags; /* ioctl r/o */
1889 char lo_name[LO_NAME_SIZE];
1890 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
1891 unsigned int lo_init[2];
1892 char reserved[4];
1893 };
1894
loop_status(unsigned int fd,unsigned int cmd,unsigned long arg)1895 static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg)
1896 {
1897 mm_segment_t old_fs = get_fs();
1898 struct loop_info l;
1899 int err = -EINVAL;
1900
1901 switch(cmd) {
1902 case LOOP_SET_STATUS:
1903 err = get_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);
1904 err |= __get_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);
1905 err |= __get_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);
1906 err |= __get_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);
1907
1908 err |= __copy_from_user((char *)&l.lo_offset, (char *)&((struct loop_info32 *)arg)->lo_offset,
1909 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1910 if (err) {
1911 err = -EFAULT;
1912 } else {
1913 set_fs (KERNEL_DS);
1914 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1915 set_fs (old_fs);
1916 }
1917 break;
1918 case LOOP_GET_STATUS:
1919 set_fs (KERNEL_DS);
1920 err = sys_ioctl (fd, cmd, (unsigned long)&l);
1921 set_fs (old_fs);
1922 if (!err) {
1923 err = put_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);
1924 err |= __put_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);
1925 err |= __put_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);
1926 err |= __put_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);
1927 err |= __copy_to_user((char *)&((struct loop_info32 *)arg)->lo_offset,
1928 (char *)&l.lo_offset, (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
1929 if (err)
1930 err = -EFAULT;
1931 }
1932 break;
1933 default: {
1934 static int count;
1935 if (++count <= 20)
1936 printk("%s: Unknown loop ioctl cmd, fd(%d) "
1937 "cmd(%08x) arg(%08lx)\n",
1938 __FUNCTION__, fd, cmd, arg);
1939 }
1940 }
1941 return err;
1942 }
1943
1944 extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);
1945
1946 #ifdef CONFIG_VT
vt_check(struct file * file)1947 static int vt_check(struct file *file)
1948 {
1949 struct tty_struct *tty;
1950 struct inode *inode = file->f_dentry->d_inode;
1951
1952 if (file->f_op->ioctl != tty_ioctl)
1953 return -EINVAL;
1954
1955 tty = (struct tty_struct *)file->private_data;
1956 if (tty_paranoia_check(tty, inode->i_rdev, "tty_ioctl"))
1957 return -EINVAL;
1958
1959 if (tty->driver.ioctl != vt_ioctl)
1960 return -EINVAL;
1961
1962 /*
1963 * To have permissions to do most of the vt ioctls, we either have
1964 * to be the owner of the tty, or super-user.
1965 */
1966 if (current->tty == tty || suser())
1967 return 1;
1968 return 0;
1969 }
1970
1971 struct consolefontdesc32 {
1972 unsigned short charcount; /* characters in font (256 or 512) */
1973 unsigned short charheight; /* scan lines per character (1-32) */
1974 u32 chardata; /* font data in expanded form */
1975 };
1976
do_fontx_ioctl(unsigned int fd,int cmd,struct consolefontdesc32 * user_cfd,struct file * file)1977 static int do_fontx_ioctl(unsigned int fd, int cmd, struct consolefontdesc32 *user_cfd, struct file *file)
1978 {
1979 struct consolefontdesc cfdarg;
1980 struct console_font_op op;
1981 int i, perm;
1982
1983 perm = vt_check(file);
1984 if (perm < 0) return perm;
1985
1986 if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc32)))
1987 return -EFAULT;
1988
1989 cfdarg.chardata = (unsigned char *)A(((struct consolefontdesc32 *)&cfdarg)->chardata);
1990
1991 switch (cmd) {
1992 case PIO_FONTX:
1993 if (!perm)
1994 return -EPERM;
1995 op.op = KD_FONT_OP_SET;
1996 op.flags = 0;
1997 op.width = 8;
1998 op.height = cfdarg.charheight;
1999 op.charcount = cfdarg.charcount;
2000 op.data = cfdarg.chardata;
2001 return con_font_op(fg_console, &op);
2002 case GIO_FONTX:
2003 if (!cfdarg.chardata)
2004 return 0;
2005 op.op = KD_FONT_OP_GET;
2006 op.flags = 0;
2007 op.width = 8;
2008 op.height = cfdarg.charheight;
2009 op.charcount = cfdarg.charcount;
2010 op.data = cfdarg.chardata;
2011 i = con_font_op(fg_console, &op);
2012 if (i)
2013 return i;
2014 cfdarg.charheight = op.height;
2015 cfdarg.charcount = op.charcount;
2016 ((struct consolefontdesc32 *)&cfdarg)->chardata = (unsigned long)cfdarg.chardata;
2017 if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc32)))
2018 return -EFAULT;
2019 return 0;
2020 }
2021 return -EINVAL;
2022 }
2023
2024 struct console_font_op32 {
2025 unsigned int op; /* operation code KD_FONT_OP_* */
2026 unsigned int flags; /* KD_FONT_FLAG_* */
2027 unsigned int width, height; /* font size */
2028 unsigned int charcount;
2029 u32 data; /* font data with height fixed to 32 */
2030 };
2031
do_kdfontop_ioctl(unsigned int fd,unsigned int cmd,struct console_font_op32 * fontop,struct file * file)2032 static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, struct console_font_op32 *fontop, struct file *file)
2033 {
2034 struct console_font_op op;
2035 int perm = vt_check(file), i;
2036 struct vt_struct *vt;
2037
2038 if (perm < 0) return perm;
2039
2040 if (copy_from_user(&op, (void *) fontop, sizeof(struct console_font_op32)))
2041 return -EFAULT;
2042 if (!perm && op.op != KD_FONT_OP_GET)
2043 return -EPERM;
2044 op.data = (unsigned char *)A(((struct console_font_op32 *)&op)->data);
2045 op.flags |= KD_FONT_FLAG_OLD;
2046 vt = (struct vt_struct *)((struct tty_struct *)file->private_data)->driver_data;
2047 i = con_font_op(vt->vc_num, &op);
2048 if (i) return i;
2049 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
2050 if (copy_to_user((void *) fontop, &op, sizeof(struct console_font_op32)))
2051 return -EFAULT;
2052 return 0;
2053 }
2054
2055 struct unimapdesc32 {
2056 unsigned short entry_ct;
2057 u32 entries;
2058 };
2059
do_unimap_ioctl(unsigned int fd,unsigned int cmd,struct unimapdesc32 * user_ud,struct file * file)2060 static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, struct unimapdesc32 *user_ud, struct file *file)
2061 {
2062 struct unimapdesc32 tmp;
2063 int perm = vt_check(file);
2064
2065 if (perm < 0) return perm;
2066 if (copy_from_user(&tmp, user_ud, sizeof tmp))
2067 return -EFAULT;
2068 switch (cmd) {
2069 case PIO_UNIMAP:
2070 if (!perm) return -EPERM;
2071 return con_set_unimap(fg_console, tmp.entry_ct, (struct unipair *)A(tmp.entries));
2072 case GIO_UNIMAP:
2073 return con_get_unimap(fg_console, tmp.entry_ct, &(user_ud->entry_ct), (struct unipair *)A(tmp.entries));
2074 }
2075 return 0;
2076 }
2077 #endif /* CONFIG_VT */
2078
do_smb_getmountuid(unsigned int fd,unsigned int cmd,unsigned long arg)2079 static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
2080 {
2081 mm_segment_t old_fs = get_fs();
2082 __kernel_uid_t kuid;
2083 int err;
2084
2085 cmd = SMB_IOC_GETMOUNTUID;
2086
2087 set_fs(KERNEL_DS);
2088 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
2089 set_fs(old_fs);
2090
2091 if (err >= 0)
2092 err = put_user(kuid, (__kernel_uid_t32 *)arg);
2093
2094 return err;
2095 }
2096
2097 struct atmif_sioc32 {
2098 int number;
2099 int length;
2100 __kernel_caddr_t32 arg;
2101 };
2102
2103 struct atm_iobuf32 {
2104 int length;
2105 __kernel_caddr_t32 buffer;
2106 };
2107
2108 #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
2109 #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
2110 #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
2111 #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
2112 #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
2113 #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
2114 #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
2115 #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
2116 #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
2117 #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
2118 #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
2119 #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
2120 #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
2121 #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
2122 #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
2123 #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
2124 #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
2125
2126 static struct {
2127 unsigned int cmd32;
2128 unsigned int cmd;
2129 } atm_ioctl_map[] = {
2130 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
2131 { ATM_GETNAMES32, ATM_GETNAMES },
2132 { ATM_GETTYPE32, ATM_GETTYPE },
2133 { ATM_GETESI32, ATM_GETESI },
2134 { ATM_GETADDR32, ATM_GETADDR },
2135 { ATM_RSTADDR32, ATM_RSTADDR },
2136 { ATM_ADDADDR32, ATM_ADDADDR },
2137 { ATM_DELADDR32, ATM_DELADDR },
2138 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
2139 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
2140 { ATM_SETESI32, ATM_SETESI },
2141 { ATM_SETESIF32, ATM_SETESIF },
2142 { ATM_GETSTAT32, ATM_GETSTAT },
2143 { ATM_GETSTATZ32, ATM_GETSTATZ },
2144 { ATM_GETLOOP32, ATM_GETLOOP },
2145 { ATM_SETLOOP32, ATM_SETLOOP },
2146 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
2147 };
2148
2149 #define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
2150
2151
do_atm_iobuf(unsigned int fd,unsigned int cmd,unsigned long arg)2152 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
2153 {
2154 struct atm_iobuf32 iobuf32;
2155 struct atm_iobuf iobuf = { 0, NULL };
2156 mm_segment_t old_fs;
2157 int err;
2158
2159 err = copy_from_user(&iobuf32, (struct atm_iobuf32*)arg,
2160 sizeof(struct atm_iobuf32));
2161 if (err)
2162 return -EFAULT;
2163
2164 iobuf.length = iobuf32.length;
2165
2166 if (iobuf32.buffer == (__kernel_caddr_t32) NULL || iobuf32.length == 0) {
2167 iobuf.buffer = (void*)(unsigned long)iobuf32.buffer;
2168 } else {
2169 iobuf.buffer = A(iobuf32.buffer);
2170 if (verify_area(VERIFY_WRITE, iobuf.buffer, iobuf.length))
2171 return -EINVAL;
2172 }
2173
2174 old_fs = get_fs(); set_fs (KERNEL_DS);
2175 err = sys_ioctl (fd, cmd, (unsigned long)&iobuf);
2176 set_fs (old_fs);
2177 if(!err)
2178 err = __put_user(iobuf.length, &(((struct atm_iobuf32*)arg)->length));
2179
2180 return err;
2181 }
2182
2183
do_atmif_sioc(unsigned int fd,unsigned int cmd,unsigned long arg)2184 static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
2185 {
2186 struct atmif_sioc32 sioc32;
2187 struct atmif_sioc sioc = { 0, 0, NULL };
2188 mm_segment_t old_fs;
2189 int err;
2190
2191 err = copy_from_user(&sioc32, (struct atmif_sioc32*)arg,
2192 sizeof(struct atmif_sioc32));
2193 if (err)
2194 return -EFAULT;
2195
2196 sioc.number = sioc32.number;
2197 sioc.length = sioc32.length;
2198
2199 if (sioc32.arg == (__kernel_caddr_t32) NULL || sioc32.length == 0) {
2200 sioc.arg = (void*)(unsigned long)sioc32.arg;
2201 } else {
2202 sioc.arg = A(sioc32.arg);
2203 if (verify_area(VERIFY_WRITE, sioc.arg, sioc32.length))
2204 return -EFAULT;
2205 }
2206
2207 old_fs = get_fs(); set_fs (KERNEL_DS);
2208 err = sys_ioctl (fd, cmd, (unsigned long)&sioc);
2209 set_fs (old_fs);
2210 if (!err)
2211 err = __put_user(sioc.length, &(((struct atmif_sioc32*)arg)->length));
2212 return err;
2213 }
2214
2215
do_atm_ioctl(unsigned int fd,unsigned int cmd32,unsigned long arg)2216 static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
2217 {
2218 int i;
2219 unsigned int cmd = 0;
2220
2221 switch (cmd32) {
2222 case SONET_GETSTAT:
2223 case SONET_GETSTATZ:
2224 case SONET_GETDIAG:
2225 case SONET_SETDIAG:
2226 case SONET_CLRDIAG:
2227 case SONET_SETFRAMING:
2228 case SONET_GETFRAMING:
2229 case SONET_GETFRSENSE:
2230 return do_atmif_sioc(fd, cmd32, arg);
2231 }
2232
2233 for (i = 0; i < NR_ATM_IOCTL; i++) {
2234 if (cmd32 == atm_ioctl_map[i].cmd32) {
2235 cmd = atm_ioctl_map[i].cmd;
2236 break;
2237 }
2238 }
2239 if (i == NR_ATM_IOCTL) {
2240 return -EINVAL;
2241 }
2242
2243 switch (cmd) {
2244 case ATM_GETNAMES:
2245 return do_atm_iobuf(fd, cmd, arg);
2246
2247 case ATM_GETLINKRATE:
2248 case ATM_GETTYPE:
2249 case ATM_GETESI:
2250 case ATM_GETADDR:
2251 case ATM_RSTADDR:
2252 case ATM_ADDADDR:
2253 case ATM_DELADDR:
2254 case ATM_GETCIRANGE:
2255 case ATM_SETCIRANGE:
2256 case ATM_SETESI:
2257 case ATM_SETESIF:
2258 case ATM_GETSTAT:
2259 case ATM_GETSTATZ:
2260 case ATM_GETLOOP:
2261 case ATM_SETLOOP:
2262 case ATM_QUERYLOOP:
2263 return do_atmif_sioc(fd, cmd, arg);
2264 }
2265
2266 return -EINVAL;
2267 }
2268
2269 #if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)
2270 /* Ugh, LVM. Pitty it was not cleaned up before accepted :((. */
2271 typedef struct {
2272 uint8_t vg_name[NAME_LEN];
2273 uint32_t vg_number;
2274 uint32_t vg_access;
2275 uint32_t vg_status;
2276 uint32_t lv_max;
2277 uint32_t lv_cur;
2278 uint32_t lv_open;
2279 uint32_t pv_max;
2280 uint32_t pv_cur;
2281 uint32_t pv_act;
2282 uint32_t dummy;
2283 uint32_t vgda;
2284 uint32_t pe_size;
2285 uint32_t pe_total;
2286 uint32_t pe_allocated;
2287 uint32_t pvg_total;
2288 u32 proc;
2289 u32 pv[ABS_MAX_PV + 1];
2290 u32 lv[ABS_MAX_LV + 1];
2291 uint8_t vg_uuid[UUID_LEN+1]; /* volume group UUID */
2292 uint8_t dummy1[200];
2293 } vg32_t;
2294
2295 typedef struct {
2296 uint8_t id[2];
2297 uint16_t version;
2298 lvm_disk_data_t pv_on_disk;
2299 lvm_disk_data_t vg_on_disk;
2300 lvm_disk_data_t pv_namelist_on_disk;
2301 lvm_disk_data_t lv_on_disk;
2302 lvm_disk_data_t pe_on_disk;
2303 uint8_t pv_name[NAME_LEN];
2304 uint8_t vg_name[NAME_LEN];
2305 uint8_t system_id[NAME_LEN];
2306 kdev_t pv_dev;
2307 uint32_t pv_number;
2308 uint32_t pv_status;
2309 uint32_t pv_allocatable;
2310 uint32_t pv_size;
2311 uint32_t lv_cur;
2312 uint32_t pe_size;
2313 uint32_t pe_total;
2314 uint32_t pe_allocated;
2315 uint32_t pe_stale;
2316 u32 pe;
2317 u32 inode;
2318 uint8_t pv_uuid[UUID_LEN+1];
2319 } pv32_t;
2320
2321 typedef struct {
2322 char lv_name[NAME_LEN];
2323 u32 lv;
2324 } lv_req32_t;
2325
2326 typedef struct {
2327 u32 lv_index;
2328 u32 lv;
2329 /* Transfer size because user space and kernel space differ */
2330 uint16_t size;
2331 } lv_status_byindex_req32_t;
2332
2333 typedef struct {
2334 __kernel_dev_t32 dev;
2335 u32 lv;
2336 } lv_status_bydev_req32_t;
2337
2338 typedef struct {
2339 uint8_t lv_name[NAME_LEN];
2340 kdev_t old_dev;
2341 kdev_t new_dev;
2342 u32 old_pe;
2343 u32 new_pe;
2344 } le_remap_req32_t;
2345
2346 typedef struct {
2347 char pv_name[NAME_LEN];
2348 u32 pv;
2349 } pv_status_req32_t;
2350
2351 typedef struct {
2352 uint8_t lv_name[NAME_LEN];
2353 uint8_t vg_name[NAME_LEN];
2354 uint32_t lv_access;
2355 uint32_t lv_status;
2356 uint32_t lv_open;
2357 kdev_t lv_dev;
2358 uint32_t lv_number;
2359 uint32_t lv_mirror_copies;
2360 uint32_t lv_recovery;
2361 uint32_t lv_schedule;
2362 uint32_t lv_size;
2363 u32 lv_current_pe;
2364 uint32_t lv_current_le;
2365 uint32_t lv_allocated_le;
2366 uint32_t lv_stripes;
2367 uint32_t lv_stripesize;
2368 uint32_t lv_badblock;
2369 uint32_t lv_allocation;
2370 uint32_t lv_io_timeout;
2371 uint32_t lv_read_ahead;
2372 /* delta to version 1 starts here */
2373 u32 lv_snapshot_org;
2374 u32 lv_snapshot_prev;
2375 u32 lv_snapshot_next;
2376 u32 lv_block_exception;
2377 uint32_t lv_remap_ptr;
2378 uint32_t lv_remap_end;
2379 uint32_t lv_chunk_size;
2380 uint32_t lv_snapshot_minor;
2381 char dummy[200];
2382 } lv32_t;
2383
2384 typedef struct {
2385 u32 hash[2];
2386 u32 rsector_org;
2387 kdev_t rdev_org;
2388 u32 rsector_new;
2389 kdev_t rdev_new;
2390 } lv_block_exception32_t;
2391
put_lv_t(lv_t * l)2392 static void put_lv_t(lv_t *l)
2393 {
2394 if (l->lv_current_pe) vfree(l->lv_current_pe);
2395 if (l->lv_block_exception) vfree(l->lv_block_exception);
2396 kfree(l);
2397 }
2398
get_lv_t(u32 p,int * errp)2399 static lv_t *get_lv_t(u32 p, int *errp)
2400 {
2401 int err, i;
2402 u32 ptr1, ptr2;
2403 size_t size;
2404 lv_block_exception32_t *lbe32;
2405 lv_block_exception_t *lbe;
2406 lv32_t *ul = (lv32_t *)A(p);
2407 lv_t *l = (lv_t *) kmalloc(sizeof(lv_t), GFP_KERNEL);
2408
2409 if (!l) {
2410 *errp = -ENOMEM;
2411 return NULL;
2412 }
2413 memset(l, 0, sizeof(lv_t));
2414 err = copy_from_user(l, ul, (long)&((lv32_t *)0)->lv_current_pe);
2415 err |= __copy_from_user(&l->lv_current_le, &ul->lv_current_le,
2416 ((long)&ul->lv_snapshot_org) - ((long)&ul->lv_current_le));
2417 err |= __copy_from_user(&l->lv_remap_ptr, &ul->lv_remap_ptr,
2418 ((long)&ul->dummy[0]) - ((long)&ul->lv_remap_ptr));
2419 err |= __get_user(ptr1, &ul->lv_current_pe);
2420 err |= __get_user(ptr2, &ul->lv_block_exception);
2421 if (err) {
2422 kfree(l);
2423 *errp = -EFAULT;
2424 return NULL;
2425 }
2426 if (ptr1) {
2427 if (l->lv_allocated_le > 2*PAGE_SIZE/sizeof(pe_t)) {
2428 kfree(l);
2429 *errp = -EINVAL;
2430 return NULL;
2431 }
2432 size = l->lv_allocated_le * sizeof(pe_t);
2433 l->lv_current_pe = vmalloc(size);
2434 if (l->lv_current_pe)
2435 err = copy_from_user(l->lv_current_pe, (void *)A(ptr1), size);
2436 }
2437 if (!err && ptr2) {
2438 /* small limit */
2439 /* just verify area it? */
2440 if (l->lv_remap_end > 256*PAGE_SIZE/sizeof(lv_block_exception_t)) {
2441 put_lv_t(l);
2442 *errp = -EINVAL;
2443 return NULL;
2444 }
2445 size = l->lv_remap_end * sizeof(lv_block_exception_t);
2446 l->lv_block_exception = lbe = vmalloc(size);
2447 if (l->lv_block_exception) {
2448 lbe32 = (lv_block_exception32_t *)A(ptr2);
2449 memset(lbe, 0, size);
2450 for (i = 0; i < l->lv_remap_end; i++, lbe++, lbe32++) {
2451 err |= get_user(lbe->rsector_org, &lbe32->rsector_org);
2452 err |= __get_user(lbe->rdev_org, &lbe32->rdev_org);
2453 err |= __get_user(lbe->rsector_new, &lbe32->rsector_new);
2454 err |= __get_user(lbe->rdev_new, &lbe32->rdev_new);
2455 }
2456 }
2457 }
2458 if (err || (ptr1 && !l->lv_current_pe) || (ptr2 && !l->lv_block_exception)) {
2459 if (!err)
2460 *errp = -ENOMEM;
2461 else
2462 *errp = -EFAULT;
2463 put_lv_t(l);
2464 return NULL;
2465 }
2466 return l;
2467 }
2468
copy_lv_t(u32 ptr,lv_t * l)2469 static int copy_lv_t(u32 ptr, lv_t *l)
2470 {
2471 int err;
2472 lv32_t *ul = (lv32_t *)A(ptr);
2473 u32 ptr1;
2474 size_t size;
2475
2476 err = get_user(ptr1, &ul->lv_current_pe);
2477 if (err)
2478 return -EFAULT;
2479 err = copy_to_user(ul, l, (long)&((lv32_t *)0)->lv_current_pe);
2480 err |= __copy_to_user(&ul->lv_current_le, &l->lv_current_le,
2481 ((long)&ul->lv_snapshot_org) - ((long)&ul->lv_current_le));
2482 err |= __copy_to_user(&ul->lv_remap_ptr, &l->lv_remap_ptr,
2483 ((long)&ul->dummy[0]) - ((long)&ul->lv_remap_ptr));
2484 size = l->lv_allocated_le * sizeof(pe_t);
2485 if (ptr1)
2486 err |= __copy_to_user((void *)A(ptr1), l->lv_current_pe, size);
2487 return err ? -EFAULT : 0;
2488 }
2489
do_lvm_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)2490 static int do_lvm_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2491 {
2492 vg_t *v = NULL;
2493 union {
2494 lv_req_t lv_req;
2495 le_remap_req_t le_remap;
2496 lv_status_byindex_req_t lv_byindex;
2497 lv_status_bydev_req_t lv_bydev;
2498 pv_status_req_t pv_status;
2499 } u;
2500 pv_t p;
2501 int err;
2502 u32 ptr = 0;
2503 int i;
2504 mm_segment_t old_fs;
2505 void *karg = &u;
2506
2507 if (!capable(CAP_SYS_ADMIN))
2508 return -EACCES;
2509
2510 switch (cmd) {
2511 case VG_STATUS:
2512 v = kmalloc(sizeof(vg_t), GFP_KERNEL);
2513 if (!v)
2514 return -ENOMEM;
2515 karg = v;
2516 break;
2517
2518 case VG_CREATE_OLD:
2519 case VG_CREATE:
2520 v = kmalloc(sizeof(vg_t), GFP_KERNEL);
2521 if (!v)
2522 return -ENOMEM;
2523 if (copy_from_user(v, (void *)arg, (long)&((vg32_t *)0)->proc)) {
2524 kfree(v);
2525 return -EFAULT;
2526 }
2527 /* 'proc' field is unused, just NULL it out. */
2528 v->proc = NULL;
2529 if (copy_from_user(v->vg_uuid, ((vg32_t *)arg)->vg_uuid, UUID_LEN+1)) {
2530 kfree(v);
2531 return -EFAULT;
2532 }
2533
2534 karg = v;
2535 memset(v->pv, 0, sizeof(v->pv) + sizeof(v->lv));
2536 if (v->pv_max > ABS_MAX_PV || v->lv_max > ABS_MAX_LV)
2537 return -EPERM;
2538 for (i = 0; i < v->pv_max; i++) {
2539 err = __get_user(ptr, &((vg32_t *)arg)->pv[i]);
2540 if (err)
2541 break;
2542 if (ptr) {
2543 v->pv[i] = kmalloc(sizeof(pv_t), GFP_KERNEL);
2544 if (!v->pv[i]) {
2545 err = -ENOMEM;
2546 break;
2547 }
2548 err = copy_from_user(v->pv[i], (void *)A(ptr),
2549 sizeof(pv32_t) - 8 - UUID_LEN+1);
2550 if (err) {
2551 err = -EFAULT;
2552 break;
2553 }
2554 err = copy_from_user(v->pv[i]->pv_uuid,
2555 ((pv32_t *)A(ptr))->pv_uuid,
2556 UUID_LEN+1);
2557 if (err) {
2558 err = -EFAULT;
2559 break;
2560 }
2561
2562 v->pv[i]->pe = NULL;
2563 v->pv[i]->bd = NULL;
2564 }
2565 }
2566 if (!err) {
2567 for (i = 0; i < v->lv_max; i++) {
2568 err = __get_user(ptr, &((vg32_t *)arg)->lv[i]);
2569 if (err)
2570 break;
2571 if (ptr) {
2572 v->lv[i] = get_lv_t(ptr, &err);
2573 if (err)
2574 break;
2575 }
2576 }
2577 }
2578 break;
2579
2580 case LV_CREATE:
2581 case LV_EXTEND:
2582 case LV_REDUCE:
2583 case LV_REMOVE:
2584 case LV_RENAME:
2585 case LV_STATUS_BYNAME:
2586 err = copy_from_user(&u.pv_status, (void*)arg, sizeof(u.pv_status.pv_name));
2587 if (err)
2588 return -EFAULT;
2589 if (cmd != LV_REMOVE) {
2590 err = __get_user(ptr, &((lv_req32_t *)arg)->lv);
2591 if (err)
2592 return err;
2593 u.lv_req.lv = get_lv_t(ptr, &err);
2594 } else
2595 u.lv_req.lv = NULL;
2596 break;
2597
2598 case LV_STATUS_BYINDEX:
2599 err = get_user(u.lv_byindex.lv_index,
2600 &((lv_status_byindex_req32_t *)arg)->lv_index);
2601 err |= __get_user(ptr, &((lv_status_byindex_req32_t *)arg)->lv);
2602 if (err)
2603 return err;
2604 u.lv_byindex.lv = get_lv_t(ptr, &err);
2605 break;
2606
2607 case LV_STATUS_BYDEV:
2608 err = get_user(u.lv_bydev.dev, &((lv_status_bydev_req32_t *)arg)->dev);
2609 err |= __get_user(ptr, &((lv_status_bydev_req32_t *)arg)->lv);
2610 if (err)
2611 return err;
2612 u.lv_bydev.lv = get_lv_t(ptr, &err);
2613 break;
2614
2615 case VG_EXTEND:
2616 err = copy_from_user(&p, (void *)arg, sizeof(pv32_t) - 8 - UUID_LEN+1);
2617 if (err)
2618 return -EFAULT;
2619 err = copy_from_user(p.pv_uuid, ((pv32_t *)arg)->pv_uuid, UUID_LEN+1);
2620 if (err)
2621 return -EFAULT;
2622 p.pe = NULL;
2623 p.bd = NULL;
2624 karg = &p;
2625 break;
2626
2627 case PV_CHANGE:
2628 case PV_STATUS:
2629 err = copy_from_user(&u.pv_status, (void*)arg, sizeof(u.lv_req.lv_name));
2630 if (err)
2631 return -EFAULT;
2632 err = __get_user(ptr, &((pv_status_req32_t *)arg)->pv);
2633 if (err)
2634 return err;
2635 u.pv_status.pv = &p;
2636 if (cmd == PV_CHANGE) {
2637 err = copy_from_user(&p, (void *)A(ptr),
2638 sizeof(pv32_t) - 8 - UUID_LEN+1);
2639 if (err)
2640 return -EFAULT;
2641 p.pe = NULL;
2642 p.bd = NULL;
2643 }
2644 break;
2645 };
2646
2647 old_fs = get_fs(); set_fs (KERNEL_DS);
2648 err = sys_ioctl (fd, cmd, (unsigned long)karg);
2649 set_fs (old_fs);
2650
2651 switch (cmd) {
2652 case VG_STATUS:
2653 if (!err) {
2654 if (copy_to_user((void *)arg, v, (long)&((vg32_t *)0)->proc) ||
2655 clear_user(&((vg32_t *)arg)->proc, sizeof(vg32_t) - (long)&((vg32_t *)0)->proc))
2656 err = -EFAULT;
2657 }
2658 if (copy_to_user(((vg32_t *)arg)->vg_uuid, v->vg_uuid, UUID_LEN+1)) {
2659 err = -EFAULT;
2660 }
2661 kfree(v);
2662 break;
2663
2664 case VG_CREATE_OLD:
2665 case VG_CREATE:
2666 for (i = 0; i < v->pv_max; i++) {
2667 if (v->pv[i])
2668 kfree(v->pv[i]);
2669 }
2670 for (i = 0; i < v->lv_max; i++) {
2671 if (v->lv[i])
2672 put_lv_t(v->lv[i]);
2673 }
2674 kfree(v);
2675 break;
2676
2677 case LV_STATUS_BYNAME:
2678 if (!err && u.lv_req.lv)
2679 err = copy_lv_t(ptr, u.lv_req.lv);
2680 /* Fall through */
2681
2682 case LV_CREATE:
2683 case LV_EXTEND:
2684 case LV_REDUCE:
2685 if (u.lv_req.lv)
2686 put_lv_t(u.lv_req.lv);
2687 break;
2688
2689 case LV_STATUS_BYINDEX:
2690 if (u.lv_byindex.lv) {
2691 if (!err)
2692 err = copy_lv_t(ptr, u.lv_byindex.lv);
2693 put_lv_t(u.lv_byindex.lv);
2694 }
2695 break;
2696
2697 case LV_STATUS_BYDEV:
2698 if (u.lv_bydev.lv) {
2699 if (!err)
2700 err = copy_lv_t(ptr, u.lv_bydev.lv);
2701 put_lv_t(u.lv_byindex.lv);
2702 }
2703 break;
2704
2705 case PV_STATUS:
2706 if (!err) {
2707 err = copy_to_user((void *)A(ptr), &p, sizeof(pv32_t) - 8 - UUID_LEN+1);
2708 if (err)
2709 return -EFAULT;
2710 err = copy_to_user(((pv_t *)A(ptr))->pv_uuid, p.pv_uuid, UUID_LEN + 1);
2711 if (err)
2712 return -EFAULT;
2713 }
2714 break;
2715 };
2716
2717 return err;
2718 }
2719 #endif
2720
ret_einval(unsigned int fd,unsigned int cmd,unsigned long arg)2721 static int ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
2722 {
2723 return -EINVAL;
2724 }
2725
broken_blkgetsize(unsigned int fd,unsigned int cmd,unsigned long arg)2726 static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
2727 {
2728 /* The mkswap binary hard codes it to Intel value :-((( */
2729 return w_long(fd, BLKGETSIZE, arg);
2730 }
2731
2732 struct blkpg_ioctl_arg32 {
2733 int op;
2734 int flags;
2735 int datalen;
2736 u32 data;
2737 };
2738
blkpg_ioctl_trans(unsigned int fd,unsigned int cmd,struct blkpg_ioctl_arg32 * arg)2739 static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, struct blkpg_ioctl_arg32 *arg)
2740 {
2741 struct blkpg_ioctl_arg a;
2742 struct blkpg_partition p;
2743 u32 udata;
2744 int err;
2745 mm_segment_t old_fs = get_fs();
2746
2747 err = get_user(a.op, &arg->op);
2748 err |= __get_user(a.flags, &arg->flags);
2749 err |= __get_user(a.datalen, &arg->datalen);
2750 err |= __get_user(udata, &arg->data);
2751 a.data = (void*)(u64)udata;
2752 if (err) return err;
2753 switch (a.op) {
2754 case BLKPG_ADD_PARTITION:
2755 case BLKPG_DEL_PARTITION:
2756 if (a.datalen < sizeof(struct blkpg_partition))
2757 return -EINVAL;
2758 if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition)))
2759 return -EFAULT;
2760 a.data = &p;
2761 set_fs (KERNEL_DS);
2762 err = sys_ioctl(fd, cmd, (unsigned long)&a);
2763 set_fs (old_fs);
2764 default:
2765 return -EINVAL;
2766 }
2767 return err;
2768 }
2769
ioc_settimeout(unsigned int fd,unsigned int cmd,unsigned long arg)2770 static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
2771 {
2772 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
2773 }
2774
2775 #ifndef TIOCGDEV
2776 #define TIOCGDEV _IOR('T',0x32, unsigned int)
2777 #endif
tiocgdev(unsigned fd,unsigned cmd,unsigned int * ptr)2778 static int tiocgdev(unsigned fd, unsigned cmd, unsigned int *ptr)
2779 {
2780
2781 struct file *file;
2782 struct tty_struct *real_tty;
2783 int ret;
2784
2785 file = fget(fd);
2786 if (!file)
2787 return -EBADF;
2788 ret = -EINVAL;
2789 if (file->f_op->ioctl != tty_ioctl)
2790 goto out;
2791 real_tty = (struct tty_struct *)file->private_data;
2792 if (!real_tty)
2793 goto out;
2794 ret = put_user(kdev_t_to_nr(real_tty->device), ptr);
2795 out:
2796 fput(file);
2797
2798 return ret;
2799 }
2800
2801
2802 struct raw32_config_request
2803 {
2804 int raw_minor;
2805 __u64 block_major;
2806 __u64 block_minor;
2807 } __attribute__((packed));
2808
raw_ioctl(unsigned fd,unsigned cmd,void * ptr)2809 static int raw_ioctl(unsigned fd, unsigned cmd, void *ptr)
2810 {
2811 int ret;
2812 switch (cmd) {
2813 case RAW_SETBIND:
2814 case RAW_GETBIND: {
2815 struct raw_config_request req;
2816 struct raw32_config_request *user_req = ptr;
2817 mm_segment_t oldfs = get_fs();
2818
2819 if (get_user(req.raw_minor, &user_req->raw_minor) ||
2820 get_user(req.block_major, &user_req->block_major) ||
2821 get_user(req.block_minor, &user_req->block_minor))
2822 return -EFAULT;
2823 set_fs(KERNEL_DS);
2824 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2825 set_fs(oldfs);
2826 break;
2827 }
2828 default:
2829 ret = sys_ioctl(fd,cmd,(unsigned long)ptr);
2830 break;
2831 }
2832 return ret;
2833 }
2834
2835 struct serial_struct32 {
2836 int type;
2837 int line;
2838 unsigned int port;
2839 int irq;
2840 int flags;
2841 int xmit_fifo_size;
2842 int custom_divisor;
2843 int baud_base;
2844 unsigned short close_delay;
2845 char io_type;
2846 char reserved_char[1];
2847 int hub6;
2848 unsigned short closing_wait; /* time to wait before closing */
2849 unsigned short closing_wait2; /* no longer used... */
2850 __u32 iomem_base;
2851 unsigned short iomem_reg_shift;
2852 unsigned int port_high;
2853 int reserved[1];
2854 };
2855
serial_struct_ioctl(unsigned fd,unsigned cmd,void * ptr)2856 static int serial_struct_ioctl(unsigned fd, unsigned cmd, void *ptr)
2857 {
2858 typedef struct serial_struct SS;
2859 struct serial_struct32 *ss32 = ptr;
2860 int err;
2861 struct serial_struct ss;
2862 mm_segment_t oldseg = get_fs();
2863 if (cmd == TIOCSSERIAL) {
2864 if (copy_from_user(&ss, ss32, sizeof(struct serial_struct32)))
2865 return -EFAULT;
2866 memmove(&ss.iomem_reg_shift, ((char*)&ss.iomem_base)+4,
2867 sizeof(SS)-offsetof(SS,iomem_reg_shift));
2868 ss.iomem_base = (void *)((unsigned long)ss.iomem_base & 0xffffffff);
2869 }
2870 set_fs(KERNEL_DS);
2871 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2872 set_fs(oldseg);
2873 if (cmd == TIOCGSERIAL && err >= 0) {
2874 if (__copy_to_user(ss32,&ss,offsetof(SS,iomem_base)) ||
2875 __put_user((unsigned long)ss.iomem_base >> 32 ?
2876 0xffffffff : (unsigned)(unsigned long)ss.iomem_base,
2877 &ss32->iomem_base) ||
2878 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
2879 __put_user(ss.port_high, &ss32->port_high))
2880 return -EFAULT;
2881 }
2882 return err;
2883 }
2884
2885 /* Bluetooth ioctls */
2886 #define HCIUARTSETPROTO _IOW('U', 200, int)
2887 #define HCIUARTGETPROTO _IOR('U', 201, int)
2888
2889 #define BNEPCONNADD _IOW('B', 200, int)
2890 #define BNEPCONNDEL _IOW('B', 201, int)
2891 #define BNEPGETCONNLIST _IOR('B', 210, int)
2892 #define BNEPGETCONNINFO _IOR('B', 211, int)
2893
2894 #define REISERFS_IOC_UNPACK32 _IOW(0xCD,1,int)
2895
reiserfs_ioctl32(unsigned fd,unsigned cmd,unsigned long ptr)2896 static int reiserfs_ioctl32(unsigned fd, unsigned cmd, unsigned long ptr)
2897 {
2898 if (cmd == REISERFS_IOC_UNPACK32)
2899 cmd = REISERFS_IOC_UNPACK;
2900 return sys_ioctl(fd,cmd,ptr);
2901 }
2902
2903 struct dirent32 {
2904 unsigned int d_ino;
2905 __kernel_off_t32 d_off;
2906 unsigned short d_reclen;
2907 char d_name[256]; /* We must not include limits.h! */
2908 };
2909
2910 #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct dirent32 [2])
2911 #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct dirent32 [2])
2912
put_dirent32(struct dirent * src,struct dirent32 * dst)2913 static int put_dirent32(struct dirent *src, struct dirent32 *dst)
2914 {
2915 int ret;
2916 ret = put_user(src->d_ino, &dst->d_ino);
2917 ret |= __put_user(src->d_off, &dst->d_off);
2918 ret |= __put_user(src->d_reclen, &dst->d_reclen);
2919 if (__copy_to_user(&dst->d_name, src->d_name, src->d_reclen))
2920 ret |= -EFAULT;
2921 return ret;
2922 }
2923
vfat_ioctl32(unsigned fd,unsigned cmd,void * ptr)2924 static int vfat_ioctl32(unsigned fd, unsigned cmd, void *ptr)
2925 {
2926 int ret;
2927 mm_segment_t oldfs = get_fs();
2928 struct dirent d[2];
2929
2930 set_fs(KERNEL_DS);
2931 ret = sys_ioctl(fd,cmd,(unsigned long)&d);
2932 set_fs(oldfs);
2933 if (!ret) {
2934 ret |= put_dirent32(&d[0], (struct dirent32 *)ptr);
2935 ret |= put_dirent32(&d[1], ((struct dirent32 *)ptr) + 1);
2936 }
2937 return ret;
2938 }
2939
2940 #define RTC_IRQP_READ32 _IOR('p', 0x0b, unsigned int) /* Read IRQ rate */
2941 #define RTC_IRQP_SET32 _IOW('p', 0x0c, unsigned int) /* Set IRQ rate */
2942 #define RTC_EPOCH_READ32 _IOR('p', 0x0d, unsigned) /* Read epoch */
2943 #define RTC_EPOCH_SET32 _IOW('p', 0x0e, unsigned) /* Set epoch */
2944
rtc32_ioctl(unsigned fd,unsigned cmd,unsigned long arg)2945 static int rtc32_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2946 {
2947 unsigned long val;
2948 mm_segment_t oldfs = get_fs();
2949 int ret;
2950
2951 switch (cmd) {
2952 case RTC_IRQP_READ32:
2953 set_fs(KERNEL_DS);
2954 ret = sys_ioctl(fd, RTC_IRQP_READ, (unsigned long)&val);
2955 set_fs(oldfs);
2956 if (!ret)
2957 ret = put_user(val, (unsigned int*) arg);
2958 return ret;
2959
2960 case RTC_IRQP_SET32:
2961 cmd = RTC_IRQP_SET;
2962 break;
2963
2964 case RTC_EPOCH_READ32:
2965 set_fs(KERNEL_DS);
2966 ret = sys_ioctl(fd, RTC_EPOCH_READ, (unsigned long) &val);
2967 set_fs(oldfs);
2968 if (!ret)
2969 ret = put_user(val, (unsigned int*) arg);
2970 return ret;
2971
2972 case RTC_EPOCH_SET32:
2973 cmd = RTC_EPOCH_SET;
2974 break;
2975 }
2976 return sys_ioctl(fd,cmd,arg);
2977 }
2978
2979 /* Fix sizeof(sizeof()) breakage */
2980 #define BLKELVGET_32 _IOR(0x12,106,int)
2981 #define BLKELVSET_32 _IOW(0x12,107,int)
2982 #define BLKBSZGET_32 _IOR(0x12,112,int)
2983 #define BLKBSZSET_32 _IOW(0x12,113,int)
2984 #define BLKGETSIZE64_32 _IOR(0x12,114,int)
2985
do_blkelvget(unsigned int fd,unsigned int cmd,unsigned long arg)2986 static int do_blkelvget(unsigned int fd, unsigned int cmd, unsigned long arg)
2987 {
2988 return sys_ioctl(fd, BLKELVGET, arg);
2989 }
2990
do_blkelvset(unsigned int fd,unsigned int cmd,unsigned long arg)2991 static int do_blkelvset(unsigned int fd, unsigned int cmd, unsigned long arg)
2992 {
2993 return sys_ioctl(fd, BLKELVSET, arg);
2994 }
2995
do_blkbszget(unsigned int fd,unsigned int cmd,unsigned long arg)2996 static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
2997 {
2998 return sys_ioctl(fd, BLKBSZGET, arg);
2999 }
3000
do_blkbszset(unsigned int fd,unsigned int cmd,unsigned long arg)3001 static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
3002 {
3003 return sys_ioctl(fd, BLKBSZSET, arg);
3004 }
3005
do_blkgetsize64(unsigned int fd,unsigned int cmd,unsigned long arg)3006 static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
3007 unsigned long arg)
3008 {
3009 return sys_ioctl(fd, BLKGETSIZE64, arg);
3010 }
3011
3012 /* Bluetooth ioctls */
3013 #define HCIUARTSETPROTO _IOW('U', 200, int)
3014 #define HCIUARTGETPROTO _IOR('U', 201, int)
3015
3016 #define BNEPCONNADD _IOW('B', 200, int)
3017 #define BNEPCONNDEL _IOW('B', 201, int)
3018 #define BNEPGETCONNLIST _IOR('B', 210, int)
3019 #define BNEPGETCONNINFO _IOR('B', 211, int)
3020
3021 struct usbdevfs_ctrltransfer32 {
3022 __u8 requesttype;
3023 __u8 request;
3024 __u16 value;
3025 __u16 index;
3026 __u16 length;
3027 __u32 timeout; /* in milliseconds */
3028 __u32 data;
3029 };
3030
3031 #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
3032
do_usbdevfs_control(unsigned int fd,unsigned int cmd,unsigned long arg)3033 static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
3034 {
3035 struct usbdevfs_ctrltransfer kctrl;
3036 struct usbdevfs_ctrltransfer32 *uctrl;
3037 mm_segment_t old_fs;
3038 __u32 udata;
3039 void *uptr, *kptr;
3040 int err;
3041
3042 uctrl = (struct usbdevfs_ctrltransfer32 *) arg;
3043
3044 if (copy_from_user(&kctrl, uctrl,
3045 (sizeof(struct usbdevfs_ctrltransfer) -
3046 sizeof(void *))))
3047 return -EFAULT;
3048
3049 if (get_user(udata, &uctrl->data))
3050 return -EFAULT;
3051 uptr = (void *) A(udata);
3052
3053 /* In usbdevice_fs, it limits the control buffer to a page,
3054 * for simplicity so do we.
3055 */
3056 if (!uptr || kctrl.length > PAGE_SIZE)
3057 return -EINVAL;
3058
3059 kptr = (void *)__get_free_page(GFP_KERNEL);
3060
3061 if ((kctrl.requesttype & 0x80) == 0) {
3062 err = -EFAULT;
3063 if (copy_from_user(kptr, uptr, kctrl.length))
3064 goto out;
3065 }
3066
3067 kctrl.data = kptr;
3068
3069 old_fs = get_fs();
3070 set_fs(KERNEL_DS);
3071 err = sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)&kctrl);
3072 set_fs(old_fs);
3073
3074 if (err >= 0 &&
3075 ((kctrl.requesttype & 0x80) != 0)) {
3076 if (copy_to_user(uptr, kptr, kctrl.length))
3077 err = -EFAULT;
3078 }
3079
3080 out:
3081 free_page((unsigned long) kptr);
3082 return err;
3083 }
3084
3085 struct usbdevfs_bulktransfer32 {
3086 unsigned int ep;
3087 unsigned int len;
3088 unsigned int timeout; /* in milliseconds */
3089 __u32 data;
3090 };
3091
3092 #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
3093
do_usbdevfs_bulk(unsigned int fd,unsigned int cmd,unsigned long arg)3094 static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
3095 {
3096 struct usbdevfs_bulktransfer kbulk;
3097 struct usbdevfs_bulktransfer32 *ubulk;
3098 mm_segment_t old_fs;
3099 __u32 udata;
3100 void *uptr, *kptr;
3101 int err;
3102
3103 ubulk = (struct usbdevfs_bulktransfer32 *) arg;
3104
3105 if (get_user(kbulk.ep, &ubulk->ep) ||
3106 get_user(kbulk.len, &ubulk->len) ||
3107 get_user(kbulk.timeout, &ubulk->timeout) ||
3108 get_user(udata, &ubulk->data))
3109 return -EFAULT;
3110
3111 uptr = (void *) A(udata);
3112
3113 /* In usbdevice_fs, it limits the control buffer to a page,
3114 * for simplicity so do we.
3115 */
3116 if (!uptr || kbulk.len > PAGE_SIZE)
3117 return -EINVAL;
3118
3119 kptr = (void *) __get_free_page(GFP_KERNEL);
3120
3121 if ((kbulk.ep & 0x80) == 0) {
3122 err = -EFAULT;
3123 if (copy_from_user(kptr, uptr, kbulk.len))
3124 goto out;
3125 }
3126
3127 kbulk.data = kptr;
3128
3129 old_fs = get_fs();
3130 set_fs(KERNEL_DS);
3131 err = sys_ioctl(fd, USBDEVFS_BULK, (unsigned long) &kbulk);
3132 set_fs(old_fs);
3133
3134 if (err >= 0 &&
3135 ((kbulk.ep & 0x80) != 0)) {
3136 if (copy_to_user(uptr, kptr, kbulk.len))
3137 err = -EFAULT;
3138 }
3139
3140 out:
3141 free_page((unsigned long) kptr);
3142 return err;
3143 }
3144
3145 /* This needs more work before we can enable it. Unfortunately
3146 * because of the fancy asynchronous way URB status/error is written
3147 * back to userspace, we'll need to fiddle with USB devio internals
3148 * and/or reimplement entirely the frontend of it ourselves. -DaveM
3149 *
3150 * The issue is:
3151 *
3152 * When an URB is submitted via usbdevicefs it is put onto an
3153 * asynchronous queue. When the URB completes, it may be reaped
3154 * via another ioctl. During this reaping the status is written
3155 * back to userspace along with the length of the transfer.
3156 *
3157 * We must translate into 64-bit kernel types so we pass in a kernel
3158 * space copy of the usbdevfs_urb structure. This would mean that we
3159 * must do something to deal with the async entry reaping. First we
3160 * have to deal somehow with this transitory memory we've allocated.
3161 * This is problematic since there are many call sites from which the
3162 * async entries can be destroyed (and thus when we'd need to free up
3163 * this kernel memory). One of which is the close() op of usbdevicefs.
3164 * To handle that we'd need to make our own file_operations struct which
3165 * overrides usbdevicefs's release op with our own which runs usbdevicefs's
3166 * real release op then frees up the kernel memory.
3167 *
3168 * But how to keep track of these kernel buffers? We'd need to either
3169 * keep track of them in some table _or_ know about usbdevicefs internals
3170 * (ie. the exact layout of it's file private, which is actually defined
3171 * in linux/usbdevice_fs.h, the layout of the async queues are private to
3172 * devio.c)
3173 *
3174 * There is one possible other solution I considered, also involving knowledge
3175 * of usbdevicefs internals:
3176 *
3177 * After an URB is submitted, we "fix up" the address back to the user
3178 * space one. This would work if the status/length fields written back
3179 * by the async URB completion lines up perfectly in the 32-bit type with
3180 * the 64-bit kernel type. Unfortunately, it does not because the iso
3181 * frame descriptors, at the end of the struct, can be written back.
3182 *
3183 * I think we'll just need to simply duplicate the devio URB engine here.
3184 */
3185 #if 0
3186 struct usbdevfs_urb32 {
3187 __u8 type;
3188 __u8 endpoint;
3189 __s32 status;
3190 __u32 flags;
3191 __u32 buffer;
3192 __s32 buffer_length;
3193 __s32 actual_length;
3194 __s32 start_frame;
3195 __s32 number_of_packets;
3196 __s32 error_count;
3197 __u32 signr;
3198 __u32 usercontext; /* unused */
3199 struct usbdevfs_iso_packet_desc iso_frame_desc[0];
3200 };
3201
3202 #define USBDEVFS_SUBMITURB32 _IOR('U', 10, struct usbdevfs_urb32)
3203
3204 static int get_urb32(struct usbdevfs_urb *kurb,
3205 struct usbdevfs_urb32 *uurb)
3206 {
3207 if (get_user(kurb->type, &uurb->type) ||
3208 __get_user(kurb->endpoint, &uurb->endpoint) ||
3209 __get_user(kurb->status, &uurb->status) ||
3210 __get_user(kurb->flags, &uurb->flags) ||
3211 __get_user(kurb->buffer_length, &uurb->buffer_length) ||
3212 __get_user(kurb->actual_length, &uurb->actual_length) ||
3213 __get_user(kurb->start_frame, &uurb->start_frame) ||
3214 __get_user(kurb->number_of_packets, &uurb->number_of_packets) ||
3215 __get_user(kurb->error_count, &uurb->error_count) ||
3216 __get_user(kurb->signr, &uurb->signr))
3217 return -EFAULT;
3218
3219 kurb->usercontext = 0; /* unused currently */
3220
3221 return 0;
3222 }
3223
3224 /* Just put back the values which usbdevfs actually changes. */
3225 static int put_urb32(struct usbdevfs_urb *kurb,
3226 struct usbdevfs_urb32 *uurb)
3227 {
3228 if (put_user(kurb->status, &uurb->status) ||
3229 __put_user(kurb->actual_length, &uurb->actual_length) ||
3230 __put_user(kurb->error_count, &uurb->error_count))
3231 return -EFAULT;
3232
3233 if (kurb->number_of_packets != 0) {
3234 int i;
3235
3236 for (i = 0; i < kurb->number_of_packets; i++) {
3237 if (__put_user(kurb->iso_frame_desc[i].actual_length,
3238 &uurb->iso_frame_desc[i].actual_length) ||
3239 __put_user(kurb->iso_frame_desc[i].status,
3240 &uurb->iso_frame_desc[i].status))
3241 return -EFAULT;
3242 }
3243 }
3244
3245 return 0;
3246 }
3247
3248 static int get_urb32_isoframes(struct usbdevfs_urb *kurb,
3249 struct usbdevfs_urb32 *uurb)
3250 {
3251 unsigned int totlen;
3252 int i;
3253
3254 if (kurb->type != USBDEVFS_URB_TYPE_ISO) {
3255 kurb->number_of_packets = 0;
3256 return 0;
3257 }
3258
3259 if (kurb->number_of_packets < 1 ||
3260 kurb->number_of_packets > 128)
3261 return -EINVAL;
3262
3263 if (copy_from_user(&kurb->iso_frame_desc[0],
3264 &uurb->iso_frame_desc[0],
3265 sizeof(struct usbdevfs_iso_packet_desc) *
3266 kurb->number_of_packets))
3267 return -EFAULT;
3268
3269 totlen = 0;
3270 for (i = 0; i < kurb->number_of_packets; i++) {
3271 unsigned int this_len;
3272
3273 this_len = kurb->iso_frame_desc[i].length;
3274 if (this_len > 1023)
3275 return -EINVAL;
3276
3277 totlen += this_len;
3278 }
3279
3280 if (totlen > 32768)
3281 return -EINVAL;
3282
3283 kurb->buffer_length = totlen;
3284
3285 return 0;
3286 }
3287
3288 static int do_usbdevfs_urb(unsigned int fd, unsigned int cmd, unsigned long arg)
3289 {
3290 struct usbdevfs_urb *kurb;
3291 struct usbdevfs_urb32 *uurb;
3292 mm_segment_t old_fs;
3293 __u32 udata;
3294 void *uptr, *kptr;
3295 unsigned int buflen;
3296 int err;
3297
3298 uurb = (struct usbdevfs_urb32 *) arg;
3299
3300 err = -ENOMEM;
3301 kurb = kmalloc(sizeof(struct usbdevfs_urb) +
3302 (sizeof(struct usbdevfs_iso_packet_desc) * 128),
3303 GFP_KERNEL);
3304 if (!kurb)
3305 goto out;
3306
3307 err = -EFAULT;
3308 if (get_urb32(kurb, uurb))
3309 goto out;
3310
3311 err = get_urb32_isoframes(kurb, uurb);
3312 if (err)
3313 goto out;
3314
3315 err = -EFAULT;
3316 if (__get_user(udata, &uurb->buffer))
3317 goto out;
3318 uptr = (void *) A(udata);
3319
3320 buflen = kurb->buffer_length;
3321 err = verify_area(VERIFY_WRITE, uptr, buflen);
3322 if (err)
3323 goto out;
3324
3325
3326 old_fs = get_fs();
3327 set_fs(KERNEL_DS);
3328 err = sys_ioctl(fd, USBDEVFS_SUBMITURB, (unsigned long) kurb);
3329 set_fs(old_fs);
3330
3331 if (err >= 0) {
3332 /* XXX Shit, this doesn't work for async URBs :-( XXX */
3333 if (put_urb32(kurb, uurb)) {
3334 err = -EFAULT;
3335 }
3336 }
3337
3338 out:
3339 kfree(kurb);
3340 return err;
3341 }
3342 #endif
3343
3344 #define USBDEVFS_REAPURB32 _IOW('U', 12, u32)
3345 #define USBDEVFS_REAPURBNDELAY32 _IOW('U', 13, u32)
3346
do_usbdevfs_reapurb(unsigned int fd,unsigned int cmd,unsigned long arg)3347 static int do_usbdevfs_reapurb(unsigned int fd, unsigned int cmd, unsigned long arg)
3348 {
3349 mm_segment_t old_fs;
3350 void *kptr;
3351 int err;
3352
3353 old_fs = get_fs();
3354 set_fs(KERNEL_DS);
3355 err = sys_ioctl(fd,
3356 (cmd == USBDEVFS_REAPURB32 ?
3357 USBDEVFS_REAPURB :
3358 USBDEVFS_REAPURBNDELAY),
3359 (unsigned long) &kptr);
3360 set_fs(old_fs);
3361
3362 if (err >= 0 &&
3363 put_user(((u32)(long)kptr), (u32 *) A(arg)))
3364 err = -EFAULT;
3365
3366 return err;
3367 }
3368
3369 struct usbdevfs_disconnectsignal32 {
3370 unsigned int signr;
3371 u32 context;
3372 };
3373
3374 #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
3375
do_usbdevfs_discsignal(unsigned int fd,unsigned int cmd,unsigned long arg)3376 static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
3377 {
3378 struct usbdevfs_disconnectsignal kdis;
3379 struct usbdevfs_disconnectsignal32 *udis;
3380 mm_segment_t old_fs;
3381 u32 uctx;
3382 int err;
3383
3384 udis = (struct usbdevfs_disconnectsignal32 *) arg;
3385
3386 if (get_user(kdis.signr, &udis->signr) ||
3387 __get_user(uctx, &udis->context))
3388 return -EFAULT;
3389
3390 kdis.context = (void *) (long)uctx;
3391
3392 old_fs = get_fs();
3393 set_fs(KERNEL_DS);
3394 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
3395 set_fs(old_fs);
3396
3397 return err;
3398 }
3399
3400 struct mtd_oob_buf32 {
3401 u32 start;
3402 u32 length;
3403 u32 ptr; /* unsigned char* */
3404 };
3405
3406 #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
3407 #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
3408
mtd_rw_oob(unsigned int fd,unsigned int cmd,unsigned long arg)3409 static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
3410 {
3411 mm_segment_t old_fs = get_fs();
3412 struct mtd_oob_buf32 *uarg = (struct mtd_oob_buf32 *)arg;
3413 struct mtd_oob_buf karg;
3414 u32 tmp;
3415 int ret;
3416
3417 if (get_user(karg.start, &uarg->start) ||
3418 get_user(karg.length, &uarg->length) ||
3419 get_user(tmp, &uarg->ptr))
3420 return -EFAULT;
3421
3422 karg.ptr = A(tmp);
3423 if (verify_area(VERIFY_WRITE, karg.ptr, karg.length))
3424 return -EFAULT;
3425
3426 set_fs(KERNEL_DS);
3427 if (MEMREADOOB32 == cmd)
3428 ret = sys_ioctl(fd, MEMREADOOB, (unsigned long)&karg);
3429 else if (MEMWRITEOOB32 == cmd)
3430 ret = sys_ioctl(fd, MEMWRITEOOB, (unsigned long)&karg);
3431 else
3432 ret = -EINVAL;
3433 set_fs(old_fs);
3434
3435 if (0 == ret && cmd == MEMREADOOB32) {
3436 ret = put_user(karg.start, &uarg->start);
3437 ret |= put_user(karg.length, &uarg->length);
3438 }
3439
3440 return ret;
3441 }
3442
3443 /* /proc/mtrr ioctls */
3444
3445
3446 struct mtrr_sentry32
3447 {
3448 unsigned int base; /* Base address */
3449 unsigned int size; /* Size of region */
3450 unsigned int type; /* Type of region */
3451 };
3452
3453 struct mtrr_gentry32
3454 {
3455 unsigned int regnum; /* Register number */
3456 unsigned int base; /* Base address */
3457 unsigned int size; /* Size of region */
3458 unsigned int type; /* Type of region */
3459 };
3460
3461 #define MTRR_IOCTL_BASE 'M'
3462
3463 #define MTRRIOC32_ADD_ENTRY _IOW(MTRR_IOCTL_BASE, 0, struct mtrr_sentry32)
3464 #define MTRRIOC32_SET_ENTRY _IOW(MTRR_IOCTL_BASE, 1, struct mtrr_sentry32)
3465 #define MTRRIOC32_DEL_ENTRY _IOW(MTRR_IOCTL_BASE, 2, struct mtrr_sentry32)
3466 #define MTRRIOC32_GET_ENTRY _IOWR(MTRR_IOCTL_BASE, 3, struct mtrr_gentry32)
3467 #define MTRRIOC32_KILL_ENTRY _IOW(MTRR_IOCTL_BASE, 4, struct mtrr_sentry32)
3468 #define MTRRIOC32_ADD_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 5, struct mtrr_sentry32)
3469 #define MTRRIOC32_SET_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 6, struct mtrr_sentry32)
3470 #define MTRRIOC32_DEL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 7, struct mtrr_sentry32)
3471 #define MTRRIOC32_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry32)
3472 #define MTRRIOC32_KILL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry32)
3473
3474
mtrr_ioctl32(unsigned int fd,unsigned int cmd,unsigned long arg)3475 static int mtrr_ioctl32(unsigned int fd, unsigned int cmd, unsigned long arg)
3476 {
3477 struct mtrr_gentry g;
3478 struct mtrr_sentry s;
3479 int get = 0, err = 0;
3480 struct mtrr_gentry32 *g32 = (struct mtrr_gentry32 *)arg;
3481 mm_segment_t oldfs = get_fs();
3482
3483 switch (cmd) {
3484 #define SET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; break
3485 #define GET(x) case MTRRIOC32_ ## x ## _ENTRY: cmd = MTRRIOC_ ## x ## _ENTRY; get=1; break
3486 SET(ADD);
3487 SET(SET);
3488 SET(DEL);
3489 GET(GET);
3490 SET(KILL);
3491 SET(ADD_PAGE);
3492 SET(SET_PAGE);
3493 SET(DEL_PAGE);
3494 GET(GET_PAGE);
3495 SET(KILL_PAGE);
3496 }
3497
3498 if (get) {
3499 err = get_user(g.regnum, &g32->regnum);
3500 err |= get_user(g.base, &g32->base);
3501 err |= get_user(g.size, &g32->size);
3502 err |= get_user(g.type, &g32->type);
3503
3504 arg = (unsigned long)&g;
3505 } else {
3506 struct mtrr_sentry32 *s32 = (struct mtrr_sentry32 *)arg;
3507 err = get_user(s.base, &s32->base);
3508 err |= get_user(s.size, &s32->size);
3509 err |= get_user(s.type, &s32->type);
3510
3511 arg = (unsigned long)&s;
3512 }
3513 if (err) return err;
3514
3515 set_fs(KERNEL_DS);
3516 err = sys_ioctl(fd, cmd, arg);
3517 set_fs(oldfs);
3518
3519 if (!err && get) {
3520 err = put_user(g.base, &g32->base);
3521 err |= put_user(g.size, &g32->size);
3522 err |= put_user(g.regnum, &g32->regnum);
3523 err |= put_user(g.type, &g32->type);
3524 }
3525 return err;
3526 }
3527
3528
3529 struct compat_iw_point {
3530 __u32 pointer;
3531 __u16 length;
3532 __u16 flags;
3533 };
3534
do_wireless_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)3535 static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
3536 {
3537 struct iwreq *iwr, *iwr_u;
3538 struct iw_point *iwp;
3539 struct compat_iw_point *iwp_u;
3540 __u32 pointer;
3541 __u16 length, flags;
3542
3543 iwr_u = (struct iwreq *) (u64)arg;
3544 iwp_u = (struct compat_iw_point *) &iwr_u->u.data;
3545 iwr = compat_alloc_user_space(sizeof(*iwr));
3546 if (iwr == NULL)
3547 return -ENOMEM;
3548
3549 iwp = &iwr->u.data;
3550
3551 if (verify_area(VERIFY_WRITE, iwr, sizeof(*iwr)))
3552 return -EFAULT;
3553
3554 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
3555 &iwr_u->ifr_ifrn.ifrn_name[0],
3556 sizeof(iwr->ifr_ifrn.ifrn_name)))
3557 return -EFAULT;
3558
3559 if (__get_user(pointer, &iwp_u->pointer) ||
3560 __get_user(length, &iwp_u->length) ||
3561 __get_user(flags, &iwp_u->flags))
3562 return -EFAULT;
3563
3564 if (__put_user((u64)pointer, &iwp->pointer) ||
3565 __put_user(length, &iwp->length) ||
3566 __put_user(flags, &iwp->flags))
3567 return -EFAULT;
3568
3569 return sys_ioctl(fd, cmd, (unsigned long) iwr);
3570 }
3571
3572 struct compat_ctrlmsg_ioctl {
3573 struct usb_ctrlrequest req;
3574 u32 data;
3575 };
3576
3577 struct ctrlmsg_ioctl {
3578 struct usb_ctrlrequest req;
3579 void *data;
3580 };
3581
3582 #define SCANNER_IOCTL_CTRLMSG _IOWR('U', 0x22, struct usb_ctrlrequest)
3583
scanner_ioctl_ctrlmsg(unsigned int fd,unsigned int cmd,unsigned long arg)3584 static int scanner_ioctl_ctrlmsg(unsigned int fd, unsigned int cmd, unsigned long arg)
3585 {
3586 struct ctrlmsg_ioctl *c64;
3587 struct compat_ctrlmsg_ioctl *c32 = (void *)arg;
3588 u32 ptr;
3589
3590 c64 = compat_alloc_user_space(sizeof(struct ctrlmsg_ioctl));
3591
3592 if (copy_in_user(&c64->req, &c32->req, sizeof(struct usb_ctrlrequest)) ||
3593 get_user(ptr, &c32->data) ||
3594 put_user((void *)(unsigned long)ptr, &c64->data))
3595 return -EFAULT;
3596 return sys_ioctl(fd,cmd, (unsigned long)c64);
3597 }
3598
3599 struct ioctl_trans {
3600 unsigned long cmd;
3601 int (*handler)(unsigned int, unsigned int, unsigned long, struct file * filp);
3602 struct ioctl_trans *next;
3603 };
3604
3605 #define REF_SYMBOL(handler) if (0) (void)handler;
3606 #define HANDLE_IOCTL2(cmd,handler) REF_SYMBOL(handler); asm volatile(".quad %P0, " #handler ",0"::"n" (cmd));
3607 #define HANDLE_IOCTL(cmd,handler) HANDLE_IOCTL2(cmd,handler)
3608 #define COMPATIBLE_IOCTL(cmd) HANDLE_IOCTL(cmd,sys_ioctl)
3609 #define IOCTL_TABLE_START void ioctl_dummy(void) { asm volatile("\nioctl_start:\n\t" );
3610 #define IOCTL_TABLE_END asm volatile("\nioctl_end:"); }
3611
3612 IOCTL_TABLE_START
3613 /* List here explicitly which ioctl's are known to have
3614 * compatable types passed or none at all...
3615 */
3616 /* Big T */
3617 COMPATIBLE_IOCTL(TCGETA)
3618 COMPATIBLE_IOCTL(TCSETA)
3619 COMPATIBLE_IOCTL(TCSETAW)
3620 COMPATIBLE_IOCTL(TCSETAF)
3621 COMPATIBLE_IOCTL(TCSBRK)
3622 COMPATIBLE_IOCTL(TCXONC)
3623 COMPATIBLE_IOCTL(TCFLSH)
3624 COMPATIBLE_IOCTL(TCGETS)
3625 COMPATIBLE_IOCTL(TCSETS)
3626 COMPATIBLE_IOCTL(TCSETSW)
3627 COMPATIBLE_IOCTL(TCSETSF)
3628 COMPATIBLE_IOCTL(TIOCLINUX)
3629 /* Little t */
3630 COMPATIBLE_IOCTL(TIOCGETD)
3631 COMPATIBLE_IOCTL(TIOCSETD)
3632 COMPATIBLE_IOCTL(TIOCEXCL)
3633 COMPATIBLE_IOCTL(TIOCNXCL)
3634 COMPATIBLE_IOCTL(TIOCCONS)
3635 COMPATIBLE_IOCTL(TIOCGSOFTCAR)
3636 COMPATIBLE_IOCTL(TIOCSSOFTCAR)
3637 COMPATIBLE_IOCTL(TIOCSWINSZ)
3638 COMPATIBLE_IOCTL(TIOCGWINSZ)
3639 COMPATIBLE_IOCTL(TIOCMGET)
3640 COMPATIBLE_IOCTL(TIOCMBIC)
3641 COMPATIBLE_IOCTL(TIOCMBIS)
3642 COMPATIBLE_IOCTL(TIOCMSET)
3643 COMPATIBLE_IOCTL(TIOCPKT)
3644 COMPATIBLE_IOCTL(TIOCNOTTY)
3645 COMPATIBLE_IOCTL(TIOCSTI)
3646 COMPATIBLE_IOCTL(TIOCOUTQ)
3647 COMPATIBLE_IOCTL(TIOCSPGRP)
3648 COMPATIBLE_IOCTL(TIOCGPGRP)
3649 COMPATIBLE_IOCTL(TIOCSCTTY)
3650 COMPATIBLE_IOCTL(TIOCGPTN)
3651 COMPATIBLE_IOCTL(TIOCSPTLCK)
3652 COMPATIBLE_IOCTL(TIOCSERGETLSR)
3653 COMPATIBLE_IOCTL(FIOQSIZE)
3654 /* Big F */
3655 COMPATIBLE_IOCTL(FBIOGET_VSCREENINFO)
3656 COMPATIBLE_IOCTL(FBIOPUT_VSCREENINFO)
3657 COMPATIBLE_IOCTL(FBIOPAN_DISPLAY)
3658 COMPATIBLE_IOCTL(FBIOGET_FCURSORINFO)
3659 COMPATIBLE_IOCTL(FBIOGET_VCURSORINFO)
3660 COMPATIBLE_IOCTL(FBIOPUT_VCURSORINFO)
3661 COMPATIBLE_IOCTL(FBIOGET_CURSORSTATE)
3662 COMPATIBLE_IOCTL(FBIOPUT_CURSORSTATE)
3663 COMPATIBLE_IOCTL(FBIOGET_CON2FBMAP)
3664 COMPATIBLE_IOCTL(FBIOPUT_CON2FBMAP)
3665 /* Little f */
3666 COMPATIBLE_IOCTL(FIOCLEX)
3667 COMPATIBLE_IOCTL(FIONCLEX)
3668 COMPATIBLE_IOCTL(FIOASYNC)
3669 COMPATIBLE_IOCTL(FIONBIO)
3670 COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */
3671 /* 0x00 */
3672 COMPATIBLE_IOCTL(FIBMAP)
3673 COMPATIBLE_IOCTL(FIGETBSZ)
3674 /* 0x03 -- HD/IDE ioctl's used by hdparm and friends.
3675 * Some need translations, these do not.
3676 */
3677 COMPATIBLE_IOCTL(HDIO_GET_IDENTITY)
3678 COMPATIBLE_IOCTL(HDIO_SET_DMA)
3679 COMPATIBLE_IOCTL(HDIO_SET_KEEPSETTINGS)
3680 COMPATIBLE_IOCTL(HDIO_SET_UNMASKINTR)
3681 COMPATIBLE_IOCTL(HDIO_SET_NOWERR)
3682 COMPATIBLE_IOCTL(HDIO_SET_32BIT)
3683 COMPATIBLE_IOCTL(HDIO_SET_MULTCOUNT)
3684 COMPATIBLE_IOCTL(HDIO_DRIVE_CMD)
3685 COMPATIBLE_IOCTL(HDIO_SET_PIO_MODE)
3686 COMPATIBLE_IOCTL(HDIO_SCAN_HWIF)
3687 COMPATIBLE_IOCTL(HDIO_SET_NICE)
3688 /* 0x02 -- Floppy ioctls */
3689 COMPATIBLE_IOCTL(FDMSGON)
3690 COMPATIBLE_IOCTL(FDMSGOFF)
3691 COMPATIBLE_IOCTL(FDSETEMSGTRESH)
3692 COMPATIBLE_IOCTL(FDFLUSH)
3693 COMPATIBLE_IOCTL(FDWERRORCLR)
3694 COMPATIBLE_IOCTL(FDSETMAXERRS)
3695 COMPATIBLE_IOCTL(FDGETMAXERRS)
3696 COMPATIBLE_IOCTL(FDGETDRVTYP)
3697 COMPATIBLE_IOCTL(FDEJECT)
3698 COMPATIBLE_IOCTL(FDCLRPRM)
3699 COMPATIBLE_IOCTL(FDFMTBEG)
3700 COMPATIBLE_IOCTL(FDFMTEND)
3701 COMPATIBLE_IOCTL(FDRESET)
3702 COMPATIBLE_IOCTL(FDTWADDLE)
3703 COMPATIBLE_IOCTL(FDFMTTRK)
3704 COMPATIBLE_IOCTL(FDRAWCMD)
3705 /* 0x12 */
3706 COMPATIBLE_IOCTL(BLKROSET)
3707 COMPATIBLE_IOCTL(BLKROGET)
3708 COMPATIBLE_IOCTL(BLKRRPART)
3709 COMPATIBLE_IOCTL(BLKFLSBUF)
3710 COMPATIBLE_IOCTL(BLKRASET)
3711 COMPATIBLE_IOCTL(BLKFRASET)
3712 COMPATIBLE_IOCTL(BLKSECTSET)
3713 COMPATIBLE_IOCTL(BLKSSZGET)
3714 /* RAID */
3715 COMPATIBLE_IOCTL(RAID_VERSION)
3716 COMPATIBLE_IOCTL(GET_ARRAY_INFO)
3717 COMPATIBLE_IOCTL(GET_DISK_INFO)
3718 COMPATIBLE_IOCTL(PRINT_RAID_DEBUG)
3719 COMPATIBLE_IOCTL(CLEAR_ARRAY)
3720 COMPATIBLE_IOCTL(ADD_NEW_DISK)
3721 COMPATIBLE_IOCTL(HOT_REMOVE_DISK)
3722 COMPATIBLE_IOCTL(SET_ARRAY_INFO)
3723 COMPATIBLE_IOCTL(SET_DISK_INFO)
3724 COMPATIBLE_IOCTL(WRITE_RAID_INFO)
3725 COMPATIBLE_IOCTL(UNPROTECT_ARRAY)
3726 COMPATIBLE_IOCTL(PROTECT_ARRAY)
3727 COMPATIBLE_IOCTL(HOT_ADD_DISK)
3728 COMPATIBLE_IOCTL(SET_DISK_FAULTY)
3729 COMPATIBLE_IOCTL(RUN_ARRAY)
3730 COMPATIBLE_IOCTL(START_ARRAY)
3731 COMPATIBLE_IOCTL(STOP_ARRAY)
3732 COMPATIBLE_IOCTL(STOP_ARRAY_RO)
3733 COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
3734 /* Big K */
3735 COMPATIBLE_IOCTL(PIO_FONT)
3736 COMPATIBLE_IOCTL(GIO_FONT)
3737 COMPATIBLE_IOCTL(KDSIGACCEPT)
3738 COMPATIBLE_IOCTL(KDGETKEYCODE)
3739 COMPATIBLE_IOCTL(KDSETKEYCODE)
3740 COMPATIBLE_IOCTL(KIOCSOUND)
3741 COMPATIBLE_IOCTL(KDMKTONE)
3742 COMPATIBLE_IOCTL(KDGKBTYPE)
3743 COMPATIBLE_IOCTL(KDSETMODE)
3744 COMPATIBLE_IOCTL(KDGETMODE)
3745 COMPATIBLE_IOCTL(KDSKBMODE)
3746 COMPATIBLE_IOCTL(KDGKBMODE)
3747 COMPATIBLE_IOCTL(KDSKBMETA)
3748 COMPATIBLE_IOCTL(KDGKBMETA)
3749 COMPATIBLE_IOCTL(KDGKBENT)
3750 COMPATIBLE_IOCTL(KDSKBENT)
3751 COMPATIBLE_IOCTL(KDGKBSENT)
3752 COMPATIBLE_IOCTL(KDSKBSENT)
3753 COMPATIBLE_IOCTL(KDGKBDIACR)
3754 COMPATIBLE_IOCTL(KDSKBDIACR)
3755 COMPATIBLE_IOCTL(KDKBDREP)
3756 COMPATIBLE_IOCTL(KDGKBLED)
3757 COMPATIBLE_IOCTL(KDSKBLED)
3758 COMPATIBLE_IOCTL(KDGETLED)
3759 COMPATIBLE_IOCTL(KDSETLED)
3760 COMPATIBLE_IOCTL(GIO_SCRNMAP)
3761 COMPATIBLE_IOCTL(PIO_SCRNMAP)
3762 COMPATIBLE_IOCTL(GIO_UNISCRNMAP)
3763 COMPATIBLE_IOCTL(PIO_UNISCRNMAP)
3764 COMPATIBLE_IOCTL(PIO_FONTRESET)
3765 COMPATIBLE_IOCTL(PIO_UNIMAPCLR)
3766 /* Big S */
3767 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
3768 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
3769 COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
3770 COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
3771 COMPATIBLE_IOCTL(SCSI_IOCTL_TAGGED_ENABLE)
3772 COMPATIBLE_IOCTL(SCSI_IOCTL_TAGGED_DISABLE)
3773 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
3774 COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
3775 COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
3776 COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
3777 /* Big T */
3778 COMPATIBLE_IOCTL(TUNSETNOCSUM)
3779 COMPATIBLE_IOCTL(TUNSETDEBUG)
3780 COMPATIBLE_IOCTL(TUNSETIFF)
3781 COMPATIBLE_IOCTL(TUNSETPERSIST)
3782 COMPATIBLE_IOCTL(TUNSETOWNER)
3783 /* Big V */
3784 COMPATIBLE_IOCTL(VT_SETMODE)
3785 COMPATIBLE_IOCTL(VT_GETMODE)
3786 COMPATIBLE_IOCTL(VT_GETSTATE)
3787 COMPATIBLE_IOCTL(VT_OPENQRY)
3788 COMPATIBLE_IOCTL(VT_ACTIVATE)
3789 COMPATIBLE_IOCTL(VT_WAITACTIVE)
3790 COMPATIBLE_IOCTL(VT_RELDISP)
3791 COMPATIBLE_IOCTL(VT_DISALLOCATE)
3792 COMPATIBLE_IOCTL(VT_RESIZE)
3793 COMPATIBLE_IOCTL(VT_RESIZEX)
3794 COMPATIBLE_IOCTL(VT_LOCKSWITCH)
3795 COMPATIBLE_IOCTL(VT_UNLOCKSWITCH)
3796 /* Little v */
3797 /* Little v, the video4linux ioctls (conflict?) */
3798 COMPATIBLE_IOCTL(VIDIOCGCAP)
3799 COMPATIBLE_IOCTL(VIDIOCGCHAN)
3800 COMPATIBLE_IOCTL(VIDIOCSCHAN)
3801 COMPATIBLE_IOCTL(VIDIOCGPICT)
3802 COMPATIBLE_IOCTL(VIDIOCSPICT)
3803 COMPATIBLE_IOCTL(VIDIOCCAPTURE)
3804 COMPATIBLE_IOCTL(VIDIOCKEY)
3805 COMPATIBLE_IOCTL(VIDIOCGAUDIO)
3806 COMPATIBLE_IOCTL(VIDIOCSAUDIO)
3807 COMPATIBLE_IOCTL(VIDIOCSYNC)
3808 COMPATIBLE_IOCTL(VIDIOCMCAPTURE)
3809 COMPATIBLE_IOCTL(VIDIOCGMBUF)
3810 COMPATIBLE_IOCTL(VIDIOCGUNIT)
3811 COMPATIBLE_IOCTL(VIDIOCGCAPTURE)
3812 COMPATIBLE_IOCTL(VIDIOCSCAPTURE)
3813 /* BTTV specific... */
3814 COMPATIBLE_IOCTL(_IOW('v', BASE_VIDIOCPRIVATE+0, char [256]))
3815 COMPATIBLE_IOCTL(_IOR('v', BASE_VIDIOCPRIVATE+1, char [256]))
3816 COMPATIBLE_IOCTL(_IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int))
3817 COMPATIBLE_IOCTL(_IOW('v' , BASE_VIDIOCPRIVATE+3, char [16])) /* struct bttv_pll_info */
3818 COMPATIBLE_IOCTL(_IOR('v' , BASE_VIDIOCPRIVATE+4, int))
3819 COMPATIBLE_IOCTL(_IOR('v' , BASE_VIDIOCPRIVATE+5, int))
3820 COMPATIBLE_IOCTL(_IOR('v' , BASE_VIDIOCPRIVATE+6, int))
3821 COMPATIBLE_IOCTL(_IOR('v' , BASE_VIDIOCPRIVATE+7, int))
3822 /* Little p (/dev/rtc, /dev/envctrl, etc.) */
3823 COMPATIBLE_IOCTL(RTC_AIE_ON)
3824 COMPATIBLE_IOCTL(RTC_AIE_OFF)
3825 COMPATIBLE_IOCTL(RTC_UIE_ON)
3826 COMPATIBLE_IOCTL(RTC_UIE_OFF)
3827 COMPATIBLE_IOCTL(RTC_PIE_ON)
3828 COMPATIBLE_IOCTL(RTC_PIE_OFF)
3829 COMPATIBLE_IOCTL(RTC_WIE_ON)
3830 COMPATIBLE_IOCTL(RTC_WIE_OFF)
3831 COMPATIBLE_IOCTL(RTC_ALM_SET)
3832 COMPATIBLE_IOCTL(RTC_ALM_READ)
3833 COMPATIBLE_IOCTL(RTC_RD_TIME)
3834 COMPATIBLE_IOCTL(RTC_SET_TIME)
3835 COMPATIBLE_IOCTL(RTC_WKALM_SET)
3836 COMPATIBLE_IOCTL(RTC_WKALM_RD)
3837 /* Little m */
3838 COMPATIBLE_IOCTL(MTIOCTOP)
3839 /* Socket level stuff */
3840 COMPATIBLE_IOCTL(FIOSETOWN)
3841 COMPATIBLE_IOCTL(SIOCSPGRP)
3842 COMPATIBLE_IOCTL(FIOGETOWN)
3843 COMPATIBLE_IOCTL(SIOCGPGRP)
3844 COMPATIBLE_IOCTL(SIOCATMARK)
3845 COMPATIBLE_IOCTL(SIOCSIFLINK)
3846 COMPATIBLE_IOCTL(SIOCSIFENCAP)
3847 COMPATIBLE_IOCTL(SIOCGIFENCAP)
3848 COMPATIBLE_IOCTL(SIOCSIFBR)
3849 COMPATIBLE_IOCTL(SIOCGIFBR)
3850 COMPATIBLE_IOCTL(SIOCSARP)
3851 COMPATIBLE_IOCTL(SIOCGARP)
3852 COMPATIBLE_IOCTL(SIOCDARP)
3853 COMPATIBLE_IOCTL(SIOCSRARP)
3854 COMPATIBLE_IOCTL(SIOCGRARP)
3855 COMPATIBLE_IOCTL(SIOCDRARP)
3856 COMPATIBLE_IOCTL(SIOCADDDLCI)
3857 COMPATIBLE_IOCTL(SIOCDELDLCI)
3858 COMPATIBLE_IOCTL(SIOCGMIIPHY)
3859 COMPATIBLE_IOCTL(SIOCGMIIREG)
3860 COMPATIBLE_IOCTL(SIOCSMIIREG)
3861 COMPATIBLE_IOCTL(SIOCGIFVLAN)
3862 COMPATIBLE_IOCTL(SIOCSIFVLAN)
3863 /* SG stuff */
3864 COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
3865 COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
3866 COMPATIBLE_IOCTL(SG_EMULATED_HOST)
3867 COMPATIBLE_IOCTL(SG_SET_TRANSFORM)
3868 COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
3869 COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
3870 COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
3871 COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
3872 COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
3873 COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
3874 COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
3875 COMPATIBLE_IOCTL(SG_GET_PACK_ID)
3876 COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
3877 COMPATIBLE_IOCTL(SG_SET_DEBUG)
3878 COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
3879 COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
3880 COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
3881 COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
3882 COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
3883 COMPATIBLE_IOCTL(SG_SCSI_RESET)
3884 COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
3885 COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
3886 COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
3887 /* PPP stuff */
3888 COMPATIBLE_IOCTL(PPPIOCGFLAGS)
3889 COMPATIBLE_IOCTL(PPPIOCSFLAGS)
3890 COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
3891 COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
3892 COMPATIBLE_IOCTL(PPPIOCGUNIT)
3893 COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
3894 COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
3895 COMPATIBLE_IOCTL(PPPIOCGMRU)
3896 COMPATIBLE_IOCTL(PPPIOCSMRU)
3897 COMPATIBLE_IOCTL(PPPIOCSMAXCID)
3898 COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
3899 COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
3900 COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
3901 /* PPPIOCSCOMPRESS is translated */
3902 COMPATIBLE_IOCTL(PPPIOCGNPMODE)
3903 COMPATIBLE_IOCTL(PPPIOCSNPMODE)
3904 COMPATIBLE_IOCTL(PPPIOCGDEBUG)
3905 COMPATIBLE_IOCTL(PPPIOCSDEBUG)
3906 /* PPPIOCSPASS is translated */
3907 /* PPPIOCSACTIVE is translated */
3908 /* PPPIOCGIDLE is translated */
3909 COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
3910 COMPATIBLE_IOCTL(PPPIOCATTACH)
3911 COMPATIBLE_IOCTL(PPPIOCDETACH)
3912 COMPATIBLE_IOCTL(PPPIOCSMRRU)
3913 COMPATIBLE_IOCTL(PPPIOCCONNECT)
3914 COMPATIBLE_IOCTL(PPPIOCDISCONN)
3915 COMPATIBLE_IOCTL(PPPIOCATTCHAN)
3916 COMPATIBLE_IOCTL(PPPIOCGCHAN)
3917 /* PPPOX */
3918 COMPATIBLE_IOCTL(PPPOEIOCSFWD)
3919 COMPATIBLE_IOCTL(PPPOEIOCDFWD)
3920 /* LP */
3921 COMPATIBLE_IOCTL(LPGETSTATUS)
3922 /* CDROM stuff */
3923 COMPATIBLE_IOCTL(CDROMPAUSE)
3924 COMPATIBLE_IOCTL(CDROMRESUME)
3925 COMPATIBLE_IOCTL(CDROMPLAYMSF)
3926 COMPATIBLE_IOCTL(CDROMPLAYTRKIND)
3927 COMPATIBLE_IOCTL(CDROMREADTOCHDR)
3928 COMPATIBLE_IOCTL(CDROMREADTOCENTRY)
3929 COMPATIBLE_IOCTL(CDROMSTOP)
3930 COMPATIBLE_IOCTL(CDROMSTART)
3931 COMPATIBLE_IOCTL(CDROMEJECT)
3932 COMPATIBLE_IOCTL(CDROMVOLCTRL)
3933 COMPATIBLE_IOCTL(CDROMSUBCHNL)
3934 COMPATIBLE_IOCTL(CDROMEJECT_SW)
3935 COMPATIBLE_IOCTL(CDROMMULTISESSION)
3936 COMPATIBLE_IOCTL(CDROM_GET_MCN)
3937 COMPATIBLE_IOCTL(CDROMRESET)
3938 COMPATIBLE_IOCTL(CDROMVOLREAD)
3939 COMPATIBLE_IOCTL(CDROMSEEK)
3940 COMPATIBLE_IOCTL(CDROMPLAYBLK)
3941 COMPATIBLE_IOCTL(CDROMCLOSETRAY)
3942 COMPATIBLE_IOCTL(CDROM_SET_OPTIONS)
3943 COMPATIBLE_IOCTL(CDROM_CLEAR_OPTIONS)
3944 COMPATIBLE_IOCTL(CDROM_SELECT_SPEED)
3945 COMPATIBLE_IOCTL(CDROM_SELECT_DISC)
3946 COMPATIBLE_IOCTL(CDROM_MEDIA_CHANGED)
3947 COMPATIBLE_IOCTL(CDROM_DRIVE_STATUS)
3948 COMPATIBLE_IOCTL(CDROM_DISC_STATUS)
3949 COMPATIBLE_IOCTL(CDROM_CHANGER_NSLOTS)
3950 COMPATIBLE_IOCTL(CDROM_LOCKDOOR)
3951 COMPATIBLE_IOCTL(CDROM_DEBUG)
3952 COMPATIBLE_IOCTL(CDROM_GET_CAPABILITY)
3953 /* DVD ioctls */
3954 COMPATIBLE_IOCTL(DVD_READ_STRUCT)
3955 COMPATIBLE_IOCTL(DVD_WRITE_STRUCT)
3956 COMPATIBLE_IOCTL(DVD_AUTH)
3957 /* Big L */
3958 COMPATIBLE_IOCTL(LOOP_SET_FD)
3959 COMPATIBLE_IOCTL(LOOP_CLR_FD)
3960 /* Big A */
3961 /* sparc only */
3962 /* Big Q for sound/OSS */
3963 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
3964 COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
3965 COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
3966 COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
3967 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
3968 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
3969 COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
3970 COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
3971 COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
3972 COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
3973 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
3974 COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
3975 COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
3976 COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
3977 COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
3978 COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
3979 COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
3980 COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
3981 COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
3982 COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
3983 COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
3984 COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
3985 /* Big T for sound/OSS */
3986 COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
3987 COMPATIBLE_IOCTL(SNDCTL_TMR_START)
3988 COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
3989 COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
3990 COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
3991 COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
3992 COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
3993 COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
3994 /* Little m for sound/OSS */
3995 COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
3996 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
3997 COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
3998 /* Big P for sound/OSS */
3999 COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
4000 COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
4001 COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
4002 COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
4003 COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
4004 COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
4005 COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
4006 COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
4007 COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
4008 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
4009 COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
4010 COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
4011 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
4012 COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
4013 COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
4014 COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
4015 COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
4016 COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
4017 COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
4018 COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
4019 /* SNDCTL_DSP_MAPINBUF, XXX needs translation */
4020 /* SNDCTL_DSP_MAPOUTBUF, XXX needs translation */
4021 COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
4022 COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
4023 COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
4024 COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
4025 COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
4026 COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
4027 COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
4028 COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
4029 /* Big C for sound/OSS */
4030 COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
4031 COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
4032 COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
4033 COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
4034 COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
4035 COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
4036 COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
4037 COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
4038 COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
4039 COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
4040 /* Big M for sound/OSS */
4041 COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
4042 COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
4043 COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
4044 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
4045 COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
4046 COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
4047 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
4048 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
4049 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
4050 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
4051 COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
4052 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
4053 COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
4054 COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
4055 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
4056 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
4057 COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
4058 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
4059 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
4060 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
4061 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
4062 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
4063 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
4064 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
4065 COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
4066 COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
4067 /* SOUND_MIXER_READ_ENHANCE, same value as READ_MUTE */
4068 /* SOUND_MIXER_READ_LOUD, same value as READ_MUTE */
4069 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
4070 COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
4071 COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
4072 COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
4073 COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
4074 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
4075 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
4076 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
4077 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
4078 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
4079 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
4080 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
4081 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
4082 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
4083 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
4084 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
4085 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
4086 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
4087 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
4088 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
4089 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
4090 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
4091 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
4092 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
4093 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
4094 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
4095 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
4096 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
4097 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
4098 COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
4099 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
4100 /* SOUND_MIXER_WRITE_ENHANCE, same value as WRITE_MUTE */
4101 /* SOUND_MIXER_WRITE_LOUD, same value as WRITE_MUTE */
4102 COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
4103 COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
4104 COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
4105 COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
4106 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
4107 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
4108 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
4109 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
4110 COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
4111 COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
4112 COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
4113 COMPATIBLE_IOCTL(OSS_GETVERSION)
4114 /* AUTOFS */
4115 COMPATIBLE_IOCTL(AUTOFS_IOC_READY)
4116 COMPATIBLE_IOCTL(AUTOFS_IOC_FAIL)
4117 COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
4118 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
4119 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
4120 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
4121 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
4122 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
4123 COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
4124 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
4125 /* DEVFS */
4126 COMPATIBLE_IOCTL(DEVFSDIOC_GET_PROTO_REV)
4127 COMPATIBLE_IOCTL(DEVFSDIOC_SET_EVENT_MASK)
4128 COMPATIBLE_IOCTL(DEVFSDIOC_RELEASE_EVENT_QUEUE)
4129 COMPATIBLE_IOCTL(DEVFSDIOC_SET_DEBUG_MASK)
4130 /* SMB ioctls which do not need any translations */
4131 COMPATIBLE_IOCTL(SMB_IOC_NEWCONN)
4132 /* Little a */
4133 COMPATIBLE_IOCTL(ATMSIGD_CTRL)
4134 COMPATIBLE_IOCTL(ATMARPD_CTRL)
4135 COMPATIBLE_IOCTL(ATMLEC_CTRL)
4136 COMPATIBLE_IOCTL(ATMLEC_MCAST)
4137 COMPATIBLE_IOCTL(ATMLEC_DATA)
4138 COMPATIBLE_IOCTL(ATM_SETSC)
4139 COMPATIBLE_IOCTL(SIOCSIFATMTCP)
4140 COMPATIBLE_IOCTL(SIOCMKCLIP)
4141 COMPATIBLE_IOCTL(ATMARP_MKIP)
4142 COMPATIBLE_IOCTL(ATMARP_SETENTRY)
4143 COMPATIBLE_IOCTL(ATMARP_ENCAP)
4144 COMPATIBLE_IOCTL(ATMTCP_CREATE)
4145 COMPATIBLE_IOCTL(ATMTCP_REMOVE)
4146 COMPATIBLE_IOCTL(ATMMPC_CTRL)
4147 COMPATIBLE_IOCTL(ATMMPC_DATA)
4148 #if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)
4149 /* 0xfe - lvm */
4150 COMPATIBLE_IOCTL(VG_SET_EXTENDABLE)
4151 COMPATIBLE_IOCTL(VG_STATUS_GET_COUNT)
4152 COMPATIBLE_IOCTL(VG_STATUS_GET_NAMELIST)
4153 COMPATIBLE_IOCTL(VG_REMOVE)
4154 COMPATIBLE_IOCTL(VG_RENAME)
4155 COMPATIBLE_IOCTL(VG_REDUCE)
4156 COMPATIBLE_IOCTL(PE_LOCK_UNLOCK)
4157 COMPATIBLE_IOCTL(PV_FLUSH)
4158 COMPATIBLE_IOCTL(LVM_LOCK_LVM)
4159 COMPATIBLE_IOCTL(LVM_GET_IOP_VERSION)
4160 #ifdef LVM_TOTAL_RESET
4161 COMPATIBLE_IOCTL(LVM_RESET)
4162 #endif
4163 COMPATIBLE_IOCTL(LV_SET_ACCESS)
4164 COMPATIBLE_IOCTL(LV_SET_STATUS)
4165 COMPATIBLE_IOCTL(LV_SET_ALLOCATION)
4166 COMPATIBLE_IOCTL(LE_REMAP)
4167 COMPATIBLE_IOCTL(LV_BMAP)
4168 COMPATIBLE_IOCTL(LV_SNAPSHOT_USE_RATE)
4169 #endif /* LVM */
4170 #ifdef CONFIG_AUTOFS_FS
4171 COMPATIBLE_IOCTL(AUTOFS_IOC_READY)
4172 COMPATIBLE_IOCTL(AUTOFS_IOC_FAIL)
4173 COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
4174 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
4175 COMPATIBLE_IOCTL(AUTOFS_IOC_SETTIMEOUT)
4176 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
4177 #endif
4178 #ifdef CONFIG_RTC
4179 COMPATIBLE_IOCTL(RTC_AIE_ON)
4180 COMPATIBLE_IOCTL(RTC_AIE_OFF)
4181 COMPATIBLE_IOCTL(RTC_UIE_ON)
4182 COMPATIBLE_IOCTL(RTC_UIE_OFF)
4183 COMPATIBLE_IOCTL(RTC_PIE_ON)
4184 COMPATIBLE_IOCTL(RTC_PIE_OFF)
4185 COMPATIBLE_IOCTL(RTC_WIE_ON)
4186 COMPATIBLE_IOCTL(RTC_WIE_OFF)
4187 COMPATIBLE_IOCTL(RTC_ALM_SET)
4188 COMPATIBLE_IOCTL(RTC_ALM_READ)
4189 COMPATIBLE_IOCTL(RTC_RD_TIME)
4190 COMPATIBLE_IOCTL(RTC_SET_TIME)
4191 COMPATIBLE_IOCTL(RTC_WKALM_SET)
4192 COMPATIBLE_IOCTL(RTC_WKALM_RD)
4193 #endif
4194 /* Big W */
4195 /* WIOC_GETSUPPORT not yet implemented -E */
4196 COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
4197 COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
4198 COMPATIBLE_IOCTL(WDIOC_GETTEMP)
4199 COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
4200 COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
4201 #if 0 /* sparc only ? */
4202 COMPATIBLE_IOCTL(WIOCSTART)
4203 COMPATIBLE_IOCTL(WIOCSTOP)
4204 COMPATIBLE_IOCTL(WIOCGSTAT)
4205 #endif
4206 /* Big R */
4207 COMPATIBLE_IOCTL(RNDGETENTCNT)
4208 COMPATIBLE_IOCTL(RNDADDTOENTCNT)
4209 COMPATIBLE_IOCTL(RNDGETPOOL)
4210 COMPATIBLE_IOCTL(RNDADDENTROPY)
4211 COMPATIBLE_IOCTL(RNDZAPENTCNT)
4212 COMPATIBLE_IOCTL(RNDCLEARPOOL)
4213 /* Bluetooth ioctls */
4214 COMPATIBLE_IOCTL(HCIDEVUP)
4215 COMPATIBLE_IOCTL(HCIDEVDOWN)
4216 COMPATIBLE_IOCTL(HCIDEVRESET)
4217 COMPATIBLE_IOCTL(HCIDEVRESTAT)
4218 COMPATIBLE_IOCTL(HCIGETDEVLIST)
4219 COMPATIBLE_IOCTL(HCIGETDEVINFO)
4220 COMPATIBLE_IOCTL(HCIGETCONNLIST)
4221 COMPATIBLE_IOCTL(HCIGETCONNINFO)
4222 COMPATIBLE_IOCTL(HCISETRAW)
4223 COMPATIBLE_IOCTL(HCISETSCAN)
4224 COMPATIBLE_IOCTL(HCISETAUTH)
4225 COMPATIBLE_IOCTL(HCISETENCRYPT)
4226 COMPATIBLE_IOCTL(HCISETPTYPE)
4227 COMPATIBLE_IOCTL(HCISETLINKPOL)
4228 COMPATIBLE_IOCTL(HCISETLINKMODE)
4229 COMPATIBLE_IOCTL(HCISETACLMTU)
4230 COMPATIBLE_IOCTL(HCISETSCOMTU)
4231 COMPATIBLE_IOCTL(HCIINQUIRY)
4232 COMPATIBLE_IOCTL(HCIUARTSETPROTO)
4233 COMPATIBLE_IOCTL(HCIUARTGETPROTO)
4234 COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
4235 COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
4236 COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
4237 COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
4238 COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
4239 COMPATIBLE_IOCTL(BNEPCONNADD)
4240 COMPATIBLE_IOCTL(BNEPCONNDEL)
4241 COMPATIBLE_IOCTL(BNEPGETCONNLIST)
4242 COMPATIBLE_IOCTL(BNEPGETCONNINFO)
4243 /* Misc. */
4244 COMPATIBLE_IOCTL(0x41545900) /* ATYIO_CLKR */
4245 COMPATIBLE_IOCTL(0x41545901) /* ATYIO_CLKW */
4246 COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
4247 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
4248 COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
4249 COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
4250 COMPATIBLE_IOCTL(0x4B50); /* KDGHWCLK - not in the kernel, but don't complain */
4251 COMPATIBLE_IOCTL(0x4B51); /* KDSHWCLK - not in the kernel, but don't complain */
4252 /* USB */
4253 COMPATIBLE_IOCTL(USBDEVFS_RESETEP)
4254 COMPATIBLE_IOCTL(USBDEVFS_SETINTERFACE)
4255 COMPATIBLE_IOCTL(USBDEVFS_SETCONFIGURATION)
4256 COMPATIBLE_IOCTL(USBDEVFS_GETDRIVER)
4257 COMPATIBLE_IOCTL(USBDEVFS_DISCARDURB)
4258 COMPATIBLE_IOCTL(USBDEVFS_CLAIMINTERFACE)
4259 COMPATIBLE_IOCTL(USBDEVFS_RELEASEINTERFACE)
4260 COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
4261 COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
4262 COMPATIBLE_IOCTL(USBDEVFS_RESET)
4263 COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
4264 /* MTD */
4265 COMPATIBLE_IOCTL(MEMGETINFO)
4266 COMPATIBLE_IOCTL(MEMERASE)
4267 COMPATIBLE_IOCTL(MEMLOCK)
4268 COMPATIBLE_IOCTL(MEMUNLOCK)
4269 COMPATIBLE_IOCTL(MEMGETREGIONCOUNT)
4270 COMPATIBLE_IOCTL(MEMGETREGIONINFO)
4271 /* NBD */
4272 COMPATIBLE_IOCTL(NBD_SET_SOCK)
4273 COMPATIBLE_IOCTL(NBD_SET_BLKSIZE)
4274 COMPATIBLE_IOCTL(NBD_SET_SIZE)
4275 COMPATIBLE_IOCTL(NBD_DO_IT)
4276 COMPATIBLE_IOCTL(NBD_CLEAR_SOCK)
4277 COMPATIBLE_IOCTL(NBD_CLEAR_QUE)
4278 COMPATIBLE_IOCTL(NBD_PRINT_DEBUG)
4279 COMPATIBLE_IOCTL(NBD_SET_SIZE_BLOCKS)
4280 COMPATIBLE_IOCTL(NBD_DISCONNECT)
4281 /* And these ioctls need translation */
4282 HANDLE_IOCTL(TIOCGDEV, tiocgdev)
4283 HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
4284 HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
4285 HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
4286 HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
4287 #ifdef CONFIG_NET
4288 HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
4289 #endif
4290 HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
4291 HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
4292 HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
4293 HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
4294 HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
4295 HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
4296 HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
4297 HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
4298 HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
4299 HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
4300 HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
4301 HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
4302 HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
4303 HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
4304 HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
4305 HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
4306 HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
4307 HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
4308 HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
4309 HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
4310 HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
4311 HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
4312 HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
4313 HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
4314 HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
4315 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
4316 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
4317 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
4318 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
4319 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
4320 HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
4321 HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
4322 HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
4323 HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
4324 HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
4325 HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
4326 HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
4327 /* realtime device */
4328 HANDLE_IOCTL(RTC_IRQP_READ, rtc32_ioctl)
4329 HANDLE_IOCTL(RTC_IRQP_READ32,rtc32_ioctl)
4330 HANDLE_IOCTL(RTC_IRQP_SET32, rtc32_ioctl)
4331 HANDLE_IOCTL(RTC_EPOCH_READ32, rtc32_ioctl)
4332 HANDLE_IOCTL(RTC_EPOCH_SET32, rtc32_ioctl)
4333 HANDLE_IOCTL(REISERFS_IOC_UNPACK32, reiserfs_ioctl32)
4334 HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
4335 HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
4336 /* Raw devices */
4337 HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
4338 /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
4339 HANDLE_IOCTL(SIOCRTMSG, ret_einval)
4340 HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
4341 HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
4342 HANDLE_IOCTL(BLKRAGET, w_long)
4343 HANDLE_IOCTL(BLKGETSIZE, w_long)
4344 HANDLE_IOCTL(0x1260, broken_blkgetsize)
4345 HANDLE_IOCTL(BLKFRAGET, w_long)
4346 HANDLE_IOCTL(BLKSECTGET, w_long)
4347 HANDLE_IOCTL(FBIOGET_FSCREENINFO, fb_ioctl_trans)
4348 HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
4349 HANDLE_IOCTL(FBIOGETCMAP, fb_ioctl_trans)
4350 HANDLE_IOCTL(FBIOPUTCMAP, fb_ioctl_trans)
4351 HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
4352 HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
4353 HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
4354 HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
4355 HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
4356 HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
4357 HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
4358 HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
4359 HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
4360 HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
4361 HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
4362 HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
4363 HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
4364 HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
4365 HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
4366 HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
4367 HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
4368 HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
4369 HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
4370 HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
4371 HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
4372 HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
4373 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
4374 HANDLE_IOCTL(MTIOCGETCONFIG32, mt_ioctl_trans)
4375 HANDLE_IOCTL(MTIOCSETCONFIG32, mt_ioctl_trans)
4376 HANDLE_IOCTL(CDROMREADMODE2, cdrom_ioctl_trans)
4377 HANDLE_IOCTL(CDROMREADMODE1, cdrom_ioctl_trans)
4378 HANDLE_IOCTL(CDROMREADRAW, cdrom_ioctl_trans)
4379 HANDLE_IOCTL(CDROMREADCOOKED, cdrom_ioctl_trans)
4380 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
4381 HANDLE_IOCTL(CDROMREADALL, cdrom_ioctl_trans)
4382 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
4383 HANDLE_IOCTL(LOOP_SET_STATUS, loop_status)
4384 HANDLE_IOCTL(LOOP_GET_STATUS, loop_status)
4385 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
4386 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
4387 #ifdef CONFIG_VT
4388 HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
4389 HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
4390 HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
4391 HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
4392 HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
4393 #endif
4394 HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl)
4395 HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl)
4396 HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl)
4397 HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl)
4398 HANDLE_IOCTL(VIDIOCGTUNER32, do_video_ioctl)
4399 HANDLE_IOCTL(VIDIOCSTUNER32, do_video_ioctl)
4400 HANDLE_IOCTL(VIDIOCGWIN32, do_video_ioctl)
4401 HANDLE_IOCTL(VIDIOCSWIN32, do_video_ioctl)
4402 HANDLE_IOCTL(VIDIOCGFBUF32, do_video_ioctl)
4403 HANDLE_IOCTL(VIDIOCSFBUF32, do_video_ioctl)
4404 HANDLE_IOCTL(VIDIOCGFREQ32, do_video_ioctl)
4405 HANDLE_IOCTL(VIDIOCSFREQ32, do_video_ioctl)
4406 /* One SMB ioctl needs translations. */
4407 #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, __kernel_uid_t32)
4408 HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
4409 HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
4410 HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
4411 HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
4412 HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
4413 HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
4414 HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
4415 HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
4416 HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
4417 HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
4418 HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
4419 HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
4420 HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
4421 HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
4422 HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
4423 HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
4424 HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
4425 HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
4426 HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
4427 HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
4428 HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
4429 HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
4430 HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
4431 HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
4432 HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
4433 HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
4434 #if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)
4435 HANDLE_IOCTL(VG_STATUS, do_lvm_ioctl)
4436 HANDLE_IOCTL(VG_CREATE, do_lvm_ioctl)
4437 HANDLE_IOCTL(VG_EXTEND, do_lvm_ioctl)
4438 HANDLE_IOCTL(LV_CREATE, do_lvm_ioctl)
4439 HANDLE_IOCTL(LV_REMOVE, do_lvm_ioctl)
4440 HANDLE_IOCTL(LV_EXTEND, do_lvm_ioctl)
4441 HANDLE_IOCTL(LV_REDUCE, do_lvm_ioctl)
4442 HANDLE_IOCTL(LV_RENAME, do_lvm_ioctl)
4443 HANDLE_IOCTL(LV_STATUS_BYNAME, do_lvm_ioctl)
4444 HANDLE_IOCTL(LV_STATUS_BYINDEX, do_lvm_ioctl)
4445 HANDLE_IOCTL(PV_CHANGE, do_lvm_ioctl)
4446 HANDLE_IOCTL(PV_STATUS, do_lvm_ioctl)
4447 HANDLE_IOCTL(VG_CREATE_OLD, do_lvm_ioctl)
4448 HANDLE_IOCTL(LV_STATUS_BYDEV, do_lvm_ioctl)
4449 #endif /* LVM */
4450 /* VFAT */
4451 HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32)
4452 HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32)
4453 HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
4454 HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
4455 /*HANDLE_IOCTL(USBDEVFS_SUBMITURB32, do_usbdevfs_urb)*/
4456 HANDLE_IOCTL(USBDEVFS_REAPURB32, do_usbdevfs_reapurb)
4457 HANDLE_IOCTL(USBDEVFS_REAPURBNDELAY32, do_usbdevfs_reapurb)
4458 HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
4459 /* take care of sizeof(sizeof()) breakage */
4460 /* elevator */
4461 HANDLE_IOCTL(BLKELVGET_32, do_blkelvget)
4462 HANDLE_IOCTL(BLKELVSET_32, do_blkelvset)
4463 /* block stuff */
4464 HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
4465 HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
4466 HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
4467 /* mtrr */
4468 HANDLE_IOCTL(MTRRIOC32_ADD_ENTRY, mtrr_ioctl32)
4469 HANDLE_IOCTL(MTRRIOC32_SET_ENTRY, mtrr_ioctl32)
4470 HANDLE_IOCTL(MTRRIOC32_DEL_ENTRY, mtrr_ioctl32)
4471 HANDLE_IOCTL(MTRRIOC32_GET_ENTRY, mtrr_ioctl32)
4472 HANDLE_IOCTL(MTRRIOC32_KILL_ENTRY, mtrr_ioctl32)
4473 HANDLE_IOCTL(MTRRIOC32_ADD_PAGE_ENTRY, mtrr_ioctl32)
4474 HANDLE_IOCTL(MTRRIOC32_SET_PAGE_ENTRY, mtrr_ioctl32)
4475 HANDLE_IOCTL(MTRRIOC32_DEL_PAGE_ENTRY, mtrr_ioctl32)
4476 HANDLE_IOCTL(MTRRIOC32_GET_PAGE_ENTRY, mtrr_ioctl32)
4477 HANDLE_IOCTL(MTRRIOC32_KILL_PAGE_ENTRY, mtrr_ioctl32)
4478 /* wireless */
4479 HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
4480 HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
4481 HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
4482 HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
4483 HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
4484 HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
4485 HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
4486 HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
4487 HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
4488 HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
4489 HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
4490 HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
4491 HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
4492 COMPATIBLE_IOCTL(SIOCGIWNAME)
4493
4494 COMPATIBLE_IOCTL(SIOCSIFNAME)
4495 /* usb scanner */
4496 #define SCANNER_IOCTL_VENDOR _IOR('U', 0x20, int)
4497 #define SCANNER_IOCTL_PRODUCT _IOR('U', 0x21, int)
4498
4499 COMPATIBLE_IOCTL(SCANNER_IOCTL_VENDOR)
4500 COMPATIBLE_IOCTL(SCANNER_IOCTL_PRODUCT)
4501 /* USB scanner 'U' */
4502 HANDLE_IOCTL(SCANNER_IOCTL_CTRLMSG, scanner_ioctl_ctrlmsg)
4503
4504 IOCTL_TABLE_END
4505
4506 #define IOCTL_HASHSIZE 256
4507 struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
4508
4509 extern struct ioctl_trans ioctl_start[], ioctl_end[];
4510
ioctl32_hash(unsigned long cmd)4511 static inline unsigned long ioctl32_hash(unsigned long cmd)
4512 {
4513 return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
4514 }
4515
ioctl32_insert_translation(struct ioctl_trans * trans)4516 static void ioctl32_insert_translation(struct ioctl_trans *trans)
4517 {
4518 unsigned long hash;
4519 struct ioctl_trans *t;
4520
4521 hash = ioctl32_hash (trans->cmd);
4522 if (!ioctl32_hash_table[hash])
4523 ioctl32_hash_table[hash] = trans;
4524 else {
4525 t = ioctl32_hash_table[hash];
4526 while (t->next)
4527 t = t->next;
4528 trans->next = 0;
4529 t->next = trans;
4530 }
4531 }
4532
init_sys32_ioctl(void)4533 static int __init init_sys32_ioctl(void)
4534 {
4535 int i;
4536
4537 for (i = 0; &ioctl_start[i] < &ioctl_end[0]; i++) {
4538 if (ioctl_start[i].next != 0) {
4539 printk("ioctl translation %d bad\n",i);
4540 return -1;
4541 }
4542
4543 ioctl32_insert_translation(&ioctl_start[i]);
4544 }
4545 return 0;
4546 }
4547
4548 __initcall(init_sys32_ioctl);
4549
4550 static struct ioctl_trans *ioctl_free_list;
4551
4552 /* Never free them really. This avoids SMP races. With a Read-Copy-Update
4553 enabled kernel we could just use the RCU infrastructure for this. */
free_ioctl(struct ioctl_trans * t)4554 static void free_ioctl(struct ioctl_trans *t)
4555 {
4556 t->cmd = 0;
4557 mb();
4558 t->next = ioctl_free_list;
4559 ioctl_free_list = t;
4560 }
4561
register_ioctl32_conversion(unsigned int cmd,int (* handler)(unsigned int,unsigned int,unsigned long,struct file *))4562 int register_ioctl32_conversion(unsigned int cmd, int (*handler)(unsigned int, unsigned int, unsigned long, struct file *))
4563 {
4564 struct ioctl_trans *t;
4565 unsigned long hash = ioctl32_hash(cmd);
4566
4567 if (handler == NULL)
4568 handler = (void *)sys_ioctl;
4569
4570 lock_kernel();
4571 for (t = (struct ioctl_trans *)ioctl32_hash_table[hash];
4572 t;
4573 t = t->next) {
4574 if (t->cmd == cmd) {
4575 printk("Trying to register duplicated ioctl32 handler %x\n", cmd);
4576 unlock_kernel();
4577 return -EINVAL;
4578 }
4579 }
4580
4581 if (ioctl_free_list) {
4582 t = ioctl_free_list;
4583 ioctl_free_list = t->next;
4584 } else {
4585 t = kmalloc(sizeof(struct ioctl_trans), GFP_KERNEL);
4586 if (!t) {
4587 unlock_kernel();
4588 return -ENOMEM;
4589 }
4590 }
4591
4592 t->next = NULL;
4593 t->cmd = cmd;
4594 t->handler = handler;
4595 ioctl32_insert_translation(t);
4596
4597 unlock_kernel();
4598 return 0;
4599 }
4600
builtin_ioctl(struct ioctl_trans * t)4601 static inline int builtin_ioctl(struct ioctl_trans *t)
4602 {
4603 return t >= (struct ioctl_trans *)ioctl_start &&
4604 t < (struct ioctl_trans *)ioctl_end;
4605 }
4606
4607 /* Problem:
4608 This function cannot unregister duplicate ioctls, because they are not
4609 unique.
4610 When they happen we need to extend the prototype to pass the handler too. */
4611
unregister_ioctl32_conversion(unsigned int cmd)4612 int unregister_ioctl32_conversion(unsigned int cmd)
4613 {
4614 unsigned long hash = ioctl32_hash(cmd);
4615 struct ioctl_trans *t, *t1;
4616
4617 lock_kernel();
4618
4619 t = (struct ioctl_trans *)ioctl32_hash_table[hash];
4620 if (!t) {
4621 unlock_kernel();
4622 return -EINVAL;
4623 }
4624
4625 if (t->cmd == cmd) {
4626 if (builtin_ioctl(t)) {
4627 printk("%p tried to unregister builtin ioctl %x\n",
4628 __builtin_return_address(0), cmd);
4629 } else {
4630 ioctl32_hash_table[hash] = t->next;
4631 free_ioctl(t);
4632 unlock_kernel();
4633 return 0;
4634 }
4635 }
4636 while (t->next) {
4637 t1 = (struct ioctl_trans *)(long)t->next;
4638 if (t1->cmd == cmd) {
4639 if (builtin_ioctl(t1)) {
4640 printk("%p tried to unregister builtin ioctl %x\n",
4641 __builtin_return_address(0), cmd);
4642 goto out;
4643 } else {
4644 t->next = t1->next;
4645 free_ioctl(t1);
4646 unlock_kernel();
4647 return 0;
4648 }
4649 }
4650 t = t1;
4651 }
4652 printk(KERN_ERR "Trying to free unknown 32bit ioctl handler %x\n", cmd);
4653 out:
4654 unlock_kernel();
4655 return -EINVAL;
4656 }
4657
4658 EXPORT_SYMBOL(register_ioctl32_conversion);
4659 EXPORT_SYMBOL(unregister_ioctl32_conversion);
4660
sys32_ioctl(unsigned int fd,unsigned int cmd,unsigned long arg)4661 asmlinkage long sys32_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
4662 {
4663 struct file * filp;
4664 long error = -EBADF;
4665 int (*handler)(unsigned int, unsigned int, unsigned long, struct file * filp);
4666 struct ioctl_trans *t;
4667
4668 filp = fget(fd);
4669 if(!filp)
4670 goto out2;
4671
4672 if (!filp->f_op || !filp->f_op->ioctl) {
4673 error = sys_ioctl (fd, cmd, arg);
4674 goto out;
4675 }
4676
4677 t = (struct ioctl_trans *)ioctl32_hash_table [ioctl32_hash (cmd)];
4678
4679 while (t && t->cmd != cmd)
4680 t = (struct ioctl_trans *)t->next;
4681 if (t) {
4682 handler = t->handler;
4683 lock_kernel();
4684 error = handler(fd, cmd, arg, filp);
4685 unlock_kernel();
4686 } else if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
4687 error = siocdevprivate_ioctl(fd, cmd, arg);
4688 } else {
4689 static int count;
4690 if (++count <= 50) {
4691 char buf[10];
4692 char *path = (char *)__get_free_page(GFP_KERNEL), *fn = "?";
4693
4694 /* find the name of the device. */
4695 if (path) {
4696 struct file *f = fget(fd);
4697 if (f) {
4698 fn = d_path(f->f_dentry, f->f_vfsmnt,
4699 path, PAGE_SIZE);
4700 fput(f);
4701 }
4702 }
4703
4704 sprintf(buf,"'%c'", (cmd>>24) & 0x3f);
4705 if (!isprint(buf[1]))
4706 sprintf(buf, "%02x", buf[1]);
4707 printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
4708 "cmd(%08x){%s} arg(%08x) on %s\n",
4709 current->comm, current->pid,
4710 (int)fd, (unsigned int)cmd, buf, (unsigned int)arg,
4711 fn);
4712 if (path)
4713 free_page((unsigned long)path);
4714 }
4715 error = -EINVAL;
4716 }
4717 out:
4718 fput(filp);
4719 out2:
4720 return error;
4721 }
4722
4723 extern unsigned long ia32_sys_call_table[];
4724 EXPORT_SYMBOL(ia32_sys_call_table);
4725