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