From: NeilBrown -ENODEV is not generally an error meaning "the object is a device" and nfsd - the only intended caller of vfs_lookup_open() - does not benefit from knowing it was a device file. So return -EFTYPE in that case. Also switch to testing the dentry type rather than dereferencing the inode to get the type. This requires d_is_negative_acquire() as no lock is held. -EISDIR is widely used to mean "the object is a directory which is not what is wanted". -ELOOP is sometimes used elsewhere to mean "a symlink was found but cannot be handled". Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/namei.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 11e3e1bee05a..45292c152c75 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4746,9 +4746,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, * determine the type of file found from the error. * -EISDIR : a directory was found * -ELOOP : a symlink was found - * -ENODEV : a block or character device special file was found - * -EFTYPE : any other non-regular file was found, such as FIFO or SOCK. - * or ->atomic_open responded to __O_REGULAR. + * -EFTYPE : any other non-regular file was found, device-special, FIFO or SOCK * * Returns: the opened struct file, or an error. */ @@ -4792,28 +4790,16 @@ struct file *vfs_lookup_open(struct path *parent, struct qstr *last, if (IS_ERR(dentry)) return ERR_CAST(dentry); - if (d_really_is_negative(dentry)) { + if (d_is_negative_acquire(dentry)) { error = -ENOENT; } else if (!(file->f_mode & FMODE_CREATED) && (open_flag & O_EXCL)) { error = -EEXIST; - } else if ((dentry->d_inode->i_mode & S_IFMT) != S_IFREG) { - switch (dentry->d_inode->i_mode & S_IFMT) { - case S_IFDIR: + } else if (!d_is_reg(dentry)) { + error = -EFTYPE; + if (d_is_dir(dentry)) error = -EISDIR; - break; - case S_IFLNK: + if (d_is_symlink(dentry)) error = -ELOOP; - break; - case S_IFBLK: - case S_IFCHR: - error = -ENODEV; - break; - case S_IFIFO: - case S_IFSOCK: - default: - error = -EFTYPE; - break; - } } else if (!(file->f_mode & FMODE_OPENED)) { nd.path.dentry = dentry; error = vfs_open(&nd.path, file); -- 2.50.0.107.gf914562f5916.dirty