Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 234264
b: refs/heads/master
c: ca344a8
h: refs/heads/master
v: v3
  • Loading branch information
Al Viro committed Mar 14, 2011
1 parent b49ac7f commit 153665d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9b44f1b3928b6f41532c9a1dc9a6fc665989ad5b
refs/heads/master: ca344a894b41a133dab07dfbbdf652c053f6658c
59 changes: 22 additions & 37 deletions trunk/fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,10 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
const struct open_flags *op, const char *pathname)
{
struct dentry *dir = nd->path.dentry;
int open_flag = op->open_flag;
int will_truncate;
int want_write = 0;
int skip_perm = 0;
struct file *filp;
struct inode *inode;
int error;
Expand All @@ -2138,7 +2141,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
if (error)
goto exit;
audit_inode(pathname, nd->path.dentry);
if (op->open_flag & O_CREAT) {
if (open_flag & O_CREAT) {
error = -EISDIR;
goto exit;
}
Expand All @@ -2152,7 +2155,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
goto ok;
}

if (!(op->open_flag & O_CREAT)) {
if (!(open_flag & O_CREAT)) {
if (nd->last.name[nd->last.len])
nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
/* we _can_ be in RCU mode here */
Expand Down Expand Up @@ -2230,28 +2233,15 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
error = mnt_want_write(nd->path.mnt);
if (error)
goto exit_mutex_unlock;
error = __open_namei_create(nd, path, op->open_flag, op->mode);
if (error) {
mnt_drop_write(nd->path.mnt);
want_write = 1;
will_truncate = 0;
error = __open_namei_create(nd, path, open_flag, op->mode);
if (error)
goto exit;
}
/* Don't check for write permission, don't truncate */
error = may_open(&nd->path, 0, op->open_flag & ~O_TRUNC);
if (error) {
mnt_drop_write(nd->path.mnt);
goto exit;
}
filp = nameidata_to_filp(nd);
mnt_drop_write(nd->path.mnt);
path_put(&nd->path);
if (!IS_ERR(filp)) {
error = ima_file_check(filp, op->acc_mode);
if (error) {
fput(filp);
filp = ERR_PTR(error);
}
}
return filp;
open_flag &= ~O_TRUNC;
skip_perm = 1;
goto common;
}

/*
Expand All @@ -2261,7 +2251,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
audit_inode(pathname, path->dentry);

error = -EEXIST;
if (op->open_flag & O_EXCL)
if (open_flag & O_EXCL)
goto exit_dput;

error = follow_managed(path, nd->flags);
Expand All @@ -2281,18 +2271,17 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
if (S_ISDIR(nd->inode->i_mode))
goto exit;
ok:
will_truncate = open_will_truncate(op->open_flag, nd->path.dentry->d_inode);
will_truncate = open_will_truncate(open_flag, nd->path.dentry->d_inode);
if (will_truncate) {
error = mnt_want_write(nd->path.mnt);
if (error)
goto exit;
want_write = 1;
}
error = may_open(&nd->path, op->acc_mode, op->open_flag);
if (error) {
if (will_truncate)
mnt_drop_write(nd->path.mnt);
common:
error = may_open(&nd->path, skip_perm ? 0 : op->acc_mode, open_flag);
if (error)
goto exit;
}
filp = nameidata_to_filp(nd);
if (!IS_ERR(filp)) {
error = ima_file_check(filp, op->acc_mode);
Expand All @@ -2310,12 +2299,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
}
}
}
/*
* It is now safe to drop the mnt write
* because the filp has had a write taken
* on its behalf.
*/
if (will_truncate)
out:
if (want_write)
mnt_drop_write(nd->path.mnt);
path_put(&nd->path);
return filp;
Expand All @@ -2325,8 +2310,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
exit_dput:
path_put_conditional(path, nd);
exit:
path_put(&nd->path);
return ERR_PTR(error);
filp = ERR_PTR(error);
goto out;
}

static struct file *path_openat(int dfd, const char *pathname,
Expand Down

0 comments on commit 153665d

Please sign in to comment.