]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2014 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_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 License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1985, 1989, 1991, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * | |
33 | * Redistribution and use in source and binary forms, with or without | |
34 | * modification, are permitted provided that the following conditions | |
35 | * are met: | |
36 | * 1. Redistributions of source code must retain the above copyright | |
37 | * notice, this list of conditions and the following disclaimer. | |
38 | * 2. Redistributions in binary form must reproduce the above copyright | |
39 | * notice, this list of conditions and the following disclaimer in the | |
40 | * documentation and/or other materials provided with the distribution. | |
41 | * 3. All advertising materials mentioning features or use of this software | |
42 | * must display the following acknowledgement: | |
43 | * This product includes software developed by the University of | |
44 | * California, Berkeley and its contributors. | |
45 | * 4. Neither the name of the University nor the names of its contributors | |
46 | * may be used to endorse or promote products derived from this software | |
47 | * without specific prior written permission. | |
48 | * | |
49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | |
60 | * | |
61 | * @(#)namei.h 8.4 (Berkeley) 8/20/94 | |
62 | */ | |
63 | ||
64 | #ifndef _SYS_NAMEI_H_ | |
65 | #define _SYS_NAMEI_H_ | |
66 | ||
67 | #include <sys/appleapiopts.h> | |
68 | ||
69 | #ifdef KERNEL | |
70 | #define LOCKLEAF 0x0004 /* lock inode on return */ | |
71 | #define LOCKPARENT 0x0008 /* want parent vnode returned */ | |
72 | #define WANTPARENT 0x0010 /* want parent vnode returned */ | |
73 | ||
74 | #ifdef KERNEL_PRIVATE | |
75 | #define CN_SECLUDE_RENAME 0x10000000 /*rename iff ¬(hard-linked ∨ opened ∨ mmaped)*/ | |
76 | #define CN_RAW_ENCRYPTED 0x80000000 /* Look-up is for RO raw encrypted access. */ | |
77 | #endif | |
78 | ||
79 | #endif // KERNEL | |
80 | ||
81 | #ifdef BSD_KERNEL_PRIVATE | |
82 | ||
83 | /* VFS Supports "/..namedfork/rsrc" access. */ | |
84 | #define NAMEDRSRCFORK NAMEDSTREAMS | |
85 | ||
86 | ||
87 | #include <sys/queue.h> | |
88 | #include <sys/uio.h> | |
89 | #include <sys/vnode.h> | |
90 | #include <sys/mount.h> | |
91 | #include <sys/filedesc.h> | |
92 | ||
93 | #define PATHBUFLEN 256 | |
94 | ||
95 | /* | |
96 | * Encapsulation of namei parameters. | |
97 | */ | |
98 | struct nameidata { | |
99 | /* | |
100 | * Arguments to namei/lookup. | |
101 | */ | |
102 | user_addr_t ni_dirp; /* pathname pointer */ | |
103 | enum uio_seg ni_segflg; /* location of pathname */ | |
104 | #if CONFIG_TRIGGERS | |
105 | enum path_operation ni_op; /* intended operation, see enum path_operation in vnode.h */ | |
106 | #endif /* CONFIG_TRIGGERS */ | |
107 | /* | |
108 | * Arguments to lookup. | |
109 | */ | |
110 | struct vnode *ni_startdir; /* starting directory */ | |
111 | struct vnode *ni_rootdir; /* logical root directory */ | |
112 | struct vnode *ni_usedvp; /* directory passed in via USEDVP */ | |
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 | char ni_pathbuf[PATHBUFLEN]; | |
124 | u_long ni_loopcnt; /* count of symlinks encountered */ | |
125 | ||
126 | struct componentname ni_cnd; | |
127 | int32_t ni_flag; | |
128 | int ni_ncgeneration; /* For a batched vnop, grab generation beforehand */ | |
129 | }; | |
130 | ||
131 | #define NAMEI_CONTLOOKUP 0x002 /* Continue processing a lookup which was partially processed in a compound VNOP */ | |
132 | #define NAMEI_TRAILINGSLASH 0x004 /* There was at least one trailing slash after last component */ | |
133 | #define NAMEI_UNFINISHED 0x008 /* We broke off a lookup to do a compound op */ | |
134 | /* | |
135 | * XXX Hack: we need to encode the intended VNOP in order to | |
136 | * be able to include information about which operations a filesystem | |
137 | * supports in the decision to break off a lookup early. | |
138 | */ | |
139 | #define NAMEI_COMPOUNDOPEN 0x010 | |
140 | #define NAMEI_COMPOUNDREMOVE 0x020 | |
141 | #define NAMEI_COMPOUNDMKDIR 0x040 | |
142 | #define NAMEI_COMPOUNDRMDIR 0x080 | |
143 | #define NAMEI_COMPOUNDRENAME 0x100 | |
144 | #define NAMEI_COMPOUND_OP_MASK (NAMEI_COMPOUNDOPEN | NAMEI_COMPOUNDREMOVE | NAMEI_COMPOUNDMKDIR | NAMEI_COMPOUNDRMDIR | NAMEI_COMPOUNDRENAME) | |
145 | ||
146 | #ifdef KERNEL | |
147 | /* | |
148 | * namei operational modifier flags, stored in ni_cnd.flags | |
149 | * Also includes LOCKLEAF, LOCKPARENT, and WANTPARENT flags, defined above. | |
150 | */ | |
151 | #define NOCACHE 0x00000020 /* name must not be left in cache */ | |
152 | #define NOFOLLOW 0x00000000 /* do not follow symbolic links (pseudo) */ | |
153 | /* public FOLLOW 0x00000040 see vnode.h */ | |
154 | #define SHAREDLEAF 0x00000080 /* OK to have shared leaf lock */ | |
155 | #define MODMASK 0x100000fc /* mask of operational modifiers */ | |
156 | /* | |
157 | * Namei parameter descriptors. | |
158 | * | |
159 | * SAVESTART is set only by the callers of namei. It implies SAVENAME | |
160 | * plus the addition of saving the parent directory that contains the | |
161 | * name in ni_startdir. It allows repeated calls to lookup for the | |
162 | * name being sought. The caller is responsible for releasing the | |
163 | * buffer and for vrele'ing ni_startdir. | |
164 | */ | |
165 | #define SAVENAME 0 /* save pathanme buffer ***obsolete */ | |
166 | #define NOCROSSMOUNT 0x00000100 /* do not cross mount points */ | |
167 | #define RDONLY 0x00000200 /* lookup with read-only semantics */ | |
168 | #define HASBUF 0x00000400 /* has allocated pathname buffer */ | |
169 | #define DONOTAUTH 0x00000800 /* do not authorize during lookup */ | |
170 | #define SAVESTART 0x00001000 /* save starting directory */ | |
171 | /* public ISDOTDOT 0x00002000 see vnode.h */ | |
172 | /* public MAKEENTRY 0x00004000 see vnode.h */ | |
173 | /* public ISLASTCN 0x00008000 see vnode.h */ | |
174 | #define ISSYMLINK 0x00010000 /* symlink needs interpretation */ | |
175 | /* public ISWHITEOUT 0x00020000 see vnode.h */ | |
176 | /* public DOWHITEOUT 0x00040000 see vnode.h */ | |
177 | #define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */ | |
178 | #define AUDITVNPATH1 0x00100000 /* audit the path/vnode info */ | |
179 | #define AUDITVNPATH2 0x00200000 /* audit the path/vnode info */ | |
180 | #define USEDVP 0x00400000 /* start the lookup at ndp.ni_dvp */ | |
181 | #define CN_VOLFSPATH 0x00800000 /* user path was a volfs style path */ | |
182 | #define CN_FIRMLINK_NOFOLLOW 0x01000000 /* Do not follow firm links */ | |
183 | #define UNIONCREATED 0x02000000 /* union fs creation of vnode */ | |
184 | #if NAMEDRSRCFORK | |
185 | #define CN_WANTSRSRCFORK 0x04000000 | |
186 | #define CN_ALLOWRSRCFORK 0x08000000 | |
187 | #endif // NAMEDRSRCFORK | |
188 | // CN_SECLUDE_RENAME is defined above as 0x10000000 (SPI) | |
189 | #define CN_NBMOUNTLOOK 0x20000000 /* do not block for cross mount lookups */ | |
190 | #ifdef BSD_KERNEL_PRIVATE | |
191 | #define CN_SKIPNAMECACHE 0x40000000 /* skip cache during lookup(), allow FS to handle all components */ | |
192 | #endif | |
193 | // CN_RAW_ENCRYPTED is defined above as 0x80000000 (SPI) | |
194 | ||
195 | /* | |
196 | * Initialization of an nameidata structure. | |
197 | */ | |
198 | ||
199 | #if CONFIG_TRIGGERS | |
200 | /* Note: vnode triggers require more precise path operation (ni_op) */ | |
201 | ||
202 | #define NDINIT(ndp, op, pop, flags, segflg, namep, ctx) { \ | |
203 | (ndp)->ni_cnd.cn_nameiop = op; \ | |
204 | (ndp)->ni_op = pop; \ | |
205 | (ndp)->ni_cnd.cn_flags = flags; \ | |
206 | if ((segflg) == UIO_USERSPACE) { \ | |
207 | (ndp)->ni_segflg = ((IS_64BIT_PROCESS(vfs_context_proc(ctx))) ? UIO_USERSPACE64 : UIO_USERSPACE32); \ | |
208 | } \ | |
209 | else { \ | |
210 | (ndp)->ni_segflg = segflg; \ | |
211 | } \ | |
212 | (ndp)->ni_dirp = namep; \ | |
213 | (ndp)->ni_cnd.cn_context = ctx; \ | |
214 | (ndp)->ni_flag = 0; \ | |
215 | (ndp)->ni_cnd.cn_ndp = (ndp); \ | |
216 | } | |
217 | #else | |
218 | #define NDINIT(ndp, op, _unused_, flags, segflg, namep, ctx) { \ | |
219 | (ndp)->ni_cnd.cn_nameiop = op; \ | |
220 | (ndp)->ni_cnd.cn_flags = flags; \ | |
221 | if ((segflg) == UIO_USERSPACE) { \ | |
222 | (ndp)->ni_segflg = ((IS_64BIT_PROCESS(vfs_context_proc(ctx))) ? UIO_USERSPACE64 : UIO_USERSPACE32); \ | |
223 | } \ | |
224 | else { \ | |
225 | (ndp)->ni_segflg = segflg; \ | |
226 | } \ | |
227 | (ndp)->ni_dirp = namep; \ | |
228 | (ndp)->ni_cnd.cn_context = ctx; \ | |
229 | (ndp)->ni_flag = 0; \ | |
230 | (ndp)->ni_cnd.cn_ndp = (ndp); \ | |
231 | } | |
232 | #endif /* CONFIG_TRIGGERS */ | |
233 | ||
234 | #endif /* KERNEL */ | |
235 | ||
236 | /* | |
237 | * This structure describes the elements in the cache of recent | |
238 | * names looked up by namei. | |
239 | */ | |
240 | struct namecache { | |
241 | TAILQ_ENTRY(namecache) nc_entry; /* chain of all entries */ | |
242 | TAILQ_ENTRY(namecache) nc_child; /* chain of ncp's that are children of a vp */ | |
243 | union { | |
244 | LIST_ENTRY(namecache) nc_link; /* chain of ncp's that 'name' a vp */ | |
245 | TAILQ_ENTRY(namecache) nc_negentry; /* chain of ncp's that 'name' a vp */ | |
246 | } nc_un; | |
247 | LIST_ENTRY(namecache) nc_hash; /* hash chain */ | |
248 | vnode_t nc_dvp; /* vnode of parent of name */ | |
249 | vnode_t nc_vp; /* vnode the name refers to */ | |
250 | unsigned int nc_hashval; /* hashval of stringname */ | |
251 | const char *nc_name; /* pointer to segment name in string cache */ | |
252 | }; | |
253 | ||
254 | ||
255 | #ifdef KERNEL | |
256 | ||
257 | int namei(struct nameidata *ndp); | |
258 | void nameidone(struct nameidata *); | |
259 | int lookup(struct nameidata *ndp); | |
260 | int relookup(struct vnode *dvp, struct vnode **vpp, | |
261 | struct componentname *cnp); | |
262 | int lookup_traverse_union(vnode_t dvp, vnode_t *new_dvp, vfs_context_t ctx); | |
263 | void lookup_compound_vnop_post_hook(int error, vnode_t dvp, vnode_t vp, struct nameidata *ndp, int did_create); | |
264 | void kdebug_lookup(struct vnode *dp, struct componentname *cnp); | |
265 | ||
266 | /* | |
267 | * namecache function prototypes | |
268 | */ | |
269 | void cache_purgevfs(mount_t mp); | |
270 | int cache_lookup_path(struct nameidata *ndp, struct componentname *cnp, vnode_t dp, | |
271 | vfs_context_t context, int *dp_authorized, vnode_t last_dp); | |
272 | ||
273 | void vnode_cache_authorized_action(vnode_t vp, vfs_context_t context, kauth_action_t action); | |
274 | void vnode_uncache_authorized_action(vnode_t vp, kauth_action_t action); | |
275 | boolean_t vnode_cache_is_stale(vnode_t vp); | |
276 | boolean_t vnode_cache_is_authorized(vnode_t vp, vfs_context_t context, kauth_action_t action); | |
277 | int lookup_validate_creation_path(struct nameidata *ndp); | |
278 | int namei_compound_available(vnode_t dp, struct nameidata *ndp); | |
279 | ||
280 | #endif /* KERNEL */ | |
281 | ||
282 | /* | |
283 | * Stats on usefulness of namei caches. | |
284 | */ | |
285 | struct nchstats { | |
286 | long ncs_goodhits; /* hits that we can really use */ | |
287 | long ncs_neghits; /* negative hits that we can use */ | |
288 | long ncs_badhits; /* hits we must drop */ | |
289 | long ncs_miss; /* misses */ | |
290 | long ncs_pass2; /* names found with passes == 2 */ | |
291 | long ncs_2passes; /* number of times we attempt it */ | |
292 | long ncs_stolen; | |
293 | long ncs_enters; | |
294 | long ncs_deletes; | |
295 | long ncs_badvid; | |
296 | }; | |
297 | #endif /* BSD_KERNEL_PRIVATE */ | |
298 | ||
299 | #endif /* !_SYS_NAMEI_H_ */ |