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