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