diff options
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/fs/namei.c b/fs/namei.c index 0dc4cbf21f37..645268f23eb6 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -2656,6 +2656,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2656 | int acc_mode; | 2656 | int acc_mode; |
2657 | int create_error = 0; | 2657 | int create_error = 0; |
2658 | struct dentry *const DENTRY_NOT_SET = (void *) -1UL; | 2658 | struct dentry *const DENTRY_NOT_SET = (void *) -1UL; |
2659 | bool excl; | ||
2659 | 2660 | ||
2660 | BUG_ON(dentry->d_inode); | 2661 | BUG_ON(dentry->d_inode); |
2661 | 2662 | ||
@@ -2669,10 +2670,9 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2669 | if ((open_flag & O_CREAT) && !IS_POSIXACL(dir)) | 2670 | if ((open_flag & O_CREAT) && !IS_POSIXACL(dir)) |
2670 | mode &= ~current_umask(); | 2671 | mode &= ~current_umask(); |
2671 | 2672 | ||
2672 | if ((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) { | 2673 | excl = (open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT); |
2674 | if (excl) | ||
2673 | open_flag &= ~O_TRUNC; | 2675 | open_flag &= ~O_TRUNC; |
2674 | *opened |= FILE_CREATED; | ||
2675 | } | ||
2676 | 2676 | ||
2677 | /* | 2677 | /* |
2678 | * Checking write permission is tricky, bacuse we don't know if we are | 2678 | * Checking write permission is tricky, bacuse we don't know if we are |
@@ -2725,12 +2725,6 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2725 | goto out; | 2725 | goto out; |
2726 | } | 2726 | } |
2727 | 2727 | ||
2728 | acc_mode = op->acc_mode; | ||
2729 | if (*opened & FILE_CREATED) { | ||
2730 | fsnotify_create(dir, dentry); | ||
2731 | acc_mode = MAY_OPEN; | ||
2732 | } | ||
2733 | |||
2734 | if (error) { /* returned 1, that is */ | 2728 | if (error) { /* returned 1, that is */ |
2735 | if (WARN_ON(file->f_path.dentry == DENTRY_NOT_SET)) { | 2729 | if (WARN_ON(file->f_path.dentry == DENTRY_NOT_SET)) { |
2736 | error = -EIO; | 2730 | error = -EIO; |
@@ -2740,9 +2734,19 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2740 | dput(dentry); | 2734 | dput(dentry); |
2741 | dentry = file->f_path.dentry; | 2735 | dentry = file->f_path.dentry; |
2742 | } | 2736 | } |
2743 | if (create_error && dentry->d_inode == NULL) { | 2737 | if (*opened & FILE_CREATED) |
2744 | error = create_error; | 2738 | fsnotify_create(dir, dentry); |
2745 | goto out; | 2739 | if (!dentry->d_inode) { |
2740 | WARN_ON(*opened & FILE_CREATED); | ||
2741 | if (create_error) { | ||
2742 | error = create_error; | ||
2743 | goto out; | ||
2744 | } | ||
2745 | } else { | ||
2746 | if (excl && !(*opened & FILE_CREATED)) { | ||
2747 | error = -EEXIST; | ||
2748 | goto out; | ||
2749 | } | ||
2746 | } | 2750 | } |
2747 | goto looked_up; | 2751 | goto looked_up; |
2748 | } | 2752 | } |
@@ -2751,6 +2755,12 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, | |||
2751 | * We didn't have the inode before the open, so check open permission | 2755 | * We didn't have the inode before the open, so check open permission |
2752 | * here. | 2756 | * here. |
2753 | */ | 2757 | */ |
2758 | acc_mode = op->acc_mode; | ||
2759 | if (*opened & FILE_CREATED) { | ||
2760 | WARN_ON(!(open_flag & O_CREAT)); | ||
2761 | fsnotify_create(dir, dentry); | ||
2762 | acc_mode = MAY_OPEN; | ||
2763 | } | ||
2754 | error = may_open(&file->f_path, acc_mode, open_flag); | 2764 | error = may_open(&file->f_path, acc_mode, open_flag); |
2755 | if (error) | 2765 | if (error) |
2756 | fput(file); | 2766 | fput(file); |