Skip to content

Commit ea73ea7

Browse files
author
Al Viro
committed
pass ->f_flags value to alloc_empty_file()
... and have it set the f_flags-derived part of ->f_mode. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 6de37b6 commit ea73ea7

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎fs/file_table.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int proc_nr_files(struct ctl_table *table, int write,
101101
* done, you will imbalance int the mount's writer count
102102
* and a warning at __fput() time.
103103
*/
104-
struct file *alloc_empty_file(const struct cred *cred)
104+
struct file *alloc_empty_file(int flags, const struct cred *cred)
105105
{
106106
static long old_max;
107107
struct file *f;
@@ -135,6 +135,8 @@ struct file *alloc_empty_file(const struct cred *cred)
135135
spin_lock_init(&f->f_lock);
136136
mutex_init(&f->f_pos_lock);
137137
eventpoll_init_file(f);
138+
f->f_flags = flags;
139+
f->f_mode = OPEN_FMODE(flags);
138140
/* f->f_version: 0 */
139141
percpu_counter_inc(&nr_files);
140142
return f;
@@ -160,12 +162,10 @@ struct file *alloc_file(const struct path *path, int flags,
160162
{
161163
struct file *file;
162164

163-
file = alloc_empty_file(current_cred());
165+
file = alloc_empty_file(flags, current_cred());
164166
if (IS_ERR(file))
165167
return file;
166168

167-
file->f_mode = OPEN_FMODE(flags);
168-
file->f_flags = flags;
169169
file->f_path = *path;
170170
file->f_inode = path->dentry->d_inode;
171171
file->f_mapping = path->dentry->d_inode->i_mapping;

‎fs/internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extern void chroot_fs_refs(const struct path *, const struct path *);
9393
/*
9494
* file_table.c
9595
*/
96-
extern struct file *alloc_empty_file(const struct cred *);
96+
extern struct file *alloc_empty_file(int, const struct cred *);
9797

9898
/*
9999
* super.c

‎fs/namei.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,12 +3513,10 @@ static struct file *path_openat(struct nameidata *nd,
35133513
int opened = 0;
35143514
int error;
35153515

3516-
file = alloc_empty_file(current_cred());
3516+
file = alloc_empty_file(op->open_flag, current_cred());
35173517
if (IS_ERR(file))
35183518
return file;
35193519

3520-
file->f_flags = op->open_flag;
3521-
35223520
if (unlikely(file->f_flags & __O_TMPFILE)) {
35233521
error = do_tmpfile(nd, flags, op, file, &opened);
35243522
goto out2;

‎fs/open.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,6 @@ static int do_dentry_open(struct file *f,
742742
static const struct file_operations empty_fops = {};
743743
int error;
744744

745-
f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
746-
FMODE_PREAD | FMODE_PWRITE;
747-
748745
path_get(&f->f_path);
749746
f->f_inode = inode;
750747
f->f_mapping = inode->i_mapping;
@@ -788,6 +785,8 @@ static int do_dentry_open(struct file *f,
788785
if (error)
789786
goto cleanup_all;
790787

788+
/* normally all 3 are set; ->open() can clear them if needed */
789+
f->f_mode |= FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE;
791790
if (!open)
792791
open = f->f_op->open;
793792
if (open) {
@@ -921,9 +920,8 @@ struct file *dentry_open(const struct path *path, int flags,
921920
/* We must always pass in a valid mount pointer. */
922921
BUG_ON(!path->mnt);
923922

924-
f = alloc_empty_file(cred);
923+
f = alloc_empty_file(flags, cred);
925924
if (!IS_ERR(f)) {
926-
f->f_flags = flags;
927925
error = vfs_open(path, f, cred);
928926
if (!error) {
929927
/* from now on we need fput() to dispose of f */

0 commit comments

Comments
 (0)