diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2 --- a/lib/libc/sys/getdirentries.2 +++ b/lib/libc/sys/getdirentries.2 @@ -193,6 +193,8 @@ error occurred while reading from or writing to the file system. .It Bq Er EINTEGRITY Corrupted data was detected while reading from the file system. +.It Bq Er ENOENT +Directory unlinked but still open. .El .Sh SEE ALSO .Xr lseek 2 , diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -5980,6 +5980,7 @@ vn_seqc_write_end(dvp); vn_seqc_write_end(vp); if (!rc) { + vp->v_vflag |= VV_UNLINKED; VFS_KNOTE_LOCKED(dvp, NOTE_WRITE | NOTE_LINK); VFS_KNOTE_LOCKED(vp, NOTE_DELETE); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -4195,6 +4195,10 @@ error = EINVAL; goto fail; } + if (__predict_false((vp->v_vflag & VV_UNLINKED) != 0)) { + error = ENOENT; + goto fail; + } aiov.iov_base = buf; aiov.iov_len = count; auio.uio_iov = &aiov; diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -270,7 +270,7 @@ #define VV_COPYONWRITE 0x0040 /* vnode is doing copy-on-write */ #define VV_SYSTEM 0x0080 /* vnode being used by kernel */ #define VV_PROCDEP 0x0100 /* vnode is process dependent */ -/* UNUSED 0x0200 */ +#define VV_UNLINKED 0x0200 /* unlinked but stil open directory */ #define VV_DELETED 0x0400 /* should be removed */ #define VV_MD 0x0800 /* vnode backs the md device */ #define VV_FORCEINSMQ 0x1000 /* force the insmntque to succeed */