summaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2009-01-05 19:27:23 +0100
committerAl Viro <viro@zeniv.linux.org.uk>2009-03-27 14:43:57 -0400
commitc8fe8f30c7fe6ce6fc44a1db7d5bfa5144cd9211 (patch)
tree4432fe47893442907d1e60ab362208dd9ae12bd2 /fs/namei.c
parentb6520c81934848cef126d93951f7ce242e0f656d (diff)
downloadlinux-c8fe8f30c7fe6ce6fc44a1db7d5bfa5144cd9211.tar.bz2
cleanup may_open
Add a switch for the various i_mode fmt cases, and remove the comment about writeability of devices nodes - that part is handled in inode_permission and comment on (briefly) there. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/fs/namei.c b/fs/namei.c
index bbc15c237558..2a40409e3e03 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1486,24 +1486,22 @@ int may_open(struct path *path, int acc_mode, int flag)
if (!inode)
return -ENOENT;
- if (S_ISLNK(inode->i_mode))
+ switch (inode->i_mode & S_IFMT) {
+ case S_IFLNK:
return -ELOOP;
-
- if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE))
- return -EISDIR;
-
- /*
- * FIFO's, sockets and device files are special: they don't
- * actually live on the filesystem itself, and as such you
- * can write to them even if the filesystem is read-only.
- */
- if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
- flag &= ~O_TRUNC;
- } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
+ case S_IFDIR:
+ if (acc_mode & MAY_WRITE)
+ return -EISDIR;
+ break;
+ case S_IFBLK:
+ case S_IFCHR:
if (path->mnt->mnt_flags & MNT_NODEV)
return -EACCES;
-
+ /*FALLTHRU*/
+ case S_IFIFO:
+ case S_IFSOCK:
flag &= ~O_TRUNC;
+ break;
}
error = inode_permission(inode, acc_mode);