xref: /freebsd/share/man/man9/namei.9 (revision 6b8a3687a192349bffaf5a21048543dbdaaa4b9a)
1c78f3f0dSEivind Eklund.\"
29a8fa3c1SEivind Eklund.\" Copyright (c) 1998, 1999 Eivind Eklund
309f84dd1SRuslan Ermilov.\" Copyright (c) 2003 Hiten M. Pandya
46b8a3687SRobert Watson.\" Copyright (c) 2005 Robert N. M. Watson
5c78f3f0dSEivind Eklund.\"
6c78f3f0dSEivind Eklund.\" All rights reserved.
7c78f3f0dSEivind Eklund.\"
8c78f3f0dSEivind Eklund.\" This program is free software.
9c78f3f0dSEivind Eklund.\"
10c78f3f0dSEivind Eklund.\" Redistribution and use in source and binary forms, with or without
11c78f3f0dSEivind Eklund.\" modification, are permitted provided that the following conditions
12c78f3f0dSEivind Eklund.\" are met:
13c78f3f0dSEivind Eklund.\" 1. Redistributions of source code must retain the above copyright
14c78f3f0dSEivind Eklund.\"    notice, this list of conditions and the following disclaimer.
15c78f3f0dSEivind Eklund.\" 2. Redistributions in binary form must reproduce the above copyright
16c78f3f0dSEivind Eklund.\"    notice, this list of conditions and the following disclaimer in the
17c78f3f0dSEivind Eklund.\"    documentation and/or other materials provided with the distribution.
18c78f3f0dSEivind Eklund.\"
19c78f3f0dSEivind Eklund.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
20c78f3f0dSEivind Eklund.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c78f3f0dSEivind Eklund.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22c78f3f0dSEivind Eklund.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
23c78f3f0dSEivind Eklund.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24c78f3f0dSEivind Eklund.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25c78f3f0dSEivind Eklund.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26c78f3f0dSEivind Eklund.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27c78f3f0dSEivind Eklund.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28c78f3f0dSEivind Eklund.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c78f3f0dSEivind Eklund.\"
30c78f3f0dSEivind Eklund.\"
31c78f3f0dSEivind Eklund.\" If you integrate this manpage in another OS, I'd appreciate a note
32e87b9f28SJeroen Ruigrok van der Werven.\"	- eivind@FreeBSD.org
33c78f3f0dSEivind Eklund.\"
347f3dea24SPeter Wemm.\" $FreeBSD$
35c78f3f0dSEivind Eklund.\"
3615c3fb05SHiten Pandya.Dd May 27, 2003
37c78f3f0dSEivind Eklund.Os
38def37e7cSMike Pritchard.Dt NAMEI 9
39c78f3f0dSEivind Eklund.Sh NAME
40c78f3f0dSEivind Eklund.Nm namei ,
4115c3fb05SHiten Pandya.Nm NDINIT ,
426b8a3687SRobert Watson.Nm NDFREE ,
436b8a3687SRobert Watson.Nm NDHASGIANT
4415c3fb05SHiten Pandya.Nd pathname translation and lookup operations
45c78f3f0dSEivind Eklund.Sh SYNOPSIS
46f16b3c0dSChad David.In sys/param.h
47f16b3c0dSChad David.In sys/proc.h
4832eef9aeSRuslan Ermilov.In sys/namei.h
49c78f3f0dSEivind Eklund.Ft int
50c78f3f0dSEivind Eklund.Fn namei "struct nameidata *ndp"
51c78f3f0dSEivind Eklund.Ft void
5209f84dd1SRuslan Ermilov.Fo NDINIT
5309f84dd1SRuslan Ermilov.Fa "struct nameidata *ndp" "u_long op" "u_long flags"
5409f84dd1SRuslan Ermilov.Fa "enum uio_seg segflg" "const char *namep" "struct thread *td"
5509f84dd1SRuslan Ermilov.Fc
56eac993bcSBruce Evans.Ft void
5715c3fb05SHiten Pandya.Fn NDFREE "struct nameidata *ndp" "const uint flags"
586b8a3687SRobert Watson.Ft int
596b8a3687SRobert Watson.Fn NDHASGIANT "struct nameidata *ndp"
60c78f3f0dSEivind Eklund.Sh DESCRIPTION
6160dca836SPhilippe CharnierThe
6215c3fb05SHiten Pandya.Nm
6315c3fb05SHiten Pandyafacility allows the client to perform pathname translation and lookup
6415c3fb05SHiten Pandyaoperations.
6515c3fb05SHiten PandyaThe
6615c3fb05SHiten Pandya.Nm
6715c3fb05SHiten Pandyafunctions will increment the reference count for the vnode in question.
6815c3fb05SHiten PandyaThe reference count has to be decremented after use of the vnode, by
6915c3fb05SHiten Pandyausing either
70c78f3f0dSEivind Eklund.Xr vrele 9
71c78f3f0dSEivind Eklundor
72c78f3f0dSEivind Eklund.Xr vput 9 ,
7309f84dd1SRuslan Ermilovdepending on whether the
7415c3fb05SHiten Pandya.Dv LOCKLEAF
7509f84dd1SRuslan Ermilovflag was specified or not.
766b8a3687SRobert WatsonIf the
776b8a3687SRobert Watson.Va Giant
786b8a3687SRobert Watsonlock is required,
796b8a3687SRobert Watson.Nm
806b8a3687SRobert Watsonwill acquire it if the caller indicates it is
816b8a3687SRobert Watson.Dv MPSAFE ,
826b8a3687SRobert Watsonin which case the caller must later release
836b8a3687SRobert Watson.Va Giant
846b8a3687SRobert Watsonbased on the results of
856b8a3687SRobert Watson.Fn NDHASGIANT.
86c78f3f0dSEivind Eklund.Pp
8715c3fb05SHiten PandyaThe
8815c3fb05SHiten Pandya.Fn NDINIT
8915c3fb05SHiten Pandyafunction is used to initialize
9015c3fb05SHiten Pandya.Nm
9115c3fb05SHiten Pandyacomponents.
92c78f3f0dSEivind EklundIt takes the following arguments:
9309f84dd1SRuslan Ermilov.Bl -tag -width ".Fa segflg"
9415c3fb05SHiten Pandya.It Fa ndp
9515c3fb05SHiten PandyaThe
9615c3fb05SHiten Pandya.Vt "struct nameidata"
9715c3fb05SHiten Pandyato initialize.
9815c3fb05SHiten Pandya.It Fa op
9915c3fb05SHiten PandyaThe operation which
100c78f3f0dSEivind Eklund.Fn namei
10115c3fb05SHiten Pandyawill perform.
10215c3fb05SHiten PandyaThe following operations are valid:
10309f84dd1SRuslan Ermilov.Dv LOOKUP , CREATE , DELETE ,
104c78f3f0dSEivind Eklundand
105c78f3f0dSEivind Eklund.Dv RENAME .
106c78f3f0dSEivind EklundThe latter three are just setup for those
107c78f3f0dSEivind Eklundeffects; just calling
108c78f3f0dSEivind Eklund.Fn namei
109c78f3f0dSEivind Eklundwill not result in
110c78f3f0dSEivind Eklund.Fn VOP_RENAME
111c78f3f0dSEivind Eklundbeing called.
11215c3fb05SHiten Pandya.It Fa flags
11315c3fb05SHiten PandyaOperation flags.
11415c3fb05SHiten PandyaSeveral of these can be effective at the same time.
11515c3fb05SHiten Pandya.It Fa segflg
11615c3fb05SHiten PandyaUIO segment indicator.
11715c3fb05SHiten PandyaThis indicates if the name of the object is in userspace
11815c3fb05SHiten Pandya.Pq Dv UIO_USERSPACE
11915c3fb05SHiten Pandyaor in the kernel address space
12015c3fb05SHiten Pandya.Pq Dv UIO_SYSSPACE .
12115c3fb05SHiten Pandya.It Fa namep
12215c3fb05SHiten PandyaPointer to the component's pathname buffer
12309f84dd1SRuslan Ermilov(the file or directory name that will be looked up).
12415c3fb05SHiten Pandya.It Fa td
12515c3fb05SHiten PandyaThe thread context to use for
12615c3fb05SHiten Pandya.Nm
12715c3fb05SHiten Pandyaoperations and locks.
128c78f3f0dSEivind Eklund.El
129c78f3f0dSEivind Eklund.Sh NAMEI OPERATION FLAGS
13060dca836SPhilippe CharnierThe
131c78f3f0dSEivind Eklund.Fn namei
13215c3fb05SHiten Pandyafunction takes the following set of
13309f84dd1SRuslan Ermilov.Dq "operation flags"
13415c3fb05SHiten Pandyathat influence its operation:
13509f84dd1SRuslan Ermilov.Bl -tag -width ".Dv WANTPARENT"
136c78f3f0dSEivind Eklund.It Dv LOCKLEAF
13715c3fb05SHiten PandyaLock vnode on return.
13809f84dd1SRuslan ErmilovThis is a full lock of the vnode; the
139c78f3f0dSEivind Eklund.Xr VOP_UNLOCK 9
14009f84dd1SRuslan Ermilovshould be used
14109f84dd1SRuslan Ermilovto release the lock (or
142c78f3f0dSEivind Eklund.Xr vput 9
14309f84dd1SRuslan Ermilovwhich is equivalent to calling
14409f84dd1SRuslan Ermilov.Xr VOP_UNLOCK 9
14509f84dd1SRuslan Ermilovfollowed by
146c78f3f0dSEivind Eklund.Xr vrele 9 ,
147c78f3f0dSEivind Eklundall in one).
148c78f3f0dSEivind Eklund.It Dv LOCKPARENT
14915c3fb05SHiten PandyaThis flag lets the
150c78f3f0dSEivind Eklund.Fn namei
15115c3fb05SHiten Pandyafunction return the parent (directory) vnode,
15215c3fb05SHiten Pandya.Va ni_dvp
15315c3fb05SHiten Pandyain locked state, unless it is identical to
15415c3fb05SHiten Pandya.Va ni_vp ,
15515c3fb05SHiten Pandyain which case
15615c3fb05SHiten Pandya.Va ni_dvp
15715c3fb05SHiten Pandyais not locked per se (but may be locked due to
15815c3fb05SHiten Pandya.Dv LOCKLEAF ) .
15915c3fb05SHiten PandyaIf a lock is enforced, it should be released using
160c78f3f0dSEivind Eklund.Xr vput 9
161c78f3f0dSEivind Eklundor
162c78f3f0dSEivind Eklund.Xr VOP_UNLOCK 9
163c78f3f0dSEivind Eklundand
16415c3fb05SHiten Pandya.Xr vrele 9 .
165c78f3f0dSEivind Eklund.It Dv WANTPARENT
16615c3fb05SHiten PandyaThis flag allows the
167c78f3f0dSEivind Eklund.Fn namei
16815c3fb05SHiten Pandyafunction to return the parent (directory) vnode in an unlocked state.
16915c3fb05SHiten PandyaThe parent vnode must be released separately by using
17015c3fb05SHiten Pandya.Xr vrele 9 .
1716b8a3687SRobert Watson.It Dv MPSAFE
1726b8a3687SRobert WatsonWith this flag set,
1736b8a3687SRobert Watson.Fn namei
1746b8a3687SRobert Watsonwill conditionally acquire
1756b8a3687SRobert Watson.Va Giant
1766b8a3687SRobert Watsonif it is required by a traversed file system.
1776b8a3687SRobert WatsonMPSAFE callers should pass the results of
1786b8a3687SRobert Watson.Fn NDHASGIANT
1796b8a3687SRobert Watsonto
1806b8a3687SRobert Watson.Xr VFS_UNLOCK_GIANT
1816b8a3687SRobert Watsonin order to conditionally release
1826b8a3687SRobert Watson.Va Giant
1836b8a3687SRobert Watsonif necessary.
184c78f3f0dSEivind Eklund.It Dv NOCACHE
185c78f3f0dSEivind EklundAvoid
186c78f3f0dSEivind Eklund.Fn namei
187c78f3f0dSEivind Eklundcreating this entry in the namecache if it is not
18809f84dd1SRuslan Ermilovalready present.
18909f84dd1SRuslan ErmilovNormally,
190c78f3f0dSEivind Eklund.Fn namei
191c78f3f0dSEivind Eklundwill add entries to the name cache
19209f84dd1SRuslan Ermilovif they are not already there.
193c78f3f0dSEivind Eklund.It Dv FOLLOW
194c78f3f0dSEivind EklundWith this flag,
195c78f3f0dSEivind Eklund.Fn namei
196c78f3f0dSEivind Eklundwill follow the symbolic link if the last part
197c78f3f0dSEivind Eklundof the path supplied is a symbolic link (i.e., it will return a vnode
198c78f3f0dSEivind Eklundfor whatever the link points at, instead for the link itself).
199c78f3f0dSEivind Eklund.It Dv NOOBJ
200c78f3f0dSEivind EklundDo not call
201c78f3f0dSEivind Eklund.Fn vfs_object_create
20215c3fb05SHiten Pandyafor the returned vnode, even though it meets required criteria for VM support.
203c78f3f0dSEivind Eklund.It Dv NOFOLLOW
2049a8fa3c1SEivind EklundDo not follow symbolic links (pseudo).
2059a8fa3c1SEivind EklundThis flag is not looked for by the actual code, which looks for
20615c3fb05SHiten Pandya.Dv FOLLOW .
20715c3fb05SHiten Pandya.Dv NOFOLLOW
20815c3fb05SHiten Pandyais used to indicate to the source code reader that symlinks
2099a8fa3c1SEivind Eklundare intentionally not followed.
210060c42c3SRobert Watson.It Dv SAVENAME
21115c3fb05SHiten PandyaDo not free the pathname buffer at the end of the
212060c42c3SRobert Watson.Fn namei
21309f84dd1SRuslan Ermilovinvocation; instead, free it later in
214060c42c3SRobert Watson.Fn NDFREE
21515c3fb05SHiten Pandyaso that the caller may access the pathname buffer.
216060c42c3SRobert WatsonSee below for details.
217060c42c3SRobert Watson.It Dv SAVESTART
218060c42c3SRobert WatsonRetain an additional reference to the parent directory; do not free
21915c3fb05SHiten Pandyathe pathname buffer.
220060c42c3SRobert WatsonSee below for details.
221c78f3f0dSEivind Eklund.El
2229a8fa3c1SEivind Eklund.Sh ALLOCATED ELEMENTS
22315c3fb05SHiten PandyaThe
22415c3fb05SHiten Pandya.Vt nameidata
22515c3fb05SHiten Pandyastructure is composed of the following fields:
22609f84dd1SRuslan Ermilov.Bl -tag -width ".Va ni_cnd.cn_pnbuf"
22715c3fb05SHiten Pandya.It Va ni_startdir
2289a8fa3c1SEivind EklundIn the normal case, this is either the current directory or the root.
22909f84dd1SRuslan ErmilovIt is the current directory if the name passed in does not start with
23009f84dd1SRuslan Ermilov.Ql /
2319a8fa3c1SEivind Eklundand we have not gone through any symlinks with an absolute path, and
2329a8fa3c1SEivind Eklundthe root otherwise.
2333136363fSRuslan Ermilov.Pp
2349e28aca5SDima DorfmanIn this case, it is only used by
2359e28aca5SDima Dorfman.Fn lookup ,
2369e28aca5SDima Dorfmanand should not be
2379e28aca5SDima Dorfmanconsidered valid after a call to
2389e28aca5SDima Dorfman.Fn namei .
23915c3fb05SHiten PandyaIf
24015c3fb05SHiten Pandya.Dv SAVESTART
24115c3fb05SHiten Pandyais set, this is set to the same as
24215c3fb05SHiten Pandya.Va ni_dvp ,
24315c3fb05SHiten Pandyawith an extra
24415c3fb05SHiten Pandya.Xr vref 9 .
24515c3fb05SHiten PandyaTo block
24615c3fb05SHiten Pandya.Fn NDFREE
24715c3fb05SHiten Pandyafrom releasing
24815c3fb05SHiten Pandya.Va ni_startdir ,
24915c3fb05SHiten Pandyathe
25015c3fb05SHiten Pandya.Dv NDF_NO_STARTDIR_RELE
25115c3fb05SHiten Pandyacan be set.
25215c3fb05SHiten Pandya.It Va ni_dvp
25315c3fb05SHiten PandyaVnode pointer to directory of the object on which lookup is performed.
25415c3fb05SHiten PandyaThis is available on successful return if
25515c3fb05SHiten Pandya.Dv LOCKPARENT
25615c3fb05SHiten Pandyaor
25715c3fb05SHiten Pandya.Dv WANTPARENT
25815c3fb05SHiten Pandyais set.
25915c3fb05SHiten PandyaIt is locked if
26015c3fb05SHiten Pandya.Dv LOCKPARENT
26115c3fb05SHiten Pandyais set.
26215c3fb05SHiten PandyaFreeing this in
26309f84dd1SRuslan Ermilov.Fn NDFREE
26415c3fb05SHiten Pandyacan be inhibited by
26509f84dd1SRuslan Ermilov.Dv NDF_NO_DVP_RELE , NDF_NO_DVP_PUT ,
26615c3fb05SHiten Pandyaor
26715c3fb05SHiten Pandya.Dv NDF_NO_DVP_UNLOCK
2689a8fa3c1SEivind Eklund(with the obvious effects).
26915c3fb05SHiten Pandya.It Va ni_vp
27015c3fb05SHiten PandyaVnode pointer to the resulting object,
27115c3fb05SHiten Pandya.Dv NULL
27215c3fb05SHiten Pandyaotherwise.
27315c3fb05SHiten PandyaThe
27415c3fb05SHiten Pandya.Va v_usecount
27515c3fb05SHiten Pandyafield of this vnode is incremented.
27615c3fb05SHiten PandyaIf
27715c3fb05SHiten Pandya.Dv LOCKLEAF
27815c3fb05SHiten Pandyais set, it is also locked.
2793136363fSRuslan Ermilov.Pp
28015c3fb05SHiten PandyaFreeing this in
28115c3fb05SHiten Pandya.Fn NDFREE
28215c3fb05SHiten Pandyacan be inhibited by
28309f84dd1SRuslan Ermilov.Dv NDF_NO_VP_RELE , NDF_NO_VP_PUT ,
28415c3fb05SHiten Pandyaor
28515c3fb05SHiten Pandya.Dv NDF_NO_VP_UNLOCK
28609f84dd1SRuslan Ermilov(with the obvious effects).
28715c3fb05SHiten Pandya.It Va ni_cnd.cn_pnbuf
28815c3fb05SHiten PandyaThe pathname buffer contains the location of the file or directory
28915c3fb05SHiten Pandyathat will be used by the
29015c3fb05SHiten Pandya.Nm
29115c3fb05SHiten Pandyaoperations.
29215c3fb05SHiten PandyaIt is managed by the
29315c3fb05SHiten Pandya.Xr uma 9
29415c3fb05SHiten Pandyazone allocation interface.
29515c3fb05SHiten PandyaIf the
29615c3fb05SHiten Pandya.Dv SAVESTART
29715c3fb05SHiten Pandyaor
29815c3fb05SHiten Pandya.Dv SAVENAME
29915c3fb05SHiten Pandyaflag is set, then the pathname buffer is available
30015c3fb05SHiten Pandyaafter calling the
30109f84dd1SRuslan Ermilov.Fn namei
30215c3fb05SHiten Pandyafunction.
3033136363fSRuslan Ermilov.Pp
30415c3fb05SHiten PandyaTo only deallocate resources used by the pathname buffer,
30515c3fb05SHiten Pandya.Va ni_cnd.cn_pnbuf ,
30615c3fb05SHiten Pandyathen
30715c3fb05SHiten Pandya.Dv NDF_ONLY_PNBUF
30815c3fb05SHiten Pandyaflag can be passed to the
30915c3fb05SHiten Pandya.Fn NDFREE
31015c3fb05SHiten Pandyafunction.
31115c3fb05SHiten PandyaTo keep the pathname buffer intact,
31215c3fb05SHiten Pandyathe
313eafe5f83SChristian Brueffer.Dv NDF_NO_FREE_PNBUF
31415c3fb05SHiten Pandyaflag can be passed to the
31515c3fb05SHiten Pandya.Fn NDFREE
31615c3fb05SHiten Pandyafunction.
3173136363fSRuslan Ermilov.El
31815c3fb05SHiten Pandya.Sh FILES
31909f84dd1SRuslan Ermilov.Bl -tag
32009f84dd1SRuslan Ermilov.It Pa src/sys/kern/vfs_lookup.c
32109f84dd1SRuslan Ermilov.El
32215c3fb05SHiten Pandya.Sh SEE ALSO
32315c3fb05SHiten Pandya.Xr uio 9 ,
32415c3fb05SHiten Pandya.Xr uma 9 ,
32515c3fb05SHiten Pandya.Xr VFS 9 ,
3266b8a3687SRobert Watson.Xr VFS_UNLOCK_GIANT 9 ,
32715c3fb05SHiten Pandya.Xr vnode 9 ,
32815c3fb05SHiten Pandya.Xr vput 9 ,
32915c3fb05SHiten Pandya.Xr vref 9
330c78f3f0dSEivind Eklund.Sh AUTHORS
33109f84dd1SRuslan Ermilov.An -nosplit
33215c3fb05SHiten PandyaThis manual page was written by
33309f84dd1SRuslan Ermilov.An Eivind Eklund Aq eivind@FreeBSD.org
33415c3fb05SHiten Pandyaand later significantly revised by
33509f84dd1SRuslan Ermilov.An Hiten M. Pandya Aq hmp@FreeBSD.org .
33615c3fb05SHiten Pandya.Sh BUGS
33715c3fb05SHiten PandyaThe
33815c3fb05SHiten Pandya.Dv LOCKPARENT
33915c3fb05SHiten Pandyaflag does not always result in the parent vnode being locked.
34015c3fb05SHiten PandyaThis results in complications when the
34115c3fb05SHiten Pandya.Dv LOCKPARENT
34215c3fb05SHiten Pandyais used.
34315c3fb05SHiten PandyaIn order to solve this for the cases where both
34415c3fb05SHiten Pandya.Dv LOCKPARENT
34515c3fb05SHiten Pandyaand
34615c3fb05SHiten Pandya.Dv LOCKLEAF
34715c3fb05SHiten Pandyaare used, it is necessary to resort to recursive locking.
3486b8a3687SRobert Watson.Pp
3496b8a3687SRobert WatsonNon-MPSAFE file systems exist, requiring callers to conditionally unlock
3506b8a3687SRobert Watson.Va Giant .
351