There are historically two families of fixed size integers, u_intX_t and
[dragonfly.git] / share / man / man9 / namei.9
1 .\" -*- nroff -*-
2 .\"
3 .\" Copyright (c) 1998, 1999 Eivind Eklund
4 .\"
5 .\" All rights reserved.
6 .\"
7 .\" This program is free software.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
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.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\"
29 .\"
30 .\" If you integrate this manpage in another OS, I'd appreciate a note
31 .\"     - eivind@FreeBSD.org
32 .\"
33 .\" $FreeBSD: src/share/man/man9/namei.9,v 1.8.2.8 2001/12/17 11:30:18 ru Exp $
34 .\" $DragonFly: src/share/man/man9/Attic/namei.9,v 1.2 2003/06/17 04:37:01 dillon Exp $
35 .\"
36 .Dd December 16, 1998
37 .Os
38 .Dt NAMEI 9
39 .Sh NAME
40 .Nm namei ,
41 .Nm NDINIT
42 .Nd convert pathname to a pointer to a locked vnode
43 .Sh SYNOPSIS
44 .In sys/types.h
45 .In sys/namei.h
46 .Ft int
47 .Fn namei "struct nameidata *ndp"
48 .Ft void
49 .Fn NDINIT "struct nameidata *ndp" "u_long operation" "u_long operflags" "enum uio_seg segflag" "const char *path" "struct proc *proc"
50 .Ft void
51 .Fn NDFREE "struct nameidata *ndp" "u_int operflags"
52 .Sh DESCRIPTION
53 .Fn namei
54 is used to get from a pathname to a vnode for the object.
55 This is a necessity to start doing VFS operations.  The vnode
56 returned will have its reference count increased; when you're through
57 with it, you have to release it using either
58 .Xr vrele 9
59 or
60 .Xr vput 9 ,
61 depending on whether you specified the LOCKLEAF flag or not.
62 .Pp
63 To initialize the nameidata struct, you usually use
64 .Fn NDINIT .
65 It takes the following arguments:
66 .Pp
67 .Bl -tag -width nameidatap
68 .It Ar nameidatap
69 pointer to the struct nameidata to initialize
70 .It Ar operation
71 The operation to have
72 .Fn namei
73 do.  The relevant operations are
74 .Dv LOOKUP ,
75 .Dv CREATE ,
76 .Dv DELETE ,
77 and
78 .Dv RENAME .
79 The latter three are just setup for those
80 effects; just calling
81 .Fn namei
82 will not result in
83 .Fn VOP_RENAME
84 being called.
85 .It Ar operflags
86 Operation flags.  Several of these can be effective at the same time.
87 .It Ar segflag
88 Segment indicator.  This tells if the name of the object is in
89 userspace (UIO_USERSPACE) or in the kernel address space (UIO_SYSSPACE).
90 .It Ar path
91 Pointer to pathname buffer (the file or directory name that will be
92 looked up)
93 .It Ar proc
94 Which process context to use for the
95 .Fn namei
96 locks.
97 .El
98 .Sh NAMEI OPERATION FLAGS
99 .Fn namei
100 takes the following set of 'operation flags' that influence
101 how it operates:
102 .Bl -tag -width WANTPARENT
103 .It Dv LOCKLEAF
104 Lock vnode on return.  This is a full lock of the vnode; you'll have to use
105 .Xr VOP_UNLOCK 9
106 to release the lock (or use
107 .Xr vput 9
108 to release the lock and do a
109 .Xr vrele 9 ,
110 all in one).
111 .It Dv LOCKPARENT
112 Make
113 .Fn namei
114 also return the parent (directory) vnode (in nd.ni_dvp),
115 in locked state, unless the dvp is identical to the vp, in which case the dvp
116 is not locked per se (but may be locked due to LOCKLEAF).
117 If you get a lock, remember to release the lock (using
118 .Xr vput 9
119 or
120 .Xr VOP_UNLOCK 9
121 and
122 .Xr vrele 9 . )
123 .It Dv WANTPARENT
124 Make
125 .Fn namei
126 also return the parent (directory) vnode, in unlocked
127 state.  Remember to release it (using
128 .Xr vrele 9 . )
129 .It Dv NOCACHE
130 Avoid
131 .Fn namei
132 creating this entry in the namecache if it is not
133 already present.  Normally
134 .Fn namei
135 will add entries to the name cache
136 if they're not already there.
137 .It Dv FOLLOW
138 With this flag,
139 .Fn namei
140 will follow the symbolic link if the last part
141 of the path supplied is a symbolic link (i.e., it will return a vnode
142 for whatever the link points at, instead for the link itself).
143 .It Dv NOOBJ
144 Do not call
145 .Fn vfs_object_create
146 for the returned vnode even if it is
147 just a VREG and we're able to (ie, it is locked).
148 .It Dv NOFOLLOW
149 Do not follow symbolic links (pseudo).
150 This flag is not looked for by the actual code, which looks for
151 FOLLOW.
152 NOFOLLOW is used to indicate to the source code reader that symlinks
153 are intentionally not followed.
154 .El
155 .Sh ALLOCATED ELEMENTS
156 .Bl -tag -width WANTPARENT
157 .It Dv ni_startdir
158 Where we did lookup relative to.
159 In the normal case, this is either the current directory or the root.
160 It is the current directory if the name passed in doesn't start with /
161 and we have not gone through any symlinks with an absolute path, and
162 the root otherwise.
163 .Pp
164 In this case, it is only used by
165 .Fn lookup ,
166 and should not be
167 considered valid after a call to
168 .Fn namei .
169 .Pp
170 If SAVESTART is set, this is set to the same as ni_dvp, with an extra
171 .Fn VREF .
172 .Pp
173 To block NDFREE from releasing ni_startdir when it is set, use the
174 flag NDF_NO_STARTDIR_RELE.
175 .It Dv ni_dvp
176 The directory vp for the directory the object we're looking up is in.
177 This is available on successful return if LOCKPARENT or WANTPARENT is
178 set.  It is locked if LOCKPARENT is set.  Freeing this in NDFREE can
179 be inhibited by NDF_NO_DVP_RELE, NDF_NO_DVP_PUT, or NDF_NO_DVP_UNLOCK
180 (with the obvious effects).
181 .It Dv ni_vp
182 The vp for the target of the of the pathname exists, NULL otherwise.
183 The vp is returned with increased reference count (VREF'ed).  If
184 LOCKLEAF is set, it is also locked.
185 .Pp
186 Freeing this in NDFREE can be inhibited by NDF_NO_VP_RELE,
187 NDF_NO_VP_PUT, or NDF_NO_VP_UNLOCK (with the obvious effects).
188 .It Dv ni_cnd.cn_pnbuf
189 Path name buffer.  This is allocated through zalloc(namei_zone)
190 and freed through zfree(namei_zone, ...).
191 .Pp
192 This is available to the caller (who must free it using
193 .Xr NDFREE 9 )
194 if SAVESTART or SAVENAME is set.
195 To free only the ni_cnd.cn_pnbuf, there is a special flags NDF_ONLY_PNBUF.
196 To not free the cnd, use the flag ND_NO_FREE_PNBUF.
197 .El
198 .Sh BUGS
199 LOCKPARENT does not always result in parent vp being locked (see details in
200 description).
201 This results in complications everywhere LOCKPARENT is used.
202 In order to solve this for the cases that include both LOCKPARENT and LOCKLEAF,
203 it will be necessary to go to recursive locking.
204 .Sh SEE ALSO
205 .Xr VFS 9 ,
206 .Xr vnode 9
207 .Pp
208 .Pa src/sys/kern/vfs_lookup.c
209 .Sh AUTHORS
210 This man page was written by
211 .An Eivind Eklund .