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