diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2000-04-28 01:09:25 +0000 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2000-04-28 01:09:25 +0000 |
commit | b9ba7aeb165cffecdffb60aec8c3fa8d590d9ca9 (patch) | |
tree | 42d07b0c7246ae2536a702e7c5de9e2732341116 /fs/open.c | |
parent | 7406b0a326f2d70ade2671c37d1beef62249db97 (diff) |
Merge with 2.3.99-pre6.
Diffstat (limited to 'fs/open.c')
-rw-r--r-- | fs/open.c | 85 |
1 files changed, 36 insertions, 49 deletions
@@ -327,12 +327,10 @@ asmlinkage long sys_access(const char * filename, int mode) return res; } -/* MOUNT_REWRITE: pass &mnt to lookup_dentry */ asmlinkage long sys_chdir(const char * filename) { int error; - struct dentry *dentry, *tmp; - struct vfsmount *mnt = NULL, *tmp_mnt; + struct nameidata nd; char *name; lock_kernel(); @@ -342,27 +340,22 @@ asmlinkage long sys_chdir(const char * filename) if (IS_ERR(name)) goto out; - dentry = lookup_dentry(name, LOOKUP_POSITIVE | LOOKUP_FOLLOW | LOOKUP_DIRECTORY); + error = 0; + if (walk_init(name,LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&nd)) + error = walk_name(name, &nd); putname(name); - error = PTR_ERR(dentry); - if (IS_ERR(dentry)) + if (error) goto out; - error = permission(dentry->d_inode,MAY_EXEC); + error = permission(nd.dentry->d_inode,MAY_EXEC); if (error) goto dput_and_out; - /* exchange dentries */ - tmp = current->fs->pwd; - tmp_mnt = current->fs->pwdmnt; - current->fs->pwd = dentry; - current->fs->pwdmnt = mnt; - dentry = tmp; - mnt = tmp_mnt; + set_fs_pwd(current->fs, nd.mnt, nd.dentry); dput_and_out: - mntput(mnt); - dput(dentry); + dput(nd.dentry); + mntput(nd.mnt); out: unlock_kernel(); return error; @@ -391,14 +384,8 @@ asmlinkage long sys_fchdir(unsigned int fd) lock_kernel(); error = permission(inode, MAY_EXEC); - if (!error) { - struct dentry *tmp = current->fs->pwd; - struct vfsmount *tmp_mnt = current->fs->pwdmnt; - current->fs->pwd = dget(dentry); - current->fs->pwdmnt = mntget(mnt); - mntput(tmp_mnt); - dput(tmp); - } + if (!error) + set_fs_pwd(current->fs, mnt, dentry); unlock_kernel(); out_putf: fput(file); @@ -406,12 +393,10 @@ out: return error; } -/* MOUNT_REWRITE: pass &mnt to lookup_dentry */ asmlinkage long sys_chroot(const char * filename) { int error; - struct dentry *dentry, *tmp; - struct vfsmount *mnt = NULL, *tmp_mnt; + struct nameidata nd; char *name; lock_kernel(); @@ -421,13 +406,14 @@ asmlinkage long sys_chroot(const char * filename) if (IS_ERR(name)) goto out; - dentry = lookup_dentry(name, LOOKUP_POSITIVE | LOOKUP_FOLLOW | LOOKUP_DIRECTORY); + walk_init(name, LOOKUP_POSITIVE | LOOKUP_FOLLOW | + LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); + error = walk_name(name, &nd); putname(name); - error = PTR_ERR(dentry); - if (IS_ERR(dentry)) + if (error) goto out; - error = permission(dentry->d_inode,MAY_EXEC); + error = permission(nd.dentry->d_inode,MAY_EXEC); if (error) goto dput_and_out; @@ -435,18 +421,12 @@ asmlinkage long sys_chroot(const char * filename) if (!capable(CAP_SYS_CHROOT)) goto dput_and_out; - /* exchange dentries */ - tmp = current->fs->root; - tmp_mnt = current->fs->rootmnt; - current->fs->root = dentry; - current->fs->rootmnt = mnt; - dentry = tmp; - mnt = tmp_mnt; + set_fs_root(current->fs, nd.mnt, nd.dentry); + set_fs_altroot(); error = 0; - dput_and_out: - mntput(mnt); - dput(dentry); + dput(nd.dentry); + mntput(nd.mnt); out: unlock_kernel(); return error; @@ -776,13 +756,20 @@ out: return error; } +inline void __put_unused_fd(struct files_struct *files, unsigned int fd) +{ + FD_CLR(fd, files->open_fds); + if (fd < files->next_fd) + files->next_fd = fd; +} + inline void put_unused_fd(unsigned int fd) { - write_lock(¤t->files->file_lock); - FD_CLR(fd, current->files->open_fds); - if (fd < current->files->next_fd) - current->files->next_fd = fd; - write_unlock(¤t->files->file_lock); + struct files_struct *files = current->files; + + write_lock(&files->file_lock); + __put_unused_fd(files, fd); + write_unlock(&files->file_lock); } asmlinkage long sys_open(const char * filename, int flags, int mode) @@ -868,13 +855,13 @@ int do_close(unsigned int fd, int release) error = -EBADF; write_lock(&files->file_lock); - filp = frip(fd); + filp = frip(files, fd); if (!filp) goto out_unlock; FD_CLR(fd, files->close_on_exec); - write_unlock(&files->file_lock); if (release) - put_unused_fd(fd); + __put_unused_fd(files, fd); + write_unlock(&files->file_lock); lock_kernel(); error = filp_close(filp, files); unlock_kernel(); |