~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/compat_ioctl.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp