]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
55e303ae | 2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 A |
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 | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
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 | ||
9bccf70c A |
67 | #include <sys/appleapiopts.h> |
68 | ||
91447636 A |
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 | #endif | |
74 | ||
75 | ||
76 | #ifdef BSD_KERNEL_PRIVATE | |
9bccf70c | 77 | |
1c79356b A |
78 | #include <sys/queue.h> |
79 | #include <sys/uio.h> | |
91447636 A |
80 | #include <sys/vnode.h> |
81 | #include <sys/mount.h> | |
82 | #include <sys/filedesc.h> | |
1c79356b | 83 | |
91447636 | 84 | #define PATHBUFLEN 256 |
1c79356b A |
85 | |
86 | /* | |
87 | * Encapsulation of namei parameters. | |
88 | */ | |
89 | struct nameidata { | |
90 | /* | |
91 | * Arguments to namei/lookup. | |
92 | */ | |
91447636 | 93 | user_addr_t ni_dirp; /* pathname pointer */ |
1c79356b | 94 | enum uio_seg ni_segflg; /* location of pathname */ |
1c79356b A |
95 | /* |
96 | * Arguments to lookup. | |
97 | */ | |
1c79356b A |
98 | struct vnode *ni_startdir; /* starting directory */ |
99 | struct vnode *ni_rootdir; /* logical root directory */ | |
91447636 | 100 | struct vnode *ni_usedvp; /* directory passed in via USEDVP */ |
1c79356b A |
101 | /* |
102 | * Results: returned from/manipulated by lookup | |
103 | */ | |
104 | struct vnode *ni_vp; /* vnode of result */ | |
105 | struct vnode *ni_dvp; /* vnode of intermediate directory */ | |
106 | /* | |
107 | * Shared between namei and lookup/commit routines. | |
108 | */ | |
109 | u_int ni_pathlen; /* remaining chars in path */ | |
110 | char *ni_next; /* next location in pathname */ | |
91447636 | 111 | char ni_pathbuf[PATHBUFLEN]; |
1c79356b | 112 | u_long ni_loopcnt; /* count of symlinks encountered */ |
91447636 | 113 | |
1c79356b A |
114 | struct componentname ni_cnd; |
115 | }; | |
116 | ||
117 | #ifdef KERNEL | |
1c79356b A |
118 | /* |
119 | * namei operational modifier flags, stored in ni_cnd.flags | |
120 | */ | |
1c79356b | 121 | #define NOCACHE 0x0020 /* name must not be left in cache */ |
1c79356b | 122 | #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ |
55e303ae | 123 | #define SHAREDLEAF 0x0080 /* OK to have shared leaf lock */ |
1c79356b A |
124 | #define MODMASK 0x00fc /* mask of operational modifiers */ |
125 | /* | |
126 | * Namei parameter descriptors. | |
127 | * | |
1c79356b A |
128 | * SAVESTART is set only by the callers of namei. It implies SAVENAME |
129 | * plus the addition of saving the parent directory that contains the | |
130 | * name in ni_startdir. It allows repeated calls to lookup for the | |
131 | * name being sought. The caller is responsible for releasing the | |
132 | * buffer and for vrele'ing ni_startdir. | |
133 | */ | |
91447636 A |
134 | #define NOCROSSMOUNT 0x00000100 /* do not cross mount points */ |
135 | #define RDONLY 0x00000200 /* lookup with read-only semantics */ | |
136 | #define HASBUF 0x00000400 /* has allocated pathname buffer */ | |
137 | #define SAVENAME 0x00000800 /* save pathanme buffer */ | |
138 | #define SAVESTART 0x00001000 /* save starting directory */ | |
139 | #define ISSYMLINK 0x00010000 /* symlink needs interpretation */ | |
140 | #define DONOTAUTH 0x00020000 /* do not authorize during lookup */ | |
141 | #define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */ | |
142 | #define AUDITVNPATH1 0x00100000 /* audit the path/vnode info */ | |
143 | #define AUDITVNPATH2 0x00200000 /* audit the path/vnode info */ | |
144 | #define USEDVP 0x00400000 /* start the lookup at ndp.ni_dvp */ | |
145 | #define PARAMASK 0x003fff00 /* mask of parameter descriptors */ | |
146 | #define FSNODELOCKHELD 0x01000000 | |
147 | ||
1c79356b A |
148 | /* |
149 | * Initialization of an nameidata structure. | |
150 | */ | |
91447636 | 151 | #define NDINIT(ndp, op, flags, segflg, namep, ctx) { \ |
1c79356b A |
152 | (ndp)->ni_cnd.cn_nameiop = op; \ |
153 | (ndp)->ni_cnd.cn_flags = flags; \ | |
91447636 A |
154 | if ((segflg) == UIO_USERSPACE) { \ |
155 | (ndp)->ni_segflg = ((IS_64BIT_PROCESS(vfs_context_proc(ctx))) ? UIO_USERSPACE64 : UIO_USERSPACE32); \ | |
156 | } \ | |
157 | else if ((segflg) == UIO_SYSSPACE) { \ | |
158 | (ndp)->ni_segflg = UIO_SYSSPACE32; \ | |
159 | } \ | |
160 | else { \ | |
161 | (ndp)->ni_segflg = segflg; \ | |
162 | } \ | |
1c79356b | 163 | (ndp)->ni_dirp = namep; \ |
91447636 | 164 | (ndp)->ni_cnd.cn_context = ctx; \ |
1c79356b A |
165 | } |
166 | #endif /* KERNEL */ | |
167 | ||
168 | /* | |
169 | * This structure describes the elements in the cache of recent | |
91447636 | 170 | * names looked up by namei. |
1c79356b A |
171 | */ |
172 | ||
173 | #define NCHNAMLEN 31 /* maximum name segment length we bother with */ | |
91447636 | 174 | #define NCHASHMASK 0x7fffffff |
1c79356b A |
175 | |
176 | struct namecache { | |
91447636 A |
177 | TAILQ_ENTRY(namecache) nc_entry; /* chain of all entries */ |
178 | LIST_ENTRY(namecache) nc_hash; /* hash chain */ | |
179 | LIST_ENTRY(namecache) nc_child; /* chain of ncp's that are children of a vp */ | |
180 | union { | |
181 | LIST_ENTRY(namecache) nc_link; /* chain of ncp's that 'name' a vp */ | |
182 | TAILQ_ENTRY(namecache) nc_negentry; /* chain of ncp's that 'name' a vp */ | |
183 | } nc_un; | |
184 | vnode_t nc_dvp; /* vnode of parent of name */ | |
185 | vnode_t nc_vp; /* vnode the name refers to */ | |
186 | unsigned int nc_whiteout:1, /* name has whiteout applied */ | |
187 | nc_hashval:31; /* hashval of stringname */ | |
188 | char * nc_name; /* pointer to segment name in string cache */ | |
1c79356b A |
189 | }; |
190 | ||
91447636 | 191 | |
1c79356b | 192 | #ifdef KERNEL |
55e303ae | 193 | |
91447636 A |
194 | int namei(struct nameidata *ndp); |
195 | void nameidone(struct nameidata *); | |
196 | int lookup(struct nameidata *ndp); | |
197 | int relookup(struct vnode *dvp, struct vnode **vpp, | |
198 | struct componentname *cnp); | |
199 | ||
200 | /* | |
201 | * namecache function prototypes | |
202 | */ | |
203 | void cache_purgevfs(mount_t mp); | |
204 | int cache_lookup_path(struct nameidata *ndp, struct componentname *cnp, vnode_t dp, | |
205 | vfs_context_t context, int *trailing_slash, int *dp_authorized); | |
206 | ||
207 | void vnode_cache_credentials(vnode_t vp, vfs_context_t context); | |
208 | void vnode_uncache_credentials(vnode_t vp); | |
209 | int reverse_lookup(vnode_t start_vp, vnode_t *lookup_vpp, | |
210 | struct filedesc *fdp, vfs_context_t context, int *dp_authorized); | |
55e303ae | 211 | |
1c79356b A |
212 | #endif /* KERNEL */ |
213 | ||
214 | /* | |
215 | * Stats on usefulness of namei caches. | |
216 | */ | |
217 | struct nchstats { | |
21362eb3 | 218 | long ncs_negtotal; |
1c79356b A |
219 | long ncs_goodhits; /* hits that we can really use */ |
220 | long ncs_neghits; /* negative hits that we can use */ | |
221 | long ncs_badhits; /* hits we must drop */ | |
1c79356b | 222 | long ncs_miss; /* misses */ |
1c79356b A |
223 | long ncs_pass2; /* names found with passes == 2 */ |
224 | long ncs_2passes; /* number of times we attempt it */ | |
91447636 A |
225 | long ncs_stolen; |
226 | long ncs_enters; | |
227 | long ncs_deletes; | |
228 | long ncs_badvid; | |
1c79356b | 229 | }; |
91447636 | 230 | #endif /* BSD_KERNEL_PRIVATE */ |
9bccf70c | 231 | |
1c79356b | 232 | #endif /* !_SYS_NAMEI_H_ */ |