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
41 .Nd pathname translation and lookup operations
47 .Fn namei "struct nameidata *ndp"
50 .Fa "struct nameidata *ndp" "u_long op" "u_long flags"
51 .Fa "enum uio_seg segflg" "const char *namep" "struct thread *td"
54 .Fn NDFREE "struct nameidata *ndp" "const uint flags"
58 facility allows the client to perform pathname translation and lookup
62 functions will increment the reference count for the vnode in question.
63 The reference count has to be decremented after use of the vnode, by
68 depending on whether the
70 flag was specified or not.
74 function is used to initialize
77 It takes the following arguments:
78 .Bl -tag -width ".Fa segflg"
81 .Vt "struct nameidata"
87 The following operations are valid:
88 .Dv LOOKUP , CREATE , DELETE ,
91 The latter three are just setup for those
99 Several of these can be effective at the same time.
101 UIO segment indicator.
102 This indicates if the name of the object is in userspace
104 or in the kernel address space
105 .Pq Dv UIO_SYSSPACE .
107 Pointer to the component's pathname buffer
108 (the file or directory name that will be looked up).
110 The thread context to use for
112 operations and locks.
114 .Sh NAMEI OPERATION FLAGS
117 function takes the following set of
118 .Dq "operation flags"
119 that influence its operation:
120 .Bl -tag -width ".Dv WANTPARENT"
122 Lock vnode on return with
130 to release the lock (or
132 which is equivalent to calling
140 function return the parent (directory) vnode,
142 in locked state, unless it is identical to
146 is not locked per se (but may be locked due to
148 If a lock is enforced, it should be released using
155 Lock vnode on return with
160 to release the lock (or
162 which is equivalent to calling
170 function to return the parent (directory) vnode in an unlocked state.
171 The parent vnode must be released separately by using
176 creating this entry in the namecache if it is not
180 will add entries to the name cache
181 if they are not already there.
185 will follow the symbolic link if the last part
186 of the path supplied is a symbolic link (i.e., it will return a vnode
187 for whatever the link points at, instead for the link itself).
189 Do not follow symbolic links (pseudo).
190 This flag is not looked for by the actual code, which looks for
193 is used to indicate to the source code reader that symlinks
194 are intentionally not followed.
196 Do not free the pathname buffer at the end of the
198 invocation; instead, free it later in
200 so that the caller may access the pathname buffer.
201 See below for details.
203 Retain an additional reference to the parent directory; do not free
205 See below for details.
207 .Sh ALLOCATED ELEMENTS
210 structure is composed of the following fields:
211 .Bl -tag -width ".Va ni_cnd.cn_pnbuf"
213 In the normal case, this is either the current directory or the root.
214 It is the current directory if the name passed in does not start with
216 and we have not gone through any symlinks with an absolute path, and
219 In this case, it is only used by
222 considered valid after a call to
225 Vnode pointer to directory of the object on which lookup is performed.
226 This is available on successful return if
235 Vnode pointer to the resulting object,
240 field of this vnode is incremented.
243 is set, it is also locked.
245 .It Va ni_cnd.cn_pnbuf
246 The pathname buffer contains the location of the file or directory
247 that will be used by the
252 zone allocation interface.
257 will return 0, otherwise it will return an error.
260 .It Pa src/sys/kern/vfs_lookup.c
268 A component of the specified pathname is not a directory when a directory is
270 .It Bq Er ENAMETOOLONG
271 A component of a pathname exceeded 255 characters,
272 or an entire pathname exceeded 1023 characters.
274 A component of the specified pathname does not exist,
275 or the pathname is an empty string.
277 An attempt is made to access a file in a way forbidden by its file access
280 Too many symbolic links were encountered in translating the pathname.
282 An attempt is made to open a directory with write mode specified.
284 The last component of the pathname specified for a
291 An attempt is made to modify a file or directory on a read-only file system.
302 This manual page was written by
303 .An Eivind Eklund Aq Mt eivind@FreeBSD.org
304 and later significantly revised by
305 .An Hiten M. Pandya Aq Mt hmp@FreeBSD.org .
309 flag does not always result in the parent vnode being locked.
310 This results in complications when the
313 In order to solve this for the cases where both
317 are used, it is necessary to resort to recursive locking.