init: add an init_chdir helper
[linux-block.git] / fs / open.c
index 6cd48a61cda3b969c0717c30c8bed879efa3d8cc..723e0ac898935e0c3a1f14de3a974641d497a4a4 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -482,7 +482,7 @@ SYSCALL_DEFINE2(access, const char __user *, filename, int, mode)
        return do_faccessat(AT_FDCWD, filename, mode, 0);
 }
 
-int ksys_chdir(const char __user *filename)
+SYSCALL_DEFINE1(chdir, const char __user *, filename)
 {
        struct path path;
        int error;
@@ -508,11 +508,6 @@ out:
        return error;
 }
 
-SYSCALL_DEFINE1(chdir, const char __user *, filename)
-{
-       return ksys_chdir(filename);
-}
-
 SYSCALL_DEFINE1(fchdir, unsigned int, fd)
 {
        struct fd f = fdget_raw(fd);
@@ -602,24 +597,24 @@ out_unlock:
        return error;
 }
 
-int ksys_fchmod(unsigned int fd, umode_t mode)
+int vfs_fchmod(struct file *file, umode_t mode)
+{
+       audit_file(file);
+       return chmod_common(&file->f_path, mode);
+}
+
+SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
 {
        struct fd f = fdget(fd);
        int err = -EBADF;
 
        if (f.file) {
-               audit_file(f.file);
-               err = chmod_common(&f.file->f_path, mode);
+               err = vfs_fchmod(f.file, mode);
                fdput(f);
        }
        return err;
 }
 
-SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
-{
-       return ksys_fchmod(fd, mode);
-}
-
 int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
 {
        struct path path;
@@ -740,23 +735,28 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
                           AT_SYMLINK_NOFOLLOW);
 }
 
+int vfs_fchown(struct file *file, uid_t user, gid_t group)
+{
+       int error;
+
+       error = mnt_want_write_file(file);
+       if (error)
+               return error;
+       audit_file(file);
+       error = chown_common(&file->f_path, user, group);
+       mnt_drop_write_file(file);
+       return error;
+}
+
 int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
 {
        struct fd f = fdget(fd);
        int error = -EBADF;
 
-       if (!f.file)
-               goto out;
-
-       error = mnt_want_write_file(f.file);
-       if (error)
-               goto out_fput;
-       audit_file(f.file);
-       error = chown_common(&f.file->f_path, user, group);
-       mnt_drop_write_file(f.file);
-out_fput:
-       fdput(f);
-out:
+       if (f.file) {
+               error = vfs_fchown(f.file, user, group);
+               fdput(f);
+       }
        return error;
 }
 
@@ -1198,7 +1198,9 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
 
 SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
 {
-       return ksys_open(filename, flags, mode);
+       if (force_o_largefile())
+               flags |= O_LARGEFILE;
+       return do_sys_open(AT_FDCWD, filename, flags, mode);
 }
 
 SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, flags,
@@ -1260,9 +1262,12 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla
  */
 SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
 {
-       return ksys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
-}
+       int flags = O_CREAT | O_WRONLY | O_TRUNC;
 
+       if (force_o_largefile())
+               flags |= O_LARGEFILE;
+       return do_sys_open(AT_FDCWD, pathname, flags, mode);
+}
 #endif
 
 /*