getdirentries: return ENOENT for unlinked but still open directory.

To be more compatible to IEEE Std 1003.1-2008 (“POSIX.1”).

Reviewed by:		mjg, Pau Amma (doc)
Differential revision:  https://reviews.freebsd.org/D34680
MFC after:		2 weeks
This commit is contained in:
Dmitry Chagin 2022-04-11 23:30:16 +03:00
parent bb46e9b510
commit c6487446d7
4 changed files with 8 additions and 1 deletions

View File

@ -193,6 +193,8 @@ An
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 ,

View File

@ -5980,6 +5980,7 @@ vop_rmdir_post(void *ap, int rc)
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);
}

View File

@ -4195,6 +4195,10 @@ kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
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;

View File

@ -270,7 +270,7 @@ struct xvnode {
#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 */