From nobody Sun May 18 21:38:27 2025 X-Original-To: dev-commits-src-main@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 4b0vM83RDMz5vtP3; Sun, 18 May 2025 21:38:28 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b0vM816b8z3wcx; Sun, 18 May 2025 21:38:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747604308; 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=aCBrfKvtiooLFE+URaWg6FIPV+jbZiNK9XJteTatd/w=; b=CRyOyzEskWokeKWSygocnGqHzmbBH2nzEvxkyNMMLgov+W+kJC9qqDCuFyyNjdXOQS3CIr 61zXttIzw+a+mV6H21auGAWtB5T1bdtD74RuxEpsU4Y+HtKE/ymJugZQmGscfhGbWjfQvk 6y40NCindBFfr5ueiXdh/hf6I/B+dKzTMmdi9tgZ7jlkZB+M+fCPfS5zFNsfEt62vesvMM qpuNPDKWH7oXqvWEiMeH/ocIKICQJzHvS/ZUdy4PqY5+SHFU3SlUMN0F0XNyNcTM8Ha5hr KfX2opSSA7Xw6VdXuedmkkh+l5XsIy4I/DG8+zHWIiaWs48RtEzh7e+YZ06mFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747604308; 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=aCBrfKvtiooLFE+URaWg6FIPV+jbZiNK9XJteTatd/w=; b=xVoaPKDk9lNX0WwkxK1VzbuD0wD5ESoEg9u48rzmmjhJgSfoLIXNv8yFTQLluOis7BPQuF 4czQYBa1VUrIE17Aflp0dm9+vXvXt9xG4mjpT4jeKaqkciQ4EvFlvykrNf7csnPgPDTWT4 n4uTFPKK14HE/6YaPiLN7MGT0lu2LMU38stPwYfdmE5POv3iKPNfS4JiQlFfGyqgD7Gjfq 8VY1J0i4sXtni1efYIfvZum2bu8OMlBZfl11z5KC3VQj6u+UgNjZl2NkI9gk/PrS1Xj7B2 TMLSrQssJvPHdSRzGpZqU1wlmqxQzdp9HrDvLGCbZvfTvvQJE75ZySB5bZSTYQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747604308; a=rsa-sha256; cv=none; b=j2jxi3QZakIYzrWyvXl+j/Ac5X32p/2FlCTn4r1MC3QWmwPfqS90FM1Jogz+ZWP3qUilSN 6tKIkFNyBjhPe5N4lsrjd+Rag5LZ135MxcCjn5nKdVBxut8fQ0joKOG8BK80V3yyg1uvTv R3XikxPG87uFxn4Q5jQo2h3gkn5W7Solod6aIo6Ejwn4S8FMlefPeadEbK/DcQk3cAJipd ndVkIYe24+1O22rZdBNWjoYj/LzVAzTUFWSsmZ0D0PidZODzaC//wjWc09Q19JgpLPybbK nBu7hFxJyefRblS8i5MSQOarYUbwUDzOit3G8e505KCs59LlexisfhpSar+wuw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4b0vM80TZlzcM4; Sun, 18 May 2025 21:38:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54ILcRZf081805; Sun, 18 May 2025 21:38:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54ILcRds081802; Sun, 18 May 2025 21:38:27 GMT (envelope-from git) Date: Sun, 18 May 2025 21:38:27 GMT Message-Id: <202505182138.54ILcRds081802@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: 66024c07cb58 - main - namei(9): document the rest List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 66024c07cb586cfa8121b57b7931e0cc24d04aed Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=66024c07cb586cfa8121b57b7931e0cc24d04aed commit 66024c07cb586cfa8121b57b7931e0cc24d04aed Author: Konstantin Belousov AuthorDate: 2025-05-17 17:38:19 +0000 Commit: Konstantin Belousov CommitDate: 2025-05-18 21:37:13 +0000 namei(9): document the rest Reviewed by: mckusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D50401 --- share/man/man9/namei.9 | 187 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) diff --git a/share/man/man9/namei.9 b/share/man/man9/namei.9 index 1703faaeee99..fc0826cc7206 100644 --- a/share/man/man9/namei.9 +++ b/share/man/man9/namei.9 @@ -234,6 +234,147 @@ This flag is not looked for by the actual code, which looks for .Dv NOFOLLOW is used to indicate to the source code reader that symlinks are intentionally not followed. +.It Dv NC_KEEPPOSENTRY +Keep the positive-caching entry in cache. +This flag is typically combined with +.Dv NOCACHE +to not cache a new entry, +but keep existing one, or with +.Dv MAKEENTRY . +.It Dv FAILIFEXISTS +Makes the +.Nm +operation fail if the target exists. +It requires that the +.Dv LOCKPARENT +flag is set and +.Dv LOCKLEAF +is not. +.It Dv EMPTYPATH +For +.Nm +call initialized with +.Fn NDINIT_AT , +allow the +.Fa namep +path to be empty. +In this case, the +.Fa dirfd +file descriptor may reference a file of arbitrary type, not +necessary a directory, and lookup returns the vnode for this file. +.It Dv RBENEATH +Requires that +.Nm +did not cross the +.Fa dirfd +directory. +The flag is used to implement +.Dv O_RESOLVE_BENEATH +flag for +.Xr openat 2 . +.El +.Sh PARAMETERS DESCRIPTORS FLAGS +These flags are used for several purposes. +Some of them affects the global +.Nm +operation, some provide information for processing of the specific +path element, for instance, by the +.Dv VOP_LOOKUP +implementation of the involved filesystem. +.Bl -tag -width IGNOREWHITEOUT +.It Dv RDONLY +Specifies that the lookup should act as if the final node is located on +read-only mount. +The flag is typically used by file servers, e.g. NFS, +to handle read-only exports. +.It Dv ISRESTARTED +The +.Nm +was restarted with +.Fn NDRESTART . +This is used internally for double-root lookups used by ABI subsystems, +after the lookup with native root failed. +The components are reset to the original values, and lookup is repeated +with different root, once. +.It Dv IGNOREWHITEOUT +Ignore whiteouts, e.g. when checking if a directory is empty. +.It Dv ISWHITEOUT +The result of lookup is whiteout. +.It Dv DOWHITEOUT +Handle whiteouts, the instruction for the +.Fn VOP_LOOKUP +filesystem methods. +.It Dv WILLBEDIR +The lookup is done for creating a new entry that will be directory. +It allows the trailing slash in the path string. +.It Dv ISOPEN +The caller is the code that opens a file. +This allows to weaken the lock mode of the return vnode, if the +mount point indicates extended shared lock support. +.It Dv NOCROSSMOUNT +Do not cross mount points during lookup. +.Pp +For .. lookups leading to mount roots, returns the root vnode of +the mount instead of the covered vnode of the filesystem where +the mount was placed. +.Pp +For other lookups passing over mount, do not jump into the mounted +filesystem. +This allows to descend into the file hierarchy otherwise shadowed +by the mount point. +.It Dv NOMACCHECK +Do not perform MAC checks during lookup. +.It Dv AUDITVNODE1 +Audit the looked up vnode information, use the first slot for audit information. +.It Dv AUDITVNODE2 +Same as +.Dv AUDITVNODE1 +but use the second slot. +.It Dv NOCAPCHECK +Do not perform capability checks. +If the calling process is in capability mode, lookup is denied outright. +.It Dv OPENREAD +The lookup was for open and file will be opened for read. +.It Dv OPENWRITE +The lookup was for open and file will be opened for write. +.It Dv WANTIOCTLCAPS +Leave ioctl caps for the caller. +See the description of +.Nm +results. +.It Dv OPENNAMED +Opening a named attribute (directory). +.It Dv NOEXECCHECK +Do not perform check for allowed execution on the starting directory. +It is used to implement the POSIX-required semantic for +.Xr openat 2 +lookups that must use the permissions from time the directory was +opened, and not when used for lookup. +.It Dv MAKEENTRY +Looked-up entry is to be added to name cache. +.It Dv ISSYMLINK +Current component is symlink, and it needs the interpretation +according to the +.Dv FOLLOW +or +.Dv NOFOLLOW +flags. +.It Dv ISLASTCN +This is last component of pathname. +It is handled specially, many flags augments its processing. +.It Dv ISDOTDOT +Current component name is .. . +Usually implies a need to specially handle the vnode locking +for instantiation of the target vnode. +The generic +.Fn vn_vget_ino_gen +function and its more specialized variant +.Fn vn_vget_ino +might be useful. +.It Dv TRAILINGSLASH +Path ended in a slash. +.It Dv CREATENAMED +Create a named attribute dir. .El .Sh ALLOCATED ELEMENTS The @@ -282,6 +423,34 @@ It is managed by the .Xr uma 9 zone allocation interface. .El +.Sh RESULTS +The +.Vt struct namei +member +.Dv ni_resflags +returns the following flags giving some details of the succesfull operation: +.Bl -tag -width NIRES_EMPTYPATH +.It Dv NIRES_ABS +The path passed was absolute. +.It Dv NIRES_STRICTREL +Restricted lookup result. +Only relative lookups were done to resolve the path to vnode. +.It Dv NIRES_EMPTYPATH +The +.Dv EMPTYPATH +flag was provided and used. +In particular, the passed path was empty. +.El +.Pp +If the +.Dv WANTIOCTLCAPS +flag was specified, on return the +.Va ni_filecaps +member of the +.Vt struct namei +contains the capabilities of the file descriptor used as +the lookup starting point +.Pq Va dirfd . .Sh RETURN VALUES If successful, .Fn namei @@ -290,6 +459,24 @@ will return 0, otherwise it will return an error. .Bl -tag -width Pa .It Pa src/sys/kern/vfs_lookup.c .El +.Sh EXAMPLES +Assuming the +.Dv path +variable contains a pointer to userspace path string, the following +example looks up the file named by it, and performs required error +and resource handling: +.Bd -literal + char *path; + struct nameidata nd; + int error; + + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, + path); + if ((error = namei(&nd)) != 0) + return (error); + NDFREE_PNBUF(&nd); + ... use nd.ni_vp vnode +.Ed .Sh ERRORS Errors which .Fn namei