]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
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 | ||
61 | #include <sys/queue.h> | |
62 | #include <sys/uio.h> | |
63 | ||
64 | /* | |
65 | * Lookup parameters: this structure describes the subset of | |
66 | * information from the nameidata structure that is passed | |
67 | * through the VOP interface. | |
68 | */ | |
69 | struct componentname { | |
70 | /* | |
71 | * Arguments to lookup. | |
72 | */ | |
73 | u_long cn_nameiop; /* namei operation */ | |
74 | u_long cn_flags; /* flags to namei */ | |
75 | struct proc *cn_proc; /* process requesting lookup */ | |
76 | struct ucred *cn_cred; /* credentials */ | |
77 | /* | |
78 | * Shared between lookup and commit routines. | |
79 | */ | |
80 | char *cn_pnbuf; /* pathname buffer */ | |
81 | long cn_pnlen; /* length of allocated buffer */ | |
82 | char *cn_nameptr; /* pointer to looked up name */ | |
83 | long cn_namelen; /* length of looked up component */ | |
84 | u_long cn_hash; /* hash value of looked up name */ | |
85 | long cn_consume; /* chars to consume in lookup() */ | |
86 | }; | |
87 | ||
88 | /* | |
89 | * Encapsulation of namei parameters. | |
90 | */ | |
91 | struct nameidata { | |
92 | /* | |
93 | * Arguments to namei/lookup. | |
94 | */ | |
95 | caddr_t ni_dirp; /* pathname pointer */ | |
96 | enum uio_seg ni_segflg; /* location of pathname */ | |
97 | /* u_long ni_nameiop; namei operation */ | |
98 | /* u_long ni_flags; flags to namei */ | |
99 | /* struct proc *ni_proc; process requesting lookup */ | |
100 | /* | |
101 | * Arguments to lookup. | |
102 | */ | |
103 | /* struct ucred *ni_cred; credentials */ | |
104 | struct vnode *ni_startdir; /* starting directory */ | |
105 | struct vnode *ni_rootdir; /* logical root directory */ | |
106 | /* | |
107 | * Results: returned from/manipulated by lookup | |
108 | */ | |
109 | struct vnode *ni_vp; /* vnode of result */ | |
110 | struct vnode *ni_dvp; /* vnode of intermediate directory */ | |
111 | /* | |
112 | * Shared between namei and lookup/commit routines. | |
113 | */ | |
114 | u_int ni_pathlen; /* remaining chars in path */ | |
115 | char *ni_next; /* next location in pathname */ | |
116 | u_long ni_loopcnt; /* count of symlinks encountered */ | |
117 | struct componentname ni_cnd; | |
118 | }; | |
119 | ||
120 | #ifdef KERNEL | |
121 | /* | |
122 | * namei operations | |
123 | */ | |
124 | #define LOOKUP 0 /* perform name lookup only */ | |
125 | #define CREATE 1 /* setup for file creation */ | |
126 | #define DELETE 2 /* setup for file deletion */ | |
127 | #define RENAME 3 /* setup for file renaming */ | |
128 | #define OPMASK 3 /* mask for operation */ | |
129 | /* | |
130 | * namei operational modifier flags, stored in ni_cnd.flags | |
131 | */ | |
132 | #define LOCKLEAF 0x0004 /* lock inode on return */ | |
133 | #define LOCKPARENT 0x0008 /* want parent vnode returned locked */ | |
134 | #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ | |
135 | #define NOCACHE 0x0020 /* name must not be left in cache */ | |
136 | #define FOLLOW 0x0040 /* follow symbolic links */ | |
137 | #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ | |
138 | #define MODMASK 0x00fc /* mask of operational modifiers */ | |
139 | /* | |
140 | * Namei parameter descriptors. | |
141 | * | |
142 | * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. | |
143 | * If the caller of namei sets the flag (for example execve wants to | |
144 | * know the name of the program that is being executed), then it must | |
145 | * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must | |
146 | * be freed by either the commit routine or the VOP_ABORT routine. | |
147 | * SAVESTART is set only by the callers of namei. It implies SAVENAME | |
148 | * plus the addition of saving the parent directory that contains the | |
149 | * name in ni_startdir. It allows repeated calls to lookup for the | |
150 | * name being sought. The caller is responsible for releasing the | |
151 | * buffer and for vrele'ing ni_startdir. | |
152 | */ | |
153 | #define NOCROSSMOUNT 0x000100 /* do not cross mount points */ | |
154 | #define RDONLY 0x000200 /* lookup with read-only semantics */ | |
155 | #define HASBUF 0x000400 /* has allocated pathname buffer */ | |
156 | #define SAVENAME 0x000800 /* save pathanme buffer */ | |
157 | #define SAVESTART 0x001000 /* save starting directory */ | |
158 | #define ISDOTDOT 0x002000 /* current component name is .. */ | |
159 | #define MAKEENTRY 0x004000 /* entry is to be added to name cache */ | |
160 | #define ISLASTCN 0x008000 /* this is last component of pathname */ | |
161 | #define ISSYMLINK 0x010000 /* symlink needs interpretation */ | |
162 | #define ISWHITEOUT 0x020000 /* found whiteout */ | |
163 | #define DOWHITEOUT 0x040000 /* do whiteouts */ | |
164 | #define NODELETEBUSY 0x800000 /* do not delete busy files (HFS semantic) */ | |
165 | #define PARAMASK 0x0fff00 /* mask of parameter descriptors */ | |
166 | /* | |
167 | * Initialization of an nameidata structure. | |
168 | */ | |
169 | #define NDINIT(ndp, op, flags, segflg, namep, p) { \ | |
170 | (ndp)->ni_cnd.cn_nameiop = op; \ | |
171 | (ndp)->ni_cnd.cn_flags = flags; \ | |
172 | (ndp)->ni_segflg = segflg; \ | |
173 | (ndp)->ni_dirp = namep; \ | |
174 | (ndp)->ni_cnd.cn_proc = p; \ | |
175 | } | |
176 | #endif /* KERNEL */ | |
177 | ||
178 | /* | |
179 | * This structure describes the elements in the cache of recent | |
180 | * names looked up by namei. NCHNAMLEN is sized to make structure | |
181 | * size a power of two to optimize malloc's. Minimum reasonable | |
182 | * size is 15. | |
183 | */ | |
184 | ||
185 | #define NCHNAMLEN 31 /* maximum name segment length we bother with */ | |
186 | ||
187 | struct namecache { | |
188 | LIST_ENTRY(namecache) nc_hash; /* hash chain */ | |
189 | TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */ | |
190 | struct vnode *nc_dvp; /* vnode of parent of name */ | |
191 | u_long nc_dvpid; /* capability number of nc_dvp */ | |
192 | struct vnode *nc_vp; /* vnode the name refers to */ | |
193 | u_long nc_vpid; /* capability number of nc_vp */ | |
194 | char nc_nlen; /* length of name */ | |
195 | char nc_name[NCHNAMLEN]; /* segment name */ | |
196 | }; | |
197 | ||
198 | #ifdef KERNEL | |
199 | extern u_long nextvnodeid; | |
200 | int namei __P((struct nameidata *ndp)); | |
201 | int lookup __P((struct nameidata *ndp)); | |
202 | int relookup __P((struct vnode *dvp, struct vnode **vpp, | |
203 | struct componentname *cnp)); | |
204 | ||
205 | /* namecache function prototypes */ | |
206 | int cache_lookup __P((struct vnode *dvp, struct vnode **vpp, | |
207 | struct componentname *cnp)); | |
208 | void cache_enter __P((struct vnode *dvp, struct vnode *vpp, | |
209 | struct componentname *cnp)); | |
210 | void cache_purge __P((struct vnode *vp)); | |
211 | void cache_purgevfs __P((struct mount *mp)); | |
212 | #endif /* KERNEL */ | |
213 | ||
214 | /* | |
215 | * Stats on usefulness of namei caches. | |
216 | */ | |
217 | struct nchstats { | |
218 | long ncs_goodhits; /* hits that we can really use */ | |
219 | long ncs_neghits; /* negative hits that we can use */ | |
220 | long ncs_badhits; /* hits we must drop */ | |
221 | long ncs_falsehits; /* hits with id mismatch */ | |
222 | long ncs_miss; /* misses */ | |
223 | long ncs_long; /* long names that ignore cache */ | |
224 | long ncs_pass2; /* names found with passes == 2 */ | |
225 | long ncs_2passes; /* number of times we attempt it */ | |
226 | }; | |
227 | #endif /* !_SYS_NAMEI_H_ */ |