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