1 .\" Copyright (c) 1998, 1999 Eivind Eklund
3 .\" All rights reserved.
5 .\" This program is free software.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\" If you integrate this manpage in another OS, I'd appreciate a note
29 .\" - eivind@FreeBSD.org
31 .\" $FreeBSD: src/share/man/man9/namei.9,v 1.8.2.8 2001/12/17 11:30:18 ru Exp $
32 .\" $DragonFly: src/share/man/man9/Attic/namei.9,v 1.3 2004/06/01 11:36:53 hmp Exp $
40 .Nd convert pathname to a pointer to a locked vnode
45 .Fn namei "struct nameidata *ndp"
47 .Fn NDINIT "struct nameidata *ndp" "u_long operation" "u_long operflags" "enum uio_seg segflag" "const char *path" "struct proc *proc"
49 .Fn NDFREE "struct nameidata *ndp" "u_int operflags"
52 is used to get from a pathname to a vnode for the object.
53 This is a necessity to start doing VFS operations. The vnode
54 returned will have its reference count increased; when you're through
55 with it, you have to release it using either
59 depending on whether you specified the LOCKLEAF flag or not.
61 To initialize the nameidata struct, you usually use
63 It takes the following arguments:
65 .Bl -tag -width nameidatap
67 pointer to the struct nameidata to initialize
71 do. The relevant operations are
77 The latter three are just setup for those
84 Operation flags. Several of these can be effective at the same time.
86 Segment indicator. This tells if the name of the object is in
87 userspace (UIO_USERSPACE) or in the kernel address space (UIO_SYSSPACE).
89 Pointer to pathname buffer (the file or directory name that will be
92 Which process context to use for the
96 .Sh NAMEI OPERATION FLAGS
98 takes the following set of 'operation flags' that influence
100 .Bl -tag -width WANTPARENT
102 Lock vnode on return. This is a full lock of the vnode; you'll have to use
104 to release the lock (or use
106 to release the lock and do a
112 also return the parent (directory) vnode (in nd.ni_dvp),
113 in locked state, unless the dvp is identical to the vp, in which case the dvp
114 is not locked per se (but may be locked due to LOCKLEAF).
115 If you get a lock, remember to release the lock (using
124 also return the parent (directory) vnode, in unlocked
125 state. Remember to release it (using
130 creating this entry in the namecache if it is not
131 already present. Normally
133 will add entries to the name cache
134 if they're not already there.
138 will follow the symbolic link if the last part
139 of the path supplied is a symbolic link (i.e., it will return a vnode
140 for whatever the link points at, instead for the link itself).
143 .Fn vfs_object_create
144 for the returned vnode even if it is
145 just a VREG and we're able to (ie, it is locked).
147 Do not follow symbolic links (pseudo).
148 This flag is not looked for by the actual code, which looks for
150 NOFOLLOW is used to indicate to the source code reader that symlinks
151 are intentionally not followed.
153 .Sh ALLOCATED ELEMENTS
154 .Bl -tag -width WANTPARENT
156 Where we did lookup relative to.
157 In the normal case, this is either the current directory or the root.
158 It is the current directory if the name passed in doesn't start with /
159 and we have not gone through any symlinks with an absolute path, and
162 In this case, it is only used by
165 considered valid after a call to
168 If SAVESTART is set, this is set to the same as ni_dvp, with an extra
171 To block NDFREE from releasing ni_startdir when it is set, use the
172 flag NDF_NO_STARTDIR_RELE.
174 The directory vp for the directory the object we're looking up is in.
175 This is available on successful return if LOCKPARENT or WANTPARENT is
176 set. It is locked if LOCKPARENT is set. Freeing this in NDFREE can
177 be inhibited by NDF_NO_DVP_RELE, NDF_NO_DVP_PUT, or NDF_NO_DVP_UNLOCK
178 (with the obvious effects).
180 The vp for the target of the of the pathname exists, NULL otherwise.
181 The vp is returned with increased reference count (VREF'ed). If
182 LOCKLEAF is set, it is also locked.
184 Freeing this in NDFREE can be inhibited by NDF_NO_VP_RELE,
185 NDF_NO_VP_PUT, or NDF_NO_VP_UNLOCK (with the obvious effects).
186 .It Dv ni_cnd.cn_pnbuf
187 Path name buffer. This is allocated through zalloc(namei_zone)
188 and freed through zfree(namei_zone, ...).
190 This is available to the caller (who must free it using
192 if SAVESTART or SAVENAME is set.
193 To free only the ni_cnd.cn_pnbuf, there is a special flags NDF_ONLY_PNBUF.
194 To not free the cnd, use the flag ND_NO_FREE_PNBUF.
197 LOCKPARENT does not always result in parent vp being locked (see details in
199 This results in complications everywhere LOCKPARENT is used.
200 In order to solve this for the cases that include both LOCKPARENT and LOCKLEAF,
201 it will be necessary to go to recursive locking.
206 .Pa src/sys/kern/vfs_lookup.c
208 This man page was written by