From nobody Wed Jan 24 05:13:36 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 4TKXDJ6wKVz57T3q; Wed, 24 Jan 2024 05:13:36 +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 4TKXDJ5VX3z4dsw; Wed, 24 Jan 2024 05:13:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706073216; 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=Pa7E+lbHW8cbmeBA/YjU+U0PUW+r6nwNGU2RTQytfLs=; b=oqEuXS5HdCps+sREN2P8gX3fSZXNGC1f8YPcxVchhM17xii9GhD30Vf+vUmq6vGVt3nne/ 69cuOn2tBlUttiGMxRDv94nAAdrF8xeq5BnvoSisXTQJ++VXjjrV/F91K7oc7pD0oiSzcm We0C85Oh6lbfrd1nd5Yr2YHD10oOAYmDDv9DdBYQ/gFFGG02TpAUhPN/6vJmCUUMH6prlr hp6sfzkBq2H2wo9Dn7YvEgT93R0sT2Fw/I1OuMMI0j14xmo6UuVV1Ky6BOhXHjhxJccM5B Ao4r3kY2kxJZx/KuiO91i8Gj/olgPvqHIdd0JFncrUooUwAWB4mUu0aoAeSSgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706073216; 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=Pa7E+lbHW8cbmeBA/YjU+U0PUW+r6nwNGU2RTQytfLs=; b=giPjvjt3t19dJX6bDWIUI4yq+P5Hvtowu3e0/EhZNLEiET3kRh3y07ocGbG4UhUkuKGwv1 56KNWQ296CTAKguCbprTeNJj67wdqeJwnyFdNjG3fDYSa72sxoPt9/gyI9zOprNl+NmA23 4LiFOSwnhbicaBVU7exDqF0dviVkRs2ypvVwvyIuP/v66XsbjU2lqMNl0GOjHlnoUOcyaK rHaIo+KDsJkvJMSVSiZlGJHQmkz/I+kpuQ0IeSE3BXrYUVdnt/PsEvTq2+zbHzbnJUHMs5 AXpukSAhggYMqWawsACCirM0WNAW/T5bb/kjSN/kr9+C5jDq26mApgbcRVcw3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706073216; a=rsa-sha256; cv=none; b=sqOrLmUngqPTt6Z7/DWkni0Tc789eJnQHwvQ9TnZUuBWoE5YX7bDk3uh7lFpm+Qf6oOTO8 ctz/FdMqUp7hy2a3uRUCQAYNjJf9QA8B7lq3jcOrXLyqtoFNj6xxovQwPeXTRZx3AbUoVm qjtAiVAkXzBhfz+ymKJEISWA4qjbUs+J1iTXkYTTVOBw5oAmbyUF9FcrMPREK1/yCFngZ1 W9WJE+u1pzWT19YFL6VKm65do6/+8PIRI1a42PFSGu2yVIlWTl+e0v4Xt0iAd7PvmUlF+8 FoN4AzFJZZUfwHMmS/1rnHVqmCatOV960RyMyx9R4jNfCGGDmqjlWiFobKqfzQ== 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 4TKXDJ4ZvZz11Sw; Wed, 24 Jan 2024 05:13:36 +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 40O5DaJ4041805; Wed, 24 Jan 2024 05:13:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40O5Daih041802; Wed, 24 Jan 2024 05:13:36 GMT (envelope-from git) Date: Wed, 24 Jan 2024 05:13:36 GMT Message-Id: <202401240513.40O5Daih041802@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: c662306e19ce - main - 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/main X-Git-Reftype: branch X-Git-Commit: c662306e19ce60d0f5e5e32a22ddcd5c79a90849 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c662306e19ce60d0f5e5e32a22ddcd5c79a90849 commit c662306e19ce60d0f5e5e32a22ddcd5c79a90849 Author: Konstantin Belousov AuthorDate: 2024-01-20 20:34:46 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-24 05:13:26 +0000 Add kern_openatfp(9) Reviewed by: markj, pjd Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43529 --- 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 5d065e638203..c9a039515a77 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1110,9 +1110,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; @@ -1186,6 +1191,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) @@ -1227,6 +1233,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. */ @@ -1256,6 +1269,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 50dc3ad7d126..c99eebd6d5d4 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,