From: NeilBrown <neilb@ownmail.net>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 6/8] vfs: don't return -ENODEV from vfs_lookup_open()
Date: Wed, 2 Dec 2026 17:05:06 +1100 [thread overview]
Message-ID: <20261202060607.2627366-7-neilb@ownmail.net> (raw)
In-Reply-To: <20261202060607.2627366-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
-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.
-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 <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/namei.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 38b6eb37d08d..d7980391a40d 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.
*/
@@ -4796,24 +4794,12 @@ struct file *vfs_lookup_open(struct path *parent, struct qstr *last,
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
next prev parent reply other threads:[~2026-12-02 6:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 6:05 [PATCH 0/8] vfs: improvements for atomic_open and vfs_lookup_open NeilBrown
2026-12-02 6:05 ` [PATCH 1/8] vfs: revise and expand documentation for atomic_open NeilBrown
2026-12-02 6:05 ` [PATCH 2/8] vfs: only set op.mode when O_CREAT in vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 3/8] vfs: don't call ->atomic_open with hashed negative in non-O_CREAT case NeilBrown
2026-12-02 6:05 ` [PATCH 4/8] vfs: add some allowed open flags to vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 5/8] vfs: O_NONBLOCK|O_CREAT open shouldn't wait for directory delegation NeilBrown
2026-12-02 6:05 ` NeilBrown [this message]
2026-12-02 6:05 ` [PATCH 7/8] vfs: change vfs_lookup_open() to use do_open(), not vfs_open() NeilBrown
2026-12-02 6:05 ` [PATCH 8/8] vfs: add MAY_SERVE_FILE and FMODE_SERVE_FILE NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202060607.2627366-7-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®