[PATCH 65/76] union-mount: Implement union-aware writable open()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Valerie Aurora <vaurora@xxxxxxxxxx>

Copy up a file when opened with write permissions.  Does not copy up
the file data when O_TRUNC is specified.
---

 fs/namei.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index b2548e9..d52b800 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2473,6 +2473,24 @@ static inline int open_to_namei_flags(int flag)
 	return flag;
 }
 
+static int open_union_copyup(struct nameidata *nd, struct path *path,
+			     int open_flag)
+{
+	struct vfsmount *oldmnt = path->mnt;
+	int error;
+
+	if (open_flag & O_TRUNC)
+		error = union_copyup_len(nd, path, 0);
+	else
+		error = union_copyup(nd, path);
+	if (error)
+		return error;
+	if (oldmnt != path->mnt)
+		mntput(nd->path.mnt);
+
+	return error;
+}
+
 /*
  * Handle the last step of open()
  */
@@ -2538,6 +2556,13 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
 			if (!nd->inode->i_op->lookup)
 				goto exit;
 		}
+
+		if (acc_mode & MAY_WRITE) {
+			error = open_union_copyup(nd, &nd->path, open_flag);
+			if (error)
+				goto exit;
+		}
+
 		audit_inode(pathname, nd->path.dentry);
 		goto ok;
 	}
@@ -2614,6 +2639,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
 	if (path->dentry->d_inode->i_op->follow_link)
 		return NULL;
 
+	if (acc_mode & MAY_WRITE) {
+		error = open_union_copyup(nd, path, open_flag);
+		if (error)
+			goto exit_dput;
+	}
+
 	path_to_nameidata(path, nd);
 	nd->inode = path->dentry->d_inode;
 	error = -EISDIR;

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux