[PATCH 25/35] VFS: Create user_path_nd() to lookup both parent and target

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Valerie Aurora
Date: Thursday, April 15, 2010 - 4:04 pm

Proof-of-concept implementation of user_path_nd().  Lookup both the
parent and the target of a user-supplied filename, to supply later to
union copyup routines.
---
 fs/namei.c            |   31 +++++++++++++++++++++++++++++++
 include/linux/namei.h |    2 ++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 24e0cb2..68aa8ab 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1563,6 +1563,37 @@ static int user_path_parent(int dfd, const char __user *path,
 	return error;
 }
 
+int user_path_nd(int dfd, const char __user *filename,
+			 unsigned flags, struct nameidata *parent_nd,
+			 struct path *child, char **tmp)
+{
+	struct nameidata child_nd;
+	char *s = getname(filename);
+	int error;
+
+	if (IS_ERR(s))
+		return PTR_ERR(s);
+
+	/* Lookup parent */
+	error = do_path_lookup(dfd, s, LOOKUP_PARENT, parent_nd);
+	if (error)
+		goto out_putname;
+
+	/* Lookup child - XXX optimize, racy */
+	error = do_path_lookup(dfd, s, flags, &child_nd);
+	if (error)
+		goto out_path_put;
+	*child = child_nd.path;
+	*tmp = s;
+	return 0;
+
+out_path_put:
+	path_put(&parent_nd->path);
+out_putname:
+	putname(s);
+	return error;
+}
+
 /*
  * It's inline, so penalty for filesystems that don't use sticky bit is
  * minimal.
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 05b441d..83dc8b5 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -58,6 +58,8 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 #define LOOKUP_RENAME_TARGET	0x0800
 
 extern int user_path_at(int, const char __user *, unsigned, struct path *);
+extern int user_path_nd(int, const char __user *, unsigned,
+			struct nameidata *, struct path *, char **);
 
 #define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
 #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
-- 
1.6.3.3

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/35] Union mounts - everything but the xattrs, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 01/35] VFS: Make lookup_hash() return a struct path, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 02/35] VFS: Add read-only users count to superblock, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 08/35] whiteout: tmpfs whiteout support, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 10/35] whiteout: ext2 whiteout support, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 11/35] whiteout: jffs2 whiteout support, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 12/35] fallthru: Basic fallthru definitions, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 13/35] fallthru: ext2 fallthru support, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 14/35] fallthru: jffs2 fallthru support, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 15/35] fallthru: tmpfs fallthru support, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 20/35] union-mount: Implement union lookup, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 25/35] VFS: Create user_path_nd() to lookup both pa ..., Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 26/35] union-mount: In-kernel copyup routines, Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 28/35] union-mount: Implement union-aware link(), Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 29/35] union-mount: Implement union-aware rename(), Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 31/35] union-mount: Implement union-aware chown(), Valerie Aurora, (Thu Apr 15, 4:04 pm)
[PATCH 34/35] union-mount: Implement union-aware lchown(), Valerie Aurora, (Thu Apr 15, 4:04 pm)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, David Woodhouse, (Mon Apr 19, 6:02 am)
Re: [PATCH 11/35] whiteout: jffs2 whiteout support, David Woodhouse, (Mon Apr 19, 6:03 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jan Blunck, (Mon Apr 19, 6:23 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jan Blunck, (Mon Apr 19, 7:12 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Valerie Aurora, (Mon Apr 19, 7:23 am)
Re: [PATCH 11/35] whiteout: jffs2 whiteout support, Valerie Aurora, (Mon Apr 19, 7:26 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jan Blunck, (Wed Apr 21, 1:42 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jamie Lokier, (Wed Apr 21, 2:22 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jamie Lokier, (Wed Apr 21, 2:52 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Miklos Szeredi, (Wed Apr 21, 3:17 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jamie Lokier, (Wed Apr 21, 10:36 am)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Valerie Aurora, (Wed Apr 21, 2:38 pm)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, Jamie Lokier, (Wed Apr 21, 3:10 pm)
Re: [PATCH 00/35] Union mounts - everything but the xattrs, Valerie Aurora, (Wed Apr 21, 4:35 pm)
Re: [PATCH 13/35] fallthru: ext2 fallthru support, J. R. Okajima, (Thu Apr 22, 3:30 am)