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