aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2009-01-05 13:27:23 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2009-03-27 14:43:57 -0400
commitc8fe8f30c7fe6ce6fc44a1db7d5bfa5144cd9211 (patch)
tree4432fe47893442907d1e60ab362208dd9ae12bd2 /fs/namei.c
parentb6520c81934848cef126d93951f7ce242e0f656d (diff)
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)
1486 if (!inode) 1486 if (!inode)
1487 return -ENOENT; 1487 return -ENOENT;
1488 1488
1489 if (S_ISLNK(inode->i_mode)) 1489 switch (inode->i_mode & S_IFMT) {
1490 case S_IFLNK:
1490 return -ELOOP; 1491 return -ELOOP;
1491 1492 case S_IFDIR:
1492 if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE)) 1493 if (acc_mode & MAY_WRITE)
1493 return -EISDIR; 1494 return -EISDIR;
1494 1495 break;
1495 /* 1496 case S_IFBLK:
1496 * FIFO's, sockets and device files are special: they don't 1497 case S_IFCHR:
1497 * actually live on the filesystem itself, and as such you
1498 * can write to them even if the filesystem is read-only.
1499 */
1500 if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
1501 flag &= ~O_TRUNC;
1502 } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
1503 if (path->mnt->mnt_flags & MNT_NODEV) 1498 if (path->mnt->mnt_flags & MNT_NODEV)
1504 return -EACCES; 1499 return -EACCES;
1505 1500 /*FALLTHRU*/
1501 case S_IFIFO:
1502 case S_IFSOCK:
1506 flag &= ~O_TRUNC; 1503 flag &= ~O_TRUNC;
1504 break;
1507 } 1505 }
1508 1506
1509 error = inode_permission(inode, acc_mode); 1507 error = inode_permission(inode, acc_mode);