]> git.hungrycats.org Git - linux/commitdiff
[PATCH] compat_sys_fcntl{,64} Generic part
authorStephen Rothwell <sfr@canb.auug.org.au>
Tue, 11 Mar 2003 01:34:01 +0000 (17:34 -0800)
committerChristoph Hellwig <hch@lst.de>
Tue, 11 Mar 2003 01:34:01 +0000 (17:34 -0800)
This patch creates compat_sys_fcntl{,64}.  The diffstat for the whole
patch set is below, but this is just the generic part, the architecture
specific parts will follow.

This patch also removes struct flock64 from all the 64 bit architectures
(except parisc).

fs/compat.c
include/linux/compat.h
include/linux/fs.h

index f8eb0e7b043a7117808c11916035b22afea774cf..94aae781930ffc114daa2827da44f9e6a82dd336 100644 (file)
@@ -75,36 +75,6 @@ asmlinkage long compat_sys_newfstat(unsigned int fd,
        return error;
 }
 
-int get_compat_flock(struct flock *kfl, struct compat_flock *ufl)
-{
-       int err;
-
-       if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)))
-               return -EFAULT;
-
-       err = __get_user(kfl->l_type, &ufl->l_type);
-       err |= __get_user(kfl->l_whence, &ufl->l_whence);
-       err |= __get_user(kfl->l_start, &ufl->l_start);
-       err |= __get_user(kfl->l_len, &ufl->l_len);
-       err |= __get_user(kfl->l_pid, &ufl->l_pid);
-       return err;
-}
-
-int put_compat_flock(struct flock *kfl, struct compat_flock *ufl)
-{
-       int err;
-
-       if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)))
-               return -EFAULT;
-
-       err = __put_user(kfl->l_type, &ufl->l_type);
-       err |= __put_user(kfl->l_whence, &ufl->l_whence);
-       err |= __put_user(kfl->l_start, &ufl->l_start);
-       err |= __put_user(kfl->l_len, &ufl->l_len);
-       err |= __put_user(kfl->l_pid, &ufl->l_pid);
-       return err;
-}
-
 static int put_compat_statfs(struct compat_statfs *ubuf, struct statfs *kbuf)
 {
        if (verify_area(VERIFY_WRITE, ubuf, sizeof(*ubuf)) ||
@@ -159,3 +129,120 @@ asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs *buf)
 out:
        return error;
 }
+
+static int get_compat_flock(struct flock *kfl, struct compat_flock *ufl)
+{
+       if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
+           __get_user(kfl->l_type, &ufl->l_type) ||
+           __get_user(kfl->l_whence, &ufl->l_whence) ||
+           __get_user(kfl->l_start, &ufl->l_start) ||
+           __get_user(kfl->l_len, &ufl->l_len) ||
+           __get_user(kfl->l_pid, &ufl->l_pid))
+               return -EFAULT;
+       return 0;
+}
+
+static int put_compat_flock(struct flock *kfl, struct compat_flock *ufl)
+{
+       if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
+           __put_user(kfl->l_type, &ufl->l_type) ||
+           __put_user(kfl->l_whence, &ufl->l_whence) ||
+           __put_user(kfl->l_start, &ufl->l_start) ||
+           __put_user(kfl->l_len, &ufl->l_len) ||
+           __put_user(kfl->l_pid, &ufl->l_pid))
+               return -EFAULT;
+       return 0;
+}
+
+static int get_compat_flock64(struct flock *kfl, struct compat_flock64 *ufl)
+{
+       if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
+           __get_user(kfl->l_type, &ufl->l_type) ||
+           __get_user(kfl->l_whence, &ufl->l_whence) ||
+           __get_user(kfl->l_start, &ufl->l_start) ||
+           __get_user(kfl->l_len, &ufl->l_len) ||
+           __get_user(kfl->l_pid, &ufl->l_pid))
+               return -EFAULT;
+       return 0;
+}
+
+static int put_compat_flock64(struct flock *kfl, struct compat_flock64 *ufl)
+{
+       if (!access_ok(VERIFY_WRITE, ufl, sizeof(*ufl)) ||
+           __put_user(kfl->l_type, &ufl->l_type) ||
+           __put_user(kfl->l_whence, &ufl->l_whence) ||
+           __put_user(kfl->l_start, &ufl->l_start) ||
+           __put_user(kfl->l_len, &ufl->l_len) ||
+           __put_user(kfl->l_pid, &ufl->l_pid))
+               return -EFAULT;
+       return 0;
+}
+
+extern asmlinkage long sys_fcntl(unsigned int, unsigned int, unsigned long);
+
+asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
+               unsigned long arg)
+{
+       mm_segment_t old_fs;
+       struct flock f;
+       long ret;
+
+       switch (cmd) {
+       case F_GETLK:
+       case F_SETLK:
+       case F_SETLKW:
+               ret = get_compat_flock(&f, (struct compat_flock *)arg);
+               if (ret != 0)
+                       break;
+               old_fs = get_fs();
+               set_fs(KERNEL_DS);
+               ret = sys_fcntl(fd, cmd, (unsigned long)&f);
+               set_fs(old_fs);
+               if ((cmd == F_GETLK) && (ret == 0)) {
+                       if ((f.l_start >= COMPAT_OFF_T_MAX) ||
+                           ((f.l_start + f.l_len) >= COMPAT_OFF_T_MAX))
+                               ret = -EOVERFLOW;
+                       if (ret == 0)
+                               ret = put_compat_flock(&f,
+                                               (struct compat_flock *)arg);
+               }
+               break;
+
+       case F_GETLK64:
+       case F_SETLK64:
+       case F_SETLKW64:
+               ret = get_compat_flock64(&f, (struct compat_flock64 *)arg);
+               if (ret != 0)
+                       break;
+               old_fs = get_fs();
+               set_fs(KERNEL_DS);
+               ret = sys_fcntl(fd, F_GETLK, (unsigned long)&f);
+               ret = sys_fcntl(fd, (cmd == F_GETLK64) ? F_GETLK :
+                               ((cmd == F_SETLK64) ? F_SETLK : F_SETLKW),
+                               (unsigned long)&f);
+               set_fs(old_fs);
+               if ((cmd == F_GETLK64) && (ret == 0)) {
+                       if ((f.l_start >= COMPAT_LOFF_T_MAX) ||
+                           ((f.l_start + f.l_len) >= COMPAT_LOFF_T_MAX))
+                               ret = -EOVERFLOW;
+                       if (ret == 0)
+                               ret = put_compat_flock64(&f,
+                                               (struct compat_flock64 *)arg);
+               }
+               break;
+
+       default:
+               ret = sys_fcntl(fd, cmd, arg);
+               break;
+       }
+       return ret;
+}
+
+asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
+               unsigned long arg)
+{
+       if ((cmd == F_GETLK64) || (cmd == F_SETLK64) || (cmd == F_SETLKW64))
+               return -EINVAL;
+       return compat_sys_fcntl64(fd, cmd, arg);
+}
+
index 34bc3233e10d8b2b333db928d5339ea5201df4c6..48930c9b513660b89367584850a74ff9ea083a0f 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <linux/stat.h>
 #include <linux/param.h>       /* for HZ */
-#include <linux/fcntl.h>       /* for struct flock */
 #include <asm/compat.h>
 
 #define compat_jiffies_to_clock_t(x)   \
@@ -40,8 +39,6 @@ typedef struct {
 } compat_sigset_t;
 
 extern int cp_compat_stat(struct kstat *, struct compat_stat *);
-extern int get_compat_flock(struct flock *, struct compat_flock *);
-extern int put_compat_flock(struct flock *, struct compat_flock *);
 extern int get_compat_timespec(struct timespec *, struct compat_timespec *);
 extern int put_compat_timespec(struct timespec *, struct compat_timespec *);
 
index e7706105ac86f51fac847bdc31cae55e77f7f7fe..14bd953f6a64a04b4e9be17d89033f42697d28ca 100644 (file)
@@ -526,8 +526,10 @@ extern struct list_head file_lock_list;
 extern int fcntl_getlk(struct file *, struct flock *);
 extern int fcntl_setlk(struct file *, unsigned int, struct flock *);
 
+#if BITS_PER_LONG == 32
 extern int fcntl_getlk64(struct file *, struct flock64 *);
 extern int fcntl_setlk64(struct file *, unsigned int, struct flock64 *);
+#endif
 
 /* fs/locks.c */
 extern void locks_init_lock(struct file_lock *);