aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2009-12-19 10:15:07 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2009-12-22 12:27:34 -0500
commit5300990c0370e804e49d9a59d928c5d53fb73487 (patch)
tree08ed922afd172662039c082ec9e9410070f4afe8 /fs
parent482928d59db668b8d82a48717f78986d8cea72e9 (diff)
Sanitize f_flags helpers
* pull ACC_MODE to fs.h; we have several copies all over the place * nightmarish expression calculating f_mode by f_flags deserves a helper too (OPEN_FMODE(flags)) Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/anon_inodes.c10
-rw-r--r--fs/namei.c2
-rw-r--r--fs/open.c2
3 files changed, 2 insertions, 12 deletions
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 598237e97221..9f0bf13291e5 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -89,19 +89,11 @@ struct file *anon_inode_getfile(const char *name,
89 struct qstr this; 89 struct qstr this;
90 struct path path; 90 struct path path;
91 struct file *file; 91 struct file *file;
92 fmode_t mode;
93 int error; 92 int error;
94 93
95 if (IS_ERR(anon_inode_inode)) 94 if (IS_ERR(anon_inode_inode))
96 return ERR_PTR(-ENODEV); 95 return ERR_PTR(-ENODEV);
97 96
98 switch (flags & O_ACCMODE) {
99 case O_RDONLY: mode = FMODE_READ; break;
100 case O_WRONLY: mode = FMODE_WRITE; break;
101 case O_RDWR: mode = FMODE_READ | FMODE_WRITE; break;
102 default: return ERR_PTR(-EINVAL);
103 }
104
105 if (fops->owner && !try_module_get(fops->owner)) 97 if (fops->owner && !try_module_get(fops->owner))
106 return ERR_PTR(-ENOENT); 98 return ERR_PTR(-ENOENT);
107 99
@@ -129,7 +121,7 @@ struct file *anon_inode_getfile(const char *name,
129 d_instantiate(path.dentry, anon_inode_inode); 121 d_instantiate(path.dentry, anon_inode_inode);
130 122
131 error = -ENFILE; 123 error = -ENFILE;
132 file = alloc_file(&path, mode, fops); 124 file = alloc_file(&path, OPEN_FMODE(flags), fops);
133 if (!file) 125 if (!file)
134 goto err_dput; 126 goto err_dput;
135 file->f_mapping = anon_inode_inode->i_mapping; 127 file->f_mapping = anon_inode_inode->i_mapping;
diff --git a/fs/namei.c b/fs/namei.c
index d517f73aa36b..68921d9b5302 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -37,8 +37,6 @@
37 37
38#include "internal.h" 38#include "internal.h"
39 39
40#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
41
42/* [Feb-1997 T. Schoebel-Theuer] 40/* [Feb-1997 T. Schoebel-Theuer]
43 * Fundamental changes in the pathname lookup mechanisms (namei) 41 * Fundamental changes in the pathname lookup mechanisms (namei)
44 * were necessary because of omirr. The reason is that omirr needs 42 * were necessary because of omirr. The reason is that omirr needs
diff --git a/fs/open.c b/fs/open.c
index 6daee28f6e8f..040cef72bc00 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -828,7 +828,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
828 struct inode *inode; 828 struct inode *inode;
829 int error; 829 int error;
830 830
831 f->f_mode = (__force fmode_t)((f->f_flags+1) & O_ACCMODE) | FMODE_LSEEK | 831 f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
832 FMODE_PREAD | FMODE_PWRITE; 832 FMODE_PREAD | FMODE_PWRITE;
833 inode = dentry->d_inode; 833 inode = dentry->d_inode;
834 if (f->f_mode & FMODE_WRITE) { 834 if (f->f_mode & FMODE_WRITE) {