aboutsummaryrefslogtreecommitdiffstats
path: root/fs/compat_ioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/compat_ioctl.c')
-rw-r--r--fs/compat_ioctl.c1551
1 files changed, 217 insertions, 1334 deletions
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index d84e7058c298..641640dc7ae5 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -23,7 +23,6 @@
23#include <linux/ioctl.h> 23#include <linux/ioctl.h>
24#include <linux/if.h> 24#include <linux/if.h>
25#include <linux/if_bridge.h> 25#include <linux/if_bridge.h>
26#include <linux/slab.h>
27#include <linux/raid/md_u.h> 26#include <linux/raid/md_u.h>
28#include <linux/kd.h> 27#include <linux/kd.h>
29#include <linux/route.h> 28#include <linux/route.h>
@@ -60,6 +59,7 @@
60#include <linux/i2c.h> 59#include <linux/i2c.h>
61#include <linux/i2c-dev.h> 60#include <linux/i2c-dev.h>
62#include <linux/atalk.h> 61#include <linux/atalk.h>
62#include <linux/gfp.h>
63 63
64#include <net/bluetooth/bluetooth.h> 64#include <net/bluetooth/bluetooth.h>
65#include <net/bluetooth/hci.h> 65#include <net/bluetooth/hci.h>
@@ -102,7 +102,6 @@
102#include <linux/nbd.h> 102#include <linux/nbd.h>
103#include <linux/random.h> 103#include <linux/random.h>
104#include <linux/filter.h> 104#include <linux/filter.h>
105#include <linux/pktcdvd.h>
106 105
107#include <linux/hiddev.h> 106#include <linux/hiddev.h>
108 107
@@ -111,43 +110,40 @@
111#include <linux/dvb/frontend.h> 110#include <linux/dvb/frontend.h>
112#include <linux/dvb/video.h> 111#include <linux/dvb/video.h>
113 112
113#include <linux/sort.h>
114
114#ifdef CONFIG_SPARC 115#ifdef CONFIG_SPARC
115#include <asm/fbio.h> 116#include <asm/fbio.h>
116#endif 117#endif
117 118
118static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd, 119static int w_long(unsigned int fd, unsigned int cmd,
119 unsigned long arg, struct file *f) 120 compat_ulong_t __user *argp)
120{
121 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
122}
123
124static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
125{ 121{
126 mm_segment_t old_fs = get_fs(); 122 mm_segment_t old_fs = get_fs();
127 int err; 123 int err;
128 unsigned long val; 124 unsigned long val;
129 125
130 set_fs (KERNEL_DS); 126 set_fs (KERNEL_DS);
131 err = sys_ioctl(fd, cmd, (unsigned long)&val); 127 err = sys_ioctl(fd, cmd, (unsigned long)&val);
132 set_fs (old_fs); 128 set_fs (old_fs);
133 if (!err && put_user(val, (u32 __user *)compat_ptr(arg))) 129 if (!err && put_user(val, argp))
134 return -EFAULT; 130 return -EFAULT;
135 return err; 131 return err;
136} 132}
137 133
138static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg) 134static int rw_long(unsigned int fd, unsigned int cmd,
135 compat_ulong_t __user *argp)
139{ 136{
140 mm_segment_t old_fs = get_fs(); 137 mm_segment_t old_fs = get_fs();
141 u32 __user *argptr = compat_ptr(arg);
142 int err; 138 int err;
143 unsigned long val; 139 unsigned long val;
144 140
145 if(get_user(val, argptr)) 141 if(get_user(val, argp))
146 return -EFAULT; 142 return -EFAULT;
147 set_fs (KERNEL_DS); 143 set_fs (KERNEL_DS);
148 err = sys_ioctl(fd, cmd, (unsigned long)&val); 144 err = sys_ioctl(fd, cmd, (unsigned long)&val);
149 set_fs (old_fs); 145 set_fs (old_fs);
150 if (!err && put_user(val, argptr)) 146 if (!err && put_user(val, argp))
151 return -EFAULT; 147 return -EFAULT;
152 return err; 148 return err;
153} 149}
@@ -161,7 +157,8 @@ struct compat_video_event {
161 } u; 157 } u;
162}; 158};
163 159
164static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg) 160static int do_video_get_event(unsigned int fd, unsigned int cmd,
161 struct compat_video_event __user *up)
165{ 162{
166 struct video_event kevent; 163 struct video_event kevent;
167 mm_segment_t old_fs = get_fs(); 164 mm_segment_t old_fs = get_fs();
@@ -172,8 +169,6 @@ static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long a
172 set_fs(old_fs); 169 set_fs(old_fs);
173 170
174 if (!err) { 171 if (!err) {
175 struct compat_video_event __user *up = compat_ptr(arg);
176
177 err = put_user(kevent.type, &up->type); 172 err = put_user(kevent.type, &up->type);
178 err |= put_user(kevent.timestamp, &up->timestamp); 173 err |= put_user(kevent.timestamp, &up->timestamp);
179 err |= put_user(kevent.u.size.w, &up->u.size.w); 174 err |= put_user(kevent.u.size.w, &up->u.size.w);
@@ -192,15 +187,14 @@ struct compat_video_still_picture {
192 int32_t size; 187 int32_t size;
193}; 188};
194 189
195static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg) 190static int do_video_stillpicture(unsigned int fd, unsigned int cmd,
191 struct compat_video_still_picture __user *up)
196{ 192{
197 struct compat_video_still_picture __user *up;
198 struct video_still_picture __user *up_native; 193 struct video_still_picture __user *up_native;
199 compat_uptr_t fp; 194 compat_uptr_t fp;
200 int32_t size; 195 int32_t size;
201 int err; 196 int err;
202 197
203 up = (struct compat_video_still_picture __user *) arg;
204 err = get_user(fp, &up->iFrame); 198 err = get_user(fp, &up->iFrame);
205 err |= get_user(size, &up->size); 199 err |= get_user(size, &up->size);
206 if (err) 200 if (err)
@@ -224,14 +218,13 @@ struct compat_video_spu_palette {
224 compat_uptr_t palette; 218 compat_uptr_t palette;
225}; 219};
226 220
227static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg) 221static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
222 struct compat_video_spu_palette __user *up)
228{ 223{
229 struct compat_video_spu_palette __user *up;
230 struct video_spu_palette __user *up_native; 224 struct video_spu_palette __user *up_native;
231 compat_uptr_t palp; 225 compat_uptr_t palp;
232 int length, err; 226 int length, err;
233 227
234 up = (struct compat_video_spu_palette __user *) arg;
235 err = get_user(palp, &up->palette); 228 err = get_user(palp, &up->palette);
236 err |= get_user(length, &up->length); 229 err |= get_user(length, &up->length);
237 230
@@ -246,428 +239,6 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned
246 return err; 239 return err;
247} 240}
248 241
249#ifdef CONFIG_NET
250static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
251{
252 struct compat_timeval __user *up = compat_ptr(arg);
253 struct timeval ktv;
254 mm_segment_t old_fs = get_fs();
255 int err;
256
257 set_fs(KERNEL_DS);
258 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
259 set_fs(old_fs);
260 if(!err) {
261 err = put_user(ktv.tv_sec, &up->tv_sec);
262 err |= __put_user(ktv.tv_usec, &up->tv_usec);
263 }
264 return err;
265}
266
267static int do_siocgstampns(unsigned int fd, unsigned int cmd, unsigned long arg)
268{
269 struct compat_timespec __user *up = compat_ptr(arg);
270 struct timespec kts;
271 mm_segment_t old_fs = get_fs();
272 int err;
273
274 set_fs(KERNEL_DS);
275 err = sys_ioctl(fd, cmd, (unsigned long)&kts);
276 set_fs(old_fs);
277 if (!err) {
278 err = put_user(kts.tv_sec, &up->tv_sec);
279 err |= __put_user(kts.tv_nsec, &up->tv_nsec);
280 }
281 return err;
282}
283
284struct ifmap32 {
285 compat_ulong_t mem_start;
286 compat_ulong_t mem_end;
287 unsigned short base_addr;
288 unsigned char irq;
289 unsigned char dma;
290 unsigned char port;
291};
292
293struct ifreq32 {
294#define IFHWADDRLEN 6
295#define IFNAMSIZ 16
296 union {
297 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
298 } ifr_ifrn;
299 union {
300 struct sockaddr ifru_addr;
301 struct sockaddr ifru_dstaddr;
302 struct sockaddr ifru_broadaddr;
303 struct sockaddr ifru_netmask;
304 struct sockaddr ifru_hwaddr;
305 short ifru_flags;
306 compat_int_t ifru_ivalue;
307 compat_int_t ifru_mtu;
308 struct ifmap32 ifru_map;
309 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
310 char ifru_newname[IFNAMSIZ];
311 compat_caddr_t ifru_data;
312 /* XXXX? ifru_settings should be here */
313 } ifr_ifru;
314};
315
316struct ifconf32 {
317 compat_int_t ifc_len; /* size of buffer */
318 compat_caddr_t ifcbuf;
319};
320
321static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
322{
323 struct ifreq __user *uifr;
324 int err;
325
326 uifr = compat_alloc_user_space(sizeof(struct ifreq));
327 if (copy_in_user(uifr, compat_ptr(arg), sizeof(struct ifreq32)))
328 return -EFAULT;
329
330 err = sys_ioctl(fd, SIOCGIFNAME, (unsigned long)uifr);
331 if (err)
332 return err;
333
334 if (copy_in_user(compat_ptr(arg), uifr, sizeof(struct ifreq32)))
335 return -EFAULT;
336
337 return 0;
338}
339
340static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
341{
342 struct ifconf32 ifc32;
343 struct ifconf ifc;
344 struct ifconf __user *uifc;
345 struct ifreq32 __user *ifr32;
346 struct ifreq __user *ifr;
347 unsigned int i, j;
348 int err;
349
350 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
351 return -EFAULT;
352
353 if (ifc32.ifcbuf == 0) {
354 ifc32.ifc_len = 0;
355 ifc.ifc_len = 0;
356 ifc.ifc_req = NULL;
357 uifc = compat_alloc_user_space(sizeof(struct ifconf));
358 } else {
359 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
360 sizeof (struct ifreq);
361 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
362 ifc.ifc_len = len;
363 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
364 ifr32 = compat_ptr(ifc32.ifcbuf);
365 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
366 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
367 return -EFAULT;
368 ifr++;
369 ifr32++;
370 }
371 }
372 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
373 return -EFAULT;
374
375 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
376 if (err)
377 return err;
378
379 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
380 return -EFAULT;
381
382 ifr = ifc.ifc_req;
383 ifr32 = compat_ptr(ifc32.ifcbuf);
384 for (i = 0, j = 0;
385 i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
386 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
387 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
388 return -EFAULT;
389 ifr32++;
390 ifr++;
391 }
392
393 if (ifc32.ifcbuf == 0) {
394 /* Translate from 64-bit structure multiple to
395 * a 32-bit one.
396 */
397 i = ifc.ifc_len;
398 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
399 ifc32.ifc_len = i;
400 } else {
401 ifc32.ifc_len = i;
402 }
403 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
404 return -EFAULT;
405
406 return 0;
407}
408
409static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
410{
411 struct ifreq __user *ifr;
412 struct ifreq32 __user *ifr32;
413 u32 data;
414 void __user *datap;
415
416 ifr = compat_alloc_user_space(sizeof(*ifr));
417 ifr32 = compat_ptr(arg);
418
419 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
420 return -EFAULT;
421
422 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
423 return -EFAULT;
424
425 datap = compat_ptr(data);
426 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
427 return -EFAULT;
428
429 return sys_ioctl(fd, cmd, (unsigned long) ifr);
430}
431
432static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
433{
434 struct ifreq kifr;
435 struct ifreq __user *uifr;
436 struct ifreq32 __user *ifr32 = compat_ptr(arg);
437 mm_segment_t old_fs;
438 int err;
439 u32 data;
440 void __user *datap;
441
442 switch (cmd) {
443 case SIOCBONDENSLAVE:
444 case SIOCBONDRELEASE:
445 case SIOCBONDSETHWADDR:
446 case SIOCBONDCHANGEACTIVE:
447 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
448 return -EFAULT;
449
450 old_fs = get_fs();
451 set_fs (KERNEL_DS);
452 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
453 set_fs (old_fs);
454
455 return err;
456 case SIOCBONDSLAVEINFOQUERY:
457 case SIOCBONDINFOQUERY:
458 uifr = compat_alloc_user_space(sizeof(*uifr));
459 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
460 return -EFAULT;
461
462 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
463 return -EFAULT;
464
465 datap = compat_ptr(data);
466 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
467 return -EFAULT;
468
469 return sys_ioctl (fd, cmd, (unsigned long)uifr);
470 default:
471 return -EINVAL;
472 };
473}
474
475static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
476{
477 struct ifreq __user *u_ifreq64;
478 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
479 char tmp_buf[IFNAMSIZ];
480 void __user *data64;
481 u32 data32;
482
483 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
484 IFNAMSIZ))
485 return -EFAULT;
486 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
487 return -EFAULT;
488 data64 = compat_ptr(data32);
489
490 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
491
492 /* Don't check these user accesses, just let that get trapped
493 * in the ioctl handler instead.
494 */
495 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
496 IFNAMSIZ))
497 return -EFAULT;
498 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
499 return -EFAULT;
500
501 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
502}
503
504static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
505{
506 struct ifreq ifr;
507 struct ifreq32 __user *uifr32;
508 struct ifmap32 __user *uifmap32;
509 mm_segment_t old_fs;
510 int err;
511
512 uifr32 = compat_ptr(arg);
513 uifmap32 = &uifr32->ifr_ifru.ifru_map;
514 switch (cmd) {
515 case SIOCSIFMAP:
516 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
517 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
518 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
519 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
520 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
521 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
522 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
523 if (err)
524 return -EFAULT;
525 break;
526 case SIOCSHWTSTAMP:
527 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
528 return -EFAULT;
529 ifr.ifr_data = compat_ptr(uifr32->ifr_ifru.ifru_data);
530 break;
531 default:
532 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
533 return -EFAULT;
534 break;
535 }
536 old_fs = get_fs();
537 set_fs (KERNEL_DS);
538 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
539 set_fs (old_fs);
540 if (!err) {
541 switch (cmd) {
542 /* TUNSETIFF is defined as _IOW, it should be _IORW
543 * as the data is copied back to user space, but that
544 * cannot be fixed without breaking all existing apps.
545 */
546 case TUNSETIFF:
547 case TUNGETIFF:
548 case SIOCGIFFLAGS:
549 case SIOCGIFMETRIC:
550 case SIOCGIFMTU:
551 case SIOCGIFMEM:
552 case SIOCGIFHWADDR:
553 case SIOCGIFINDEX:
554 case SIOCGIFADDR:
555 case SIOCGIFBRDADDR:
556 case SIOCGIFDSTADDR:
557 case SIOCGIFNETMASK:
558 case SIOCGIFTXQLEN:
559 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
560 return -EFAULT;
561 break;
562 case SIOCGIFMAP:
563 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
564 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
565 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
566 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
567 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
568 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
569 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
570 if (err)
571 err = -EFAULT;
572 break;
573 }
574 }
575 return err;
576}
577
578struct rtentry32 {
579 u32 rt_pad1;
580 struct sockaddr rt_dst; /* target address */
581 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
582 struct sockaddr rt_genmask; /* target network mask (IP) */
583 unsigned short rt_flags;
584 short rt_pad2;
585 u32 rt_pad3;
586 unsigned char rt_tos;
587 unsigned char rt_class;
588 short rt_pad4;
589 short rt_metric; /* +1 for binary compatibility! */
590 /* char * */ u32 rt_dev; /* forcing the device at add */
591 u32 rt_mtu; /* per route MTU/Window */
592 u32 rt_window; /* Window clamping */
593 unsigned short rt_irtt; /* Initial RTT */
594
595};
596
597struct in6_rtmsg32 {
598 struct in6_addr rtmsg_dst;
599 struct in6_addr rtmsg_src;
600 struct in6_addr rtmsg_gateway;
601 u32 rtmsg_type;
602 u16 rtmsg_dst_len;
603 u16 rtmsg_src_len;
604 u32 rtmsg_metric;
605 u32 rtmsg_info;
606 u32 rtmsg_flags;
607 s32 rtmsg_ifindex;
608};
609
610static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
611{
612 int ret;
613 void *r = NULL;
614 struct in6_rtmsg r6;
615 struct rtentry r4;
616 char devname[16];
617 u32 rtdev;
618 mm_segment_t old_fs = get_fs();
619
620 struct socket *mysock = sockfd_lookup(fd, &ret);
621
622 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
623 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
624 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
625 3 * sizeof(struct in6_addr));
626 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
627 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
628 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
629 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
630 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
631 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
632 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
633
634 r = (void *) &r6;
635 } else { /* ipv4 */
636 struct rtentry32 __user *ur4 = compat_ptr(arg);
637 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
638 3 * sizeof(struct sockaddr));
639 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
640 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
641 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
642 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
643 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
644 ret |= __get_user (rtdev, &(ur4->rt_dev));
645 if (rtdev) {
646 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
647 r4.rt_dev = devname; devname[15] = 0;
648 } else
649 r4.rt_dev = NULL;
650
651 r = (void *) &r4;
652 }
653
654 if (ret) {
655 ret = -EFAULT;
656 goto out;
657 }
658
659 set_fs (KERNEL_DS);
660 ret = sys_ioctl (fd, cmd, (unsigned long) r);
661 set_fs (old_fs);
662
663out:
664 if (mysock)
665 sockfd_put(mysock);
666
667 return ret;
668}
669#endif
670
671#ifdef CONFIG_BLOCK 242#ifdef CONFIG_BLOCK
672typedef struct sg_io_hdr32 { 243typedef struct sg_io_hdr32 {
673 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ 244 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
@@ -721,16 +292,21 @@ static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iov
721 return 0; 292 return 0;
722} 293}
723 294
724static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) 295static int sg_ioctl_trans(unsigned int fd, unsigned int cmd,
296 sg_io_hdr32_t __user *sgio32)
725{ 297{
726 sg_io_hdr_t __user *sgio; 298 sg_io_hdr_t __user *sgio;
727 sg_io_hdr32_t __user *sgio32;
728 u16 iovec_count; 299 u16 iovec_count;
729 u32 data; 300 u32 data;
730 void __user *dxferp; 301 void __user *dxferp;
731 int err; 302 int err;
303 int interface_id;
304
305 if (get_user(interface_id, &sgio32->interface_id))
306 return -EFAULT;
307 if (interface_id != 'S')
308 return sys_ioctl(fd, cmd, (unsigned long)sgio32);
732 309
733 sgio32 = compat_ptr(arg);
734 if (get_user(iovec_count, &sgio32->iovec_count)) 310 if (get_user(iovec_count, &sgio32->iovec_count))
735 return -EFAULT; 311 return -EFAULT;
736 312
@@ -820,11 +396,11 @@ struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
820 int unused; 396 int unused;
821}; 397};
822 398
823static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg) 399static int sg_grt_trans(unsigned int fd, unsigned int cmd, struct
400 compat_sg_req_info __user *o)
824{ 401{
825 int err, i; 402 int err, i;
826 sg_req_info_t __user *r; 403 sg_req_info_t __user *r;
827 struct compat_sg_req_info __user *o = (void __user *)arg;
828 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE); 404 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
829 err = sys_ioctl(fd,cmd,(unsigned long)r); 405 err = sys_ioctl(fd,cmd,(unsigned long)r);
830 if (err < 0) 406 if (err < 0)
@@ -852,9 +428,9 @@ struct sock_fprog32 {
852#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32) 428#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
853#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32) 429#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
854 430
855static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) 431static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd,
432 struct sock_fprog32 __user *u_fprog32)
856{ 433{
857 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
858 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog)); 434 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
859 void __user *fptr64; 435 void __user *fptr64;
860 u32 fptr32; 436 u32 fptr32;
@@ -891,15 +467,14 @@ struct ppp_idle32 {
891}; 467};
892#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32) 468#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
893 469
894static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg) 470static int ppp_gidle(unsigned int fd, unsigned int cmd,
471 struct ppp_idle32 __user *idle32)
895{ 472{
896 struct ppp_idle __user *idle; 473 struct ppp_idle __user *idle;
897 struct ppp_idle32 __user *idle32;
898 __kernel_time_t xmit, recv; 474 __kernel_time_t xmit, recv;
899 int err; 475 int err;
900 476
901 idle = compat_alloc_user_space(sizeof(*idle)); 477 idle = compat_alloc_user_space(sizeof(*idle));
902 idle32 = compat_ptr(arg);
903 478
904 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle); 479 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
905 480
@@ -913,15 +488,14 @@ static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
913 return err; 488 return err;
914} 489}
915 490
916static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg) 491static int ppp_scompress(unsigned int fd, unsigned int cmd,
492 struct ppp_option_data32 __user *odata32)
917{ 493{
918 struct ppp_option_data __user *odata; 494 struct ppp_option_data __user *odata;
919 struct ppp_option_data32 __user *odata32;
920 __u32 data; 495 __u32 data;
921 void __user *datap; 496 void __user *datap;
922 497
923 odata = compat_alloc_user_space(sizeof(*odata)); 498 odata = compat_alloc_user_space(sizeof(*odata));
924 odata32 = compat_ptr(arg);
925 499
926 if (get_user(data, &odata32->ptr)) 500 if (get_user(data, &odata32->ptr))
927 return -EFAULT; 501 return -EFAULT;
@@ -937,35 +511,6 @@ static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
937 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata); 511 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
938} 512}
939 513
940static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
941{
942 int err;
943
944 switch (cmd) {
945 case PPPIOCGIDLE32:
946 err = ppp_gidle(fd, cmd, arg);
947 break;
948
949 case PPPIOCSCOMPRESS32:
950 err = ppp_scompress(fd, cmd, arg);
951 break;
952
953 default:
954 do {
955 static int count;
956 if (++count <= 20)
957 printk("ppp_ioctl: Unknown cmd fd(%d) "
958 "cmd(%08x) arg(%08x)\n",
959 (int)fd, (unsigned int)cmd, (unsigned int)arg);
960 } while(0);
961 err = -EINVAL;
962 break;
963 };
964
965 return err;
966}
967
968
969#ifdef CONFIG_BLOCK 514#ifdef CONFIG_BLOCK
970struct mtget32 { 515struct mtget32 {
971 compat_long_t mt_type; 516 compat_long_t mt_type;
@@ -983,7 +528,7 @@ struct mtpos32 {
983}; 528};
984#define MTIOCPOS32 _IOR('m', 3, struct mtpos32) 529#define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
985 530
986static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) 531static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, void __user *argp)
987{ 532{
988 mm_segment_t old_fs = get_fs(); 533 mm_segment_t old_fs = get_fs();
989 struct mtget get; 534 struct mtget get;
@@ -999,19 +544,10 @@ static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
999 kcmd = MTIOCPOS; 544 kcmd = MTIOCPOS;
1000 karg = &pos; 545 karg = &pos;
1001 break; 546 break;
1002 case MTIOCGET32: 547 default: /* MTIOCGET32 */
1003 kcmd = MTIOCGET; 548 kcmd = MTIOCGET;
1004 karg = &get; 549 karg = &get;
1005 break; 550 break;
1006 default:
1007 do {
1008 static int count;
1009 if (++count <= 20)
1010 printk("mt_ioctl: Unknown cmd fd(%d) "
1011 "cmd(%08x) arg(%08x)\n",
1012 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1013 } while(0);
1014 return -EINVAL;
1015 } 551 }
1016 set_fs (KERNEL_DS); 552 set_fs (KERNEL_DS);
1017 err = sys_ioctl (fd, kcmd, (unsigned long)karg); 553 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
@@ -1020,11 +556,11 @@ static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1020 return err; 556 return err;
1021 switch (cmd) { 557 switch (cmd) {
1022 case MTIOCPOS32: 558 case MTIOCPOS32:
1023 upos32 = compat_ptr(arg); 559 upos32 = argp;
1024 err = __put_user(pos.mt_blkno, &upos32->mt_blkno); 560 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1025 break; 561 break;
1026 case MTIOCGET32: 562 case MTIOCGET32:
1027 umget32 = compat_ptr(arg); 563 umget32 = argp;
1028 err = __put_user(get.mt_type, &umget32->mt_type); 564 err = __put_user(get.mt_type, &umget32->mt_type);
1029 err |= __put_user(get.mt_resid, &umget32->mt_resid); 565 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1030 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg); 566 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
@@ -1039,162 +575,8 @@ static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1039 575
1040#endif /* CONFIG_BLOCK */ 576#endif /* CONFIG_BLOCK */
1041 577
1042#ifdef CONFIG_VT 578static int do_smb_getmountuid(unsigned int fd, unsigned int cmd,
1043 579 compat_uid_t __user *argp)
1044static int vt_check(struct file *file)
1045{
1046 struct tty_struct *tty;
1047 struct inode *inode = file->f_path.dentry->d_inode;
1048 struct vc_data *vc;
1049
1050 if (file->f_op->unlocked_ioctl != tty_ioctl)
1051 return -EINVAL;
1052
1053 tty = (struct tty_struct *)file->private_data;
1054 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1055 return -EINVAL;
1056
1057 if (tty->ops->ioctl != vt_ioctl)
1058 return -EINVAL;
1059
1060 vc = (struct vc_data *)tty->driver_data;
1061 if (!vc_cons_allocated(vc->vc_num)) /* impossible? */
1062 return -ENOIOCTLCMD;
1063
1064 /*
1065 * To have permissions to do most of the vt ioctls, we either have
1066 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
1067 */
1068 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1069 return 1;
1070 return 0;
1071}
1072
1073struct consolefontdesc32 {
1074 unsigned short charcount; /* characters in font (256 or 512) */
1075 unsigned short charheight; /* scan lines per character (1-32) */
1076 compat_caddr_t chardata; /* font data in expanded form */
1077};
1078
1079static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1080{
1081 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1082 struct console_font_op op;
1083 compat_caddr_t data;
1084 int i, perm;
1085
1086 perm = vt_check(file);
1087 if (perm < 0) return perm;
1088
1089 switch (cmd) {
1090 case PIO_FONTX:
1091 if (!perm)
1092 return -EPERM;
1093 op.op = KD_FONT_OP_SET;
1094 op.flags = 0;
1095 op.width = 8;
1096 if (get_user(op.height, &user_cfd->charheight) ||
1097 get_user(op.charcount, &user_cfd->charcount) ||
1098 get_user(data, &user_cfd->chardata))
1099 return -EFAULT;
1100 op.data = compat_ptr(data);
1101 return con_font_op(vc_cons[fg_console].d, &op);
1102 case GIO_FONTX:
1103 op.op = KD_FONT_OP_GET;
1104 op.flags = 0;
1105 op.width = 8;
1106 if (get_user(op.height, &user_cfd->charheight) ||
1107 get_user(op.charcount, &user_cfd->charcount) ||
1108 get_user(data, &user_cfd->chardata))
1109 return -EFAULT;
1110 if (!data)
1111 return 0;
1112 op.data = compat_ptr(data);
1113 i = con_font_op(vc_cons[fg_console].d, &op);
1114 if (i)
1115 return i;
1116 if (put_user(op.height, &user_cfd->charheight) ||
1117 put_user(op.charcount, &user_cfd->charcount) ||
1118 put_user((compat_caddr_t)(unsigned long)op.data,
1119 &user_cfd->chardata))
1120 return -EFAULT;
1121 return 0;
1122 }
1123 return -EINVAL;
1124}
1125
1126struct console_font_op32 {
1127 compat_uint_t op; /* operation code KD_FONT_OP_* */
1128 compat_uint_t flags; /* KD_FONT_FLAG_* */
1129 compat_uint_t width, height; /* font size */
1130 compat_uint_t charcount;
1131 compat_caddr_t data; /* font data with height fixed to 32 */
1132};
1133
1134static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1135{
1136 struct console_font_op op;
1137 struct console_font_op32 __user *fontop = compat_ptr(arg);
1138 int perm = vt_check(file), i;
1139 struct vc_data *vc;
1140
1141 if (perm < 0) return perm;
1142
1143 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1144 return -EFAULT;
1145 if (!perm && op.op != KD_FONT_OP_GET)
1146 return -EPERM;
1147 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1148 op.flags |= KD_FONT_FLAG_OLD;
1149 vc = ((struct tty_struct *)file->private_data)->driver_data;
1150 i = con_font_op(vc, &op);
1151 if (i)
1152 return i;
1153 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1154 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1155 return -EFAULT;
1156 return 0;
1157}
1158
1159struct unimapdesc32 {
1160 unsigned short entry_ct;
1161 compat_caddr_t entries;
1162};
1163
1164static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1165{
1166 struct unimapdesc32 tmp;
1167 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1168 int perm = vt_check(file);
1169 struct vc_data *vc;
1170
1171 if (perm < 0)
1172 return perm;
1173 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1174 return -EFAULT;
1175 if (tmp.entries)
1176 if (!access_ok(VERIFY_WRITE, compat_ptr(tmp.entries),
1177 tmp.entry_ct*sizeof(struct unipair)))
1178 return -EFAULT;
1179 vc = ((struct tty_struct *)file->private_data)->driver_data;
1180 switch (cmd) {
1181 case PIO_UNIMAP:
1182 if (!perm)
1183 return -EPERM;
1184 return con_set_unimap(vc, tmp.entry_ct,
1185 compat_ptr(tmp.entries));
1186 case GIO_UNIMAP:
1187 if (!perm && fg_console != vc->vc_num)
1188 return -EPERM;
1189 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct),
1190 compat_ptr(tmp.entries));
1191 }
1192 return 0;
1193}
1194
1195#endif /* CONFIG_VT */
1196
1197static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1198{ 580{
1199 mm_segment_t old_fs = get_fs(); 581 mm_segment_t old_fs = get_fs();
1200 __kernel_uid_t kuid; 582 __kernel_uid_t kuid;
@@ -1207,184 +589,15 @@ static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long a
1207 set_fs(old_fs); 589 set_fs(old_fs);
1208 590
1209 if (err >= 0) 591 if (err >= 0)
1210 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg)); 592 err = put_user(kuid, argp);
1211
1212 return err;
1213}
1214
1215struct atmif_sioc32 {
1216 compat_int_t number;
1217 compat_int_t length;
1218 compat_caddr_t arg;
1219};
1220
1221struct atm_iobuf32 {
1222 compat_int_t length;
1223 compat_caddr_t buffer;
1224};
1225
1226#define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1227#define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1228#define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1229#define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1230#define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1231#define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1232#define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1233#define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1234#define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1235#define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1236#define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1237#define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1238#define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1239#define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1240#define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1241#define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1242#define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1243
1244static struct {
1245 unsigned int cmd32;
1246 unsigned int cmd;
1247} atm_ioctl_map[] = {
1248 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1249 { ATM_GETNAMES32, ATM_GETNAMES },
1250 { ATM_GETTYPE32, ATM_GETTYPE },
1251 { ATM_GETESI32, ATM_GETESI },
1252 { ATM_GETADDR32, ATM_GETADDR },
1253 { ATM_RSTADDR32, ATM_RSTADDR },
1254 { ATM_ADDADDR32, ATM_ADDADDR },
1255 { ATM_DELADDR32, ATM_DELADDR },
1256 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1257 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1258 { ATM_SETESI32, ATM_SETESI },
1259 { ATM_SETESIF32, ATM_SETESIF },
1260 { ATM_GETSTAT32, ATM_GETSTAT },
1261 { ATM_GETSTATZ32, ATM_GETSTATZ },
1262 { ATM_GETLOOP32, ATM_GETLOOP },
1263 { ATM_SETLOOP32, ATM_SETLOOP },
1264 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1265};
1266
1267#define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
1268
1269static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1270{
1271 struct atm_iobuf __user *iobuf;
1272 struct atm_iobuf32 __user *iobuf32;
1273 u32 data;
1274 void __user *datap;
1275 int len, err;
1276
1277 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1278 iobuf32 = compat_ptr(arg);
1279
1280 if (get_user(len, &iobuf32->length) ||
1281 get_user(data, &iobuf32->buffer))
1282 return -EFAULT;
1283 datap = compat_ptr(data);
1284 if (put_user(len, &iobuf->length) ||
1285 put_user(datap, &iobuf->buffer))
1286 return -EFAULT;
1287
1288 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1289
1290 if (!err) {
1291 if (copy_in_user(&iobuf32->length, &iobuf->length,
1292 sizeof(int)))
1293 err = -EFAULT;
1294 }
1295
1296 return err;
1297}
1298
1299static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1300{
1301 struct atmif_sioc __user *sioc;
1302 struct atmif_sioc32 __user *sioc32;
1303 u32 data;
1304 void __user *datap;
1305 int err;
1306
1307 sioc = compat_alloc_user_space(sizeof(*sioc));
1308 sioc32 = compat_ptr(arg);
1309
1310 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1311 get_user(data, &sioc32->arg))
1312 return -EFAULT;
1313 datap = compat_ptr(data);
1314 if (put_user(datap, &sioc->arg))
1315 return -EFAULT;
1316 593
1317 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1318
1319 if (!err) {
1320 if (copy_in_user(&sioc32->length, &sioc->length,
1321 sizeof(int)))
1322 err = -EFAULT;
1323 }
1324 return err; 594 return err;
1325} 595}
1326 596
1327static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg) 597static int ioc_settimeout(unsigned int fd, unsigned int cmd,
1328{ 598 compat_ulong_t __user *argp)
1329 int i;
1330 unsigned int cmd = 0;
1331
1332 switch (cmd32) {
1333 case SONET_GETSTAT:
1334 case SONET_GETSTATZ:
1335 case SONET_GETDIAG:
1336 case SONET_SETDIAG:
1337 case SONET_CLRDIAG:
1338 case SONET_SETFRAMING:
1339 case SONET_GETFRAMING:
1340 case SONET_GETFRSENSE:
1341 return do_atmif_sioc(fd, cmd32, arg);
1342 }
1343
1344 for (i = 0; i < NR_ATM_IOCTL; i++) {
1345 if (cmd32 == atm_ioctl_map[i].cmd32) {
1346 cmd = atm_ioctl_map[i].cmd;
1347 break;
1348 }
1349 }
1350 if (i == NR_ATM_IOCTL)
1351 return -EINVAL;
1352
1353 switch (cmd) {
1354 case ATM_GETNAMES:
1355 return do_atm_iobuf(fd, cmd, arg);
1356
1357 case ATM_GETLINKRATE:
1358 case ATM_GETTYPE:
1359 case ATM_GETESI:
1360 case ATM_GETADDR:
1361 case ATM_RSTADDR:
1362 case ATM_ADDADDR:
1363 case ATM_DELADDR:
1364 case ATM_GETCIRANGE:
1365 case ATM_SETCIRANGE:
1366 case ATM_SETESI:
1367 case ATM_SETESIF:
1368 case ATM_GETSTAT:
1369 case ATM_GETSTATZ:
1370 case ATM_GETLOOP:
1371 case ATM_SETLOOP:
1372 case ATM_QUERYLOOP:
1373 return do_atmif_sioc(fd, cmd, arg);
1374 }
1375
1376 return -EINVAL;
1377}
1378
1379static __used int
1380ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1381{
1382 return -EINVAL;
1383}
1384
1385static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1386{ 599{
1387 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg); 600 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, argp);
1388} 601}
1389 602
1390/* Bluetooth ioctls */ 603/* Bluetooth ioctls */
@@ -1442,15 +655,15 @@ static int set_raw32_request(struct raw_config_request *req, struct raw32_config
1442 return ret ? -EFAULT : 0; 655 return ret ? -EFAULT : 0;
1443} 656}
1444 657
1445static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg) 658static int raw_ioctl(unsigned fd, unsigned cmd,
659 struct raw32_config_request __user *user_req)
1446{ 660{
1447 int ret; 661 int ret;
1448 662
1449 switch (cmd) { 663 switch (cmd) {
1450 case RAW_SETBIND: 664 case RAW_SETBIND:
1451 case RAW_GETBIND: { 665 default: { /* RAW_GETBIND */
1452 struct raw_config_request req; 666 struct raw_config_request req;
1453 struct raw32_config_request __user *user_req = compat_ptr(arg);
1454 mm_segment_t oldfs = get_fs(); 667 mm_segment_t oldfs = get_fs();
1455 668
1456 if ((ret = get_raw32_request(&req, user_req))) 669 if ((ret = get_raw32_request(&req, user_req)))
@@ -1465,9 +678,6 @@ static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1465 } 678 }
1466 break; 679 break;
1467 } 680 }
1468 default:
1469 ret = sys_ioctl(fd, cmd, arg);
1470 break;
1471 } 681 }
1472 return ret; 682 return ret;
1473} 683}
@@ -1495,11 +705,11 @@ struct serial_struct32 {
1495 compat_int_t reserved[1]; 705 compat_int_t reserved[1];
1496}; 706};
1497 707
1498static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg) 708static int serial_struct_ioctl(unsigned fd, unsigned cmd,
709 struct serial_struct32 __user *ss32)
1499{ 710{
1500 typedef struct serial_struct SS; 711 typedef struct serial_struct SS;
1501 typedef struct serial_struct32 SS32; 712 typedef struct serial_struct32 SS32;
1502 struct serial_struct32 __user *ss32 = compat_ptr(arg);
1503 int err; 713 int err;
1504 struct serial_struct ss; 714 struct serial_struct ss;
1505 mm_segment_t oldseg = get_fs(); 715 mm_segment_t oldseg = get_fs();
@@ -1537,96 +747,6 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1537 return err; 747 return err;
1538} 748}
1539 749
1540struct usbdevfs_ctrltransfer32 {
1541 u8 bRequestType;
1542 u8 bRequest;
1543 u16 wValue;
1544 u16 wIndex;
1545 u16 wLength;
1546 u32 timeout; /* in milliseconds */
1547 compat_caddr_t data;
1548};
1549
1550#define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
1551
1552static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
1553{
1554 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
1555 struct usbdevfs_ctrltransfer __user *p;
1556 __u32 udata;
1557 p = compat_alloc_user_space(sizeof(*p));
1558 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
1559 get_user(udata, &p32->data) ||
1560 put_user(compat_ptr(udata), &p->data))
1561 return -EFAULT;
1562 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
1563}
1564
1565
1566struct usbdevfs_bulktransfer32 {
1567 compat_uint_t ep;
1568 compat_uint_t len;
1569 compat_uint_t timeout; /* in milliseconds */
1570 compat_caddr_t data;
1571};
1572
1573#define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
1574
1575static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
1576{
1577 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
1578 struct usbdevfs_bulktransfer __user *p;
1579 compat_uint_t n;
1580 compat_caddr_t addr;
1581
1582 p = compat_alloc_user_space(sizeof(*p));
1583
1584 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
1585 get_user(n, &p32->len) || put_user(n, &p->len) ||
1586 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
1587 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
1588 return -EFAULT;
1589
1590 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
1591}
1592
1593
1594/*
1595 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
1596 * are handled in usbdevfs core. -Christopher Li
1597 */
1598
1599struct usbdevfs_disconnectsignal32 {
1600 compat_int_t signr;
1601 compat_caddr_t context;
1602};
1603
1604#define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
1605
1606static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
1607{
1608 struct usbdevfs_disconnectsignal kdis;
1609 struct usbdevfs_disconnectsignal32 __user *udis;
1610 mm_segment_t old_fs;
1611 u32 uctx;
1612 int err;
1613
1614 udis = compat_ptr(arg);
1615
1616 if (get_user(kdis.signr, &udis->signr) ||
1617 __get_user(uctx, &udis->context))
1618 return -EFAULT;
1619
1620 kdis.context = compat_ptr(uctx);
1621
1622 old_fs = get_fs();
1623 set_fs(KERNEL_DS);
1624 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
1625 set_fs(old_fs);
1626
1627 return err;
1628}
1629
1630/* 750/*
1631 * I2C layer ioctls 751 * I2C layer ioctls
1632 */ 752 */
@@ -1655,9 +775,9 @@ struct i2c_rdwr_aligned {
1655 struct i2c_msg msgs[0]; 775 struct i2c_msg msgs[0];
1656}; 776};
1657 777
1658static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) 778static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
779 struct i2c_rdwr_ioctl_data32 __user *udata)
1659{ 780{
1660 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
1661 struct i2c_rdwr_aligned __user *tdata; 781 struct i2c_rdwr_aligned __user *tdata;
1662 struct i2c_msg __user *tmsgs; 782 struct i2c_msg __user *tmsgs;
1663 struct i2c_msg32 __user *umsgs; 783 struct i2c_msg32 __user *umsgs;
@@ -1691,10 +811,10 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long ar
1691 return sys_ioctl(fd, cmd, (unsigned long)tdata); 811 return sys_ioctl(fd, cmd, (unsigned long)tdata);
1692} 812}
1693 813
1694static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) 814static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd,
815 struct i2c_smbus_ioctl_data32 __user *udata)
1695{ 816{
1696 struct i2c_smbus_ioctl_data __user *tdata; 817 struct i2c_smbus_ioctl_data __user *tdata;
1697 struct i2c_smbus_ioctl_data32 __user *udata;
1698 compat_caddr_t datap; 818 compat_caddr_t datap;
1699 819
1700 tdata = compat_alloc_user_space(sizeof(*tdata)); 820 tdata = compat_alloc_user_space(sizeof(*tdata));
@@ -1703,7 +823,6 @@ static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long a
1703 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata))) 823 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
1704 return -EFAULT; 824 return -EFAULT;
1705 825
1706 udata = compat_ptr(arg);
1707 if (!access_ok(VERIFY_READ, udata, sizeof(*udata))) 826 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
1708 return -EFAULT; 827 return -EFAULT;
1709 828
@@ -1718,27 +837,12 @@ static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long a
1718 return sys_ioctl(fd, cmd, (unsigned long)tdata); 837 return sys_ioctl(fd, cmd, (unsigned long)tdata);
1719} 838}
1720 839
1721/* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
1722 * for some operations; this forces use of the newer bridge-utils that
1723 * use compatible ioctls
1724 */
1725static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
1726{
1727 u32 tmp;
1728
1729 if (get_user(tmp, (u32 __user *) arg))
1730 return -EFAULT;
1731 if (tmp == BRCTL_GET_VERSION)
1732 return BRCTL_VERSION + 1;
1733 return -EINVAL;
1734}
1735
1736#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t) 840#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
1737#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t) 841#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
1738#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t) 842#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
1739#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t) 843#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
1740 844
1741static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg) 845static int rtc_ioctl(unsigned fd, unsigned cmd, void __user *argp)
1742{ 846{
1743 mm_segment_t oldfs = get_fs(); 847 mm_segment_t oldfs = get_fs();
1744 compat_ulong_t val32; 848 compat_ulong_t val32;
@@ -1756,29 +860,14 @@ static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1756 if (ret) 860 if (ret)
1757 return ret; 861 return ret;
1758 val32 = kval; 862 val32 = kval;
1759 return put_user(val32, (unsigned int __user *)arg); 863 return put_user(val32, (unsigned int __user *)argp);
1760 case RTC_IRQP_SET32: 864 case RTC_IRQP_SET32:
1761 return sys_ioctl(fd, RTC_IRQP_SET, arg); 865 return sys_ioctl(fd, RTC_IRQP_SET, (unsigned long)argp);
1762 case RTC_EPOCH_SET32: 866 case RTC_EPOCH_SET32:
1763 return sys_ioctl(fd, RTC_EPOCH_SET, arg); 867 return sys_ioctl(fd, RTC_EPOCH_SET, (unsigned long)argp);
1764 default:
1765 /* unreached */
1766 return -ENOIOCTLCMD;
1767 } 868 }
1768}
1769 869
1770static int 870 return -ENOIOCTLCMD;
1771lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1772{
1773 struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
1774 struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
1775 struct timeval ts;
1776 if (get_user(ts.tv_sec, &tc->tv_sec) ||
1777 get_user(ts.tv_usec, &tc->tv_usec) ||
1778 put_user(ts.tv_sec, &tn->tv_sec) ||
1779 put_user(ts.tv_usec, &tn->tv_usec))
1780 return -EFAULT;
1781 return sys_ioctl(fd, cmd, (unsigned long)tn);
1782} 871}
1783 872
1784/* on ia32 l_start is on a 32-bit boundary */ 873/* on ia32 l_start is on a 32-bit boundary */
@@ -1798,9 +887,9 @@ struct space_resv_32 {
1798#define FS_IOC_RESVSP64_32 _IOW ('X', 42, struct space_resv_32) 887#define FS_IOC_RESVSP64_32 _IOW ('X', 42, struct space_resv_32)
1799 888
1800/* just account for different alignment */ 889/* just account for different alignment */
1801static int compat_ioctl_preallocate(struct file *file, unsigned long arg) 890static int compat_ioctl_preallocate(struct file *file,
891 struct space_resv_32 __user *p32)
1802{ 892{
1803 struct space_resv_32 __user *p32 = compat_ptr(arg);
1804 struct space_resv __user *p = compat_alloc_user_space(sizeof(*p)); 893 struct space_resv __user *p = compat_alloc_user_space(sizeof(*p));
1805 894
1806 if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) || 895 if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
@@ -1816,27 +905,13 @@ static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
1816} 905}
1817#endif 906#endif
1818 907
908/*
909 * simple reversible transform to make our table more evenly
910 * distributed after sorting.
911 */
912#define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff)
1819 913
1820typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int, 914#define COMPATIBLE_IOCTL(cmd) XFORM(cmd),
1821 unsigned long, struct file *);
1822
1823struct ioctl_trans {
1824 unsigned long cmd;
1825 ioctl_trans_handler_t handler;
1826 struct ioctl_trans *next;
1827};
1828
1829#define HANDLE_IOCTL(cmd,handler) \
1830 { (cmd), (ioctl_trans_handler_t)(handler) },
1831
1832/* pointer to compatible structure or no argument */
1833#define COMPATIBLE_IOCTL(cmd) \
1834 { (cmd), do_ioctl32_pointer },
1835
1836/* argument is an unsigned long integer, not a pointer */
1837#define ULONG_IOCTL(cmd) \
1838 { (cmd), (ioctl_trans_handler_t)sys_ioctl },
1839
1840/* ioctl should not be warned about even if it's not implemented. 915/* ioctl should not be warned about even if it's not implemented.
1841 Valid reasons to use this: 916 Valid reasons to use this:
1842 - It is implemented with ->compat_ioctl on some device, but programs 917 - It is implemented with ->compat_ioctl on some device, but programs
@@ -1846,7 +921,7 @@ struct ioctl_trans {
1846 Most other reasons are not valid. */ 921 Most other reasons are not valid. */
1847#define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd) 922#define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
1848 923
1849static struct ioctl_trans ioctl_start[] = { 924static unsigned int ioctl_pointer[] = {
1850/* compatible ioctls first */ 925/* compatible ioctls first */
1851COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */ 926COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */
1852COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */ 927COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */
@@ -1857,7 +932,6 @@ COMPATIBLE_IOCTL(TCSETA)
1857COMPATIBLE_IOCTL(TCSETAW) 932COMPATIBLE_IOCTL(TCSETAW)
1858COMPATIBLE_IOCTL(TCSETAF) 933COMPATIBLE_IOCTL(TCSETAF)
1859COMPATIBLE_IOCTL(TCSBRK) 934COMPATIBLE_IOCTL(TCSBRK)
1860ULONG_IOCTL(TCSBRKP)
1861COMPATIBLE_IOCTL(TCXONC) 935COMPATIBLE_IOCTL(TCXONC)
1862COMPATIBLE_IOCTL(TCFLSH) 936COMPATIBLE_IOCTL(TCFLSH)
1863COMPATIBLE_IOCTL(TCGETS) 937COMPATIBLE_IOCTL(TCGETS)
@@ -1867,7 +941,7 @@ COMPATIBLE_IOCTL(TCSETSF)
1867COMPATIBLE_IOCTL(TIOCLINUX) 941COMPATIBLE_IOCTL(TIOCLINUX)
1868COMPATIBLE_IOCTL(TIOCSBRK) 942COMPATIBLE_IOCTL(TIOCSBRK)
1869COMPATIBLE_IOCTL(TIOCCBRK) 943COMPATIBLE_IOCTL(TIOCCBRK)
1870ULONG_IOCTL(TIOCMIWAIT) 944COMPATIBLE_IOCTL(TIOCGSID)
1871COMPATIBLE_IOCTL(TIOCGICOUNT) 945COMPATIBLE_IOCTL(TIOCGICOUNT)
1872/* Little t */ 946/* Little t */
1873COMPATIBLE_IOCTL(TIOCGETD) 947COMPATIBLE_IOCTL(TIOCGETD)
@@ -1889,7 +963,6 @@ COMPATIBLE_IOCTL(TIOCSTI)
1889COMPATIBLE_IOCTL(TIOCOUTQ) 963COMPATIBLE_IOCTL(TIOCOUTQ)
1890COMPATIBLE_IOCTL(TIOCSPGRP) 964COMPATIBLE_IOCTL(TIOCSPGRP)
1891COMPATIBLE_IOCTL(TIOCGPGRP) 965COMPATIBLE_IOCTL(TIOCGPGRP)
1892ULONG_IOCTL(TIOCSCTTY)
1893COMPATIBLE_IOCTL(TIOCGPTN) 966COMPATIBLE_IOCTL(TIOCGPTN)
1894COMPATIBLE_IOCTL(TIOCSPTLCK) 967COMPATIBLE_IOCTL(TIOCSPTLCK)
1895COMPATIBLE_IOCTL(TIOCSERGETLSR) 968COMPATIBLE_IOCTL(TIOCSERGETLSR)
@@ -1912,44 +985,11 @@ COMPATIBLE_IOCTL(FIGETBSZ)
1912/* 'X' - originally XFS but some now in the VFS */ 985/* 'X' - originally XFS but some now in the VFS */
1913COMPATIBLE_IOCTL(FIFREEZE) 986COMPATIBLE_IOCTL(FIFREEZE)
1914COMPATIBLE_IOCTL(FITHAW) 987COMPATIBLE_IOCTL(FITHAW)
1915/* RAID */
1916COMPATIBLE_IOCTL(RAID_VERSION)
1917COMPATIBLE_IOCTL(GET_ARRAY_INFO)
1918COMPATIBLE_IOCTL(GET_DISK_INFO)
1919COMPATIBLE_IOCTL(PRINT_RAID_DEBUG)
1920COMPATIBLE_IOCTL(RAID_AUTORUN)
1921COMPATIBLE_IOCTL(CLEAR_ARRAY)
1922COMPATIBLE_IOCTL(ADD_NEW_DISK)
1923ULONG_IOCTL(HOT_REMOVE_DISK)
1924COMPATIBLE_IOCTL(SET_ARRAY_INFO)
1925COMPATIBLE_IOCTL(SET_DISK_INFO)
1926COMPATIBLE_IOCTL(WRITE_RAID_INFO)
1927COMPATIBLE_IOCTL(UNPROTECT_ARRAY)
1928COMPATIBLE_IOCTL(PROTECT_ARRAY)
1929ULONG_IOCTL(HOT_ADD_DISK)
1930ULONG_IOCTL(SET_DISK_FAULTY)
1931COMPATIBLE_IOCTL(RUN_ARRAY)
1932COMPATIBLE_IOCTL(STOP_ARRAY)
1933COMPATIBLE_IOCTL(STOP_ARRAY_RO)
1934COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
1935COMPATIBLE_IOCTL(GET_BITMAP_FILE)
1936ULONG_IOCTL(SET_BITMAP_FILE)
1937/* Big K */
1938COMPATIBLE_IOCTL(PIO_FONT)
1939COMPATIBLE_IOCTL(GIO_FONT)
1940COMPATIBLE_IOCTL(PIO_CMAP)
1941COMPATIBLE_IOCTL(GIO_CMAP)
1942ULONG_IOCTL(KDSIGACCEPT)
1943COMPATIBLE_IOCTL(KDGETKEYCODE) 988COMPATIBLE_IOCTL(KDGETKEYCODE)
1944COMPATIBLE_IOCTL(KDSETKEYCODE) 989COMPATIBLE_IOCTL(KDSETKEYCODE)
1945ULONG_IOCTL(KIOCSOUND)
1946ULONG_IOCTL(KDMKTONE)
1947COMPATIBLE_IOCTL(KDGKBTYPE) 990COMPATIBLE_IOCTL(KDGKBTYPE)
1948ULONG_IOCTL(KDSETMODE)
1949COMPATIBLE_IOCTL(KDGETMODE) 991COMPATIBLE_IOCTL(KDGETMODE)
1950ULONG_IOCTL(KDSKBMODE)
1951COMPATIBLE_IOCTL(KDGKBMODE) 992COMPATIBLE_IOCTL(KDGKBMODE)
1952ULONG_IOCTL(KDSKBMETA)
1953COMPATIBLE_IOCTL(KDGKBMETA) 993COMPATIBLE_IOCTL(KDGKBMETA)
1954COMPATIBLE_IOCTL(KDGKBENT) 994COMPATIBLE_IOCTL(KDGKBENT)
1955COMPATIBLE_IOCTL(KDSKBENT) 995COMPATIBLE_IOCTL(KDSKBENT)
@@ -1959,15 +999,7 @@ COMPATIBLE_IOCTL(KDGKBDIACR)
1959COMPATIBLE_IOCTL(KDSKBDIACR) 999COMPATIBLE_IOCTL(KDSKBDIACR)
1960COMPATIBLE_IOCTL(KDKBDREP) 1000COMPATIBLE_IOCTL(KDKBDREP)
1961COMPATIBLE_IOCTL(KDGKBLED) 1001COMPATIBLE_IOCTL(KDGKBLED)
1962ULONG_IOCTL(KDSKBLED)
1963COMPATIBLE_IOCTL(KDGETLED) 1002COMPATIBLE_IOCTL(KDGETLED)
1964ULONG_IOCTL(KDSETLED)
1965COMPATIBLE_IOCTL(GIO_SCRNMAP)
1966COMPATIBLE_IOCTL(PIO_SCRNMAP)
1967COMPATIBLE_IOCTL(GIO_UNISCRNMAP)
1968COMPATIBLE_IOCTL(PIO_UNISCRNMAP)
1969COMPATIBLE_IOCTL(PIO_FONTRESET)
1970COMPATIBLE_IOCTL(PIO_UNIMAPCLR)
1971#ifdef CONFIG_BLOCK 1003#ifdef CONFIG_BLOCK
1972/* Big S */ 1004/* Big S */
1973COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN) 1005COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
@@ -1979,32 +1011,9 @@ COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
1979COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST) 1011COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
1980COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI) 1012COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
1981#endif 1013#endif
1982/* Big T */ 1014/* Big V (don't complain on serial console) */
1983COMPATIBLE_IOCTL(TUNSETNOCSUM) 1015IGNORE_IOCTL(VT_OPENQRY)
1984COMPATIBLE_IOCTL(TUNSETDEBUG) 1016IGNORE_IOCTL(VT_GETMODE)
1985COMPATIBLE_IOCTL(TUNSETPERSIST)
1986COMPATIBLE_IOCTL(TUNSETOWNER)
1987COMPATIBLE_IOCTL(TUNSETLINK)
1988COMPATIBLE_IOCTL(TUNSETGROUP)
1989COMPATIBLE_IOCTL(TUNGETFEATURES)
1990COMPATIBLE_IOCTL(TUNSETOFFLOAD)
1991COMPATIBLE_IOCTL(TUNSETTXFILTER)
1992COMPATIBLE_IOCTL(TUNGETSNDBUF)
1993COMPATIBLE_IOCTL(TUNSETSNDBUF)
1994/* Big V */
1995COMPATIBLE_IOCTL(VT_SETMODE)
1996COMPATIBLE_IOCTL(VT_GETMODE)
1997COMPATIBLE_IOCTL(VT_GETSTATE)
1998COMPATIBLE_IOCTL(VT_OPENQRY)
1999ULONG_IOCTL(VT_ACTIVATE)
2000ULONG_IOCTL(VT_WAITACTIVE)
2001ULONG_IOCTL(VT_RELDISP)
2002ULONG_IOCTL(VT_DISALLOCATE)
2003COMPATIBLE_IOCTL(VT_RESIZE)
2004COMPATIBLE_IOCTL(VT_RESIZEX)
2005COMPATIBLE_IOCTL(VT_LOCKSWITCH)
2006COMPATIBLE_IOCTL(VT_UNLOCKSWITCH)
2007COMPATIBLE_IOCTL(VT_GETHIFONTMASK)
2008/* Little p (/dev/rtc, /dev/envctrl, etc.) */ 1017/* Little p (/dev/rtc, /dev/envctrl, etc.) */
2009COMPATIBLE_IOCTL(RTC_AIE_ON) 1018COMPATIBLE_IOCTL(RTC_AIE_ON)
2010COMPATIBLE_IOCTL(RTC_AIE_OFF) 1019COMPATIBLE_IOCTL(RTC_AIE_OFF)
@@ -2032,36 +1041,15 @@ COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
2032COMPATIBLE_IOCTL(MTIOCTOP) 1041COMPATIBLE_IOCTL(MTIOCTOP)
2033/* Socket level stuff */ 1042/* Socket level stuff */
2034COMPATIBLE_IOCTL(FIOQSIZE) 1043COMPATIBLE_IOCTL(FIOQSIZE)
2035COMPATIBLE_IOCTL(FIOSETOWN)
2036COMPATIBLE_IOCTL(SIOCSPGRP)
2037COMPATIBLE_IOCTL(FIOGETOWN)
2038COMPATIBLE_IOCTL(SIOCGPGRP)
2039COMPATIBLE_IOCTL(SIOCATMARK)
2040COMPATIBLE_IOCTL(SIOCSIFLINK)
2041COMPATIBLE_IOCTL(SIOCSIFENCAP)
2042COMPATIBLE_IOCTL(SIOCGIFENCAP)
2043COMPATIBLE_IOCTL(SIOCSIFNAME)
2044COMPATIBLE_IOCTL(SIOCSARP)
2045COMPATIBLE_IOCTL(SIOCGARP)
2046COMPATIBLE_IOCTL(SIOCDARP)
2047COMPATIBLE_IOCTL(SIOCSRARP)
2048COMPATIBLE_IOCTL(SIOCGRARP)
2049COMPATIBLE_IOCTL(SIOCDRARP)
2050COMPATIBLE_IOCTL(SIOCADDDLCI)
2051COMPATIBLE_IOCTL(SIOCDELDLCI)
2052COMPATIBLE_IOCTL(SIOCGMIIPHY)
2053COMPATIBLE_IOCTL(SIOCGMIIREG)
2054COMPATIBLE_IOCTL(SIOCSMIIREG)
2055COMPATIBLE_IOCTL(SIOCGIFVLAN)
2056COMPATIBLE_IOCTL(SIOCSIFVLAN)
2057COMPATIBLE_IOCTL(SIOCBRADDBR)
2058COMPATIBLE_IOCTL(SIOCBRDELBR)
2059#ifdef CONFIG_BLOCK 1044#ifdef CONFIG_BLOCK
1045/* loop */
1046IGNORE_IOCTL(LOOP_CLR_FD)
1047/* md calls this on random blockdevs */
1048IGNORE_IOCTL(RAID_VERSION)
2060/* SG stuff */ 1049/* SG stuff */
2061COMPATIBLE_IOCTL(SG_SET_TIMEOUT) 1050COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
2062COMPATIBLE_IOCTL(SG_GET_TIMEOUT) 1051COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
2063COMPATIBLE_IOCTL(SG_EMULATED_HOST) 1052COMPATIBLE_IOCTL(SG_EMULATED_HOST)
2064ULONG_IOCTL(SG_SET_TRANSFORM)
2065COMPATIBLE_IOCTL(SG_GET_TRANSFORM) 1053COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
2066COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE) 1054COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
2067COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE) 1055COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
@@ -2115,8 +1103,6 @@ COMPATIBLE_IOCTL(PPPIOCGCHAN)
2115/* PPPOX */ 1103/* PPPOX */
2116COMPATIBLE_IOCTL(PPPOEIOCSFWD) 1104COMPATIBLE_IOCTL(PPPOEIOCSFWD)
2117COMPATIBLE_IOCTL(PPPOEIOCDFWD) 1105COMPATIBLE_IOCTL(PPPOEIOCDFWD)
2118/* LP */
2119COMPATIBLE_IOCTL(LPGETSTATUS)
2120/* ppdev */ 1106/* ppdev */
2121COMPATIBLE_IOCTL(PPSETMODE) 1107COMPATIBLE_IOCTL(PPSETMODE)
2122COMPATIBLE_IOCTL(PPRSTATUS) 1108COMPATIBLE_IOCTL(PPRSTATUS)
@@ -2139,8 +1125,6 @@ COMPATIBLE_IOCTL(PPGETMODE)
2139COMPATIBLE_IOCTL(PPGETPHASE) 1125COMPATIBLE_IOCTL(PPGETPHASE)
2140COMPATIBLE_IOCTL(PPGETFLAGS) 1126COMPATIBLE_IOCTL(PPGETFLAGS)
2141COMPATIBLE_IOCTL(PPSETFLAGS) 1127COMPATIBLE_IOCTL(PPSETFLAGS)
2142/* pktcdvd */
2143COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
2144/* Big A */ 1128/* Big A */
2145/* sparc only */ 1129/* sparc only */
2146/* Big Q for sound/OSS */ 1130/* Big Q for sound/OSS */
@@ -2298,8 +1282,6 @@ COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
2298COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS) 1282COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
2299COMPATIBLE_IOCTL(OSS_GETVERSION) 1283COMPATIBLE_IOCTL(OSS_GETVERSION)
2300/* AUTOFS */ 1284/* AUTOFS */
2301ULONG_IOCTL(AUTOFS_IOC_READY)
2302ULONG_IOCTL(AUTOFS_IOC_FAIL)
2303COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC) 1285COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
2304COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER) 1286COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
2305COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE) 1287COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
@@ -2311,22 +1293,6 @@ COMPATIBLE_IOCTL(RAW_SETBIND)
2311COMPATIBLE_IOCTL(RAW_GETBIND) 1293COMPATIBLE_IOCTL(RAW_GETBIND)
2312/* SMB ioctls which do not need any translations */ 1294/* SMB ioctls which do not need any translations */
2313COMPATIBLE_IOCTL(SMB_IOC_NEWCONN) 1295COMPATIBLE_IOCTL(SMB_IOC_NEWCONN)
2314/* Little a */
2315COMPATIBLE_IOCTL(ATMSIGD_CTRL)
2316COMPATIBLE_IOCTL(ATMARPD_CTRL)
2317COMPATIBLE_IOCTL(ATMLEC_CTRL)
2318COMPATIBLE_IOCTL(ATMLEC_MCAST)
2319COMPATIBLE_IOCTL(ATMLEC_DATA)
2320COMPATIBLE_IOCTL(ATM_SETSC)
2321COMPATIBLE_IOCTL(SIOCSIFATMTCP)
2322COMPATIBLE_IOCTL(SIOCMKCLIP)
2323COMPATIBLE_IOCTL(ATMARP_MKIP)
2324COMPATIBLE_IOCTL(ATMARP_SETENTRY)
2325COMPATIBLE_IOCTL(ATMARP_ENCAP)
2326COMPATIBLE_IOCTL(ATMTCP_CREATE)
2327COMPATIBLE_IOCTL(ATMTCP_REMOVE)
2328COMPATIBLE_IOCTL(ATMMPC_CTRL)
2329COMPATIBLE_IOCTL(ATMMPC_DATA)
2330/* Watchdog */ 1296/* Watchdog */
2331COMPATIBLE_IOCTL(WDIOC_GETSUPPORT) 1297COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
2332COMPATIBLE_IOCTL(WDIOC_GETSTATUS) 1298COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
@@ -2408,30 +1374,11 @@ COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
2408COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO) 1374COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
2409COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM) 1375COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
2410COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE) 1376COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
2411/* USB */
2412COMPATIBLE_IOCTL(USBDEVFS_RESETEP)
2413COMPATIBLE_IOCTL(USBDEVFS_SETINTERFACE)
2414COMPATIBLE_IOCTL(USBDEVFS_SETCONFIGURATION)
2415COMPATIBLE_IOCTL(USBDEVFS_GETDRIVER)
2416COMPATIBLE_IOCTL(USBDEVFS_DISCARDURB)
2417COMPATIBLE_IOCTL(USBDEVFS_CLAIMINTERFACE)
2418COMPATIBLE_IOCTL(USBDEVFS_RELEASEINTERFACE)
2419COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
2420COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
2421COMPATIBLE_IOCTL(USBDEVFS_RESET)
2422COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
2423COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
2424COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
2425COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
2426/* NBD */ 1377/* NBD */
2427ULONG_IOCTL(NBD_SET_SOCK)
2428ULONG_IOCTL(NBD_SET_BLKSIZE)
2429ULONG_IOCTL(NBD_SET_SIZE)
2430COMPATIBLE_IOCTL(NBD_DO_IT) 1378COMPATIBLE_IOCTL(NBD_DO_IT)
2431COMPATIBLE_IOCTL(NBD_CLEAR_SOCK) 1379COMPATIBLE_IOCTL(NBD_CLEAR_SOCK)
2432COMPATIBLE_IOCTL(NBD_CLEAR_QUE) 1380COMPATIBLE_IOCTL(NBD_CLEAR_QUE)
2433COMPATIBLE_IOCTL(NBD_PRINT_DEBUG) 1381COMPATIBLE_IOCTL(NBD_PRINT_DEBUG)
2434ULONG_IOCTL(NBD_SET_SIZE_BLOCKS)
2435COMPATIBLE_IOCTL(NBD_DISCONNECT) 1382COMPATIBLE_IOCTL(NBD_DISCONNECT)
2436/* i2c */ 1383/* i2c */
2437COMPATIBLE_IOCTL(I2C_SLAVE) 1384COMPATIBLE_IOCTL(I2C_SLAVE)
@@ -2531,131 +1478,13 @@ COMPATIBLE_IOCTL(JSIOCGAXES)
2531COMPATIBLE_IOCTL(JSIOCGBUTTONS) 1478COMPATIBLE_IOCTL(JSIOCGBUTTONS)
2532COMPATIBLE_IOCTL(JSIOCGNAME(0)) 1479COMPATIBLE_IOCTL(JSIOCGNAME(0))
2533 1480
2534/* now things that need handlers */
2535#ifdef CONFIG_NET
2536HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
2537HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
2538HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
2539HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
2540HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
2541HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
2542HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
2543HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
2544HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
2545HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
2546HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
2547HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
2548HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
2549HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
2550HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
2551HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
2552HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2553HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2554HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
2555HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
2556HANDLE_IOCTL(SIOCSHWTSTAMP, dev_ifsioc)
2557
2558/* ioctls used by appletalk ddp.c */
2559HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
2560HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
2561HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
2562HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
2563
2564HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
2565HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
2566HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
2567HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
2568HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
2569HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
2570HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
2571HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
2572HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
2573HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
2574HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
2575HANDLE_IOCTL(TUNGETIFF, dev_ifsioc)
2576HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
2577HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
2578HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
2579HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
2580HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
2581HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
2582HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
2583HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
2584HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
2585HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
2586HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
2587/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
2588HANDLE_IOCTL(SIOCRTMSG, ret_einval)
2589HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
2590HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
2591#endif
2592#ifdef CONFIG_BLOCK
2593HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
2594HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
2595#endif
2596HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
2597HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
2598HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
2599HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
2600#ifdef CONFIG_BLOCK
2601HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
2602HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
2603#endif
2604#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
2605HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
2606#ifdef CONFIG_VT
2607HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
2608HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
2609HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
2610HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
2611HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
2612#endif
2613/* One SMB ioctl needs translations. */
2614#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
2615HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
2616HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
2617HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
2618HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
2619HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
2620HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
2621HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
2622HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
2623HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
2624HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
2625HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
2626HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
2627HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
2628HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
2629HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
2630HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
2631HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
2632HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
2633HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
2634HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
2635HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
2636HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
2637HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
2638HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
2639HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
2640HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
2641/* block stuff */
2642#ifdef CONFIG_BLOCK
2643/* loop */
2644IGNORE_IOCTL(LOOP_CLR_FD)
2645/* Raw devices */
2646HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
2647HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
2648#endif
2649/* Serial */
2650HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
2651HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
2652#ifdef TIOCGLTC 1481#ifdef TIOCGLTC
2653COMPATIBLE_IOCTL(TIOCGLTC) 1482COMPATIBLE_IOCTL(TIOCGLTC)
2654COMPATIBLE_IOCTL(TIOCSLTC) 1483COMPATIBLE_IOCTL(TIOCSLTC)
2655#endif 1484#endif
2656#ifdef TIOCSTART 1485#ifdef TIOCSTART
2657/* 1486/*
2658 * For these two we have defintions in ioctls.h and/or termios.h on 1487 * For these two we have definitions in ioctls.h and/or termios.h on
2659 * some architectures but no actual implemention. Some applications 1488 * some architectures but no actual implemention. Some applications
2660 * like bash call them if they are defined in the headers, so we provide 1489 * like bash call them if they are defined in the headers, so we provide
2661 * entries here to avoid syslog message spew. 1490 * entries here to avoid syslog message spew.
@@ -2663,43 +1492,6 @@ COMPATIBLE_IOCTL(TIOCSLTC)
2663COMPATIBLE_IOCTL(TIOCSTART) 1492COMPATIBLE_IOCTL(TIOCSTART)
2664COMPATIBLE_IOCTL(TIOCSTOP) 1493COMPATIBLE_IOCTL(TIOCSTOP)
2665#endif 1494#endif
2666/* Usbdevfs */
2667HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
2668HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
2669HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
2670COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
2671/* i2c */
2672HANDLE_IOCTL(I2C_FUNCS, w_long)
2673HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
2674HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
2675/* bridge */
2676HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
2677HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
2678/* Not implemented in the native kernel */
2679IGNORE_IOCTL(SIOCGIFCOUNT)
2680HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
2681HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
2682HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
2683HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
2684
2685/* dvb */
2686HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
2687HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
2688HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
2689
2690/* parport */
2691COMPATIBLE_IOCTL(LPTIME)
2692COMPATIBLE_IOCTL(LPCHAR)
2693COMPATIBLE_IOCTL(LPABORTOPEN)
2694COMPATIBLE_IOCTL(LPCAREFUL)
2695COMPATIBLE_IOCTL(LPWAIT)
2696COMPATIBLE_IOCTL(LPSETIRQ)
2697COMPATIBLE_IOCTL(LPGETSTATUS)
2698COMPATIBLE_IOCTL(LPGETSTATUS)
2699COMPATIBLE_IOCTL(LPRESET)
2700/*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
2701COMPATIBLE_IOCTL(LPGETFLAGS)
2702HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
2703 1495
2704/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl, 1496/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
2705 but we don't want warnings on other file systems. So declare 1497 but we don't want warnings on other file systems. So declare
@@ -2727,12 +1519,108 @@ IGNORE_IOCTL(FBIOGCURSOR32)
2727#endif 1519#endif
2728}; 1520};
2729 1521
2730#define IOCTL_HASHSIZE 256 1522/*
2731static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE]; 1523 * Convert common ioctl arguments based on their command number
2732 1524 *
2733static inline unsigned long ioctl32_hash(unsigned long cmd) 1525 * Please do not add any code in here. Instead, implement
1526 * a compat_ioctl operation in the place that handleѕ the
1527 * ioctl for the native case.
1528 */
1529static long do_ioctl_trans(int fd, unsigned int cmd,
1530 unsigned long arg, struct file *file)
2734{ 1531{
2735 return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE; 1532 void __user *argp = compat_ptr(arg);
1533
1534 switch (cmd) {
1535 case PPPIOCGIDLE32:
1536 return ppp_gidle(fd, cmd, argp);
1537 case PPPIOCSCOMPRESS32:
1538 return ppp_scompress(fd, cmd, argp);
1539 case PPPIOCSPASS32:
1540 case PPPIOCSACTIVE32:
1541 return ppp_sock_fprog_ioctl_trans(fd, cmd, argp);
1542#ifdef CONFIG_BLOCK
1543 case SG_IO:
1544 return sg_ioctl_trans(fd, cmd, argp);
1545 case SG_GET_REQUEST_TABLE:
1546 return sg_grt_trans(fd, cmd, argp);
1547 case MTIOCGET32:
1548 case MTIOCPOS32:
1549 return mt_ioctl_trans(fd, cmd, argp);
1550 /* Raw devices */
1551 case RAW_SETBIND:
1552 case RAW_GETBIND:
1553 return raw_ioctl(fd, cmd, argp);
1554#endif
1555#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
1556 case AUTOFS_IOC_SETTIMEOUT32:
1557 return ioc_settimeout(fd, cmd, argp);
1558 /* One SMB ioctl needs translations. */
1559#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
1560 case SMB_IOC_GETMOUNTUID_32:
1561 return do_smb_getmountuid(fd, cmd, argp);
1562 /* Serial */
1563 case TIOCGSERIAL:
1564 case TIOCSSERIAL:
1565 return serial_struct_ioctl(fd, cmd, argp);
1566 /* i2c */
1567 case I2C_FUNCS:
1568 return w_long(fd, cmd, argp);
1569 case I2C_RDWR:
1570 return do_i2c_rdwr_ioctl(fd, cmd, argp);
1571 case I2C_SMBUS:
1572 return do_i2c_smbus_ioctl(fd, cmd, argp);
1573 /* Not implemented in the native kernel */
1574 case RTC_IRQP_READ32:
1575 case RTC_IRQP_SET32:
1576 case RTC_EPOCH_READ32:
1577 case RTC_EPOCH_SET32:
1578 return rtc_ioctl(fd, cmd, argp);
1579
1580 /* dvb */
1581 case VIDEO_GET_EVENT:
1582 return do_video_get_event(fd, cmd, argp);
1583 case VIDEO_STILLPICTURE:
1584 return do_video_stillpicture(fd, cmd, argp);
1585 case VIDEO_SET_SPU_PALETTE:
1586 return do_video_set_spu_palette(fd, cmd, argp);
1587 }
1588
1589 /*
1590 * These take an integer instead of a pointer as 'arg',
1591 * so we must not do a compat_ptr() translation.
1592 */
1593 switch (cmd) {
1594 /* Big T */
1595 case TCSBRKP:
1596 case TIOCMIWAIT:
1597 case TIOCSCTTY:
1598 /* RAID */
1599 case HOT_REMOVE_DISK:
1600 case HOT_ADD_DISK:
1601 case SET_DISK_FAULTY:
1602 case SET_BITMAP_FILE:
1603 /* Big K */
1604 case KDSIGACCEPT:
1605 case KIOCSOUND:
1606 case KDMKTONE:
1607 case KDSETMODE:
1608 case KDSKBMODE:
1609 case KDSKBMETA:
1610 case KDSKBLED:
1611 case KDSETLED:
1612 /* AUTOFS */
1613 case AUTOFS_IOC_READY:
1614 case AUTOFS_IOC_FAIL:
1615 /* NBD */
1616 case NBD_SET_SOCK:
1617 case NBD_SET_BLKSIZE:
1618 case NBD_SET_SIZE:
1619 case NBD_SET_SIZE_BLOCKS:
1620 return do_vfs_ioctl(file, fd, cmd, arg);
1621 }
1622
1623 return -ENOIOCTLCMD;
2736} 1624}
2737 1625
2738static void compat_ioctl_error(struct file *filp, unsigned int fd, 1626static void compat_ioctl_error(struct file *filp, unsigned int fd,
@@ -2764,12 +1652,33 @@ static void compat_ioctl_error(struct file *filp, unsigned int fd,
2764 free_page((unsigned long)path); 1652 free_page((unsigned long)path);
2765} 1653}
2766 1654
1655static int compat_ioctl_check_table(unsigned int xcmd)
1656{
1657 int i;
1658 const int max = ARRAY_SIZE(ioctl_pointer) - 1;
1659
1660 BUILD_BUG_ON(max >= (1 << 16));
1661
1662 /* guess initial offset into table, assuming a
1663 normalized distribution */
1664 i = ((xcmd >> 16) * max) >> 16;
1665
1666 /* do linear search up first, until greater or equal */
1667 while (ioctl_pointer[i] < xcmd && i < max)
1668 i++;
1669
1670 /* then do linear search down */
1671 while (ioctl_pointer[i] > xcmd && i > 0)
1672 i--;
1673
1674 return ioctl_pointer[i] == xcmd;
1675}
1676
2767asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, 1677asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2768 unsigned long arg) 1678 unsigned long arg)
2769{ 1679{
2770 struct file *filp; 1680 struct file *filp;
2771 int error = -EBADF; 1681 int error = -EBADF;
2772 struct ioctl_trans *t;
2773 int fput_needed; 1682 int fput_needed;
2774 1683
2775 filp = fget_light(fd, &fput_needed); 1684 filp = fget_light(fd, &fput_needed);
@@ -2797,7 +1706,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2797#if defined(CONFIG_IA64) || defined(CONFIG_X86_64) 1706#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
2798 case FS_IOC_RESVSP_32: 1707 case FS_IOC_RESVSP_32:
2799 case FS_IOC_RESVSP64_32: 1708 case FS_IOC_RESVSP64_32:
2800 error = compat_ioctl_preallocate(filp, arg); 1709 error = compat_ioctl_preallocate(filp, compat_ptr(arg));
2801 goto out_fput; 1710 goto out_fput;
2802#else 1711#else
2803 case FS_IOC_RESVSP: 1712 case FS_IOC_RESVSP:
@@ -2826,18 +1735,11 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2826 break; 1735 break;
2827 } 1736 }
2828 1737
2829 for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) { 1738 if (compat_ioctl_check_table(XFORM(cmd)))
2830 if (t->cmd == cmd) 1739 goto found_handler;
2831 goto found_handler;
2832 }
2833 1740
2834#ifdef CONFIG_NET 1741 error = do_ioctl_trans(fd, cmd, arg, filp);
2835 if (S_ISSOCK(filp->f_path.dentry->d_inode->i_mode) && 1742 if (error == -ENOIOCTLCMD) {
2836 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
2837 error = siocdevprivate_ioctl(fd, cmd, arg);
2838 } else
2839#endif
2840 {
2841 static int count; 1743 static int count;
2842 1744
2843 if (++count <= 50) 1745 if (++count <= 50)
@@ -2848,13 +1750,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2848 goto out_fput; 1750 goto out_fput;
2849 1751
2850 found_handler: 1752 found_handler:
2851 if (t->handler) { 1753 arg = (unsigned long)compat_ptr(arg);
2852 lock_kernel();
2853 error = t->handler(fd, cmd, arg, filp);
2854 unlock_kernel();
2855 goto out_fput;
2856 }
2857
2858 do_ioctl: 1754 do_ioctl:
2859 error = do_vfs_ioctl(filp, fd, cmd, arg); 1755 error = do_vfs_ioctl(filp, fd, cmd, arg);
2860 out_fput: 1756 out_fput:
@@ -2863,35 +1759,22 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2863 return error; 1759 return error;
2864} 1760}
2865 1761
2866static void ioctl32_insert_translation(struct ioctl_trans *trans) 1762static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
2867{ 1763{
2868 unsigned long hash; 1764 unsigned int a, b;
2869 struct ioctl_trans *t; 1765 a = *(unsigned int *)p;
2870 1766 b = *(unsigned int *)q;
2871 hash = ioctl32_hash (trans->cmd); 1767 if (a > b)
2872 if (!ioctl32_hash_table[hash]) 1768 return 1;
2873 ioctl32_hash_table[hash] = trans; 1769 if (a < b)
2874 else { 1770 return -1;
2875 t = ioctl32_hash_table[hash]; 1771 return 0;
2876 while (t->next)
2877 t = t->next;
2878 trans->next = NULL;
2879 t->next = trans;
2880 }
2881} 1772}
2882 1773
2883static int __init init_sys32_ioctl(void) 1774static int __init init_sys32_ioctl(void)
2884{ 1775{
2885 int i; 1776 sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer),
2886 1777 init_sys32_ioctl_cmp, NULL);
2887 for (i = 0; i < ARRAY_SIZE(ioctl_start); i++) {
2888 if (ioctl_start[i].next) {
2889 printk("ioctl translation %d bad\n",i);
2890 return -1;
2891 }
2892
2893 ioctl32_insert_translation(&ioctl_start[i]);
2894 }
2895 return 0; 1778 return 0;
2896} 1779}
2897__initcall(init_sys32_ioctl); 1780__initcall(init_sys32_ioctl);