]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
9bccf70c | 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
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. | |
1c79356b A |
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 | ||
9bccf70c A |
64 | #include <sys/appleapiopts.h> |
65 | ||
66 | #ifdef __APPLE_API_UNSTABLE | |
67 | ||
1c79356b A |
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 MODMASK 0x00fc /* mask of operational modifiers */ | |
146 | /* | |
147 | * Namei parameter descriptors. | |
148 | * | |
149 | * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. | |
150 | * If the caller of namei sets the flag (for example execve wants to | |
151 | * know the name of the program that is being executed), then it must | |
152 | * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must | |
153 | * be freed by either the commit routine or the VOP_ABORT routine. | |
154 | * SAVESTART is set only by the callers of namei. It implies SAVENAME | |
155 | * plus the addition of saving the parent directory that contains the | |
156 | * name in ni_startdir. It allows repeated calls to lookup for the | |
157 | * name being sought. The caller is responsible for releasing the | |
158 | * buffer and for vrele'ing ni_startdir. | |
159 | */ | |
160 | #define NOCROSSMOUNT 0x000100 /* do not cross mount points */ | |
161 | #define RDONLY 0x000200 /* lookup with read-only semantics */ | |
162 | #define HASBUF 0x000400 /* has allocated pathname buffer */ | |
163 | #define SAVENAME 0x000800 /* save pathanme buffer */ | |
164 | #define SAVESTART 0x001000 /* save starting directory */ | |
165 | #define ISDOTDOT 0x002000 /* current component name is .. */ | |
166 | #define MAKEENTRY 0x004000 /* entry is to be added to name cache */ | |
167 | #define ISLASTCN 0x008000 /* this is last component of pathname */ | |
168 | #define ISSYMLINK 0x010000 /* symlink needs interpretation */ | |
169 | #define ISWHITEOUT 0x020000 /* found whiteout */ | |
170 | #define DOWHITEOUT 0x040000 /* do whiteouts */ | |
9bccf70c A |
171 | #define WILLBEDIR 0x080000 /* new files will be dirs; allow trailing / */ |
172 | #define NODELETEBUSY 0x800000 /* donot delete busy files (Carbon semantic) */ | |
1c79356b A |
173 | #define PARAMASK 0x0fff00 /* mask of parameter descriptors */ |
174 | /* | |
175 | * Initialization of an nameidata structure. | |
176 | */ | |
177 | #define NDINIT(ndp, op, flags, segflg, namep, p) { \ | |
178 | (ndp)->ni_cnd.cn_nameiop = op; \ | |
179 | (ndp)->ni_cnd.cn_flags = flags; \ | |
180 | (ndp)->ni_segflg = segflg; \ | |
181 | (ndp)->ni_dirp = namep; \ | |
182 | (ndp)->ni_cnd.cn_proc = p; \ | |
183 | } | |
184 | #endif /* KERNEL */ | |
185 | ||
186 | /* | |
187 | * This structure describes the elements in the cache of recent | |
188 | * names looked up by namei. NCHNAMLEN is sized to make structure | |
189 | * size a power of two to optimize malloc's. Minimum reasonable | |
190 | * size is 15. | |
191 | */ | |
192 | ||
193 | #define NCHNAMLEN 31 /* maximum name segment length we bother with */ | |
194 | ||
195 | struct namecache { | |
196 | LIST_ENTRY(namecache) nc_hash; /* hash chain */ | |
197 | TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */ | |
198 | struct vnode *nc_dvp; /* vnode of parent of name */ | |
199 | u_long nc_dvpid; /* capability number of nc_dvp */ | |
200 | struct vnode *nc_vp; /* vnode the name refers to */ | |
201 | u_long nc_vpid; /* capability number of nc_vp */ | |
202 | char nc_nlen; /* length of name */ | |
203 | char nc_name[NCHNAMLEN]; /* segment name */ | |
204 | }; | |
205 | ||
206 | #ifdef KERNEL | |
9bccf70c | 207 | struct mount; |
1c79356b A |
208 | extern u_long nextvnodeid; |
209 | int namei __P((struct nameidata *ndp)); | |
210 | int lookup __P((struct nameidata *ndp)); | |
211 | int relookup __P((struct vnode *dvp, struct vnode **vpp, | |
212 | struct componentname *cnp)); | |
213 | ||
214 | /* namecache function prototypes */ | |
215 | int cache_lookup __P((struct vnode *dvp, struct vnode **vpp, | |
216 | struct componentname *cnp)); | |
217 | void cache_enter __P((struct vnode *dvp, struct vnode *vpp, | |
218 | struct componentname *cnp)); | |
219 | void cache_purge __P((struct vnode *vp)); | |
220 | void cache_purgevfs __P((struct mount *mp)); | |
221 | #endif /* KERNEL */ | |
222 | ||
223 | /* | |
224 | * Stats on usefulness of namei caches. | |
225 | */ | |
226 | struct nchstats { | |
227 | long ncs_goodhits; /* hits that we can really use */ | |
228 | long ncs_neghits; /* negative hits that we can use */ | |
229 | long ncs_badhits; /* hits we must drop */ | |
230 | long ncs_falsehits; /* hits with id mismatch */ | |
231 | long ncs_miss; /* misses */ | |
232 | long ncs_long; /* long names that ignore cache */ | |
233 | long ncs_pass2; /* names found with passes == 2 */ | |
234 | long ncs_2passes; /* number of times we attempt it */ | |
235 | }; | |
9bccf70c A |
236 | #endif /* __APPLE_API_UNSTABLE */ |
237 | ||
1c79356b | 238 | #endif /* !_SYS_NAMEI_H_ */ |