2 .\" Copyright (c) 1998, 1999 Eivind Eklund
3 .\" Copyright (c) 2003 Hiten M. Pandya
4 .\" Copyright (c) 2005 Robert N. M. Watson
6 .\" All rights reserved.
8 .\" This program is free software.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
19 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
20 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 .\" If you integrate this manpage in another OS, I'd appreciate a note
32 .\" - eivind@FreeBSD.org
43 .Nd pathname translation and lookup operations
49 .Fn namei "struct nameidata *ndp"
52 .Fa "struct nameidata *ndp" "u_long op" "u_long flags"
53 .Fa "enum uio_seg segflg" "const char *namep" "struct thread *td"
56 .Fn NDFREE "struct nameidata *ndp" "const uint flags"
60 facility allows the client to perform pathname translation and lookup
64 functions will increment the reference count for the vnode in question.
65 The reference count has to be decremented after use of the vnode, by
70 depending on whether the
72 flag was specified or not.
76 function is used to initialize
79 It takes the following arguments:
80 .Bl -tag -width ".Fa segflg"
83 .Vt "struct nameidata"
89 The following operations are valid:
90 .Dv LOOKUP , CREATE , DELETE ,
93 The latter three are just setup for those
101 Several of these can be effective at the same time.
103 UIO segment indicator.
104 This indicates if the name of the object is in userspace
106 or in the kernel address space
107 .Pq Dv UIO_SYSSPACE .
109 Pointer to the component's pathname buffer
110 (the file or directory name that will be looked up).
112 The thread context to use for
114 operations and locks.
116 .Sh NAMEI OPERATION FLAGS
119 function takes the following set of
120 .Dq "operation flags"
121 that influence its operation:
122 .Bl -tag -width ".Dv WANTPARENT"
124 Lock vnode on return.
125 This is a full lock of the vnode; the
128 to release the lock (or
130 which is equivalent to calling
138 function return the parent (directory) vnode,
140 in locked state, unless it is identical to
144 is not locked per se (but may be locked due to
146 If a lock is enforced, it should be released using
155 function to return the parent (directory) vnode in an unlocked state.
156 The parent vnode must be released separately by using
161 creating this entry in the namecache if it is not
165 will add entries to the name cache
166 if they are not already there.
170 will follow the symbolic link if the last part
171 of the path supplied is a symbolic link (i.e., it will return a vnode
172 for whatever the link points at, instead for the link itself).
174 Do not follow symbolic links (pseudo).
175 This flag is not looked for by the actual code, which looks for
178 is used to indicate to the source code reader that symlinks
179 are intentionally not followed.
181 Do not free the pathname buffer at the end of the
183 invocation; instead, free it later in
185 so that the caller may access the pathname buffer.
186 See below for details.
188 Retain an additional reference to the parent directory; do not free
190 See below for details.
192 .Sh ALLOCATED ELEMENTS
195 structure is composed of the following fields:
196 .Bl -tag -width ".Va ni_cnd.cn_pnbuf"
198 In the normal case, this is either the current directory or the root.
199 It is the current directory if the name passed in does not start with
201 and we have not gone through any symlinks with an absolute path, and
204 In this case, it is only used by
207 considered valid after a call to
211 is set, this is set to the same as
220 .Dv NDF_NO_STARTDIR_RELE
223 Vnode pointer to directory of the object on which lookup is performed.
224 This is available on successful return if
235 .Dv NDF_NO_DVP_RELE , NDF_NO_DVP_PUT ,
237 .Dv NDF_NO_DVP_UNLOCK
238 (with the obvious effects).
240 Vnode pointer to the resulting object,
245 field of this vnode is incremented.
248 is set, it is also locked.
253 .Dv NDF_NO_VP_RELE , NDF_NO_VP_PUT ,
256 (with the obvious effects).
257 .It Va ni_cnd.cn_pnbuf
258 The pathname buffer contains the location of the file or directory
259 that will be used by the
264 zone allocation interface.
269 flag is set, then the pathname buffer is available
274 To only deallocate resources used by the pathname buffer,
275 .Va ni_cnd.cn_pnbuf ,
278 flag can be passed to the
281 To keep the pathname buffer intact,
283 .Dv NDF_NO_FREE_PNBUF
284 flag can be passed to the
291 will return 0, otherwise it will return an error.
294 .It Pa src/sys/kern/vfs_lookup.c
302 A component of the specified pathname is not a directory when a directory is
304 .It Bq Er ENAMETOOLONG
305 A component of a pathname exceeded 255 characters,
306 or an entire pathname exceeded 1023 characters.
308 A component of the specified pathname does not exist,
309 or the pathname is an empty string.
311 An attempt is made to access a file in a way forbidden by its file access
314 Too many symbolic links were encountered in translating the pathname.
316 An attempt is made to open a directory with write mode specified.
318 The last component of the pathname specified for a
325 An attempt is made to modify a file or directory on a read-only file system.
336 This manual page was written by
337 .An Eivind Eklund Aq eivind@FreeBSD.org
338 and later significantly revised by
339 .An Hiten M. Pandya Aq hmp@FreeBSD.org .
343 flag does not always result in the parent vnode being locked.
344 This results in complications when the
347 In order to solve this for the cases where both
351 are used, it is necessary to resort to recursive locking.