]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/namei.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / bsd / sys / namei.h
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1985, 1989, 1991, 1993
28 * The Regents of the University of California. All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)namei.h 8.4 (Berkeley) 8/20/94
59 */
60
61 #ifndef _SYS_NAMEI_H_
62 #define _SYS_NAMEI_H_
63
64 #include <sys/appleapiopts.h>
65
66 #ifdef __APPLE_API_UNSTABLE
67
68 #include <sys/queue.h>
69 #include <sys/uio.h>
70
71 /*
72 * Lookup parameters: this structure describes the subset of
73 * information from the nameidata structure that is passed
74 * through the VOP interface.
75 */
76 struct componentname {
77 /*
78 * Arguments to lookup.
79 */
80 u_long cn_nameiop; /* namei operation */
81 u_long cn_flags; /* flags to namei */
82 struct proc *cn_proc; /* process requesting lookup */
83 struct ucred *cn_cred; /* credentials */
84 /*
85 * Shared between lookup and commit routines.
86 */
87 char *cn_pnbuf; /* pathname buffer */
88 long cn_pnlen; /* length of allocated buffer */
89 char *cn_nameptr; /* pointer to looked up name */
90 long cn_namelen; /* length of looked up component */
91 u_long cn_hash; /* hash value of looked up name */
92 long cn_consume; /* chars to consume in lookup() */
93 };
94
95 /*
96 * Encapsulation of namei parameters.
97 */
98 struct nameidata {
99 /*
100 * Arguments to namei/lookup.
101 */
102 caddr_t ni_dirp; /* pathname pointer */
103 enum uio_seg ni_segflg; /* location of pathname */
104 /* u_long ni_nameiop; namei operation */
105 /* u_long ni_flags; flags to namei */
106 /* struct proc *ni_proc; process requesting lookup */
107 /*
108 * Arguments to lookup.
109 */
110 /* struct ucred *ni_cred; credentials */
111 struct vnode *ni_startdir; /* starting directory */
112 struct vnode *ni_rootdir; /* logical root directory */
113 /*
114 * Results: returned from/manipulated by lookup
115 */
116 struct vnode *ni_vp; /* vnode of result */
117 struct vnode *ni_dvp; /* vnode of intermediate directory */
118 /*
119 * Shared between namei and lookup/commit routines.
120 */
121 u_int ni_pathlen; /* remaining chars in path */
122 char *ni_next; /* next location in pathname */
123 u_long ni_loopcnt; /* count of symlinks encountered */
124 struct componentname ni_cnd;
125 };
126
127 #ifdef KERNEL
128 /*
129 * namei operations
130 */
131 #define LOOKUP 0 /* perform name lookup only */
132 #define CREATE 1 /* setup for file creation */
133 #define DELETE 2 /* setup for file deletion */
134 #define RENAME 3 /* setup for file renaming */
135 #define OPMASK 3 /* mask for operation */
136 /*
137 * namei operational modifier flags, stored in ni_cnd.flags
138 */
139 #define LOCKLEAF 0x0004 /* lock inode on return */
140 #define LOCKPARENT 0x0008 /* want parent vnode returned locked */
141 #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */
142 #define NOCACHE 0x0020 /* name must not be left in cache */
143 #define FOLLOW 0x0040 /* follow symbolic links */
144 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
145 #define SHAREDLEAF 0x0080 /* OK to have shared leaf lock */
146 #define MODMASK 0x00fc /* mask of operational modifiers */
147 /*
148 * Namei parameter descriptors.
149 *
150 * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
151 * If the caller of namei sets the flag (for example execve wants to
152 * know the name of the program that is being executed), then it must
153 * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
154 * be freed by either the commit routine or the VOP_ABORT routine.
155 * SAVESTART is set only by the callers of namei. It implies SAVENAME
156 * plus the addition of saving the parent directory that contains the
157 * name in ni_startdir. It allows repeated calls to lookup for the
158 * name being sought. The caller is responsible for releasing the
159 * buffer and for vrele'ing ni_startdir.
160 */
161 #define NOCROSSMOUNT 0x000100 /* do not cross mount points */
162 #define RDONLY 0x000200 /* lookup with read-only semantics */
163 #define HASBUF 0x000400 /* has allocated pathname buffer */
164 #define SAVENAME 0x000800 /* save pathanme buffer */
165 #define SAVESTART 0x001000 /* save starting directory */
166 #define ISDOTDOT 0x002000 /* current component name is .. */
167 #define MAKEENTRY 0x004000 /* entry is to be added to name cache */
168 #define ISLASTCN 0x008000 /* this is last component of pathname */
169 #define ISSYMLINK 0x010000 /* symlink needs interpretation */
170 #define ISWHITEOUT 0x020000 /* found whiteout */
171 #define DOWHITEOUT 0x040000 /* do whiteouts */
172 #define WILLBEDIR 0x080000 /* new files will be dirs; allow trailing / */
173 #define AUDITVNPATH1 0x100000 /* audit the path/vnode info */
174 #define AUDITVNPATH2 0x200000 /* audit the path/vnode info */
175 #define USEDVP 0x400000 /* start the lookup at ndp.ni_dvp */
176 #define NODELETEBUSY 0x800000 /* donot delete busy files (Carbon semantic) */
177 #define PARAMASK 0x3fff00 /* mask of parameter descriptors */
178 /*
179 * Initialization of an nameidata structure.
180 */
181 #define NDINIT(ndp, op, flags, segflg, namep, p) { \
182 (ndp)->ni_cnd.cn_nameiop = op; \
183 (ndp)->ni_cnd.cn_flags = flags; \
184 (ndp)->ni_segflg = segflg; \
185 (ndp)->ni_dirp = namep; \
186 (ndp)->ni_cnd.cn_proc = p; \
187 }
188 #endif /* KERNEL */
189
190 /*
191 * This structure describes the elements in the cache of recent
192 * names looked up by namei. NCHNAMLEN is sized to make structure
193 * size a power of two to optimize malloc's. Minimum reasonable
194 * size is 15.
195 */
196
197 #define NCHNAMLEN 31 /* maximum name segment length we bother with */
198
199 struct namecache {
200 LIST_ENTRY(namecache) nc_hash; /* hash chain */
201 TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */
202 struct vnode *nc_dvp; /* vnode of parent of name */
203 u_long nc_dvpid; /* capability number of nc_dvp */
204 struct vnode *nc_vp; /* vnode the name refers to */
205 u_long nc_vpid; /* capability number of nc_vp */
206 char *nc_name; /* segment name */
207 };
208
209 #ifdef KERNEL
210 struct mount;
211 extern u_long nextvnodeid;
212 int namei __P((struct nameidata *ndp));
213 int lookup __P((struct nameidata *ndp));
214 int relookup __P((struct vnode *dvp, struct vnode **vpp,
215 struct componentname *cnp));
216
217 /* namecache function prototypes */
218 int cache_lookup __P((struct vnode *dvp, struct vnode **vpp,
219 struct componentname *cnp));
220 void cache_enter __P((struct vnode *dvp, struct vnode *vpp,
221 struct componentname *cnp));
222 void cache_purge __P((struct vnode *vp));
223 void cache_purgevfs __P((struct mount *mp));
224
225 //
226 // Global string-cache routines. You can pass zero for nc_hash
227 // if you don't know it (add_name() will then compute the hash).
228 // There are no flags for now but maybe someday.
229 //
230 char *add_name(const char *name, size_t len, u_int nc_hash, u_int flags);
231 int remove_name(const char *name);
232
233
234 #endif /* KERNEL */
235
236 /*
237 * Stats on usefulness of namei caches.
238 */
239 struct nchstats {
240 long ncs_goodhits; /* hits that we can really use */
241 long ncs_neghits; /* negative hits that we can use */
242 long ncs_badhits; /* hits we must drop */
243 long ncs_falsehits; /* hits with id mismatch */
244 long ncs_miss; /* misses */
245 long ncs_long; /* long names that ignore cache */
246 long ncs_pass2; /* names found with passes == 2 */
247 long ncs_2passes; /* number of times we attempt it */
248 };
249 #endif /* __APPLE_API_UNSTABLE */
250
251 #endif /* !_SYS_NAMEI_H_ */