[PATCH] BLOCK: Move common FS-specific ioctls to linux/fs.h [try #6]
[safe/jmp/linux-2.6] / fs / compat_ioctl.c
index f0b7256..bd9c4f4 100644 (file)
@@ -10,7 +10,6 @@
  * ioctls.
  */
 
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/compat.h>
 #include <linux/kernel.h>
 #include <linux/if_pppox.h>
 #include <linux/mtio.h>
 #include <linux/cdrom.h>
-#include <linux/loop.h>
 #include <linux/auto_fs.h>
 #include <linux/auto_fs4.h>
-#include <linux/devfs_fs.h>
 #include <linux/tty.h>
 #include <linux/vt_kern.h>
 #include <linux/fb.h>
@@ -72,6 +69,7 @@
 #include <linux/i2c-dev.h>
 #include <linux/wireless.h>
 #include <linux/atalk.h>
+#include <linux/blktrace_api.h>
 
 #include <net/sock.h>          /* siocdevprivate_ioctl */
 #include <net/bluetooth/bluetooth.h>
@@ -79,6 +77,7 @@
 #include <net/bluetooth/rfcomm.h>
 
 #include <linux/capi.h>
+#include <linux/gigaset_dev.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_ioctl.h>
 #include <linux/dvb/dmx.h>
 #include <linux/dvb/frontend.h>
 #include <linux/dvb/video.h>
-
-/* 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 EXT3_IOC32_GETVERSION             _IOR('f', 3, int)
-#define EXT3_IOC32_SETVERSION             _IOW('f', 4, int)
-#define EXT3_IOC32_GETRSVSZ               _IOR('f', 5, int)
-#define EXT3_IOC32_SETRSVSZ               _IOW('f', 6, int)
-#define EXT3_IOC32_GROUP_EXTEND           _IOW('f', 7, unsigned int)
-#ifdef CONFIG_JBD_DEBUG
-#define EXT3_IOC32_WAIT_FOR_READONLY      _IOR('f', 99, int)
-#endif
-
-#define EXT2_IOC32_GETVERSION             _IOR('v', 1, int)
-#define EXT2_IOC32_SETVERSION             _IOW('v', 2, int)
+#include <linux/lp.h>
 
 static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
                              unsigned long arg, struct file *f)
@@ -203,38 +188,6 @@ static int do_ext3_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
        return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
 }
 
-struct compat_dmx_event {
-       dmx_event_t     event;
-       compat_time_t   timeStamp;
-       union
-       {
-               dmx_scrambling_status_t scrambling;
-       } u;
-};
-
-static int do_dmx_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
-{
-       struct dmx_event kevent;
-       mm_segment_t old_fs = get_fs();
-       int err;
-
-       set_fs(KERNEL_DS);
-       err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
-       set_fs(old_fs);
-
-       if (!err) {
-               struct compat_dmx_event __user *up = compat_ptr(arg);
-
-               err  = put_user(kevent.event, &up->event);
-               err |= put_user(kevent.timeStamp, &up->timeStamp);
-               err |= put_user(kevent.u.scrambling, &up->u.scrambling);
-               if (err)
-                       err = -EFAULT;
-       }
-
-       return err;
-}
-
 struct compat_video_event {
        int32_t         type;
        compat_time_t   timestamp;
@@ -445,7 +398,7 @@ static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
        ifr = ifc.ifc_req;
        ifr32 = compat_ptr(ifc32.ifcbuf);
        for (i = 0, j = 0;
-             i + sizeof (struct ifreq32) < ifc32.ifc_len && j < ifc.ifc_len;
+             i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
             i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
                if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
                        return -EFAULT;
@@ -930,8 +883,8 @@ struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
 static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
        int err, i;
-       sg_req_info_t *r;
-       struct compat_sg_req_info *o = (struct compat_sg_req_info *)arg;
+       sg_req_info_t __user *r;
+       struct compat_sg_req_info __user *o = (void __user *)arg;
        r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
        err = sys_ioctl(fd,cmd,(unsigned long)r);
        if (err < 0)
@@ -1245,73 +1198,6 @@ static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long ar
        return err;
 }
 
-struct loop_info32 {
-       compat_int_t    lo_number;      /* ioctl r/o */
-       compat_dev_t    lo_device;      /* ioctl r/o */
-       compat_ulong_t  lo_inode;       /* ioctl r/o */
-       compat_dev_t    lo_rdevice;     /* ioctl r/o */
-       compat_int_t    lo_offset;
-       compat_int_t    lo_encrypt_type;
-       compat_int_t    lo_encrypt_key_size;    /* ioctl w/o */
-       compat_int_t    lo_flags;       /* ioctl r/o */
-       char            lo_name[LO_NAME_SIZE];
-       unsigned char   lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
-       compat_ulong_t  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;
-       struct loop_info32 __user *ul;
-       int err = -EINVAL;
-
-       ul = compat_ptr(arg);
-       switch(cmd) {
-       case LOOP_SET_STATUS:
-               err = get_user(l.lo_number, &ul->lo_number);
-               err |= __get_user(l.lo_device, &ul->lo_device);
-               err |= __get_user(l.lo_inode, &ul->lo_inode);
-               err |= __get_user(l.lo_rdevice, &ul->lo_rdevice);
-               err |= __copy_from_user(&l.lo_offset, &ul->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, &ul->lo_number);
-                       err |= __put_user(l.lo_device, &ul->lo_device);
-                       err |= __put_user(l.lo_inode, &ul->lo_inode);
-                       err |= __put_user(l.lo_rdevice, &ul->lo_rdevice);
-                       err |= __copy_to_user(&ul->lo_offset, &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);
-
 #ifdef CONFIG_VT
 
 static int vt_check(struct file *file)
@@ -1520,8 +1406,7 @@ static struct {
        { ATM_QUERYLOOP32,   ATM_QUERYLOOP }
 };
 
-#define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
-
+#define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
 
 static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
@@ -1822,7 +1707,7 @@ static struct {
        { FDWERRORGET32, FDWERRORGET }
 };
 
-#define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
+#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
 
 static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
@@ -2530,18 +2415,9 @@ static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
                val32 = kval;
                return put_user(val32, (unsigned int __user *)arg);
        case RTC_IRQP_SET32:
+               return sys_ioctl(fd, RTC_IRQP_SET, arg); 
        case RTC_EPOCH_SET32:
-               ret = get_user(val32, (unsigned int __user *)arg);
-               if (ret)
-                       return ret;
-               kval = val32;
-
-               set_fs(KERNEL_DS);
-               ret = sys_ioctl(fd, (cmd == RTC_IRQP_SET32) ?
-                               RTC_IRQP_SET : RTC_EPOCH_SET,
-                               (unsigned long)&kval);
-               set_fs(oldfs);
-               return ret;
+               return sys_ioctl(fd, RTC_EPOCH_SET, arg);
        default:
                /* unreached */
                return -ENOIOCTLCMD;
@@ -2735,6 +2611,20 @@ static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned lon
 }
 #endif
 
+static int
+lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
+{
+       struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
+       struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
+       struct timeval ts;
+       if (get_user(ts.tv_sec, &tc->tv_sec) ||
+           get_user(ts.tv_usec, &tc->tv_usec) ||
+           put_user(ts.tv_sec, &tn->tv_sec) ||
+           put_user(ts.tv_usec, &tn->tv_usec))
+               return -EFAULT;
+       return sys_ioctl(fd, cmd, (unsigned long)tn);
+}
+
 #define HANDLE_IOCTL(cmd,handler) \
        { (cmd), (ioctl_trans_handler_t)(handler) },
 
@@ -2837,8 +2727,6 @@ HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
 HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
 HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
 HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
-HANDLE_IOCTL(LOOP_SET_STATUS, loop_status)
-HANDLE_IOCTL(LOOP_GET_STATUS, loop_status)
 #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
 HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
 #ifdef CONFIG_VT
@@ -2958,10 +2846,23 @@ HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata)
 #endif
 
 /* dvb */
-HANDLE_IOCTL(DMX_GET_EVENT, do_dmx_get_event)
 HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
 HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
 HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
+
+/* parport */
+COMPATIBLE_IOCTL(LPTIME)
+COMPATIBLE_IOCTL(LPCHAR)
+COMPATIBLE_IOCTL(LPABORTOPEN)
+COMPATIBLE_IOCTL(LPCAREFUL)
+COMPATIBLE_IOCTL(LPWAIT)
+COMPATIBLE_IOCTL(LPSETIRQ)
+COMPATIBLE_IOCTL(LPGETSTATUS)
+COMPATIBLE_IOCTL(LPGETSTATUS)
+COMPATIBLE_IOCTL(LPRESET)
+/*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
+COMPATIBLE_IOCTL(LPGETFLAGS)
+HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
 };
 
 int ioctl_table_size = ARRAY_SIZE(ioctl_start);