ioctl32.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:151k
- /* $Id: ioctl32.c,v 1.133.2.5 2002/03/01 08:52:38 davem Exp $
- * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
- *
- * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
- * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
- *
- * These routines maintain argument size conversion between 32bit and 64bit
- * ioctls.
- */
- #include <linux/config.h>
- #include <linux/types.h>
- #include <linux/kernel.h>
- #include <linux/sched.h>
- #include <linux/smp.h>
- #include <linux/smp_lock.h>
- #include <linux/ioctl.h>
- #include <linux/if.h>
- #include <linux/slab.h>
- #include <linux/hdreg.h>
- #include <linux/raid/md.h>
- #include <linux/kd.h>
- #include <linux/route.h>
- #include <linux/in6.h>
- #include <linux/ipv6_route.h>
- #include <linux/skbuff.h>
- #include <linux/netlink.h>
- #include <linux/vt.h>
- #include <linux/fs.h>
- #include <linux/file.h>
- #include <linux/fd.h>
- #include <linux/ppp_defs.h>
- #include <linux/if_ppp.h>
- #include <linux/if_pppox.h>
- #include <linux/if_tun.h>
- #include <linux/mtio.h>
- #include <linux/cdrom.h>
- #include <linux/loop.h>
- #include <linux/auto_fs.h>
- #include <linux/devfs_fs.h>
- #include <linux/tty.h>
- #include <linux/vt_kern.h>
- #include <linux/fb.h>
- #include <linux/ext2_fs.h>
- #include <linux/videodev.h>
- #include <linux/netdevice.h>
- #include <linux/raw.h>
- #include <linux/smb_fs.h>
- #include <linux/ncp_fs.h>
- #include <linux/blkpg.h>
- #include <linux/blk.h>
- #include <linux/elevator.h>
- #include <linux/rtc.h>
- #include <linux/pci.h>
- #if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)
- #include <linux/lvm.h>
- #endif /* LVM */
- #include <scsi/scsi.h>
- /* Ugly hack. */
- #undef __KERNEL__
- #include <scsi/scsi_ioctl.h>
- #define __KERNEL__
- #include <scsi/sg.h>
- #include <asm/types.h>
- #include <asm/uaccess.h>
- #include <asm/fbio.h>
- #include <asm/kbio.h>
- #include <asm/vuid_event.h>
- #include <asm/openpromio.h>
- #include <asm/envctrl.h>
- #include <asm/audioio.h>
- #include <linux/ethtool.h>
- #include <linux/mii.h>
- #include <linux/if_bonding.h>
- #include <asm/display7seg.h>
- #include <asm/watchdog.h>
- #include <asm/module.h>
- #include <linux/soundcard.h>
- #include <linux/lp.h>
- #include <linux/atm.h>
- #include <linux/atmarp.h>
- #include <linux/atmclip.h>
- #include <linux/atmdev.h>
- #include <linux/atmioc.h>
- #include <linux/atmlec.h>
- #include <linux/atmmpc.h>
- #include <linux/atmsvc.h>
- #include <linux/atm_tcp.h>
- #include <linux/sonet.h>
- #include <linux/atm_suni.h>
- #include <linux/mtd/mtd.h>
- #include <net/bluetooth/bluetooth.h>
- #include <net/bluetooth/hci.h>
- #include <linux/usb.h>
- #include <linux/usbdevice_fs.h>
- #include <linux/nbd.h>
- #include <linux/random.h>
- #include <linux/filter.h>
- /* Use this to get at 32-bit user passed pointers.
- See sys_sparc32.c for description about these. */
- #define A(__x) ((unsigned long)(__x))
- #define AA(__x)
- ({ unsigned long __ret;
- __asm__ ("srl %0, 0, %0"
- : "=r" (__ret)
- : "0" (__x));
- __ret;
- })
- /* Aiee. Someone does not find a difference between int and long */
- #define EXT2_IOC32_GETFLAGS _IOR('f', 1, int)
- #define EXT2_IOC32_SETFLAGS _IOW('f', 2, int)
- #define EXT2_IOC32_GETVERSION _IOR('v', 1, int)
- #define EXT2_IOC32_SETVERSION _IOW('v', 2, int)
- extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
- static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- int err;
- unsigned long val;
-
- set_fs (KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&val);
- set_fs (old_fs);
- if (!err && put_user(val, (u32 *)arg))
- return -EFAULT;
- return err;
- }
-
- static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- int err;
- unsigned long val;
-
- if(get_user(val, (u32 *)arg))
- return -EFAULT;
- set_fs (KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&val);
- set_fs (old_fs);
- if (!err && put_user(val, (u32 *)arg))
- return -EFAULT;
- return err;
- }
- static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- /* These are just misnamed, they actually get/put from/to user an int */
- switch (cmd) {
- case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
- case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
- case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
- case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
- }
- return sys_ioctl(fd, cmd, arg);
- }
-
- struct video_tuner32 {
- s32 tuner;
- u8 name[32];
- u32 rangelow, rangehigh;
- u32 flags;
- u16 mode, signal;
- };
- static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 *up)
- {
- int i;
- if(get_user(kp->tuner, &up->tuner))
- return -EFAULT;
- for(i = 0; i < 32; i++)
- __get_user(kp->name[i], &up->name[i]);
- __get_user(kp->rangelow, &up->rangelow);
- __get_user(kp->rangehigh, &up->rangehigh);
- __get_user(kp->flags, &up->flags);
- __get_user(kp->mode, &up->mode);
- __get_user(kp->signal, &up->signal);
- return 0;
- }
- static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 *up)
- {
- int i;
- if(put_user(kp->tuner, &up->tuner))
- return -EFAULT;
- for(i = 0; i < 32; i++)
- __put_user(kp->name[i], &up->name[i]);
- __put_user(kp->rangelow, &up->rangelow);
- __put_user(kp->rangehigh, &up->rangehigh);
- __put_user(kp->flags, &up->flags);
- __put_user(kp->mode, &up->mode);
- __put_user(kp->signal, &up->signal);
- return 0;
- }
- struct video_buffer32 {
- /* void * */ u32 base;
- s32 height, width, depth, bytesperline;
- };
- static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 *up)
- {
- u32 tmp;
- if(get_user(tmp, &up->base))
- return -EFAULT;
- kp->base = (void *) ((unsigned long)tmp);
- __get_user(kp->height, &up->height);
- __get_user(kp->width, &up->width);
- __get_user(kp->depth, &up->depth);
- __get_user(kp->bytesperline, &up->bytesperline);
- return 0;
- }
- static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 *up)
- {
- u32 tmp = (u32)((unsigned long)kp->base);
- if(put_user(tmp, &up->base))
- return -EFAULT;
- __put_user(kp->height, &up->height);
- __put_user(kp->width, &up->width);
- __put_user(kp->depth, &up->depth);
- __put_user(kp->bytesperline, &up->bytesperline);
- return 0;
- }
- struct video_clip32 {
- s32 x, y, width, height;
- /* struct video_clip32 * */ u32 next;
- };
- struct video_window32 {
- u32 x, y, width, height, chromakey, flags;
- /* struct video_clip32 * */ u32 clips;
- s32 clipcount;
- };
- static void free_kvideo_clips(struct video_window *kp)
- {
- struct video_clip *cp;
- cp = kp->clips;
- if(cp != NULL)
- kfree(cp);
- }
- static int get_video_window32(struct video_window *kp, struct video_window32 *up)
- {
- struct video_clip32 *ucp;
- struct video_clip *kcp;
- int nclips, err, i;
- u32 tmp;
- if(get_user(kp->x, &up->x))
- return -EFAULT;
- __get_user(kp->y, &up->y);
- __get_user(kp->width, &up->width);
- __get_user(kp->height, &up->height);
- __get_user(kp->chromakey, &up->chromakey);
- __get_user(kp->flags, &up->flags);
- __get_user(kp->clipcount, &up->clipcount);
- __get_user(tmp, &up->clips);
- ucp = (struct video_clip32 *)A(tmp);
- kp->clips = NULL;
- nclips = kp->clipcount;
- if(nclips == 0)
- return 0;
- if(ucp == 0)
- return -EINVAL;
- /* Peculiar interface... */
- if(nclips < 0)
- nclips = VIDEO_CLIPMAP_SIZE;
- kcp = kmalloc(nclips * sizeof(struct video_clip), GFP_KERNEL);
- err = -ENOMEM;
- if(kcp == NULL)
- goto cleanup_and_err;
- kp->clips = kcp;
- for(i = 0; i < nclips; i++) {
- __get_user(kcp[i].x, &ucp[i].x);
- __get_user(kcp[i].y, &ucp[i].y);
- __get_user(kcp[i].width, &ucp[i].width);
- __get_user(kcp[i].height, &ucp[i].height);
- kcp[nclips].next = NULL;
- }
- return 0;
- cleanup_and_err:
- free_kvideo_clips(kp);
- return err;
- }
- /* You get back everything except the clips... */
- static int put_video_window32(struct video_window *kp, struct video_window32 *up)
- {
- if(put_user(kp->x, &up->x))
- return -EFAULT;
- __put_user(kp->y, &up->y);
- __put_user(kp->width, &up->width);
- __put_user(kp->height, &up->height);
- __put_user(kp->chromakey, &up->chromakey);
- __put_user(kp->flags, &up->flags);
- __put_user(kp->clipcount, &up->clipcount);
- return 0;
- }
- #define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
- #define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
- #define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
- #define VIDIOCSWIN32 _IOW('v',10, struct video_window32)
- #define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32)
- #define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
- #define VIDIOCGFREQ32 _IOR('v',14, u32)
- #define VIDIOCSFREQ32 _IOW('v',15, u32)
- static int do_video_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- union {
- struct video_tuner vt;
- struct video_buffer vb;
- struct video_window vw;
- unsigned long vx;
- } karg;
- mm_segment_t old_fs = get_fs();
- void *up = (void *)arg;
- int err = 0;
- /* First, convert the command. */
- switch(cmd) {
- case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
- case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
- case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
- case VIDIOCSWIN32: cmd = VIDIOCSWIN; break;
- case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
- case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
- case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
- case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
- };
- switch(cmd) {
- case VIDIOCSTUNER:
- case VIDIOCGTUNER:
- err = get_video_tuner32(&karg.vt, up);
- break;
- case VIDIOCSWIN:
- err = get_video_window32(&karg.vw, up);
- break;
- case VIDIOCSFBUF:
- err = get_video_buffer32(&karg.vb, up);
- break;
- case VIDIOCSFREQ:
- err = get_user(karg.vx, (u32 *)up);
- break;
- };
- if(err)
- goto out;
- set_fs(KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&karg);
- set_fs(old_fs);
- if(cmd == VIDIOCSWIN)
- free_kvideo_clips(&karg.vw);
- if(err == 0) {
- switch(cmd) {
- case VIDIOCGTUNER:
- err = put_video_tuner32(&karg.vt, up);
- break;
- case VIDIOCGWIN:
- err = put_video_window32(&karg.vw, up);
- break;
- case VIDIOCGFBUF:
- err = put_video_buffer32(&karg.vb, up);
- break;
- case VIDIOCGFREQ:
- err = put_user(((u32)karg.vx), (u32 *)up);
- break;
- };
- }
- out:
- return err;
- }
- struct timeval32 {
- int tv_sec;
- int tv_usec;
- };
- static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct timeval32 *up = (struct timeval32 *)arg;
- struct timeval ktv;
- mm_segment_t old_fs = get_fs();
- int err;
- set_fs(KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
- set_fs(old_fs);
- if(!err) {
- err = put_user(ktv.tv_sec, &up->tv_sec);
- err |= __put_user(ktv.tv_usec, &up->tv_usec);
- }
- return err;
- }
- struct ifmap32 {
- u32 mem_start;
- u32 mem_end;
- unsigned short base_addr;
- unsigned char irq;
- unsigned char dma;
- unsigned char port;
- };
- struct ifreq32 {
- #define IFHWADDRLEN 6
- #define IFNAMSIZ 16
- union {
- char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
- } ifr_ifrn;
- union {
- struct sockaddr ifru_addr;
- struct sockaddr ifru_dstaddr;
- struct sockaddr ifru_broadaddr;
- struct sockaddr ifru_netmask;
- struct sockaddr ifru_hwaddr;
- short ifru_flags;
- int ifru_ivalue;
- int ifru_mtu;
- struct ifmap32 ifru_map;
- char ifru_slave[IFNAMSIZ]; /* Just fits the size */
- char ifru_newname[IFNAMSIZ];
- __kernel_caddr_t32 ifru_data;
- } ifr_ifru;
- };
- struct ifconf32 {
- int ifc_len; /* size of buffer */
- __kernel_caddr_t32 ifcbuf;
- };
- #ifdef CONFIG_NET
- static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct net_device *dev;
- struct ifreq32 ifr32;
- int err;
- if (copy_from_user(&ifr32, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
- return -EFAULT;
- dev = dev_get_by_index(ifr32.ifr_ifindex);
- if (!dev)
- return -ENODEV;
- strcpy(ifr32.ifr_name, dev->name);
- dev_put(dev);
- err = copy_to_user((struct ifreq32 *)arg, &ifr32, sizeof(struct ifreq32));
- return (err ? -EFAULT : 0);
- }
- #endif
- static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ifconf32 ifc32;
- struct ifconf ifc;
- struct ifreq32 *ifr32;
- struct ifreq *ifr;
- mm_segment_t old_fs;
- unsigned int i, j;
- int err;
- if (copy_from_user(&ifc32, (struct ifconf32 *)arg, sizeof(struct ifconf32)))
- return -EFAULT;
- if(ifc32.ifcbuf == 0) {
- ifc32.ifc_len = 0;
- ifc.ifc_len = 0;
- ifc.ifc_buf = NULL;
- } else {
- ifc.ifc_len = ((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
- sizeof (struct ifreq);
- ifc.ifc_buf = kmalloc (ifc.ifc_len, GFP_KERNEL);
- if (!ifc.ifc_buf)
- return -ENOMEM;
- }
- ifr = ifc.ifc_req;
- ifr32 = (struct ifreq32 *)A(ifc32.ifcbuf);
- for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
- if (copy_from_user(ifr++, ifr32++, sizeof (struct ifreq32))) {
- kfree (ifc.ifc_buf);
- return -EFAULT;
- }
- }
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)&ifc);
- set_fs (old_fs);
- if (!err) {
- ifr = ifc.ifc_req;
- ifr32 = (struct ifreq32 *)A(ifc32.ifcbuf);
- for (i = 0, j = 0; i < ifc32.ifc_len && j < ifc.ifc_len;
- i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
- if (copy_to_user(ifr32++, ifr++, sizeof (struct ifreq32))) {
- err = -EFAULT;
- break;
- }
- }
- if (!err) {
- if (ifc32.ifcbuf == 0) {
- /* Translate from 64-bit structure multiple to
- * a 32-bit one.
- */
- i = ifc.ifc_len;
- i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
- ifc32.ifc_len = i;
- } else {
- if (i <= ifc32.ifc_len)
- ifc32.ifc_len = i;
- else
- ifc32.ifc_len = i - sizeof (struct ifreq32);
- }
- if (copy_to_user((struct ifconf32 *)arg, &ifc32, sizeof(struct ifconf32)))
- err = -EFAULT;
- }
- }
- if(ifc.ifc_buf != NULL)
- kfree (ifc.ifc_buf);
- return err;
- }
- static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ifreq ifr;
- mm_segment_t old_fs;
- int err, len;
- u32 data, ethcmd;
-
- if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
- return -EFAULT;
- ifr.ifr_data = (__kernel_caddr_t)get_free_page(GFP_KERNEL);
- if (!ifr.ifr_data)
- return -EAGAIN;
- __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
- if (get_user(ethcmd, (u32 *)A(data))) {
- err = -EFAULT;
- goto out;
- }
- switch (ethcmd) {
- case ETHTOOL_GDRVINFO: len = sizeof(struct ethtool_drvinfo); break;
- case ETHTOOL_GMSGLVL:
- case ETHTOOL_SMSGLVL:
- case ETHTOOL_GLINK:
- case ETHTOOL_NWAY_RST: len = sizeof(struct ethtool_value); break;
- case ETHTOOL_GREGS: {
- struct ethtool_regs *regaddr = (struct ethtool_regs *)A(data);
- /* darned variable size arguments */
- if (get_user(len, (u32 *)®addr->len)) {
- err = -EFAULT;
- goto out;
- }
- len += sizeof(struct ethtool_regs);
- break;
- }
- case ETHTOOL_GSET:
- case ETHTOOL_SSET: len = sizeof(struct ethtool_cmd); break;
- default:
- err = -EOPNOTSUPP;
- goto out;
- }
- if (copy_from_user(ifr.ifr_data, (char *)A(data), len)) {
- err = -EFAULT;
- goto out;
- }
- old_fs = get_fs();
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
- set_fs (old_fs);
- if (!err) {
- u32 data;
- __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
- len = copy_to_user((char *)A(data), ifr.ifr_data, len);
- if (len)
- err = -EFAULT;
- }
- out:
- free_page((unsigned long)ifr.ifr_data);
- return err;
- }
- static int bond_ioctl(unsigned long fd, unsigned int cmd, unsigned long arg)
- {
- struct ifreq ifr;
- mm_segment_t old_fs;
- int err, len;
- u32 data;
-
- if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
- return -EFAULT;
- ifr.ifr_data = (__kernel_caddr_t)get_free_page(GFP_KERNEL);
- if (!ifr.ifr_data)
- return -EAGAIN;
- switch (cmd) {
- case SIOCBONDENSLAVE:
- case SIOCBONDRELEASE:
- case SIOCBONDSETHWADDR:
- case SIOCBONDCHANGEACTIVE:
- len = IFNAMSIZ * sizeof(char);
- break;
- case SIOCBONDSLAVEINFOQUERY:
- len = sizeof(struct ifslave);
- break;
- case SIOCBONDINFOQUERY:
- len = sizeof(struct ifbond);
- break;
- default:
- err = -EINVAL;
- goto out;
- };
- __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
- if (copy_from_user(ifr.ifr_data, (char *)A(data), len)) {
- err = -EFAULT;
- goto out;
- }
- old_fs = get_fs();
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
- set_fs (old_fs);
- if (!err) {
- len = copy_to_user((char *)A(data), ifr.ifr_data, len);
- if (len)
- err = -EFAULT;
- }
- out:
- free_page((unsigned long)ifr.ifr_data);
- return err;
- }
- static __inline__ void *alloc_user_space(long len)
- {
- struct pt_regs *regs = current->thread.kregs;
- unsigned long usp = regs->u_regs[UREG_I6];
- if (!(current->thread.flags & SPARC_FLAG_32BIT))
- usp += STACK_BIAS;
- return (void *) (usp - len);
- }
- static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ifreq *u_ifreq64;
- struct ifreq32 *u_ifreq32 = (struct ifreq32 *) arg;
- char tmp_buf[IFNAMSIZ];
- void *data64;
- u32 data32;
- if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
- IFNAMSIZ))
- return -EFAULT;
- if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
- return -EFAULT;
- data64 = (void *) A(data32);
- u_ifreq64 = alloc_user_space(sizeof(*u_ifreq64));
- /* Don't check these user accesses, just let that get trapped
- * in the ioctl handler instead.
- */
- copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], IFNAMSIZ);
- __put_user(data64, &u_ifreq64->ifr_ifru.ifru_data);
- return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
- }
- static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ifreq ifr;
- mm_segment_t old_fs;
- int err;
-
- switch (cmd) {
- case SIOCSIFMAP:
- err = copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(ifr.ifr_name));
- err |= __get_user(ifr.ifr_map.mem_start, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_start));
- err |= __get_user(ifr.ifr_map.mem_end, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_end));
- err |= __get_user(ifr.ifr_map.base_addr, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.base_addr));
- err |= __get_user(ifr.ifr_map.irq, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.irq));
- err |= __get_user(ifr.ifr_map.dma, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.dma));
- err |= __get_user(ifr.ifr_map.port, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.port));
- if (err)
- return -EFAULT;
- break;
- default:
- if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
- return -EFAULT;
- break;
- }
- old_fs = get_fs();
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
- set_fs (old_fs);
- if (!err) {
- switch (cmd) {
- case SIOCGIFFLAGS:
- case SIOCGIFMETRIC:
- case SIOCGIFMTU:
- case SIOCGIFMEM:
- case SIOCGIFHWADDR:
- case SIOCGIFINDEX:
- case SIOCGIFADDR:
- case SIOCGIFBRDADDR:
- case SIOCGIFDSTADDR:
- case SIOCGIFNETMASK:
- case SIOCGIFTXQLEN:
- if (copy_to_user((struct ifreq32 *)arg, &ifr, sizeof(struct ifreq32)))
- return -EFAULT;
- break;
- case SIOCGIFMAP:
- err = copy_to_user((struct ifreq32 *)arg, &ifr, sizeof(ifr.ifr_name));
- err |= __put_user(ifr.ifr_map.mem_start, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_start));
- err |= __put_user(ifr.ifr_map.mem_end, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_end));
- err |= __put_user(ifr.ifr_map.base_addr, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.base_addr));
- err |= __put_user(ifr.ifr_map.irq, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.irq));
- err |= __put_user(ifr.ifr_map.dma, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.dma));
- err |= __put_user(ifr.ifr_map.port, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.port));
- if (err)
- err = -EFAULT;
- break;
- }
- }
- return err;
- }
- struct rtentry32 {
- u32 rt_pad1;
- struct sockaddr rt_dst; /* target address */
- struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
- struct sockaddr rt_genmask; /* target network mask (IP) */
- unsigned short rt_flags;
- short rt_pad2;
- u32 rt_pad3;
- unsigned char rt_tos;
- unsigned char rt_class;
- short rt_pad4;
- short rt_metric; /* +1 for binary compatibility! */
- /* char * */ u32 rt_dev; /* forcing the device at add */
- u32 rt_mtu; /* per route MTU/Window */
- u32 rt_window; /* Window clamping */
- unsigned short rt_irtt; /* Initial RTT */
- };
- struct in6_rtmsg32 {
- struct in6_addr rtmsg_dst;
- struct in6_addr rtmsg_src;
- struct in6_addr rtmsg_gateway;
- u32 rtmsg_type;
- u16 rtmsg_dst_len;
- u16 rtmsg_src_len;
- u32 rtmsg_metric;
- u32 rtmsg_info;
- u32 rtmsg_flags;
- s32 rtmsg_ifindex;
- };
- extern struct socket *sockfd_lookup(int fd, int *err);
- extern __inline__ void sockfd_put(struct socket *sock)
- {
- fput(sock->file);
- }
- static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- int ret;
- void *r = NULL;
- struct in6_rtmsg r6;
- struct rtentry r4;
- char devname[16];
- u32 rtdev;
- mm_segment_t old_fs = get_fs();
-
- struct socket *mysock = sockfd_lookup(fd, &ret);
- if (mysock && mysock->sk && mysock->sk->family == AF_INET6) { /* ipv6 */
- ret = copy_from_user (&r6.rtmsg_dst, &(((struct in6_rtmsg32 *)arg)->rtmsg_dst),
- 3 * sizeof(struct in6_addr));
- ret |= __get_user (r6.rtmsg_type, &(((struct in6_rtmsg32 *)arg)->rtmsg_type));
- ret |= __get_user (r6.rtmsg_dst_len, &(((struct in6_rtmsg32 *)arg)->rtmsg_dst_len));
- ret |= __get_user (r6.rtmsg_src_len, &(((struct in6_rtmsg32 *)arg)->rtmsg_src_len));
- ret |= __get_user (r6.rtmsg_metric, &(((struct in6_rtmsg32 *)arg)->rtmsg_metric));
- ret |= __get_user (r6.rtmsg_info, &(((struct in6_rtmsg32 *)arg)->rtmsg_info));
- ret |= __get_user (r6.rtmsg_flags, &(((struct in6_rtmsg32 *)arg)->rtmsg_flags));
- ret |= __get_user (r6.rtmsg_ifindex, &(((struct in6_rtmsg32 *)arg)->rtmsg_ifindex));
-
- r = (void *) &r6;
- } else { /* ipv4 */
- ret = copy_from_user (&r4.rt_dst, &(((struct rtentry32 *)arg)->rt_dst), 3 * sizeof(struct sockaddr));
- ret |= __get_user (r4.rt_flags, &(((struct rtentry32 *)arg)->rt_flags));
- ret |= __get_user (r4.rt_metric, &(((struct rtentry32 *)arg)->rt_metric));
- ret |= __get_user (r4.rt_mtu, &(((struct rtentry32 *)arg)->rt_mtu));
- ret |= __get_user (r4.rt_window, &(((struct rtentry32 *)arg)->rt_window));
- ret |= __get_user (r4.rt_irtt, &(((struct rtentry32 *)arg)->rt_irtt));
- ret |= __get_user (rtdev, &(((struct rtentry32 *)arg)->rt_dev));
- if (rtdev) {
- ret |= copy_from_user (devname, (char *)A(rtdev), 15);
- r4.rt_dev = devname; devname[15] = 0;
- } else
- r4.rt_dev = 0;
- r = (void *) &r4;
- }
- if (ret)
- return -EFAULT;
- set_fs (KERNEL_DS);
- ret = sys_ioctl (fd, cmd, (long) r);
- set_fs (old_fs);
- if (mysock)
- sockfd_put(mysock);
- return ret;
- }
- struct hd_geometry32 {
- unsigned char heads;
- unsigned char sectors;
- unsigned short cylinders;
- u32 start;
- };
-
- static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct hd_geometry geo;
- int err;
-
- set_fs (KERNEL_DS);
- err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
- set_fs (old_fs);
- if (!err) {
- if (copy_to_user ((struct hd_geometry32 *)arg, &geo, 4) ||
- __put_user (geo.start, &(((struct hd_geometry32 *)arg)->start)))
- err = -EFAULT;
- }
- return err;
- }
- struct hd_big_geometry32 {
- unsigned char heads;
- unsigned char sectors;
- unsigned int cylinders;
- u32 start;
- };
-
- static int hdio_getgeo_big(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct hd_big_geometry geo;
- int err;
-
- set_fs (KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&geo);
- set_fs (old_fs);
- if (!err) {
- struct hd_big_geometry32 *up = (struct hd_big_geometry32 *) arg;
- if (put_user(geo.heads, &up->heads) ||
- __put_user(geo.sectors, &up->sectors) ||
- __put_user(geo.cylinders, &up->cylinders) ||
- __put_user(((u32) geo.start), &up->start))
- err = -EFAULT;
- }
- return err;
- }
- struct fbcmap32 {
- int index; /* first element (0 origin) */
- int count;
- u32 red;
- u32 green;
- u32 blue;
- };
- #define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32)
- #define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32)
- static int fbiogetputcmap(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct fbcmap f;
- int ret;
- char red[256], green[256], blue[256];
- u32 r, g, b;
- mm_segment_t old_fs = get_fs();
-
- ret = get_user(f.index, &(((struct fbcmap32 *)arg)->index));
- ret |= __get_user(f.count, &(((struct fbcmap32 *)arg)->count));
- ret |= __get_user(r, &(((struct fbcmap32 *)arg)->red));
- ret |= __get_user(g, &(((struct fbcmap32 *)arg)->green));
- ret |= __get_user(b, &(((struct fbcmap32 *)arg)->blue));
- if (ret)
- return -EFAULT;
- if ((f.index < 0) || (f.index > 255)) return -EINVAL;
- if (f.index + f.count > 256)
- f.count = 256 - f.index;
- if (cmd == FBIOPUTCMAP32) {
- ret = copy_from_user (red, (char *)A(r), f.count);
- ret |= copy_from_user (green, (char *)A(g), f.count);
- ret |= copy_from_user (blue, (char *)A(b), f.count);
- if (ret)
- return -EFAULT;
- }
- f.red = red; f.green = green; f.blue = blue;
- set_fs (KERNEL_DS);
- ret = sys_ioctl (fd, (cmd == FBIOPUTCMAP32) ? FBIOPUTCMAP_SPARC : FBIOGETCMAP_SPARC, (long)&f);
- set_fs (old_fs);
- if (!ret && cmd == FBIOGETCMAP32) {
- ret = copy_to_user ((char *)A(r), red, f.count);
- ret |= copy_to_user ((char *)A(g), green, f.count);
- ret |= copy_to_user ((char *)A(b), blue, f.count);
- }
- return ret ? -EFAULT : 0;
- }
- struct fbcursor32 {
- short set; /* what to set, choose from the list above */
- short enable; /* cursor on/off */
- struct fbcurpos pos; /* cursor position */
- struct fbcurpos hot; /* cursor hot spot */
- struct fbcmap32 cmap; /* color map info */
- struct fbcurpos size; /* cursor bit map size */
- u32 image; /* cursor image bits */
- u32 mask; /* cursor mask bits */
- };
-
- #define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32)
- #define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32)
- static int fbiogscursor(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct fbcursor f;
- int ret;
- char red[2], green[2], blue[2];
- char image[128], mask[128];
- u32 r, g, b;
- u32 m, i;
- mm_segment_t old_fs = get_fs();
-
- ret = copy_from_user (&f, (struct fbcursor32 *)arg, 2 * sizeof (short) + 2 * sizeof(struct fbcurpos));
- ret |= __get_user(f.size.fbx, &(((struct fbcursor32 *)arg)->size.fbx));
- ret |= __get_user(f.size.fby, &(((struct fbcursor32 *)arg)->size.fby));
- ret |= __get_user(f.cmap.index, &(((struct fbcursor32 *)arg)->cmap.index));
- ret |= __get_user(f.cmap.count, &(((struct fbcursor32 *)arg)->cmap.count));
- ret |= __get_user(r, &(((struct fbcursor32 *)arg)->cmap.red));
- ret |= __get_user(g, &(((struct fbcursor32 *)arg)->cmap.green));
- ret |= __get_user(b, &(((struct fbcursor32 *)arg)->cmap.blue));
- ret |= __get_user(m, &(((struct fbcursor32 *)arg)->mask));
- ret |= __get_user(i, &(((struct fbcursor32 *)arg)->image));
- if (ret)
- return -EFAULT;
- if (f.set & FB_CUR_SETCMAP) {
- if ((uint) f.size.fby > 32)
- return -EINVAL;
- ret = copy_from_user (mask, (char *)A(m), f.size.fby * 4);
- ret |= copy_from_user (image, (char *)A(i), f.size.fby * 4);
- if (ret)
- return -EFAULT;
- f.image = image; f.mask = mask;
- }
- if (f.set & FB_CUR_SETCMAP) {
- ret = copy_from_user (red, (char *)A(r), 2);
- ret |= copy_from_user (green, (char *)A(g), 2);
- ret |= copy_from_user (blue, (char *)A(b), 2);
- if (ret)
- return -EFAULT;
- f.cmap.red = red; f.cmap.green = green; f.cmap.blue = blue;
- }
- set_fs (KERNEL_DS);
- ret = sys_ioctl (fd, FBIOSCURSOR, (long)&f);
- set_fs (old_fs);
- return ret;
- }
- struct fb_fix_screeninfo32 {
- char id[16];
- __kernel_caddr_t32 smem_start;
- __u32 smem_len;
- __u32 type;
- __u32 type_aux;
- __u32 visual;
- __u16 xpanstep;
- __u16 ypanstep;
- __u16 ywrapstep;
- __u32 line_length;
- __kernel_caddr_t32 mmio_start;
- __u32 mmio_len;
- __u32 accel;
- __u16 reserved[3];
- };
- struct fb_cmap32 {
- __u32 start;
- __u32 len;
- __kernel_caddr_t32 red;
- __kernel_caddr_t32 green;
- __kernel_caddr_t32 blue;
- __kernel_caddr_t32 transp;
- };
- static int fb_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- u32 red = 0, green = 0, blue = 0, transp = 0;
- struct fb_fix_screeninfo fix;
- struct fb_cmap cmap;
- void *karg;
- int err = 0;
- memset(&cmap, 0, sizeof(cmap));
- switch (cmd) {
- case FBIOGET_FSCREENINFO:
- karg = &fix;
- break;
- case FBIOGETCMAP:
- case FBIOPUTCMAP:
- karg = &cmap;
- err = __get_user(cmap.start, &((struct fb_cmap32 *)arg)->start);
- err |= __get_user(cmap.len, &((struct fb_cmap32 *)arg)->len);
- err |= __get_user(red, &((struct fb_cmap32 *)arg)->red);
- err |= __get_user(green, &((struct fb_cmap32 *)arg)->green);
- err |= __get_user(blue, &((struct fb_cmap32 *)arg)->blue);
- err |= __get_user(transp, &((struct fb_cmap32 *)arg)->transp);
- if (err) {
- err = -EFAULT;
- goto out;
- }
- err = -ENOMEM;
- cmap.red = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
- if (!cmap.red)
- goto out;
- cmap.green = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
- if (!cmap.green)
- goto out;
- cmap.blue = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
- if (!cmap.blue)
- goto out;
- if (transp) {
- cmap.transp = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
- if (!cmap.transp)
- goto out;
- }
-
- if (cmd == FBIOGETCMAP)
- break;
- err = __copy_from_user(cmap.red, (char *)A(red), cmap.len * sizeof(__u16));
- err |= __copy_from_user(cmap.green, (char *)A(green), cmap.len * sizeof(__u16));
- err |= __copy_from_user(cmap.blue, (char *)A(blue), cmap.len * sizeof(__u16));
- if (cmap.transp) err |= __copy_from_user(cmap.transp, (char *)A(transp), cmap.len * sizeof(__u16));
- if (err) {
- err = -EFAULT;
- goto out;
- }
- break;
- default:
- do {
- static int count;
- if (++count <= 20)
- printk("%s: Unknown fb ioctl cmd fd(%d) "
- "cmd(%08x) arg(%08lx)n",
- __FUNCTION__, fd, cmd, arg);
- } while(0);
- return -ENOSYS;
- }
- set_fs(KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)karg);
- set_fs(old_fs);
- if (err)
- goto out;
- switch (cmd) {
- case FBIOGET_FSCREENINFO:
- err = __copy_to_user((char *)((struct fb_fix_screeninfo32 *)arg)->id, (char *)fix.id, sizeof(fix.id));
- err |= __put_user((__u32)(unsigned long)fix.smem_start, &((struct fb_fix_screeninfo32 *)arg)->smem_start);
- err |= __put_user(fix.smem_len, &((struct fb_fix_screeninfo32 *)arg)->smem_len);
- err |= __put_user(fix.type, &((struct fb_fix_screeninfo32 *)arg)->type);
- err |= __put_user(fix.type_aux, &((struct fb_fix_screeninfo32 *)arg)->type_aux);
- err |= __put_user(fix.visual, &((struct fb_fix_screeninfo32 *)arg)->visual);
- err |= __put_user(fix.xpanstep, &((struct fb_fix_screeninfo32 *)arg)->xpanstep);
- err |= __put_user(fix.ypanstep, &((struct fb_fix_screeninfo32 *)arg)->ypanstep);
- err |= __put_user(fix.ywrapstep, &((struct fb_fix_screeninfo32 *)arg)->ywrapstep);
- err |= __put_user(fix.line_length, &((struct fb_fix_screeninfo32 *)arg)->line_length);
- err |= __put_user((__u32)(unsigned long)fix.mmio_start, &((struct fb_fix_screeninfo32 *)arg)->mmio_start);
- err |= __put_user(fix.mmio_len, &((struct fb_fix_screeninfo32 *)arg)->mmio_len);
- err |= __put_user(fix.accel, &((struct fb_fix_screeninfo32 *)arg)->accel);
- err |= __copy_to_user((char *)((struct fb_fix_screeninfo32 *)arg)->reserved, (char *)fix.reserved, sizeof(fix.reserved));
- break;
- case FBIOGETCMAP:
- err = __copy_to_user((char *)A(red), cmap.red, cmap.len * sizeof(__u16));
- err |= __copy_to_user((char *)A(green), cmap.blue, cmap.len * sizeof(__u16));
- err |= __copy_to_user((char *)A(blue), cmap.blue, cmap.len * sizeof(__u16));
- if (cmap.transp)
- err |= __copy_to_user((char *)A(transp), cmap.transp, cmap.len * sizeof(__u16));
- break;
- case FBIOPUTCMAP:
- break;
- }
- if (err)
- err = -EFAULT;
- out: if (cmap.red) kfree(cmap.red);
- if (cmap.green) kfree(cmap.green);
- if (cmap.blue) kfree(cmap.blue);
- if (cmap.transp) kfree(cmap.transp);
- return err;
- }
- static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- unsigned long kval;
- unsigned int *uvp;
- int error;
- set_fs(KERNEL_DS);
- error = sys_ioctl(fd, cmd, (long)&kval);
- set_fs(old_fs);
- if(error == 0) {
- uvp = (unsigned int *)arg;
- if(put_user(kval, uvp))
- error = -EFAULT;
- }
- return error;
- }
- struct floppy_struct32 {
- unsigned int size;
- unsigned int sect;
- unsigned int head;
- unsigned int track;
- unsigned int stretch;
- unsigned char gap;
- unsigned char rate;
- unsigned char spec1;
- unsigned char fmt_gap;
- const __kernel_caddr_t32 name;
- };
- struct floppy_drive_params32 {
- char cmos;
- u32 max_dtr;
- u32 hlt;
- u32 hut;
- u32 srt;
- u32 spinup;
- u32 spindown;
- unsigned char spindown_offset;
- unsigned char select_delay;
- unsigned char rps;
- unsigned char tracks;
- u32 timeout;
- unsigned char interleave_sect;
- struct floppy_max_errors max_errors;
- char flags;
- char read_track;
- short autodetect[8];
- int checkfreq;
- int native_format;
- };
- struct floppy_drive_struct32 {
- signed char flags;
- u32 spinup_date;
- u32 select_date;
- u32 first_read_date;
- short probed_format;
- short track;
- short maxblock;
- short maxtrack;
- int generation;
- int keep_data;
- int fd_ref;
- int fd_device;
- int last_checked;
- __kernel_caddr_t32 dmabuf;
- int bufblocks;
- };
- struct floppy_fdc_state32 {
- int spec1;
- int spec2;
- int dtr;
- unsigned char version;
- unsigned char dor;
- u32 address;
- unsigned int rawcmd:2;
- unsigned int reset:1;
- unsigned int need_configure:1;
- unsigned int perp_mode:2;
- unsigned int has_fifo:1;
- unsigned int driver_version;
- unsigned char track[4];
- };
- struct floppy_write_errors32 {
- unsigned int write_errors;
- u32 first_error_sector;
- int first_error_generation;
- u32 last_error_sector;
- int last_error_generation;
- unsigned int badness;
- };
- #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
- #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
- #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
- #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
- #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
- #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
- #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
- #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
- #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
- static struct {
- unsigned int cmd32;
- unsigned int cmd;
- } fd_ioctl_trans_table[] = {
- { FDSETPRM32, FDSETPRM },
- { FDDEFPRM32, FDDEFPRM },
- { FDGETPRM32, FDGETPRM },
- { FDSETDRVPRM32, FDSETDRVPRM },
- { FDGETDRVPRM32, FDGETDRVPRM },
- { FDGETDRVSTAT32, FDGETDRVSTAT },
- { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
- { FDGETFDCSTAT32, FDGETFDCSTAT },
- { FDWERRORGET32, FDWERRORGET }
- };
- #define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
- static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- void *karg = NULL;
- unsigned int kcmd = 0;
- int i, err;
- for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
- if (cmd == fd_ioctl_trans_table[i].cmd32) {
- kcmd = fd_ioctl_trans_table[i].cmd;
- break;
- }
- if (!kcmd)
- return -EINVAL;
- switch (cmd) {
- case FDSETPRM32:
- case FDDEFPRM32:
- case FDGETPRM32:
- {
- struct floppy_struct *f;
- f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
- if (!karg)
- return -ENOMEM;
- if (cmd == FDGETPRM32)
- break;
- err = __get_user(f->size, &((struct floppy_struct32 *)arg)->size);
- err |= __get_user(f->sect, &((struct floppy_struct32 *)arg)->sect);
- err |= __get_user(f->head, &((struct floppy_struct32 *)arg)->head);
- err |= __get_user(f->track, &((struct floppy_struct32 *)arg)->track);
- err |= __get_user(f->stretch, &((struct floppy_struct32 *)arg)->stretch);
- err |= __get_user(f->gap, &((struct floppy_struct32 *)arg)->gap);
- err |= __get_user(f->rate, &((struct floppy_struct32 *)arg)->rate);
- err |= __get_user(f->spec1, &((struct floppy_struct32 *)arg)->spec1);
- err |= __get_user(f->fmt_gap, &((struct floppy_struct32 *)arg)->fmt_gap);
- err |= __get_user((u64)f->name, &((struct floppy_struct32 *)arg)->name);
- if (err) {
- err = -EFAULT;
- goto out;
- }
- break;
- }
- case FDSETDRVPRM32:
- case FDGETDRVPRM32:
- {
- struct floppy_drive_params *f;
- f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
- if (!karg)
- return -ENOMEM;
- if (cmd == FDGETDRVPRM32)
- break;
- err = __get_user(f->cmos, &((struct floppy_drive_params32 *)arg)->cmos);
- err |= __get_user(f->max_dtr, &((struct floppy_drive_params32 *)arg)->max_dtr);
- err |= __get_user(f->hlt, &((struct floppy_drive_params32 *)arg)->hlt);
- err |= __get_user(f->hut, &((struct floppy_drive_params32 *)arg)->hut);
- err |= __get_user(f->srt, &((struct floppy_drive_params32 *)arg)->srt);
- err |= __get_user(f->spinup, &((struct floppy_drive_params32 *)arg)->spinup);
- err |= __get_user(f->spindown, &((struct floppy_drive_params32 *)arg)->spindown);
- err |= __get_user(f->spindown_offset, &((struct floppy_drive_params32 *)arg)->spindown_offset);
- err |= __get_user(f->select_delay, &((struct floppy_drive_params32 *)arg)->select_delay);
- err |= __get_user(f->rps, &((struct floppy_drive_params32 *)arg)->rps);
- err |= __get_user(f->tracks, &((struct floppy_drive_params32 *)arg)->tracks);
- err |= __get_user(f->timeout, &((struct floppy_drive_params32 *)arg)->timeout);
- err |= __get_user(f->interleave_sect, &((struct floppy_drive_params32 *)arg)->interleave_sect);
- err |= __copy_from_user(&f->max_errors, &((struct floppy_drive_params32 *)arg)->max_errors, sizeof(f->max_errors));
- err |= __get_user(f->flags, &((struct floppy_drive_params32 *)arg)->flags);
- err |= __get_user(f->read_track, &((struct floppy_drive_params32 *)arg)->read_track);
- err |= __copy_from_user(f->autodetect, ((struct floppy_drive_params32 *)arg)->autodetect, sizeof(f->autodetect));
- err |= __get_user(f->checkfreq, &((struct floppy_drive_params32 *)arg)->checkfreq);
- err |= __get_user(f->native_format, &((struct floppy_drive_params32 *)arg)->native_format);
- if (err) {
- err = -EFAULT;
- goto out;
- }
- break;
- }
- case FDGETDRVSTAT32:
- case FDPOLLDRVSTAT32:
- karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
- if (!karg)
- return -ENOMEM;
- break;
- case FDGETFDCSTAT32:
- karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
- if (!karg)
- return -ENOMEM;
- break;
- case FDWERRORGET32:
- karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
- if (!karg)
- return -ENOMEM;
- break;
- default:
- return -EINVAL;
- }
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, kcmd, (unsigned long)karg);
- set_fs (old_fs);
- if (err)
- goto out;
- switch (cmd) {
- case FDGETPRM32:
- {
- struct floppy_struct *f = karg;
- err = __put_user(f->size, &((struct floppy_struct32 *)arg)->size);
- err |= __put_user(f->sect, &((struct floppy_struct32 *)arg)->sect);
- err |= __put_user(f->head, &((struct floppy_struct32 *)arg)->head);
- err |= __put_user(f->track, &((struct floppy_struct32 *)arg)->track);
- err |= __put_user(f->stretch, &((struct floppy_struct32 *)arg)->stretch);
- err |= __put_user(f->gap, &((struct floppy_struct32 *)arg)->gap);
- err |= __put_user(f->rate, &((struct floppy_struct32 *)arg)->rate);
- err |= __put_user(f->spec1, &((struct floppy_struct32 *)arg)->spec1);
- err |= __put_user(f->fmt_gap, &((struct floppy_struct32 *)arg)->fmt_gap);
- err |= __put_user((u64)f->name, &((struct floppy_struct32 *)arg)->name);
- break;
- }
- case FDGETDRVPRM32:
- {
- struct floppy_drive_params *f = karg;
- err = __put_user(f->cmos, &((struct floppy_drive_params32 *)arg)->cmos);
- err |= __put_user(f->max_dtr, &((struct floppy_drive_params32 *)arg)->max_dtr);
- err |= __put_user(f->hlt, &((struct floppy_drive_params32 *)arg)->hlt);
- err |= __put_user(f->hut, &((struct floppy_drive_params32 *)arg)->hut);
- err |= __put_user(f->srt, &((struct floppy_drive_params32 *)arg)->srt);
- err |= __put_user(f->spinup, &((struct floppy_drive_params32 *)arg)->spinup);
- err |= __put_user(f->spindown, &((struct floppy_drive_params32 *)arg)->spindown);
- err |= __put_user(f->spindown_offset, &((struct floppy_drive_params32 *)arg)->spindown_offset);
- err |= __put_user(f->select_delay, &((struct floppy_drive_params32 *)arg)->select_delay);
- err |= __put_user(f->rps, &((struct floppy_drive_params32 *)arg)->rps);
- err |= __put_user(f->tracks, &((struct floppy_drive_params32 *)arg)->tracks);
- err |= __put_user(f->timeout, &((struct floppy_drive_params32 *)arg)->timeout);
- err |= __put_user(f->interleave_sect, &((struct floppy_drive_params32 *)arg)->interleave_sect);
- err |= __copy_to_user(&((struct floppy_drive_params32 *)arg)->max_errors, &f->max_errors, sizeof(f->max_errors));
- err |= __put_user(f->flags, &((struct floppy_drive_params32 *)arg)->flags);
- err |= __put_user(f->read_track, &((struct floppy_drive_params32 *)arg)->read_track);
- err |= __copy_to_user(((struct floppy_drive_params32 *)arg)->autodetect, f->autodetect, sizeof(f->autodetect));
- err |= __put_user(f->checkfreq, &((struct floppy_drive_params32 *)arg)->checkfreq);
- err |= __put_user(f->native_format, &((struct floppy_drive_params32 *)arg)->native_format);
- break;
- }
- case FDGETDRVSTAT32:
- case FDPOLLDRVSTAT32:
- {
- struct floppy_drive_struct *f = karg;
- err = __put_user(f->flags, &((struct floppy_drive_struct32 *)arg)->flags);
- err |= __put_user(f->spinup_date, &((struct floppy_drive_struct32 *)arg)->spinup_date);
- err |= __put_user(f->select_date, &((struct floppy_drive_struct32 *)arg)->select_date);
- err |= __put_user(f->first_read_date, &((struct floppy_drive_struct32 *)arg)->first_read_date);
- err |= __put_user(f->probed_format, &((struct floppy_drive_struct32 *)arg)->probed_format);
- err |= __put_user(f->track, &((struct floppy_drive_struct32 *)arg)->track);
- err |= __put_user(f->maxblock, &((struct floppy_drive_struct32 *)arg)->maxblock);
- err |= __put_user(f->maxtrack, &((struct floppy_drive_struct32 *)arg)->maxtrack);
- err |= __put_user(f->generation, &((struct floppy_drive_struct32 *)arg)->generation);
- err |= __put_user(f->keep_data, &((struct floppy_drive_struct32 *)arg)->keep_data);
- err |= __put_user(f->fd_ref, &((struct floppy_drive_struct32 *)arg)->fd_ref);
- err |= __put_user(f->fd_device, &((struct floppy_drive_struct32 *)arg)->fd_device);
- err |= __put_user(f->last_checked, &((struct floppy_drive_struct32 *)arg)->last_checked);
- err |= __put_user((u64)f->dmabuf, &((struct floppy_drive_struct32 *)arg)->dmabuf);
- err |= __put_user((u64)f->bufblocks, &((struct floppy_drive_struct32 *)arg)->bufblocks);
- break;
- }
- case FDGETFDCSTAT32:
- {
- struct floppy_fdc_state *f = karg;
- err = __put_user(f->spec1, &((struct floppy_fdc_state32 *)arg)->spec1);
- err |= __put_user(f->spec2, &((struct floppy_fdc_state32 *)arg)->spec2);
- err |= __put_user(f->dtr, &((struct floppy_fdc_state32 *)arg)->dtr);
- err |= __put_user(f->version, &((struct floppy_fdc_state32 *)arg)->version);
- err |= __put_user(f->dor, &((struct floppy_fdc_state32 *)arg)->dor);
- err |= __put_user(f->address, &((struct floppy_fdc_state32 *)arg)->address);
- err |= __copy_to_user((char *)&((struct floppy_fdc_state32 *)arg)->address
- + sizeof(((struct floppy_fdc_state32 *)arg)->address),
- (char *)&f->address + sizeof(f->address), sizeof(int));
- err |= __put_user(f->driver_version, &((struct floppy_fdc_state32 *)arg)->driver_version);
- err |= __copy_to_user(((struct floppy_fdc_state32 *)arg)->track, f->track, sizeof(f->track));
- break;
- }
- case FDWERRORGET32:
- {
- struct floppy_write_errors *f = karg;
- err = __put_user(f->write_errors, &((struct floppy_write_errors32 *)arg)->write_errors);
- err |= __put_user(f->first_error_sector, &((struct floppy_write_errors32 *)arg)->first_error_sector);
- err |= __put_user(f->first_error_generation, &((struct floppy_write_errors32 *)arg)->first_error_generation);
- err |= __put_user(f->last_error_sector, &((struct floppy_write_errors32 *)arg)->last_error_sector);
- err |= __put_user(f->last_error_generation, &((struct floppy_write_errors32 *)arg)->last_error_generation);
- err |= __put_user(f->badness, &((struct floppy_write_errors32 *)arg)->badness);
- break;
- }
- default:
- break;
- }
- if (err)
- err = -EFAULT;
- out: if (karg) kfree(karg);
- return err;
- }
- typedef struct sg_io_hdr32 {
- s32 interface_id; /* [i] 'S' for SCSI generic (required) */
- s32 dxfer_direction; /* [i] data transfer direction */
- u8 cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
- u8 mx_sb_len; /* [i] max length to write to sbp */
- u16 iovec_count; /* [i] 0 implies no scatter gather */
- u32 dxfer_len; /* [i] byte count of data transfer */
- u32 dxferp; /* [i], [*io] points to data transfer memory
- or scatter gather list */
- u32 cmdp; /* [i], [*i] points to command to perform */
- u32 sbp; /* [i], [*o] points to sense_buffer memory */
- u32 timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
- u32 flags; /* [i] 0 -> default, see SG_FLAG... */
- s32 pack_id; /* [i->o] unused internally (normally) */
- u32 usr_ptr; /* [i->o] unused internally */
- u8 status; /* [o] scsi status */
- u8 masked_status; /* [o] shifted, masked scsi status */
- u8 msg_status; /* [o] messaging level data (optional) */
- u8 sb_len_wr; /* [o] byte count actually written to sbp */
- u16 host_status; /* [o] errors from host adapter */
- u16 driver_status; /* [o] errors from software driver */
- s32 resid; /* [o] dxfer_len - actual_transferred */
- u32 duration; /* [o] time taken by cmd (unit: millisec) */
- u32 info; /* [o] auxiliary information */
- } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
- typedef struct sg_iovec32 {
- u32 iov_base;
- u32 iov_len;
- } sg_iovec32_t;
- static int alloc_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
- {
- sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
- sg_iovec_t *kiov;
- int i;
- sgp->dxferp = kmalloc(sgp->iovec_count *
- sizeof(sg_iovec_t), GFP_KERNEL);
- if (!sgp->dxferp)
- return -ENOMEM;
- memset(sgp->dxferp, 0,
- sgp->iovec_count * sizeof(sg_iovec_t));
- kiov = (sg_iovec_t *) sgp->dxferp;
- for (i = 0; i < sgp->iovec_count; i++) {
- u32 iov_base32;
- if (__get_user(iov_base32, &uiov->iov_base) ||
- __get_user(kiov->iov_len, &uiov->iov_len))
- return -EFAULT;
- kiov->iov_base = kmalloc(kiov->iov_len, GFP_KERNEL);
- if (!kiov->iov_base)
- return -ENOMEM;
- if (copy_from_user(kiov->iov_base,
- (void *) A(iov_base32),
- kiov->iov_len))
- return -EFAULT;
- uiov++;
- kiov++;
- }
- return 0;
- }
- static int copy_back_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
- {
- sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
- sg_iovec_t *kiov = (sg_iovec_t *) sgp->dxferp;
- int i;
- for (i = 0; i < sgp->iovec_count; i++) {
- u32 iov_base32;
- if (__get_user(iov_base32, &uiov->iov_base))
- return -EFAULT;
- if (copy_to_user((void *) A(iov_base32),
- kiov->iov_base,
- kiov->iov_len))
- return -EFAULT;
- uiov++;
- kiov++;
- }
- return 0;
- }
- static void free_sg_iovec(sg_io_hdr_t *sgp)
- {
- sg_iovec_t *kiov = (sg_iovec_t *) sgp->dxferp;
- int i;
- for (i = 0; i < sgp->iovec_count; i++) {
- if (kiov->iov_base) {
- kfree(kiov->iov_base);
- kiov->iov_base = NULL;
- }
- kiov++;
- }
- kfree(sgp->dxferp);
- sgp->dxferp = NULL;
- }
- static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- sg_io_hdr32_t *sg_io32;
- sg_io_hdr_t sg_io64;
- u32 dxferp32, cmdp32, sbp32;
- mm_segment_t old_fs;
- int err = 0;
- sg_io32 = (sg_io_hdr32_t *)arg;
- err = __get_user(sg_io64.interface_id, &sg_io32->interface_id);
- err |= __get_user(sg_io64.dxfer_direction, &sg_io32->dxfer_direction);
- err |= __get_user(sg_io64.cmd_len, &sg_io32->cmd_len);
- err |= __get_user(sg_io64.mx_sb_len, &sg_io32->mx_sb_len);
- err |= __get_user(sg_io64.iovec_count, &sg_io32->iovec_count);
- err |= __get_user(sg_io64.dxfer_len, &sg_io32->dxfer_len);
- err |= __get_user(sg_io64.timeout, &sg_io32->timeout);
- err |= __get_user(sg_io64.flags, &sg_io32->flags);
- err |= __get_user(sg_io64.pack_id, &sg_io32->pack_id);
- sg_io64.dxferp = NULL;
- sg_io64.cmdp = NULL;
- sg_io64.sbp = NULL;
- err |= __get_user(cmdp32, &sg_io32->cmdp);
- sg_io64.cmdp = kmalloc(sg_io64.cmd_len, GFP_KERNEL);
- if (!sg_io64.cmdp) {
- err = -ENOMEM;
- goto out;
- }
- if (copy_from_user(sg_io64.cmdp,
- (void *) A(cmdp32),
- sg_io64.cmd_len)) {
- err = -EFAULT;
- goto out;
- }
- err |= __get_user(sbp32, &sg_io32->sbp);
- sg_io64.sbp = kmalloc(sg_io64.mx_sb_len, GFP_KERNEL);
- if (!sg_io64.sbp) {
- err = -ENOMEM;
- goto out;
- }
- if (copy_from_user(sg_io64.sbp,
- (void *) A(sbp32),
- sg_io64.mx_sb_len)) {
- err = -EFAULT;
- goto out;
- }
- err |= __get_user(dxferp32, &sg_io32->dxferp);
- if (sg_io64.iovec_count) {
- int ret;
- if ((ret = alloc_sg_iovec(&sg_io64, dxferp32))) {
- err = ret;
- goto out;
- }
- } else {
- sg_io64.dxferp = kmalloc(sg_io64.dxfer_len, GFP_KERNEL);
- if (!sg_io64.dxferp) {
- err = -ENOMEM;
- goto out;
- }
- if (copy_from_user(sg_io64.dxferp,
- (void *) A(dxferp32),
- sg_io64.dxfer_len)) {
- err = -EFAULT;
- goto out;
- }
- }
- /* Unused internally, do not even bother to copy it over. */
- sg_io64.usr_ptr = NULL;
- if (err)
- return -EFAULT;
- old_fs = get_fs();
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long) &sg_io64);
- set_fs (old_fs);
- if (err < 0)
- goto out;
- err = __put_user(sg_io64.pack_id, &sg_io32->pack_id);
- err |= __put_user(sg_io64.status, &sg_io32->status);
- err |= __put_user(sg_io64.masked_status, &sg_io32->masked_status);
- err |= __put_user(sg_io64.msg_status, &sg_io32->msg_status);
- err |= __put_user(sg_io64.sb_len_wr, &sg_io32->sb_len_wr);
- err |= __put_user(sg_io64.host_status, &sg_io32->host_status);
- err |= __put_user(sg_io64.driver_status, &sg_io32->driver_status);
- err |= __put_user(sg_io64.resid, &sg_io32->resid);
- err |= __put_user(sg_io64.duration, &sg_io32->duration);
- err |= __put_user(sg_io64.info, &sg_io32->info);
- err |= copy_to_user((void *)A(sbp32), sg_io64.sbp, sg_io64.mx_sb_len);
- if (sg_io64.dxferp) {
- if (sg_io64.iovec_count)
- err |= copy_back_sg_iovec(&sg_io64, dxferp32);
- else
- err |= copy_to_user((void *)A(dxferp32),
- sg_io64.dxferp,
- sg_io64.dxfer_len);
- }
- if (err)
- err = -EFAULT;
- out:
- if (sg_io64.cmdp)
- kfree(sg_io64.cmdp);
- if (sg_io64.sbp)
- kfree(sg_io64.sbp);
- if (sg_io64.dxferp) {
- if (sg_io64.iovec_count) {
- free_sg_iovec(&sg_io64);
- } else {
- kfree(sg_io64.dxferp);
- }
- }
- return err;
- }
- struct sock_fprog32 {
- __u16 len;
- __u32 filter;
- };
- #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
- #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
- static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct sock_fprog32 *u_fprog32 = (struct sock_fprog32 *) arg;
- struct sock_fprog *u_fprog64 = alloc_user_space(sizeof(struct sock_fprog));
- void *fptr64;
- u32 fptr32;
- u16 flen;
- if (get_user(flen, &u_fprog32->len) ||
- get_user(fptr32, &u_fprog32->filter))
- return -EFAULT;
- fptr64 = (void *) A(fptr32);
- if (put_user(flen, &u_fprog64->len) ||
- put_user(fptr64, &u_fprog64->filter))
- return -EFAULT;
- if (cmd == PPPIOCSPASS32)
- cmd = PPPIOCSPASS;
- else
- cmd = PPPIOCSACTIVE;
- return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
- }
- struct ppp_option_data32 {
- __kernel_caddr_t32 ptr;
- __u32 length;
- int transmit;
- };
- #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
- struct ppp_idle32 {
- __kernel_time_t32 xmit_idle;
- __kernel_time_t32 recv_idle;
- };
- #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
- static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct ppp_option_data32 data32;
- struct ppp_option_data data;
- struct ppp_idle32 idle32;
- struct ppp_idle idle;
- unsigned int kcmd;
- void *karg;
- int err = 0;
- switch (cmd) {
- case PPPIOCGIDLE32:
- kcmd = PPPIOCGIDLE;
- karg = &idle;
- break;
- case PPPIOCSCOMPRESS32:
- if (copy_from_user(&data32, (struct ppp_option_data32 *)arg, sizeof(struct ppp_option_data32)))
- return -EFAULT;
- data.ptr = kmalloc (data32.length, GFP_KERNEL);
- if (!data.ptr)
- return -ENOMEM;
- if (copy_from_user(data.ptr, (__u8 *)A(data32.ptr), data32.length)) {
- kfree(data.ptr);
- return -EFAULT;
- }
- data.length = data32.length;
- data.transmit = data32.transmit;
- kcmd = PPPIOCSCOMPRESS;
- karg = &data;
- break;
- default:
- do {
- static int count;
- if (++count <= 20)
- printk("ppp_ioctl: Unknown cmd fd(%d) "
- "cmd(%08x) arg(%08x)n",
- (int)fd, (unsigned int)cmd, (unsigned int)arg);
- } while(0);
- return -EINVAL;
- }
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, kcmd, (unsigned long)karg);
- set_fs (old_fs);
- switch (cmd) {
- case PPPIOCGIDLE32:
- if (err)
- return err;
- idle32.xmit_idle = idle.xmit_idle;
- idle32.recv_idle = idle.recv_idle;
- if (copy_to_user((struct ppp_idle32 *)arg, &idle32, sizeof(struct ppp_idle32)))
- return -EFAULT;
- break;
- case PPPIOCSCOMPRESS32:
- kfree(data.ptr);
- break;
- default:
- break;
- }
- return err;
- }
- struct mtget32 {
- __u32 mt_type;
- __u32 mt_resid;
- __u32 mt_dsreg;
- __u32 mt_gstat;
- __u32 mt_erreg;
- __kernel_daddr_t32 mt_fileno;
- __kernel_daddr_t32 mt_blkno;
- };
- #define MTIOCGET32 _IOR('m', 2, struct mtget32)
- struct mtpos32 {
- __u32 mt_blkno;
- };
- #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
- struct mtconfiginfo32 {
- __u32 mt_type;
- __u32 ifc_type;
- __u16 irqnr;
- __u16 dmanr;
- __u16 port;
- __u32 debug;
- __u32 have_dens:1;
- __u32 have_bsf:1;
- __u32 have_fsr:1;
- __u32 have_bsr:1;
- __u32 have_eod:1;
- __u32 have_seek:1;
- __u32 have_tell:1;
- __u32 have_ras1:1;
- __u32 have_ras2:1;
- __u32 have_ras3:1;
- __u32 have_qfa:1;
- __u32 pad1:5;
- char reserved[10];
- };
- #define MTIOCGETCONFIG32 _IOR('m', 4, struct mtconfiginfo32)
- #define MTIOCSETCONFIG32 _IOW('m', 5, struct mtconfiginfo32)
- static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct mtconfiginfo info;
- struct mtget get;
- struct mtpos pos;
- unsigned long kcmd;
- void *karg;
- int err = 0;
- switch(cmd) {
- case MTIOCPOS32:
- kcmd = MTIOCPOS;
- karg = &pos;
- break;
- case MTIOCGET32:
- kcmd = MTIOCGET;
- karg = &get;
- break;
- case MTIOCGETCONFIG32:
- kcmd = MTIOCGETCONFIG;
- karg = &info;
- break;
- case MTIOCSETCONFIG32:
- kcmd = MTIOCSETCONFIG;
- karg = &info;
- err = __get_user(info.mt_type, &((struct mtconfiginfo32 *)arg)->mt_type);
- err |= __get_user(info.ifc_type, &((struct mtconfiginfo32 *)arg)->ifc_type);
- err |= __get_user(info.irqnr, &((struct mtconfiginfo32 *)arg)->irqnr);
- err |= __get_user(info.dmanr, &((struct mtconfiginfo32 *)arg)->dmanr);
- err |= __get_user(info.port, &((struct mtconfiginfo32 *)arg)->port);
- err |= __get_user(info.debug, &((struct mtconfiginfo32 *)arg)->debug);
- err |= __copy_from_user((char *)&info.debug + sizeof(info.debug),
- (char *)&((struct mtconfiginfo32 *)arg)->debug
- + sizeof(((struct mtconfiginfo32 *)arg)->debug), sizeof(__u32));
- if (err)
- return -EFAULT;
- break;
- default:
- do {
- static int count;
- if (++count <= 20)
- printk("mt_ioctl: Unknown cmd fd(%d) "
- "cmd(%08x) arg(%08x)n",
- (int)fd, (unsigned int)cmd, (unsigned int)arg);
- } while(0);
- return -EINVAL;
- }
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, kcmd, (unsigned long)karg);
- set_fs (old_fs);
- if (err)
- return err;
- switch (cmd) {
- case MTIOCPOS32:
- err = __put_user(pos.mt_blkno, &((struct mtpos32 *)arg)->mt_blkno);
- break;
- case MTIOCGET32:
- err = __put_user(get.mt_type, &((struct mtget32 *)arg)->mt_type);
- err |= __put_user(get.mt_resid, &((struct mtget32 *)arg)->mt_resid);
- err |= __put_user(get.mt_dsreg, &((struct mtget32 *)arg)->mt_dsreg);
- err |= __put_user(get.mt_gstat, &((struct mtget32 *)arg)->mt_gstat);
- err |= __put_user(get.mt_erreg, &((struct mtget32 *)arg)->mt_erreg);
- err |= __put_user(get.mt_fileno, &((struct mtget32 *)arg)->mt_fileno);
- err |= __put_user(get.mt_blkno, &((struct mtget32 *)arg)->mt_blkno);
- break;
- case MTIOCGETCONFIG32:
- err = __put_user(info.mt_type, &((struct mtconfiginfo32 *)arg)->mt_type);
- err |= __put_user(info.ifc_type, &((struct mtconfiginfo32 *)arg)->ifc_type);
- err |= __put_user(info.irqnr, &((struct mtconfiginfo32 *)arg)->irqnr);
- err |= __put_user(info.dmanr, &((struct mtconfiginfo32 *)arg)->dmanr);
- err |= __put_user(info.port, &((struct mtconfiginfo32 *)arg)->port);
- err |= __put_user(info.debug, &((struct mtconfiginfo32 *)arg)->debug);
- err |= __copy_to_user((char *)&((struct mtconfiginfo32 *)arg)->debug
- + sizeof(((struct mtconfiginfo32 *)arg)->debug),
- (char *)&info.debug + sizeof(info.debug), sizeof(__u32));
- break;
- case MTIOCSETCONFIG32:
- break;
- }
- return err ? -EFAULT: 0;
- }
- struct cdrom_read32 {
- int cdread_lba;
- __kernel_caddr_t32 cdread_bufaddr;
- int cdread_buflen;
- };
- struct cdrom_read_audio32 {
- union cdrom_addr addr;
- u_char addr_format;
- int nframes;
- __kernel_caddr_t32 buf;
- };
- struct cdrom_generic_command32 {
- unsigned char cmd[CDROM_PACKET_SIZE];
- __kernel_caddr_t32 buffer;
- unsigned int buflen;
- int stat;
- __kernel_caddr_t32 sense;
- __kernel_caddr_t32 reserved[3];
- };
- static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct cdrom_read cdread;
- struct cdrom_read_audio cdreadaudio;
- struct cdrom_generic_command cgc;
- __kernel_caddr_t32 addr;
- char *data = 0;
- void *karg;
- int err = 0;
- switch(cmd) {
- case CDROMREADMODE2:
- case CDROMREADMODE1:
- case CDROMREADRAW:
- case CDROMREADCOOKED:
- karg = &cdread;
- err = __get_user(cdread.cdread_lba, &((struct cdrom_read32 *)arg)->cdread_lba);
- err |= __get_user(addr, &((struct cdrom_read32 *)arg)->cdread_bufaddr);
- err |= __get_user(cdread.cdread_buflen, &((struct cdrom_read32 *)arg)->cdread_buflen);
- if (err)
- return -EFAULT;
- data = kmalloc(cdread.cdread_buflen, GFP_KERNEL);
- if (!data)
- return -ENOMEM;
- cdread.cdread_bufaddr = data;
- break;
- case CDROMREADAUDIO:
- karg = &cdreadaudio;
- err = copy_from_user(&cdreadaudio.addr, &((struct cdrom_read_audio32 *)arg)->addr, sizeof(cdreadaudio.addr));
- err |= __get_user(cdreadaudio.addr_format, &((struct cdrom_read_audio32 *)arg)->addr_format);
- err |= __get_user(cdreadaudio.nframes, &((struct cdrom_read_audio32 *)arg)->nframes);
- err |= __get_user(addr, &((struct cdrom_read_audio32 *)arg)->buf);
- if (err)
- return -EFAULT;
- data = kmalloc(cdreadaudio.nframes * 2352, GFP_KERNEL);
- if (!data)
- return -ENOMEM;
- cdreadaudio.buf = data;
- break;
- case CDROM_SEND_PACKET:
- karg = &cgc;
- err = copy_from_user(cgc.cmd, &((struct cdrom_generic_command32 *)arg)->cmd, sizeof(cgc.cmd));
- err |= __get_user(addr, &((struct cdrom_generic_command32 *)arg)->buffer);
- err |= __get_user(cgc.buflen, &((struct cdrom_generic_command32 *)arg)->buflen);
- if (err)
- return -EFAULT;
- if ((data = kmalloc(cgc.buflen, GFP_KERNEL)) == NULL)
- return -ENOMEM;
- cgc.buffer = data;
- break;
- default:
- do {
- static int count;
- if (++count <= 20)
- printk("cdrom_ioctl: Unknown cmd fd(%d) "
- "cmd(%08x) arg(%08x)n",
- (int)fd, (unsigned int)cmd, (unsigned int)arg);
- } while(0);
- return -EINVAL;
- }
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)karg);
- set_fs (old_fs);
- if (err)
- goto out;
- switch (cmd) {
- case CDROMREADMODE2:
- case CDROMREADMODE1:
- case CDROMREADRAW:
- case CDROMREADCOOKED:
- err = copy_to_user((char *)A(addr), data, cdread.cdread_buflen);
- break;
- case CDROMREADAUDIO:
- err = copy_to_user((char *)A(addr), data, cdreadaudio.nframes * 2352);
- break;
- case CDROM_SEND_PACKET:
- err = copy_to_user((char *)A(addr), data, cgc.buflen);
- break;
- default:
- break;
- }
- out: if (data)
- kfree(data);
- return err ? -EFAULT : 0;
- }
- struct loop_info32 {
- int lo_number; /* ioctl r/o */
- __kernel_dev_t32 lo_device; /* ioctl r/o */
- unsigned int lo_inode; /* ioctl r/o */
- __kernel_dev_t32 lo_rdevice; /* ioctl r/o */
- int lo_offset;
- int lo_encrypt_type;
- int lo_encrypt_key_size; /* ioctl w/o */
- int lo_flags; /* ioctl r/o */
- char lo_name[LO_NAME_SIZE];
- unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
- unsigned int lo_init[2];
- char reserved[4];
- };
- static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct loop_info l;
- int err = -EINVAL;
- switch(cmd) {
- case LOOP_SET_STATUS:
- err = get_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);
- err |= __get_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);
- err |= __get_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);
- err |= __get_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);
- err |= __copy_from_user((char *)&l.lo_offset, (char *)&((struct loop_info32 *)arg)->lo_offset,
- 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
- if (err) {
- err = -EFAULT;
- } else {
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)&l);
- set_fs (old_fs);
- }
- break;
- case LOOP_GET_STATUS:
- set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)&l);
- set_fs (old_fs);
- if (!err) {
- err = put_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);
- err |= __put_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);
- err |= __put_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);
- err |= __put_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);
- err |= __copy_to_user((char *)&((struct loop_info32 *)arg)->lo_offset,
- (char *)&l.lo_offset, (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
- if (err)
- err = -EFAULT;
- }
- break;
- default: {
- static int count;
- if (++count <= 20)
- printk("%s: Unknown loop ioctl cmd, fd(%d) "
- "cmd(%08x) arg(%08lx)n",
- __FUNCTION__, fd, cmd, arg);
- }
- }
- return err;
- }
- extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);
- static int vt_check(struct file *file)
- {
- struct tty_struct *tty;
- struct inode *inode = file->f_dentry->d_inode;
-
- if (file->f_op->ioctl != tty_ioctl)
- return -EINVAL;
-
- tty = (struct tty_struct *)file->private_data;
- if (tty_paranoia_check(tty, inode->i_rdev, "tty_ioctl"))
- return -EINVAL;
-
- if (tty->driver.ioctl != vt_ioctl)
- return -EINVAL;
-
- /*
- * To have permissions to do most of the vt ioctls, we either have
- * to be the owner of the tty, or super-user.
- */
- if (current->tty == tty || suser())
- return 1;
- return 0;
- }
- struct consolefontdesc32 {
- unsigned short charcount; /* characters in font (256 or 512) */
- unsigned short charheight; /* scan lines per character (1-32) */
- u32 chardata; /* font data in expanded form */
- };
- static int do_fontx_ioctl(unsigned int fd, int cmd, struct consolefontdesc32 *user_cfd, struct file *file)
- {
- struct consolefontdesc cfdarg;
- struct console_font_op op;
- int i, perm;
- perm = vt_check(file);
- if (perm < 0) return perm;
-
- if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc32)))
- return -EFAULT;
-
- cfdarg.chardata = (unsigned char *)A(((struct consolefontdesc32 *)&cfdarg)->chardata);
-
- switch (cmd) {
- case PIO_FONTX:
- if (!perm)
- return -EPERM;
- op.op = KD_FONT_OP_SET;
- op.flags = 0;
- op.width = 8;
- op.height = cfdarg.charheight;
- op.charcount = cfdarg.charcount;
- op.data = cfdarg.chardata;
- return con_font_op(fg_console, &op);
- case GIO_FONTX:
- if (!cfdarg.chardata)
- return 0;
- op.op = KD_FONT_OP_GET;
- op.flags = 0;
- op.width = 8;
- op.height = cfdarg.charheight;
- op.charcount = cfdarg.charcount;
- op.data = cfdarg.chardata;
- i = con_font_op(fg_console, &op);
- if (i)
- return i;
- cfdarg.charheight = op.height;
- cfdarg.charcount = op.charcount;
- ((struct consolefontdesc32 *)&cfdarg)->chardata = (unsigned long)cfdarg.chardata;
- if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc32)))
- return -EFAULT;
- return 0;
- }
- return -EINVAL;
- }
- struct console_font_op32 {
- unsigned int op; /* operation code KD_FONT_OP_* */
- unsigned int flags; /* KD_FONT_FLAG_* */
- unsigned int width, height; /* font size */
- unsigned int charcount;
- u32 data; /* font data with height fixed to 32 */
- };
-
- static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, struct console_font_op32 *fontop, struct file *file)
- {
- struct console_font_op op;
- int perm = vt_check(file), i;
- struct vt_struct *vt;
-
- if (perm < 0) return perm;
-
- if (copy_from_user(&op, (void *) fontop, sizeof(struct console_font_op32)))
- return -EFAULT;
- if (!perm && op.op != KD_FONT_OP_GET)
- return -EPERM;
- op.data = (unsigned char *)A(((struct console_font_op32 *)&op)->data);
- op.flags |= KD_FONT_FLAG_OLD;
- vt = (struct vt_struct *)((struct tty_struct *)file->private_data)->driver_data;
- i = con_font_op(vt->vc_num, &op);
- if (i) return i;
- ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
- if (copy_to_user((void *) fontop, &op, sizeof(struct console_font_op32)))
- return -EFAULT;
- return 0;
- }
- struct unimapdesc32 {
- unsigned short entry_ct;
- u32 entries;
- };
- static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, struct unimapdesc32 *user_ud, struct file *file)
- {
- struct unimapdesc32 tmp;
- int perm = vt_check(file);
-
- if (perm < 0) return perm;
- if (copy_from_user(&tmp, user_ud, sizeof tmp))
- return -EFAULT;
- switch (cmd) {
- case PIO_UNIMAP:
- if (!perm) return -EPERM;
- return con_set_unimap(fg_console, tmp.entry_ct, (struct unipair *)A(tmp.entries));
- case GIO_UNIMAP:
- return con_get_unimap(fg_console, tmp.entry_ct, &(user_ud->entry_ct), (struct unipair *)A(tmp.entries));
- }
- return 0;
- }
- static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- __kernel_uid_t kuid;
- int err;
- cmd = SMB_IOC_GETMOUNTUID;
- set_fs(KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
- set_fs(old_fs);
- if (err >= 0)
- err = put_user(kuid, (__kernel_uid_t32 *)arg);
- return err;
- }
- struct ncp_ioctl_request_32 {
- unsigned int function;
- unsigned int size;
- __kernel_caddr_t32 data;
- };
- struct ncp_fs_info_v2_32 {
- int version;
- unsigned int mounted_uid;
- unsigned int connection;
- unsigned int buffer_size;
- unsigned int volume_number;
- __u32 directory_id;
- __u32 dummy1;
- __u32 dummy2;
- __u32 dummy3;
- };
- struct ncp_objectname_ioctl_32
- {
- int auth_type;
- unsigned int object_name_len;
- __kernel_caddr_t32 object_name; /* an userspace data, in most cases user name */
- };
- struct ncp_privatedata_ioctl_32
- {
- unsigned int len;
- __kernel_caddr_t32 data; /* ~1000 for NDS */
- };
- #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
- #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, unsigned int)
- #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
- #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
- #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
- #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
- #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
- static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ncp_ioctl_request_32 n32;
- struct ncp_ioctl_request n;
- mm_segment_t old_fs;
- int err;
- if (copy_from_user(&n32, (struct ncp_ioctl_request_32*)arg,
- sizeof(n32)))
- return -EFAULT;
- n.function = n32.function;
- n.size = n32.size;
- if (n.size > 65536)
- return -EINVAL;
- n.data = vmalloc(65536); /* 65536 must be same as NCP_PACKET_SIZE_INTERNAL in ncpfs */
- if (!n.data)
- return -ENOMEM;
- err = -EFAULT;
- if (copy_from_user(n.data, A(n32.data), n.size))
- goto out;
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, NCP_IOC_NCPREQUEST, (unsigned long)&n);
- set_fs (old_fs);
- if(err <= 0)
- goto out;
- if (err > 65536) {
- err = -EINVAL;
- goto out;
- }
- if (copy_to_user(A(n32.data), n.data, err)) {
- err = -EFAULT;
- goto out;
- }
- out:
- vfree(n.data);
- return err;
- }
- static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- __kernel_uid_t kuid;
- int err;
- cmd = NCP_IOC_GETMOUNTUID2;
- set_fs(KERNEL_DS);
- err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
- set_fs(old_fs);
- if (!err)
- err = put_user(kuid, (unsigned int*)arg);
- return err;
- }
- static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- mm_segment_t old_fs = get_fs();
- struct ncp_fs_info_v2_32 n32;
- struct ncp_fs_info_v2 n;
- int err;
- if (copy_from_user(&n32, (struct ncp_fs_info_v2_32*)arg, sizeof(n32)))
- return -EFAULT;
- if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
- return -EINVAL;
- n.version = NCP_GET_FS_INFO_VERSION_V2;
- set_fs(KERNEL_DS);
- err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
- set_fs(old_fs);
- if (!err) {
- n32.version = n.version;
- n32.mounted_uid = n.mounted_uid;
- n32.connection = n.connection;
- n32.buffer_size = n.buffer_size;
- n32.volume_number = n.volume_number;
- n32.directory_id = n.directory_id;
- n32.dummy1 = n.dummy1;
- n32.dummy2 = n.dummy2;
- n32.dummy3 = n.dummy3;
- err = copy_to_user((struct ncp_fs_info_v2_32*)arg, &n32, sizeof(n32)) ? -EFAULT : 0;
- }
- return err;
- }
- static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ncp_objectname_ioctl_32 n32;
- struct ncp_objectname_ioctl n;
- mm_segment_t old_fs;
- int err;
- size_t tl;
- if (copy_from_user(&n32, (struct ncp_objectname_ioctl_32*)arg,
- sizeof(n32)))
- return -EFAULT;
- n.object_name_len = tl = n32.object_name_len;
- if (tl) {
- n.object_name = kmalloc(tl, GFP_KERNEL);
- if (!n.object_name)
- return -ENOMEM;
- } else {
- n.object_name = NULL;
- }
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, NCP_IOC_GETOBJECTNAME, (unsigned long)&n);
- set_fs (old_fs);
- if(err)
- goto out;
-
- if (tl > n.object_name_len)
- tl = n.object_name_len;
- err = -EFAULT;
- if (tl && copy_to_user(A(n32.object_name), n.object_name, tl))
- goto out;
- n32.auth_type = n.auth_type;
- n32.object_name_len = n.object_name_len;
-
- if (copy_to_user((struct ncp_objectname_ioctl_32*)arg, &n32, sizeof(n32)))
- goto out;
-
- err = 0;
- out:
- if (n.object_name)
- kfree(n.object_name);
- return err;
- }
- static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ncp_objectname_ioctl_32 n32;
- struct ncp_objectname_ioctl n;
- mm_segment_t old_fs;
- int err;
- size_t tl;
- if (copy_from_user(&n32, (struct ncp_objectname_ioctl_32*)arg,
- sizeof(n32)))
- return -EFAULT;
- n.auth_type = n32.auth_type;
- n.object_name_len = tl = n32.object_name_len;
- if (tl) {
- n.object_name = kmalloc(tl, GFP_KERNEL);
- if (!n.object_name)
- return -ENOMEM;
- err = -EFAULT;
- if (copy_from_user(n.object_name, A(n32.object_name), tl))
- goto out;
- } else {
- n.object_name = NULL;
- }
-
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, NCP_IOC_SETOBJECTNAME, (unsigned long)&n);
- set_fs (old_fs);
-
- out:
- if (n.object_name)
- kfree(n.object_name);
- return err;
- }
- static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ncp_privatedata_ioctl_32 n32;
- struct ncp_privatedata_ioctl n;
- mm_segment_t old_fs;
- int err;
- size_t tl;
- if (copy_from_user(&n32, (struct ncp_privatedata_ioctl_32*)arg,
- sizeof(n32)))
- return -EFAULT;
- n.len = tl = n32.len;
- if (tl) {
- n.data = kmalloc(tl, GFP_KERNEL);
- if (!n.data)
- return -ENOMEM;
- } else {
- n.data = NULL;
- }
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)&n);
- set_fs (old_fs);
- if(err)
- goto out;
-
- if (tl > n.len)
- tl = n.len;
- err = -EFAULT;
- if (tl && copy_to_user(A(n32.data), n.data, tl))
- goto out;
- n32.len = n.len;
-
- if (copy_to_user((struct ncp_privatedata_ioctl_32*)arg, &n32, sizeof(n32)))
- goto out;
-
- err = 0;
- out:
- if (n.data)
- kfree(n.data);
- return err;
- }
- static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct ncp_privatedata_ioctl_32 n32;
- struct ncp_privatedata_ioctl n;
- mm_segment_t old_fs;
- int err;
- size_t tl;
- if (copy_from_user(&n32, (struct ncp_privatedata_ioctl_32*)arg,
- sizeof(n32)))
- return -EFAULT;
- n.len = tl = n32.len;
- if (tl) {
- n.data = kmalloc(tl, GFP_KERNEL);
- if (!n.data)
- return -ENOMEM;
- err = -EFAULT;
- if (copy_from_user(n.data, A(n32.data), tl))
- goto out;
- } else {
- n.data = NULL;
- }
-
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)&n);
- set_fs (old_fs);
-
- out:
- if (n.data)
- kfree(n.data);
- return err;
- }
- struct atmif_sioc32 {
- int number;
- int length;
- __kernel_caddr_t32 arg;
- };
- struct atm_iobuf32 {
- int length;
- __kernel_caddr_t32 buffer;
- };
- #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
- #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
- #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
- #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
- #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
- #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
- #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
- #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
- #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
- #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
- #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
- #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
- #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
- #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
- #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
- #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
- #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
- static struct {
- unsigned int cmd32;
- unsigned int cmd;
- } atm_ioctl_map[] = {
- { ATM_GETLINKRATE32, ATM_GETLINKRATE },
- { ATM_GETNAMES32, ATM_GETNAMES },
- { ATM_GETTYPE32, ATM_GETTYPE },
- { ATM_GETESI32, ATM_GETESI },
- { ATM_GETADDR32, ATM_GETADDR },
- { ATM_RSTADDR32, ATM_RSTADDR },
- { ATM_ADDADDR32, ATM_ADDADDR },
- { ATM_DELADDR32, ATM_DELADDR },
- { ATM_GETCIRANGE32, ATM_GETCIRANGE },
- { ATM_SETCIRANGE32, ATM_SETCIRANGE },
- { ATM_SETESI32, ATM_SETESI },
- { ATM_SETESIF32, ATM_SETESIF },
- { ATM_GETSTAT32, ATM_GETSTAT },
- { ATM_GETSTATZ32, ATM_GETSTATZ },
- { ATM_GETLOOP32, ATM_GETLOOP },
- { ATM_SETLOOP32, ATM_SETLOOP },
- { ATM_QUERYLOOP32, ATM_QUERYLOOP }
- };
- #define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
- static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct atm_iobuf32 iobuf32;
- struct atm_iobuf iobuf = { 0, NULL };
- mm_segment_t old_fs;
- int err;
- err = copy_from_user(&iobuf32, (struct atm_iobuf32*)arg,
- sizeof(struct atm_iobuf32));
- if (err)
- return -EFAULT;
- iobuf.length = iobuf32.length;
- if (iobuf32.buffer == (__kernel_caddr_t32) NULL || iobuf32.length == 0) {
- iobuf.buffer = (void*)(unsigned long)iobuf32.buffer;
- } else {
- iobuf.buffer = kmalloc(iobuf.length, GFP_KERNEL);
- if (iobuf.buffer == NULL) {
- err = -ENOMEM;
- goto out;
- }
- err = copy_from_user(iobuf.buffer, A(iobuf32.buffer), iobuf.length);
- if (err) {
- err = -EFAULT;
- goto out;
- }
- }
- old_fs = get_fs(); set_fs (KERNEL_DS);
- err = sys_ioctl (fd, cmd, (unsigned long)&iobuf);
- set_fs (old_fs);
- if(err)
- goto out;
- if(iobuf.buffer && iobuf.length > 0) {
- err = copy_to_user(A(iobuf32.buffer), iobuf.buffer, iobuf.length);
- if (err) {
- err = -EFAULT;
- goto out;
- }
- }
- err = __put_user(iobuf.length, &(((struct atm_iobuf32*)arg)->length));
- out:
- if(iobuf32.buffer && iobuf32.length > 0)
- kfree(iobuf.buffer);
- return err;
- }
- static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
- {
- struct atmif_sioc32 sioc32;
- struct atmif_sioc sioc = { 0, 0, NULL };