From e83a71c6564b6b86c46c2684d94071d41c9865ca Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 10 Feb 2017 14:49:04 +0000 Subject: [PATCH] Fix r313495. The file type DTYPE_VNODE can be assigned as a fallback if VOP_OPEN() did not initialized file type. This is a typical code path used by normal file systems. Also, change error returned for inappropriate file type used for O_EXLOCK to EOPNOTSUPP, as declared in the open(2) man page. Reported by: cy, dhw, Iblis Lin Tested by: dhw Sponsored by: The FreeBSD Foundation MFC after: 13 days --- sys/kern/vfs_vnops.c | 4 ++-- sys/sys/file.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 70cdcdc6f75..1f2cceaf7a6 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -351,8 +351,8 @@ vn_open_vnode(struct vnode *vp, int fmode, struct ucred *cred, while ((fmode & (O_EXLOCK | O_SHLOCK)) != 0) { KASSERT(fp != NULL, ("open with flock requires fp")); - if (fp->f_type != DTYPE_VNODE) { - error = EBADF; + if (fp->f_type != DTYPE_NONE && fp->f_type != DTYPE_VNODE) { + error = EOPNOTSUPP; break; } lock_flags = VOP_ISLOCKED(vp); diff --git a/sys/sys/file.h b/sys/sys/file.h index 353c92f365a..c51f26a41d2 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -53,6 +53,7 @@ struct vnode; #endif /* _KERNEL */ +#define DTYPE_NONE 0 /* not yet initialized */ #define DTYPE_VNODE 1 /* file */ #define DTYPE_SOCKET 2 /* communications endpoint */ #define DTYPE_PIPE 3 /* pipe */