From nobody Wed Jan 31 00:46:03 2024 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 4TPjyN1c9jz580Ry; Wed, 31 Jan 2024 00:46:04 +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 4TPjyN0bcCz45Nv; Wed, 31 Jan 2024 00:46:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706661964; 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=WhzCGmkC24qO6OO9P0pjIaq/1Z3Dh/5v/wnS6OceJxE=; b=kVNLPoGBTbv/5i2/EyREmyBwtMJRxjhBeGVlTEGcOqolB2BceXxOje4Zy+/YpPkCHTVB+9 Ncsgir9mRjgploRSW+2QdQLUZcWkP4e2CEBeu9XEOw9HsHcqiDQDHeY4rVyE3itwM6cnqI OUOyRMSvJz+m9AdpamzOol/BUcCPpIpBP2CGKDZiieFJ7bQU3t/7R4aJ2UCSsJG3lrKC6K 1xs8x5A1JTTlU9oWUrFCWAWpL3e3ubJqg7vnMZ6rPAmQMjEdzVwbFpfat9FwFXhBiWkLwp 39cMnOLVBiTI5b4Yl8PQCHu/qIf8iM6KhihfGODuXz+RLbXk+PhC24vBap0B9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706661964; 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=WhzCGmkC24qO6OO9P0pjIaq/1Z3Dh/5v/wnS6OceJxE=; b=eozmQ2cgUy6ShzhHEp21Eh3DfTm0nU9GLh6WvXzbXYJF2QCxyX2UqhwcS7KYPmxFmmo2FC 8EVFNzRa61qSLanZ976o3gTNLaN9eDeR9ahyrq1M7pSc6aeZc2K1iagCdYgNNG80RvD7on km3kwZ/08yLsECh5zJzzBzoTXfXFSBxtQPPAI5JGHebzPCSD3gzM2kQgFZqeZ06ljaM1Wb KZJBk1f75fIVbT+oV5zcBTETqL2JkO5IycdN5GS58oGjh+GNsbA9iJEfvJ21aPBeu84gZM 1Udl4DoSGXTU5iq5HHzgnXVCn7zWOQdd59ki/rwHLq/mjxP+DyCXBvtiIa6q8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706661964; a=rsa-sha256; cv=none; b=Yzs7hhC6Hvu1gHmWERu6F6BmyrUWzH3/OvsNdpb4Q4663tPVKck5Rm5UjDJEwaRW2K2Jzs lFzBwzxoHoOOANDFN7jXmfv704TrnX8RH13k5j3QHV4/voVPQa86oKJM26zoQLuNeSS2VG Pt9uTzco5urE/ZTD6xNXkWVqSI/xGHK93fTYcLaifIlowKDlz0LKh+5ECw7DzVpm3xYkn/ f/nZ278ikqD9zmCUstoPuk/IDPGj4QLyUCTpw6GH6BT6YGv0BK5cCLYMuvX0rZhVkFP2z+ Wv0h9Z2BLretcOVlhTUV/Bq9wkJ4FTNpQOT76qzJ08/GHIpMAaXzdqtDUjiBOg== 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 4TPjyM6nBtzxxF; Wed, 31 Jan 2024 00:46:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40V0k3Z7063254; Wed, 31 Jan 2024 00:46:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40V0k38U063251; Wed, 31 Jan 2024 00:46:03 GMT (envelope-from git) Date: Wed, 31 Jan 2024 00:46:03 GMT Message-Id: <202401310046.40V0k38U063251@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 8732746cbeff - stable/14 - Add kern_openatfp(9) 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 8732746cbeffb3831ba144ac5999b200d63332a0 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8732746cbeffb3831ba144ac5999b200d63332a0 commit 8732746cbeffb3831ba144ac5999b200d63332a0 Author: Konstantin Belousov AuthorDate: 2024-01-20 20:34:46 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-30 20:24:42 +0000 Add kern_openatfp(9) (cherry picked from commit c662306e19ce60d0f5e5e32a22ddcd5c79a90849) --- sys/kern/vfs_syscalls.c | 39 ++++++++++++++++++++++++++++++++++++--- sys/sys/syscallsubr.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 41bf2ff1d3c7..0915751785f4 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1112,9 +1112,14 @@ sys_openat(struct thread *td, struct openat_args *uap) uap->mode)); } -int -kern_openat(struct thread *td, int dirfd, const char *path, - enum uio_seg pathseg, int flags, int mode) +/* + * If fpp != NULL, opened file is not installed into the file + * descriptor table, instead it is returned in *fpp. This is + * incompatible with fdopen(), in which case we return EINVAL. + */ +static int +openatfp(struct thread *td, int dirfd, const char *path, + enum uio_seg pathseg, int flags, int mode, struct file **fpp) { struct proc *p; struct filedesc *fdp; @@ -1188,6 +1193,7 @@ kern_openat(struct thread *td, int dirfd, const char *path, if ((nd.ni_resflags & NIRES_STRICTREL) == 0 && (error == ENODEV || error == ENXIO) && td->td_dupfd >= 0) { + MPASS(fpp == NULL); error = dupfdopen(td, fdp, td->td_dupfd, flags, error, &indx); if (error == 0) @@ -1229,6 +1235,13 @@ kern_openat(struct thread *td, int dirfd, const char *path, goto bad; } success: + if (fpp != NULL) { + MPASS(error == 0); + NDFREE_IOCTLCAPS(&nd); + *fpp = fp; + return (0); + } + /* * If we haven't already installed the FD (for dupfdopen), do so now. */ @@ -1258,6 +1271,26 @@ bad: return (error); } +int +kern_openat(struct thread *td, int dirfd, const char *path, + enum uio_seg pathseg, int flags, int mode) +{ + return (openatfp(td, dirfd, path, pathseg, flags, mode, NULL)); +} + +int +kern_openatfp(struct thread *td, int dirfd, const char *path, + enum uio_seg pathseg, int flags, int mode, struct file **fpp) +{ + int error, old_dupfd; + + old_dupfd = td->td_dupfd; + td->td_dupfd = -1; + error = openatfp(td, dirfd, path, pathseg, flags, mode, fpp); + td->td_dupfd = old_dupfd; + return (error); +} + #ifdef COMPAT_43 /* * Create a file. diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 294ff6ef00b9..15e05985e75f 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -253,6 +253,8 @@ int kern_ommap(struct thread *td, uintptr_t hint, int len, int oprot, int oflags, int fd, long pos); int kern_openat(struct thread *td, int dirfd, const char *path, enum uio_seg pathseg, int flags, int mode); +int kern_openatfp(struct thread *td, int dirfd, const char *path, + enum uio_seg pathseg, int flags, int mode, struct file **fpp); int kern_pathconf(struct thread *td, const char *path, enum uio_seg pathseg, int name, u_long flags, long *valuep); int kern_pipe(struct thread *td, int fildes[2], int flags,