]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
29 | */ | |
30 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
31 | /* | |
32 | * Copyright (c) 1985, 1989, 1991, 1993 | |
33 | * The Regents of the University of California. All rights reserved. | |
34 | * | |
35 | * Redistribution and use in source and binary forms, with or without | |
36 | * modification, are permitted provided that the following conditions | |
37 | * are met: | |
38 | * 1. Redistributions of source code must retain the above copyright | |
39 | * notice, this list of conditions and the following disclaimer. | |
40 | * 2. Redistributions in binary form must reproduce the above copyright | |
41 | * notice, this list of conditions and the following disclaimer in the | |
42 | * documentation and/or other materials provided with the distribution. | |
43 | * 3. All advertising materials mentioning features or use of this software | |
44 | * must display the following acknowledgement: | |
45 | * This product includes software developed by the University of | |
46 | * California, Berkeley and its contributors. | |
47 | * 4. Neither the name of the University nor the names of its contributors | |
48 | * may be used to endorse or promote products derived from this software | |
49 | * without specific prior written permission. | |
50 | * | |
51 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
61 | * SUCH DAMAGE. | |
62 | * | |
63 | * @(#)namei.h 8.4 (Berkeley) 8/20/94 | |
64 | */ | |
65 | ||
66 | #ifndef _SYS_NAMEI_H_ | |
67 | #define _SYS_NAMEI_H_ | |
68 | ||
69 | #include <sys/appleapiopts.h> | |
70 | ||
71 | #ifdef KERNEL | |
72 | #define LOCKLEAF 0x0004 /* lock inode on return */ | |
73 | #define LOCKPARENT 0x0008 /* want parent vnode returned */ | |
74 | #define WANTPARENT 0x0010 /* want parent vnode returned */ | |
75 | #endif | |
76 | ||
77 | ||
78 | #ifdef BSD_KERNEL_PRIVATE | |
79 | ||
80 | #include <sys/queue.h> | |
81 | #include <sys/uio.h> | |
82 | #include <sys/vnode.h> | |
83 | #include <sys/mount.h> | |
84 | #include <sys/filedesc.h> | |
85 | ||
86 | #define PATHBUFLEN 256 | |
87 | ||
88 | /* | |
89 | * Encapsulation of namei parameters. | |
90 | */ | |
91 | struct nameidata { | |
92 | /* | |
93 | * Arguments to namei/lookup. | |
94 | */ | |
95 | user_addr_t ni_dirp; /* pathname pointer */ | |
96 | enum uio_seg ni_segflg; /* location of pathname */ | |
97 | /* | |
98 | * Arguments to lookup. | |
99 | */ | |
100 | struct vnode *ni_startdir; /* starting directory */ | |
101 | struct vnode *ni_rootdir; /* logical root directory */ | |
102 | struct vnode *ni_usedvp; /* directory passed in via USEDVP */ | |
103 | /* | |
104 | * Results: returned from/manipulated by lookup | |
105 | */ | |
106 | struct vnode *ni_vp; /* vnode of result */ | |
107 | struct vnode *ni_dvp; /* vnode of intermediate directory */ | |
108 | /* | |
109 | * Shared between namei and lookup/commit routines. | |
110 | */ | |
111 | u_int ni_pathlen; /* remaining chars in path */ | |
112 | char *ni_next; /* next location in pathname */ | |
113 | char ni_pathbuf[PATHBUFLEN]; | |
114 | u_long ni_loopcnt; /* count of symlinks encountered */ | |
115 | ||
116 | struct componentname ni_cnd; | |
117 | }; | |
118 | ||
119 | #ifdef KERNEL | |
120 | /* | |
121 | * namei operational modifier flags, stored in ni_cnd.flags | |
122 | */ | |
123 | #define NOCACHE 0x0020 /* name must not be left in cache */ | |
124 | #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ | |
125 | #define SHAREDLEAF 0x0080 /* OK to have shared leaf lock */ | |
126 | #define MODMASK 0x00fc /* mask of operational modifiers */ | |
127 | /* | |
128 | * Namei parameter descriptors. | |
129 | * | |
130 | * SAVESTART is set only by the callers of namei. It implies SAVENAME | |
131 | * plus the addition of saving the parent directory that contains the | |
132 | * name in ni_startdir. It allows repeated calls to lookup for the | |
133 | * name being sought. The caller is responsible for releasing the | |
134 | * buffer and for vrele'ing ni_startdir. | |
135 | */ | |
136 | #define NOCROSSMOUNT 0x00000100 /* do not cross mount points */ | |
137 | #define RDONLY 0x00000200 /* lookup with read-only semantics */ | |
138 | #define HASBUF 0x00000400 /* has allocated pathname buffer */ | |
139 | #define SAVENAME 0x00000800 /* save pathanme buffer */ | |
140 | #define SAVESTART 0x00001000 /* save starting directory */ | |
141 | #define ISSYMLINK 0x00010000 /* symlink needs interpretation */ | |
142 | #define DONOTAUTH 0x00020000 /* do not authorize during lookup */ | |
143 | #define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */ | |
144 | #define AUDITVNPATH1 0x00100000 /* audit the path/vnode info */ | |
145 | #define AUDITVNPATH2 0x00200000 /* audit the path/vnode info */ | |
146 | #define USEDVP 0x00400000 /* start the lookup at ndp.ni_dvp */ | |
147 | #define PARAMASK 0x003fff00 /* mask of parameter descriptors */ | |
148 | #define FSNODELOCKHELD 0x01000000 | |
149 | ||
150 | /* | |
151 | * Initialization of an nameidata structure. | |
152 | */ | |
153 | #define NDINIT(ndp, op, flags, segflg, namep, ctx) { \ | |
154 | (ndp)->ni_cnd.cn_nameiop = op; \ | |
155 | (ndp)->ni_cnd.cn_flags = flags; \ | |
156 | if ((segflg) == UIO_USERSPACE) { \ | |
157 | (ndp)->ni_segflg = ((IS_64BIT_PROCESS(vfs_context_proc(ctx))) ? UIO_USERSPACE64 : UIO_USERSPACE32); \ | |
158 | } \ | |
159 | else if ((segflg) == UIO_SYSSPACE) { \ | |
160 | (ndp)->ni_segflg = UIO_SYSSPACE32; \ | |
161 | } \ | |
162 | else { \ | |
163 | (ndp)->ni_segflg = segflg; \ | |
164 | } \ | |
165 | (ndp)->ni_dirp = namep; \ | |
166 | (ndp)->ni_cnd.cn_context = ctx; \ | |
167 | } | |
168 | #endif /* KERNEL */ | |
169 | ||
170 | /* | |
171 | * This structure describes the elements in the cache of recent | |
172 | * names looked up by namei. | |
173 | */ | |
174 | ||
175 | #define NCHNAMLEN 31 /* maximum name segment length we bother with */ | |
176 | #define NCHASHMASK 0x7fffffff | |
177 | ||
178 | struct namecache { | |
179 | TAILQ_ENTRY(namecache) nc_entry; /* chain of all entries */ | |
180 | LIST_ENTRY(namecache) nc_hash; /* hash chain */ | |
181 | LIST_ENTRY(namecache) nc_child; /* chain of ncp's that are children of a vp */ | |
182 | union { | |
183 | LIST_ENTRY(namecache) nc_link; /* chain of ncp's that 'name' a vp */ | |
184 | TAILQ_ENTRY(namecache) nc_negentry; /* chain of ncp's that 'name' a vp */ | |
185 | } nc_un; | |
186 | vnode_t nc_dvp; /* vnode of parent of name */ | |
187 | vnode_t nc_vp; /* vnode the name refers to */ | |
188 | unsigned int nc_whiteout:1, /* name has whiteout applied */ | |
189 | nc_hashval:31; /* hashval of stringname */ | |
190 | char * nc_name; /* pointer to segment name in string cache */ | |
191 | }; | |
192 | ||
193 | ||
194 | #ifdef KERNEL | |
195 | ||
196 | int namei(struct nameidata *ndp); | |
197 | void nameidone(struct nameidata *); | |
198 | int lookup(struct nameidata *ndp); | |
199 | int relookup(struct vnode *dvp, struct vnode **vpp, | |
200 | struct componentname *cnp); | |
201 | ||
202 | /* | |
203 | * namecache function prototypes | |
204 | */ | |
205 | void cache_purgevfs(mount_t mp); | |
206 | int cache_lookup_path(struct nameidata *ndp, struct componentname *cnp, vnode_t dp, | |
207 | vfs_context_t context, int *trailing_slash, int *dp_authorized); | |
208 | ||
209 | void vnode_cache_credentials(vnode_t vp, vfs_context_t context); | |
210 | void vnode_uncache_credentials(vnode_t vp); | |
211 | int reverse_lookup(vnode_t start_vp, vnode_t *lookup_vpp, | |
212 | struct filedesc *fdp, vfs_context_t context, int *dp_authorized); | |
213 | ||
214 | #endif /* KERNEL */ | |
215 | ||
216 | /* | |
217 | * Stats on usefulness of namei caches. | |
218 | */ | |
219 | struct nchstats { | |
220 | long ncs_goodhits; /* hits that we can really use */ | |
221 | long ncs_neghits; /* negative hits that we can use */ | |
222 | long ncs_badhits; /* hits we must drop */ | |
223 | long ncs_miss; /* misses */ | |
224 | long ncs_pass2; /* names found with passes == 2 */ | |
225 | long ncs_2passes; /* number of times we attempt it */ | |
226 | long ncs_stolen; | |
227 | long ncs_enters; | |
228 | long ncs_deletes; | |
229 | long ncs_badvid; | |
230 | }; | |
231 | #endif /* BSD_KERNEL_PRIVATE */ | |
232 | ||
233 | #endif /* !_SYS_NAMEI_H_ */ |