[PATCH 33/38] union-mount: Implement union-aware truncate()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Valerie Aurora
Date: Friday, August 6, 2010 - 3:35 pm

Signed-off-by: Valerie Aurora <vaurora@redhat.com>
---
 fs/open.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 8588b31..e4fc8e5 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -64,14 +64,17 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
 static long do_sys_truncate(const char __user *pathname, loff_t length)
 {
 	struct path path;
+	struct nameidata nd;
+	struct vfsmount *mnt;
 	struct inode *inode;
+	char *tmp;
 	int error;
 
 	error = -EINVAL;
 	if (length < 0)	/* sorry, but loff_t says... */
 		goto out;
 
-	error = user_path(pathname, &path);
+	error = user_path_nd(AT_FDCWD, pathname, 0, &nd, &path, &tmp);
 	if (error)
 		goto out;
 	inode = path.dentry->d_inode;
@@ -85,11 +88,16 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
 	if (!S_ISREG(inode->i_mode))
 		goto dput_and_out;
 
-	error = mnt_want_write(path.mnt);
+	if (IS_DIR_UNIONED(nd.path.dentry))
+		mnt = nd.path.mnt;
+	else
+		mnt = path.mnt;
+
+	error = mnt_want_write(mnt);
 	if (error)
 		goto dput_and_out;
 
-	error = inode_permission(inode, MAY_WRITE);
+	error = path_permission(&path, &nd.path, MAY_WRITE);
 	if (error)
 		goto mnt_drop_write_and_out;
 
@@ -97,6 +105,12 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
 	if (IS_APPEND(inode))
 		goto mnt_drop_write_and_out;
 
+	error = union_copyup_len(&nd, &path, length);
+	if (error)
+		goto mnt_drop_write_and_out;
+
+	/* path may have changed after copyup */
+	inode = path.dentry->d_inode;
 	error = get_write_access(inode);
 	if (error)
 		goto mnt_drop_write_and_out;
@@ -118,9 +132,11 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
 put_write_and_out:
 	put_write_access(inode);
 mnt_drop_write_and_out:
-	mnt_drop_write(path.mnt);
+	mnt_drop_write(mnt);
 dput_and_out:
 	path_put(&path);
+	path_put(&nd.path);
+	putname(tmp);
 out:
 	return error;
 }
-- 
1.6.3.3

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

Messages in current thread:
[PATCH 00/38] VFS union mounts - Add MS_FALLTHRU, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 09/38] whiteout: tmpfs whiteout support, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 11/38] whiteout: ext2 whiteout support, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 12/38] whiteout: jffs2 whiteout support, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 13/38] fallthru: Basic fallthru definitions, Valerie Aurora, (Fri Aug 6, 3:34 pm)
[PATCH 14/38] fallthru: ext2 fallthru support, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 15/38] fallthru: jffs2 fallthru support, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 16/38] fallthru: tmpfs fallthru support, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 17/38] union-mount: Union mounts documentation, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 22/38] union-mount: Implement union lookup, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 27/38] union-mount: In-kernel file copyup routines, Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 29/38] union-mount: Implement union-aware link(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 30/38] union-mount: Implement union-aware rename(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 32/38] union-mount: Implement union-aware chown(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 33/38] union-mount: Implement union-aware truncate(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
[PATCH 35/38] union-mount: Implement union-aware lchown(), Valerie Aurora, (Fri Aug 6, 3:35 pm)
Re: [PATCH 14/38] fallthru: ext2 fallthru support, Andreas Dilger, (Fri Aug 6, 5:28 pm)
Re: [PATCH 14/38] fallthru: ext2 fallthru support, Valerie Aurora, (Sun Aug 8, 9:40 am)