1 .\" $NetBSD: namei.9,v 1.23 2009/09/27 17:23:53 dholland Exp $
3 .\" Copyright (c) 2001, 2005, 2006 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Gregory McGarry.
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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
30 .Dd September 27, 2009
36 .Nm lookup_for_nfsd_index ,
39 .Nm namei_simple_kernel ,
47 .Fn namei "struct nameidata *ndp"
49 .Fn lookup_for_nfsd "struct nameidata *ndp" "struct vnode *startdir" \
52 .Fn lookup_for_nfsd_index "struct nameidata *ndp"
54 .Fn relookup "struct vnode *dvp" "struct vnode **vpp" \
55 "struct componentname *cnp"
57 .Fn NDINIT "struct nameidata *ndp" "u_long op" "u_long flags" \
58 "enum uio_seg segflg" "const char *namep"
60 .Fn namei_simple_kernel "const char *path" "namei_simple_flags_t sflags" \
63 .Fn namei_simple_user "const char *path" "namei_simple_flags_t sflags" \
68 interface is used to convert pathnames to file system vnodes.
70 name of the interface is actually a contraction of the words
74 for name-to-inode conversion, in the days before the
76 interface was implemented.
78 Except for the simple forms, the arguments passed to the functions are
82 It has the following structure:
86 * Arguments to namei/lookup.
88 const char *ni_dirp; /* pathname pointer */
89 enum uio_seg ni_segflg; /* location of pathname */
91 * Arguments to lookup.
93 struct vnode *ni_startdir; /* starting directory */
94 struct vnode *ni_rootdir; /* logical root directory */
96 * Results: returned from/manipulated by lookup
98 struct vnode *ni_vp; /* vnode of result */
99 struct vnode *ni_dvp; /* vnode of intermediate dir */
101 * Shared between namei and lookup/commit routines.
103 size_t ni_pathlen; /* remaining chars in path */
104 const char *ni_next; /* next location in pathname */
105 u_long ni_loopcnt; /* count of symlinks encountered */
109 struct componentname {
111 * Arguments to lookup.
113 u_long cn_nameiop; /* namei operation */
114 u_long cn_flags; /* flags to namei */
115 kauth_cred_t cn_cred; /* credentials */
117 * Shared between lookup and commit routines.
119 char *cn_pnbuf; /* pathname buffer */
120 const char *cn_nameptr; /* pointer to looked up name */
121 long cn_namelen; /* length of looked up component */
122 u_long cn_hash; /* hash value of looked up name */
123 long cn_consume; /* chars to consume in lookup() */
130 interface accesses vnode operations by passing arguments in the
131 partially initialised
135 This structure describes the subset of information from the nameidata
136 structure that is passed through to the vnode operations.
139 for more information.
140 The details of the componentname structure are not absolutely necessary
141 since the members are initialised by the helper macro
143 It is useful to know the operations and flags as specified in
150 with some additional flags.
151 These flags should be specific to the
153 interface and ignored by vnode operations.
154 However, due to the historic close relationship between the
156 interface and the vnode operations, these flags are sometimes used
157 (and set) by vnode operations, particularly
159 The additional flags are:
161 .Bl -tag -offset indent -width NOCROSSMOUNT -compact
163 do not cross mount points
165 lookup with read-only semantics
167 caller has allocated pathname buffer
172 save starting directory
174 current pathname component is ..
176 add entry to the name cache
178 this is last component of pathname
180 symlink needs interpretation
188 trailing slashes are ok
190 mask of parameter descriptors
195 sets the SAVENAME flag, then it must free the buffer.
198 sets the flag, then the buffer must be freed by either the commit
204 flag is set only by the callers of
208 plus the addition of saving the parent directory
209 that contains the name in
211 It allows repeated calls to
213 for the name being sought.
214 The caller is responsible for releasing the buffer and for invoking
221 interface must be in process context.
222 Pathname lookups cannot be done in interrupt context.
224 .Bl -tag -width compact
226 Convert a pathname into a pointer to a vnode.
227 The pathname is specified by
228 .Em ndp-\*[Gt]ni_dirp
230 .Em ndp-\*[Gt]ni_pathlen .
233 flags defines whether the name in
234 .Em ndp-\*[Gt]ni_dirp
235 is an address in kernel space
237 or an address in user space
238 .Pq Dv UIO_USERSPACE .
240 The vnode for the pathname is returned in
241 .Em ndp-\*[Gt]ni_vp .
242 The parent directory is returned locked in
249 .Em ndp-\*[Gt]ni_cnd.cn_flags
252 flag set then symbolic links are followed when they
253 occur at the end of the name translation process.
254 Symbolic links are always followed for all other pathname components
259 had a sub-function called
261 This function processed a pathname until either running out of
262 material or encountering a symbolic link.
264 worked by first setting up the start directory
265 .Em ndp-\*[Gt]ni_startdir
272 are altered by the operation specified by
273 .Em ndp-\*[Gt]ni_cnd.cn_nameiop .
279 is specified, information usable in
280 creating, renaming, or deleting a directory entry may be calculated.
282 If the target of the pathname exists and LOCKLEAF is set, the target
283 is returned locked in
284 .Em ndp-\*[Gt]ni_vp ,
285 otherwise it is returned unlocked.
287 As of this writing the internal function
289 is comparable to the historic
291 but this code is slated for refactoring.
292 .It Fn lookup_for_nfsd "ndp" "startdir" "neverfollow"
293 This is a private entry point into
295 used by the NFS server code.
296 It looks up a path starting from
302 symbolic link (not just at the end of the path) will cause an error.
303 Otherwise, it follows symlinks normally.
304 Its semantics are similar to a symlink-following loop around the historic
306 function described above.
307 It should not be used by new code.
308 .It Fn lookup_for_nfsd_index "ndp"
309 This is a (second) private entry point into
311 used by the NFS server code.
312 Its semantics are similar to the historic
314 function described above.
315 It should not be used by new code.
316 .It Fn relookup "dvp" "vpp" "cnp"
317 Reacquire a path name component is a directory.
318 This is a quicker way to lookup a pathname component when the parent
320 The locked parent directory vnode is specified by
322 and the pathname component by
324 The vnode of the pathname is returned in the address specified by
326 .It Fn NDINIT "ndp" "op" "flags" "segflg" "namep"
327 Initialise a nameidata structure pointed to by
332 It saves having to deal with the componentname structure inside
334 The operation and flags are specified by
339 These are the values to which
340 .Em ndp-\*[Gt]ni_cnd.cn_nameiop
342 .Em ndp-\*[Gt]ni_cnd.cn_flags
343 are respectively set.
344 The segment flags which defines whether the pathname is in kernel
345 address space or user address space is specified by
349 is a pointer to the pathname that
350 .Em ndp-\*[Gt]ni_dirp
353 This routine stores the credentials of the calling thread
357 In the rare case that another set of credentials is required for the
359 .Em ndp-\*[Gt]ni_cnd.cn_cred
360 must be set manually.
361 .It Fn namei_simple_kernel "path" "sflags" "ret"
364 and translate it to a vnode, returned in
368 argument must be a kernel
373 argument chooses the precise behavior.
374 It may be set to one of the following symbols:
375 .Bl -tag -offset indent -width NSM_NOFOLLOW_TRYEMULROOT -compact
376 .It Dv NSM_NOFOLLOW_NOEMULROOT
377 .It Dv NSM_NOFOLLOW_TRYEMULROOT
378 .It Dv NSM_FOLLOW_NOEMULROOT
379 .It Dv NSM_FOLLOW_TRYEMULROOT
381 These select (or not) the
386 Other flags are not available through this interface, which is
387 nonetheless sufficient for more than half the
390 Note that the encoding of
392 has deliberately been arranged to be type-incompatible with anything
394 This prevents various possible accidents while the
396 interface is being rototilled.
397 .It Fn namei_simple_user "path" "sflags" "ret"
398 This function is the same as
399 .Fn namei_simple_kernel
402 argument shall be a user pointer
404 rather than a kernel pointer.
407 This section describes places within the
409 source tree where actual code implementing or using the name
410 lookup subsystem can be found.
411 All pathnames are relative to
414 The name lookup subsystem is implemented within the file
415 .Pa sys/kern/vfs_lookup.c .
423 It is unfortunate that much of the
425 interface makes assumptions on the underlying vnode operations.
426 These assumptions are an artefact of the introduction of the vfs
427 interface to split a file system interface which was historically
428 designed as a tightly coupled module.