From nobody Fri Apr 28 01:29:54 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q6w5G59CDz47l0k; Fri, 28 Apr 2023 01:29:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q6w5G2KSRz3s28; Fri, 28 Apr 2023 01:29:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682645394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I+cOZxTVNsvYoxPSSV01KSHCy5D0xnamA+qO9rT8/Fk=; b=XBs+WYK8xk2sMI4GOXZf750jPt6HH9738zsumWTGq1gXHxCIu69PdWgT5bje3gGF1sg2bU Q/Dmpp2HuIFh7J6KxuhWiPBMOYsdYofhpPgf7H8baIquyejfjJNLnvno11N8TRSVjKuhot JQkQqPFps5ktChfEHfeK6TwA9Lprg5ctauXZYN8Lz8Edxjr1qeak4xHoPSTOMjODwMVUDE q7MdL6q6hSJ+j22zvrMK4NoXfCrAMUPGSPKlpo+nE2GExbfQmdSgVqZuOsQ7jDQC47URG1 cK2ws0UTEQg85HEJyo2KDwG8Mc654iO7k4N2v8bEQTYh3tCBBm5WQxqtV6d54w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682645394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I+cOZxTVNsvYoxPSSV01KSHCy5D0xnamA+qO9rT8/Fk=; b=mtfV/WyK0ApEeoS1NNH31XaATGgSUBh6ai/EGUh9Lv+npQSjrxLErBwdyW40pu655Q6+V2 e98FBLlCxKPvvd+nqV79j3PvA0L6LhaGV8uMZkSiwWc84/NPCF7CMkCNrUf/lIJmkWp3CU WRjrNq7sMtt6Yp139Ah+9+tiH4Aea7o5I8+L3wP9swkc7daYc+OQ6WAzPjhmMe1IjznLl5 emEKcMNSOQ5YDXDLDjIsXjQcaRhlxYYpuvMGAIXLL60pFVniokddKJgR1SgtiPl5qZ8jTz EB+US8C5x5vexAICZu+gPdJS+Byy/Am2uPv/iMe2nnFuzbn+RRwWUbhyxwa/cw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682645394; a=rsa-sha256; cv=none; b=V9xXIpFFcwbzNqoAoYOMN2z7KrZTsr5QNx+/zJKSZpbFQeQHiSbej8owvigfgC4Mpg1glT QccNZM6cJScLN3BisNZZSBiaGJOT6DhujaoTjNQ9mbiqPgLsX7MdIyfieFelnQpAhNDIVT cEIVjzeBOgl/ep4UrhcgMn6LsKr9Mk3CtNIv/zM2hRuFXWvaoNTF4Sx5c5dnwD8mLSgywN GrQYKglOhvfUrNbyamCY46fZwEnMMqWFsf0tJ8t+rGSPRczembQblRxhrIXfXQguOerU1P boiWV11LdhzqfPpv+ZJvIpVK4F2NCcIq8BrhOa1UmDYn51jJi3qZaVZt5pmr2g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q6w5G1P40zgXD; Fri, 28 Apr 2023 01:29:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33S1TsoQ075155; Fri, 28 Apr 2023 01:29:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33S1TsxR075154; Fri, 28 Apr 2023 01:29:54 GMT (envelope-from git) Date: Fri, 28 Apr 2023 01:29:54 GMT Message-Id: <202304280129.33S1TsxR075154@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 6bce3f23d0aa - main - vfs: Export get_next_dirent() as vn_dir_next_dirent() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6bce3f23d0aa045d61c0ec8d27100eb186a33375 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6bce3f23d0aa045d61c0ec8d27100eb186a33375 commit 6bce3f23d0aa045d61c0ec8d27100eb186a33375 Author: Olivier Certner AuthorDate: 2023-04-23 07:47:58 +0000 Commit: Konstantin Belousov CommitDate: 2023-04-28 01:27:54 +0000 vfs: Export get_next_dirent() as vn_dir_next_dirent() Move internal-to-'vfs_default.c' get_next_dirent() to 'vfs_vnops.c' and export it for use by other parts of the VFS. This is a preparatory change for using it in vfs_emptydir(). No functional change. Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39755 --- sys/kern/vfs_default.c | 73 +++----------------------------------------------- sys/kern/vfs_vnops.c | 62 ++++++++++++++++++++++++++++++++++++++++++ sys/sys/vnode.h | 3 +++ 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index ee1310215621..7da4f7b62cff 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -75,15 +75,9 @@ __FBSDID("$FreeBSD$"); static int vop_nolookup(struct vop_lookup_args *); static int vop_norename(struct vop_rename_args *); static int vop_nostrategy(struct vop_strategy_args *); -static int get_next_dirent(struct vnode *vp, struct dirent **dpp, - char *dirbuf, int dirbuflen, off_t *off, - char **cpos, int *len, int *eofflag, - struct thread *td); static int dirent_exists(struct vnode *vp, const char *dirname, struct thread *td); -#define DIRENT_MINSIZE (sizeof(struct dirent) - (MAXNAMLEN+1) + 4) - static int vop_stdis_text(struct vop_is_text_args *ap); static int vop_stdunset_text(struct vop_unset_text_args *ap); static int vop_stdadd_writecount(struct vop_add_writecount_args *ap); @@ -281,65 +275,6 @@ vop_nostrategy (struct vop_strategy_args *ap) return (EOPNOTSUPP); } -static int -get_next_dirent(struct vnode *vp, struct dirent **dpp, char *dirbuf, - int dirbuflen, off_t *off, char **cpos, int *len, - int *eofflag, struct thread *td) -{ - int error, reclen; - struct uio uio; - struct iovec iov; - struct dirent *dp; - - KASSERT(VOP_ISLOCKED(vp), ("vp %p is not locked", vp)); - KASSERT(vp->v_type == VDIR, ("vp %p is not a directory", vp)); - - if (*len == 0) { - iov.iov_base = dirbuf; - iov.iov_len = dirbuflen; - - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; - uio.uio_offset = *off; - uio.uio_resid = dirbuflen; - uio.uio_segflg = UIO_SYSSPACE; - uio.uio_rw = UIO_READ; - uio.uio_td = td; - - *eofflag = 0; - -#ifdef MAC - error = mac_vnode_check_readdir(td->td_ucred, vp); - if (error == 0) -#endif - error = VOP_READDIR(vp, &uio, td->td_ucred, eofflag, - NULL, NULL); - if (error) - return (error); - - *off = uio.uio_offset; - - *cpos = dirbuf; - *len = (dirbuflen - uio.uio_resid); - - if (*len == 0) - return (ENOENT); - } - - dp = (struct dirent *)(*cpos); - reclen = dp->d_reclen; - *dpp = dp; - - /* check for malformed directory.. */ - if (reclen < DIRENT_MINSIZE) - return (EINVAL); - - *cpos += reclen; - *len -= reclen; - - return (0); -} - /* * Check if a named file exists in a given directory vnode. */ @@ -369,8 +304,8 @@ dirent_exists(struct vnode *vp, const char *dirname, struct thread *td) off = 0; len = 0; do { - error = get_next_dirent(vp, &dp, dirbuf, dirbuflen, &off, - &cpos, &len, &eofflag, td); + error = vn_dir_next_dirent(vp, &dp, dirbuf, dirbuflen, &off, + &cpos, &len, &eofflag, td); if (error) goto out; @@ -808,8 +743,8 @@ vop_stdvptocnp(struct vop_vptocnp_args *ap) len = 0; do { /* call VOP_READDIR of parent */ - error = get_next_dirent(*dvp, &dp, dirbuf, dirbuflen, &off, - &cpos, &len, &eofflag, td); + error = vn_dir_next_dirent(*dvp, &dp, dirbuf, dirbuflen, &off, + &cpos, &len, &eofflag, td); if (error) goto out; diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 581d620e348e..ad9b0c8864b0 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -3736,6 +3737,67 @@ vn_fspacectl(struct file *fp, int cmd, off_t *offset, off_t *length, int flags, return (error); } +#define DIRENT_MINSIZE (sizeof(struct dirent) - (MAXNAMLEN+1) + 4) + +int +vn_dir_next_dirent(struct vnode *vp, struct dirent **dpp, char *dirbuf, + int dirbuflen, off_t *off, char **cpos, int *len, + int *eofflag, struct thread *td) +{ + int error, reclen; + struct uio uio; + struct iovec iov; + struct dirent *dp; + + KASSERT(VOP_ISLOCKED(vp), ("vp %p is not locked", vp)); + KASSERT(vp->v_type == VDIR, ("vp %p is not a directory", vp)); + + if (*len == 0) { + iov.iov_base = dirbuf; + iov.iov_len = dirbuflen; + + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + uio.uio_offset = *off; + uio.uio_resid = dirbuflen; + uio.uio_segflg = UIO_SYSSPACE; + uio.uio_rw = UIO_READ; + uio.uio_td = td; + + *eofflag = 0; + +#ifdef MAC + error = mac_vnode_check_readdir(td->td_ucred, vp); + if (error == 0) +#endif + error = VOP_READDIR(vp, &uio, td->td_ucred, eofflag, + NULL, NULL); + if (error) + return (error); + + *off = uio.uio_offset; + + *cpos = dirbuf; + *len = (dirbuflen - uio.uio_resid); + + if (*len == 0) + return (ENOENT); + } + + dp = (struct dirent *)(*cpos); + reclen = dp->d_reclen; + *dpp = dp; + + /* check for malformed directory.. */ + if (reclen < DIRENT_MINSIZE) + return (EINVAL); + + *cpos += reclen; + *len -= reclen; + + return (0); +} + static u_long vn_lock_pair_pause_cnt; SYSCTL_ULONG(_debug, OID_AUTO, vn_lock_pair_pause, CTLFLAG_RD, &vn_lock_pair_pause_cnt, 0, diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index fa889826867e..282f75bcdd71 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1099,6 +1099,9 @@ void vfs_hash_remove(struct vnode *vp); int vfs_kqfilter(struct vop_kqfilter_args *); struct dirent; +int vn_dir_next_dirent(struct vnode *vp, struct dirent **dpp, char *dirbuf, + int dirbuflen, off_t *off, char **cpos, int *len, + int *eofflag, struct thread *td); int vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off); int vfs_emptydir(struct vnode *vp);