From mboxrd@z Thu Jan 1 00:00:00 1970 From: Valerie Aurora Subject: [PATCH 67/74] union-mount: Implement union-aware writable open() Date: Tue, 22 Mar 2011 19:04:58 -0700 Message-ID: <1300845905-14433-24-git-send-email-valerie.aurora@gmail.com> References: <1300845905-14433-1-git-send-email-valerie.aurora@gmail.com> Cc: viro@zeniv.linux.org.uk, Valerie Aurora , Valerie Aurora To: linux-fsdevel@vger.kernel.org, linux@vger.kernel.org Return-path: Received: from mail-gx0-f174.google.com ([209.85.161.174]:50037 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755253Ab1CWCGR (ORCPT ); Tue, 22 Mar 2011 22:06:17 -0400 In-Reply-To: <1300845905-14433-1-git-send-email-valerie.aurora@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Valerie Aurora Copy up a file when opened with write permissions. Does not copy up the file data when O_TRUNC is specified. Signed-off-by: Valerie Aurora --- fs/namei.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 6c7cff3..7e17d13 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1945,6 +1945,24 @@ exit: return ERR_PTR(error); } +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; +} + static struct file *do_last(struct nameidata *nd, struct path *path, int open_flag, int acc_mode, int mode, const char *pathname) @@ -1996,6 +2014,11 @@ static struct file *do_last(struct nameidata *nd, struct path *path, if (!path->dentry->d_inode->i_op->lookup) goto exit_dput; } + if (acc_mode & MAY_WRITE) { + error = open_union_copyup(nd, path, open_flag); + if (error) + goto exit_dput; + } path_to_nameidata(path, nd); audit_inode(pathname, nd->path.dentry); goto ok; @@ -2067,6 +2090,11 @@ 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); error = -EISDIR; if (S_ISDIR(path->dentry->d_inode->i_mode)) -- 1.7.0.4