xref: /freebsd/share/man/man9/namei.9 (revision eafe5f83074df014d5e13fb331a188d21790e992)
1c78f3f0dSEivind Eklund.\"
29a8fa3c1SEivind Eklund.\" Copyright (c) 1998, 1999 Eivind Eklund
309f84dd1SRuslan Ermilov.\" Copyright (c) 2003 Hiten M. Pandya
4c78f3f0dSEivind Eklund.\"
5c78f3f0dSEivind Eklund.\" All rights reserved.
6c78f3f0dSEivind Eklund.\"
7c78f3f0dSEivind Eklund.\" This program is free software.
8c78f3f0dSEivind Eklund.\"
9c78f3f0dSEivind Eklund.\" Redistribution and use in source and binary forms, with or without
10c78f3f0dSEivind Eklund.\" modification, are permitted provided that the following conditions
11c78f3f0dSEivind Eklund.\" are met:
12c78f3f0dSEivind Eklund.\" 1. Redistributions of source code must retain the above copyright
13c78f3f0dSEivind Eklund.\"    notice, this list of conditions and the following disclaimer.
14c78f3f0dSEivind Eklund.\" 2. Redistributions in binary form must reproduce the above copyright
15c78f3f0dSEivind Eklund.\"    notice, this list of conditions and the following disclaimer in the
16c78f3f0dSEivind Eklund.\"    documentation and/or other materials provided with the distribution.
17c78f3f0dSEivind Eklund.\"
18c78f3f0dSEivind Eklund.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19c78f3f0dSEivind Eklund.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20c78f3f0dSEivind Eklund.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21c78f3f0dSEivind Eklund.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22c78f3f0dSEivind Eklund.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23c78f3f0dSEivind Eklund.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24c78f3f0dSEivind Eklund.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25c78f3f0dSEivind Eklund.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26c78f3f0dSEivind Eklund.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27c78f3f0dSEivind Eklund.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28c78f3f0dSEivind Eklund.\"
29c78f3f0dSEivind Eklund.\"
30c78f3f0dSEivind Eklund.\" If you integrate this manpage in another OS, I'd appreciate a note
31e87b9f28SJeroen Ruigrok van der Werven.\"	- eivind@FreeBSD.org
32c78f3f0dSEivind Eklund.\"
337f3dea24SPeter Wemm.\" $FreeBSD$
34c78f3f0dSEivind Eklund.\"
3515c3fb05SHiten Pandya.Dd May 27, 2003
36c78f3f0dSEivind Eklund.Os
37def37e7cSMike Pritchard.Dt NAMEI 9
38c78f3f0dSEivind Eklund.Sh NAME
39c78f3f0dSEivind Eklund.Nm namei ,
4015c3fb05SHiten Pandya.Nm NDINIT ,
4115c3fb05SHiten Pandya.Nm NDFREE
4215c3fb05SHiten Pandya.Nd pathname translation and lookup operations
43c78f3f0dSEivind Eklund.Sh SYNOPSIS
44f16b3c0dSChad David.In sys/param.h
45f16b3c0dSChad David.In sys/proc.h
4632eef9aeSRuslan Ermilov.In sys/namei.h
47c78f3f0dSEivind Eklund.Ft int
48c78f3f0dSEivind Eklund.Fn namei "struct nameidata *ndp"
49c78f3f0dSEivind Eklund.Ft void
5009f84dd1SRuslan Ermilov.Fo NDINIT
5109f84dd1SRuslan Ermilov.Fa "struct nameidata *ndp" "u_long op" "u_long flags"
5209f84dd1SRuslan Ermilov.Fa "enum uio_seg segflg" "const char *namep" "struct thread *td"
5309f84dd1SRuslan Ermilov.Fc
54eac993bcSBruce Evans.Ft void
5515c3fb05SHiten Pandya.Fn NDFREE "struct nameidata *ndp" "const uint flags"
56c78f3f0dSEivind Eklund.Sh DESCRIPTION
5760dca836SPhilippe CharnierThe
5815c3fb05SHiten Pandya.Nm
5915c3fb05SHiten Pandyafacility allows the client to perform pathname translation and lookup
6015c3fb05SHiten Pandyaoperations.
6115c3fb05SHiten PandyaThe
6215c3fb05SHiten Pandya.Nm
6315c3fb05SHiten Pandyafunctions will increment the reference count for the vnode in question.
6415c3fb05SHiten PandyaThe reference count has to be decremented after use of the vnode, by
6515c3fb05SHiten Pandyausing either
66c78f3f0dSEivind Eklund.Xr vrele 9
67c78f3f0dSEivind Eklundor
68c78f3f0dSEivind Eklund.Xr vput 9 ,
6909f84dd1SRuslan Ermilovdepending on whether the
7015c3fb05SHiten Pandya.Dv LOCKLEAF
7109f84dd1SRuslan Ermilovflag was specified or not.
72c78f3f0dSEivind Eklund.Pp
7315c3fb05SHiten PandyaThe
7415c3fb05SHiten Pandya.Fn NDINIT
7515c3fb05SHiten Pandyafunction is used to initialize
7615c3fb05SHiten Pandya.Nm
7715c3fb05SHiten Pandyacomponents.
78c78f3f0dSEivind EklundIt takes the following arguments:
7909f84dd1SRuslan Ermilov.Bl -tag -width ".Fa segflg"
8015c3fb05SHiten Pandya.It Fa ndp
8115c3fb05SHiten PandyaThe
8215c3fb05SHiten Pandya.Vt "struct nameidata"
8315c3fb05SHiten Pandyato initialize.
8415c3fb05SHiten Pandya.It Fa op
8515c3fb05SHiten PandyaThe operation which
86c78f3f0dSEivind Eklund.Fn namei
8715c3fb05SHiten Pandyawill perform.
8815c3fb05SHiten PandyaThe following operations are valid:
8909f84dd1SRuslan Ermilov.Dv LOOKUP , CREATE , DELETE ,
90c78f3f0dSEivind Eklundand
91c78f3f0dSEivind Eklund.Dv RENAME .
92c78f3f0dSEivind EklundThe latter three are just setup for those
93c78f3f0dSEivind Eklundeffects; just calling
94c78f3f0dSEivind Eklund.Fn namei
95c78f3f0dSEivind Eklundwill not result in
96c78f3f0dSEivind Eklund.Fn VOP_RENAME
97c78f3f0dSEivind Eklundbeing called.
9815c3fb05SHiten Pandya.It Fa flags
9915c3fb05SHiten PandyaOperation flags.
10015c3fb05SHiten PandyaSeveral of these can be effective at the same time.
10115c3fb05SHiten Pandya.It Fa segflg
10215c3fb05SHiten PandyaUIO segment indicator.
10315c3fb05SHiten PandyaThis indicates if the name of the object is in userspace
10415c3fb05SHiten Pandya.Pq Dv UIO_USERSPACE
10515c3fb05SHiten Pandyaor in the kernel address space
10615c3fb05SHiten Pandya.Pq Dv UIO_SYSSPACE .
10715c3fb05SHiten Pandya.It Fa namep
10815c3fb05SHiten PandyaPointer to the component's pathname buffer
10909f84dd1SRuslan Ermilov(the file or directory name that will be looked up).
11015c3fb05SHiten Pandya.It Fa td
11115c3fb05SHiten PandyaThe thread context to use for
11215c3fb05SHiten Pandya.Nm
11315c3fb05SHiten Pandyaoperations and locks.
114c78f3f0dSEivind Eklund.El
115c78f3f0dSEivind Eklund.Sh NAMEI OPERATION FLAGS
11660dca836SPhilippe CharnierThe
117c78f3f0dSEivind Eklund.Fn namei
11815c3fb05SHiten Pandyafunction takes the following set of
11909f84dd1SRuslan Ermilov.Dq "operation flags"
12015c3fb05SHiten Pandyathat influence its operation:
12109f84dd1SRuslan Ermilov.Bl -tag -width ".Dv WANTPARENT"
122c78f3f0dSEivind Eklund.It Dv LOCKLEAF
12315c3fb05SHiten PandyaLock vnode on return.
12409f84dd1SRuslan ErmilovThis is a full lock of the vnode; the
125c78f3f0dSEivind Eklund.Xr VOP_UNLOCK 9
12609f84dd1SRuslan Ermilovshould be used
12709f84dd1SRuslan Ermilovto release the lock (or
128c78f3f0dSEivind Eklund.Xr vput 9
12909f84dd1SRuslan Ermilovwhich is equivalent to calling
13009f84dd1SRuslan Ermilov.Xr VOP_UNLOCK 9
13109f84dd1SRuslan Ermilovfollowed by
132c78f3f0dSEivind Eklund.Xr vrele 9 ,
133c78f3f0dSEivind Eklundall in one).
134c78f3f0dSEivind Eklund.It Dv LOCKPARENT
13515c3fb05SHiten PandyaThis flag lets the
136c78f3f0dSEivind Eklund.Fn namei
13715c3fb05SHiten Pandyafunction return the parent (directory) vnode,
13815c3fb05SHiten Pandya.Va ni_dvp
13915c3fb05SHiten Pandyain locked state, unless it is identical to
14015c3fb05SHiten Pandya.Va ni_vp ,
14115c3fb05SHiten Pandyain which case
14215c3fb05SHiten Pandya.Va ni_dvp
14315c3fb05SHiten Pandyais not locked per se (but may be locked due to
14415c3fb05SHiten Pandya.Dv LOCKLEAF ) .
14515c3fb05SHiten PandyaIf a lock is enforced, it should be released using
146c78f3f0dSEivind Eklund.Xr vput 9
147c78f3f0dSEivind Eklundor
148c78f3f0dSEivind Eklund.Xr VOP_UNLOCK 9
149c78f3f0dSEivind Eklundand
15015c3fb05SHiten Pandya.Xr vrele 9 .
151c78f3f0dSEivind Eklund.It Dv WANTPARENT
15215c3fb05SHiten PandyaThis flag allows the
153c78f3f0dSEivind Eklund.Fn namei
15415c3fb05SHiten Pandyafunction to return the parent (directory) vnode in an unlocked state.
15515c3fb05SHiten PandyaThe parent vnode must be released separately by using
15615c3fb05SHiten Pandya.Xr vrele 9 .
157c78f3f0dSEivind Eklund.It Dv NOCACHE
158c78f3f0dSEivind EklundAvoid
159c78f3f0dSEivind Eklund.Fn namei
160c78f3f0dSEivind Eklundcreating this entry in the namecache if it is not
16109f84dd1SRuslan Ermilovalready present.
16209f84dd1SRuslan ErmilovNormally,
163c78f3f0dSEivind Eklund.Fn namei
164c78f3f0dSEivind Eklundwill add entries to the name cache
16509f84dd1SRuslan Ermilovif they are not already there.
166c78f3f0dSEivind Eklund.It Dv FOLLOW
167c78f3f0dSEivind EklundWith this flag,
168c78f3f0dSEivind Eklund.Fn namei
169c78f3f0dSEivind Eklundwill follow the symbolic link if the last part
170c78f3f0dSEivind Eklundof the path supplied is a symbolic link (i.e., it will return a vnode
171c78f3f0dSEivind Eklundfor whatever the link points at, instead for the link itself).
172c78f3f0dSEivind Eklund.It Dv NOOBJ
173c78f3f0dSEivind EklundDo not call
174c78f3f0dSEivind Eklund.Fn vfs_object_create
17515c3fb05SHiten Pandyafor the returned vnode, even though it meets required criteria for VM support.
176c78f3f0dSEivind Eklund.It Dv NOFOLLOW
1779a8fa3c1SEivind EklundDo not follow symbolic links (pseudo).
1789a8fa3c1SEivind EklundThis flag is not looked for by the actual code, which looks for
17915c3fb05SHiten Pandya.Dv FOLLOW .
18015c3fb05SHiten Pandya.Dv NOFOLLOW
18115c3fb05SHiten Pandyais used to indicate to the source code reader that symlinks
1829a8fa3c1SEivind Eklundare intentionally not followed.
183060c42c3SRobert Watson.It Dv SAVENAME
18415c3fb05SHiten PandyaDo not free the pathname buffer at the end of the
185060c42c3SRobert Watson.Fn namei
18609f84dd1SRuslan Ermilovinvocation; instead, free it later in
187060c42c3SRobert Watson.Fn NDFREE
18815c3fb05SHiten Pandyaso that the caller may access the pathname buffer.
189060c42c3SRobert WatsonSee below for details.
190060c42c3SRobert Watson.It Dv SAVESTART
191060c42c3SRobert WatsonRetain an additional reference to the parent directory; do not free
19215c3fb05SHiten Pandyathe pathname buffer.
193060c42c3SRobert WatsonSee below for details.
194c78f3f0dSEivind Eklund.El
1959a8fa3c1SEivind Eklund.Sh ALLOCATED ELEMENTS
19615c3fb05SHiten PandyaThe
19715c3fb05SHiten Pandya.Vt nameidata
19815c3fb05SHiten Pandyastructure is composed of the following fields:
19909f84dd1SRuslan Ermilov.Bl -tag -width ".Va ni_cnd.cn_pnbuf"
20015c3fb05SHiten Pandya.It Va ni_startdir
2019a8fa3c1SEivind EklundIn the normal case, this is either the current directory or the root.
20209f84dd1SRuslan ErmilovIt is the current directory if the name passed in does not start with
20309f84dd1SRuslan Ermilov.Ql /
2049a8fa3c1SEivind Eklundand we have not gone through any symlinks with an absolute path, and
2059a8fa3c1SEivind Eklundthe root otherwise.
2063136363fSRuslan Ermilov.Pp
2079e28aca5SDima DorfmanIn this case, it is only used by
2089e28aca5SDima Dorfman.Fn lookup ,
2099e28aca5SDima Dorfmanand should not be
2109e28aca5SDima Dorfmanconsidered valid after a call to
2119e28aca5SDima Dorfman.Fn namei .
21215c3fb05SHiten PandyaIf
21315c3fb05SHiten Pandya.Dv SAVESTART
21415c3fb05SHiten Pandyais set, this is set to the same as
21515c3fb05SHiten Pandya.Va ni_dvp ,
21615c3fb05SHiten Pandyawith an extra
21715c3fb05SHiten Pandya.Xr vref 9 .
21815c3fb05SHiten PandyaTo block
21915c3fb05SHiten Pandya.Fn NDFREE
22015c3fb05SHiten Pandyafrom releasing
22115c3fb05SHiten Pandya.Va ni_startdir ,
22215c3fb05SHiten Pandyathe
22315c3fb05SHiten Pandya.Dv NDF_NO_STARTDIR_RELE
22415c3fb05SHiten Pandyacan be set.
22515c3fb05SHiten Pandya.It Va ni_dvp
22615c3fb05SHiten PandyaVnode pointer to directory of the object on which lookup is performed.
22715c3fb05SHiten PandyaThis is available on successful return if
22815c3fb05SHiten Pandya.Dv LOCKPARENT
22915c3fb05SHiten Pandyaor
23015c3fb05SHiten Pandya.Dv WANTPARENT
23115c3fb05SHiten Pandyais set.
23215c3fb05SHiten PandyaIt is locked if
23315c3fb05SHiten Pandya.Dv LOCKPARENT
23415c3fb05SHiten Pandyais set.
23515c3fb05SHiten PandyaFreeing this in
23609f84dd1SRuslan Ermilov.Fn NDFREE
23715c3fb05SHiten Pandyacan be inhibited by
23809f84dd1SRuslan Ermilov.Dv NDF_NO_DVP_RELE , NDF_NO_DVP_PUT ,
23915c3fb05SHiten Pandyaor
24015c3fb05SHiten Pandya.Dv NDF_NO_DVP_UNLOCK
2419a8fa3c1SEivind Eklund(with the obvious effects).
24215c3fb05SHiten Pandya.It Va ni_vp
24315c3fb05SHiten PandyaVnode pointer to the resulting object,
24415c3fb05SHiten Pandya.Dv NULL
24515c3fb05SHiten Pandyaotherwise.
24615c3fb05SHiten PandyaThe
24715c3fb05SHiten Pandya.Va v_usecount
24815c3fb05SHiten Pandyafield of this vnode is incremented.
24915c3fb05SHiten PandyaIf
25015c3fb05SHiten Pandya.Dv LOCKLEAF
25115c3fb05SHiten Pandyais set, it is also locked.
2523136363fSRuslan Ermilov.Pp
25315c3fb05SHiten PandyaFreeing this in
25415c3fb05SHiten Pandya.Fn NDFREE
25515c3fb05SHiten Pandyacan be inhibited by
25609f84dd1SRuslan Ermilov.Dv NDF_NO_VP_RELE , NDF_NO_VP_PUT ,
25715c3fb05SHiten Pandyaor
25815c3fb05SHiten Pandya.Dv NDF_NO_VP_UNLOCK
25909f84dd1SRuslan Ermilov(with the obvious effects).
26015c3fb05SHiten Pandya.It Va ni_cnd.cn_pnbuf
26115c3fb05SHiten PandyaThe pathname buffer contains the location of the file or directory
26215c3fb05SHiten Pandyathat will be used by the
26315c3fb05SHiten Pandya.Nm
26415c3fb05SHiten Pandyaoperations.
26515c3fb05SHiten PandyaIt is managed by the
26615c3fb05SHiten Pandya.Xr uma 9
26715c3fb05SHiten Pandyazone allocation interface.
26815c3fb05SHiten PandyaIf the
26915c3fb05SHiten Pandya.Dv SAVESTART
27015c3fb05SHiten Pandyaor
27115c3fb05SHiten Pandya.Dv SAVENAME
27215c3fb05SHiten Pandyaflag is set, then the pathname buffer is available
27315c3fb05SHiten Pandyaafter calling the
27409f84dd1SRuslan Ermilov.Fn namei
27515c3fb05SHiten Pandyafunction.
2763136363fSRuslan Ermilov.Pp
27715c3fb05SHiten PandyaTo only deallocate resources used by the pathname buffer,
27815c3fb05SHiten Pandya.Va ni_cnd.cn_pnbuf ,
27915c3fb05SHiten Pandyathen
28015c3fb05SHiten Pandya.Dv NDF_ONLY_PNBUF
28115c3fb05SHiten Pandyaflag can be passed to the
28215c3fb05SHiten Pandya.Fn NDFREE
28315c3fb05SHiten Pandyafunction.
28415c3fb05SHiten PandyaTo keep the pathname buffer intact,
28515c3fb05SHiten Pandyathe
286eafe5f83SChristian Brueffer.Dv NDF_NO_FREE_PNBUF
28715c3fb05SHiten Pandyaflag can be passed to the
28815c3fb05SHiten Pandya.Fn NDFREE
28915c3fb05SHiten Pandyafunction.
2903136363fSRuslan Ermilov.El
29115c3fb05SHiten Pandya.Sh FILES
29209f84dd1SRuslan Ermilov.Bl -tag
29309f84dd1SRuslan Ermilov.It Pa src/sys/kern/vfs_lookup.c
29409f84dd1SRuslan Ermilov.El
29515c3fb05SHiten Pandya.Sh SEE ALSO
29615c3fb05SHiten Pandya.Xr uio 9 ,
29715c3fb05SHiten Pandya.Xr uma 9 ,
29815c3fb05SHiten Pandya.Xr VFS 9 ,
29915c3fb05SHiten Pandya.Xr vnode 9 ,
30015c3fb05SHiten Pandya.Xr vput 9 ,
30115c3fb05SHiten Pandya.Xr vref 9
302c78f3f0dSEivind Eklund.Sh AUTHORS
30309f84dd1SRuslan Ermilov.An -nosplit
30415c3fb05SHiten PandyaThis manual page was written by
30509f84dd1SRuslan Ermilov.An Eivind Eklund Aq eivind@FreeBSD.org
30615c3fb05SHiten Pandyaand later significantly revised by
30709f84dd1SRuslan Ermilov.An Hiten M. Pandya Aq hmp@FreeBSD.org .
30815c3fb05SHiten Pandya.Sh BUGS
30915c3fb05SHiten PandyaThe
31015c3fb05SHiten Pandya.Dv LOCKPARENT
31115c3fb05SHiten Pandyaflag does not always result in the parent vnode being locked.
31215c3fb05SHiten PandyaThis results in complications when the
31315c3fb05SHiten Pandya.Dv LOCKPARENT
31415c3fb05SHiten Pandyais used.
31515c3fb05SHiten PandyaIn order to solve this for the cases where both
31615c3fb05SHiten Pandya.Dv LOCKPARENT
31715c3fb05SHiten Pandyaand
31815c3fb05SHiten Pandya.Dv LOCKLEAF
31915c3fb05SHiten Pandyaare used, it is necessary to resort to recursive locking.
320