patch-2.3.99-pre6 linux/fs/open.c

Next file: linux/fs/partitions/Config.in
Previous file: linux/fs/ntfs/fs.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.99-pre5/linux/fs/open.c linux/fs/open.c
@@ -327,12 +327,10 @@
 	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 @@
 	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 @@
 
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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(&current->files->file_lock);
-	FD_CLR(fd, current->files->open_fds);
-	if (fd < current->files->next_fd)
-		current->files->next_fd = fd;
-	write_unlock(&current->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 @@
 
 	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();

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)