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