]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/compat.c
[PATCH] vfs: *at functions: core
[linux-2.6-omap-h63xx.git] / fs / compat.c
index 0f7abf246d32c80a6f2c8525809d59082ec35f9f..c6ba9deabada4a54f201fee076f9b28ab2915e54 100644 (file)
@@ -68,10 +68,10 @@ asmlinkage long compat_sys_utime(char __user *filename, struct compat_utimbuf __
                tv[0].tv_usec = 0;
                tv[1].tv_usec = 0;
        }
-       return do_utimes(filename, t ? tv : NULL);
+       return do_utimes(AT_FDCWD, filename, t ? tv : NULL);
 }
 
-asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t)
+asmlinkage long compat_sys_futimesat(int dfd, char __user *filename, struct compat_timeval __user *t)
 {
        struct timeval tv[2];
 
@@ -82,14 +82,19 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
                    get_user(tv[1].tv_usec, &t[1].tv_usec))
                        return -EFAULT; 
        } 
-       return do_utimes(filename, t ? tv : NULL);
+       return do_utimes(dfd, filename, t ? tv : NULL);
+}
+
+asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t)
+{
+       return compat_sys_futimesat(AT_FDCWD, filename, t);
 }
 
 asmlinkage long compat_sys_newstat(char __user * filename,
                struct compat_stat __user *statbuf)
 {
        struct kstat stat;
-       int error = vfs_stat(filename, &stat);
+       int error = vfs_stat_fd(AT_FDCWD, filename, &stat);
 
        if (!error)
                error = cp_compat_stat(&stat, statbuf);
@@ -100,10 +105,31 @@ asmlinkage long compat_sys_newlstat(char __user * filename,
                struct compat_stat __user *statbuf)
 {
        struct kstat stat;
-       int error = vfs_lstat(filename, &stat);
+       int error = vfs_lstat_fd(AT_FDCWD, filename, &stat);
+
+       if (!error)
+               error = cp_compat_stat(&stat, statbuf);
+       return error;
+}
+
+asmlinkage long compat_sys_newfstatat(int dfd, char __user *filename,
+               struct compat_stat __user *statbuf, int flag)
+{
+       struct kstat stat;
+       int error = -EINVAL;
+
+       if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
+               goto out;
+
+       if (flag & AT_SYMLINK_NOFOLLOW)
+               error = vfs_lstat_fd(dfd, filename, &stat);
+       else
+               error = vfs_stat_fd(dfd, filename, &stat);
 
        if (!error)
                error = cp_compat_stat(&stat, statbuf);
+
+out:
        return error;
 }
 
@@ -168,8 +194,8 @@ asmlinkage long compat_sys_statfs(const char __user *path, struct compat_statfs
        if (!error) {
                struct kstatfs tmp;
                error = vfs_statfs(nd.dentry->d_inode->i_sb, &tmp);
-               if (!error && put_compat_statfs(buf, &tmp))
-                       error = -EFAULT;
+               if (!error)
+                       error = put_compat_statfs(buf, &tmp);
                path_release(&nd);
        }
        return error;
@@ -186,8 +212,8 @@ asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user
        if (!file)
                goto out;
        error = vfs_statfs(file->f_dentry->d_inode->i_sb, &tmp);
-       if (!error && put_compat_statfs(buf, &tmp))
-               error = -EFAULT;
+       if (!error)
+               error = put_compat_statfs(buf, &tmp);
        fput(file);
 out:
        return error;
@@ -236,8 +262,8 @@ asmlinkage long compat_sys_statfs64(const char __user *path, compat_size_t sz, s
        if (!error) {
                struct kstatfs tmp;
                error = vfs_statfs(nd.dentry->d_inode->i_sb, &tmp);
-               if (!error && put_compat_statfs64(buf, &tmp))
-                       error = -EFAULT;
+               if (!error)
+                       error = put_compat_statfs64(buf, &tmp);
                path_release(&nd);
        }
        return error;
@@ -257,8 +283,8 @@ asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct c
        if (!file)
                goto out;
        error = vfs_statfs(file->f_dentry->d_inode->i_sb, &tmp);
-       if (!error && put_compat_statfs64(buf, &tmp))
-               error = -EFAULT;
+       if (!error)
+               error = put_compat_statfs64(buf, &tmp);
        fput(file);
 out:
        return error;
@@ -494,9 +520,21 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
                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))
+                       /* GETLK was successfule and we need to return the data...
+                        * but it needs to fit in the compat structure.
+                        * l_start shouldn't be too big, unless the original
+                        * start + end is greater than COMPAT_OFF_T_MAX, in which
+                        * case the app was asking for trouble, so we return
+                        * -EOVERFLOW in that case.
+                        * l_len could be too big, in which case we just truncate it,
+                        * and only allow the app to see that part of the conflicting
+                        * lock that might make sense to it anyway
+                        */
+
+                       if (f.l_start > COMPAT_OFF_T_MAX)
                                ret = -EOVERFLOW;
+                       if (f.l_len > COMPAT_OFF_T_MAX)
+                               f.l_len = COMPAT_OFF_T_MAX;
                        if (ret == 0)
                                ret = put_compat_flock(&f, compat_ptr(arg));
                }
@@ -515,9 +553,11 @@ asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
                                (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))
+                       /* need to return lock information - see above for commentary */
+                       if (f.l_start > COMPAT_LOFF_T_MAX)
                                ret = -EOVERFLOW;
+                       if (f.l_len > COMPAT_LOFF_T_MAX)
+                               f.l_len = COMPAT_LOFF_T_MAX;
                        if (ret == 0)
                                ret = put_compat_flock64(&f, compat_ptr(arg));
                }
@@ -1170,7 +1210,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
        }
 
        ret = rw_verify_area(type, file, pos, tot_len);
-       if (ret)
+       if (ret < 0)
                goto out;
 
        fnv = NULL;
@@ -1276,7 +1316,17 @@ out:
 asmlinkage long
 compat_sys_open(const char __user *filename, int flags, int mode)
 {
-       return do_sys_open(filename, flags, mode);
+       return do_sys_open(AT_FDCWD, filename, flags, mode);
+}
+
+/*
+ * Exactly like fs/open.c:sys_openat(), except that it doesn't set the
+ * O_LARGEFILE flag.
+ */
+asmlinkage long
+compat_sys_openat(int dfd, const char __user *filename, int flags, int mode)
+{
+       return do_sys_open(dfd, filename, flags, mode);
 }
 
 /*
@@ -1523,7 +1573,7 @@ out_ret:
  * Ooo, nasty.  We need here to frob 32-bit unsigned longs to
  * 64-bit unsigned longs.
  */
-static inline
+static
 int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
                        unsigned long *fdset)
 {
@@ -1556,7 +1606,7 @@ int compat_get_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
        return 0;
 }
 
-static inline
+static
 void compat_set_fd_set(unsigned long nr, compat_ulong_t __user *ufdset,
                        unsigned long *fdset)
 {