]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/namei.h
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1985, 1989, 1991, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
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.
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
55 * @(#)namei.h 8.4 (Berkeley) 8/20/94
61 #include <sys/appleapiopts.h>
63 #ifdef __APPLE_API_UNSTABLE
65 #include <sys/queue.h>
69 * Lookup parameters: this structure describes the subset of
70 * information from the nameidata structure that is passed
71 * through the VOP interface.
73 struct componentname
{
75 * Arguments to lookup.
77 u_long cn_nameiop
; /* namei operation */
78 u_long cn_flags
; /* flags to namei */
79 struct proc
*cn_proc
; /* process requesting lookup */
80 struct ucred
*cn_cred
; /* credentials */
82 * Shared between lookup and commit routines.
84 char *cn_pnbuf
; /* pathname buffer */
85 long cn_pnlen
; /* length of allocated buffer */
86 char *cn_nameptr
; /* pointer to looked up name */
87 long cn_namelen
; /* length of looked up component */
88 u_long cn_hash
; /* hash value of looked up name */
89 long cn_consume
; /* chars to consume in lookup() */
93 * Encapsulation of namei parameters.
97 * Arguments to namei/lookup.
99 caddr_t ni_dirp
; /* pathname pointer */
100 enum uio_seg ni_segflg
; /* location of pathname */
101 /* u_long ni_nameiop; namei operation */
102 /* u_long ni_flags; flags to namei */
103 /* struct proc *ni_proc; process requesting lookup */
105 * Arguments to lookup.
107 /* struct ucred *ni_cred; credentials */
108 struct vnode
*ni_startdir
; /* starting directory */
109 struct vnode
*ni_rootdir
; /* logical root directory */
111 * Results: returned from/manipulated by lookup
113 struct vnode
*ni_vp
; /* vnode of result */
114 struct vnode
*ni_dvp
; /* vnode of intermediate directory */
116 * Shared between namei and lookup/commit routines.
118 u_int ni_pathlen
; /* remaining chars in path */
119 char *ni_next
; /* next location in pathname */
120 u_long ni_loopcnt
; /* count of symlinks encountered */
121 struct componentname ni_cnd
;
128 #define LOOKUP 0 /* perform name lookup only */
129 #define CREATE 1 /* setup for file creation */
130 #define DELETE 2 /* setup for file deletion */
131 #define RENAME 3 /* setup for file renaming */
132 #define OPMASK 3 /* mask for operation */
134 * namei operational modifier flags, stored in ni_cnd.flags
136 #define LOCKLEAF 0x0004 /* lock inode on return */
137 #define LOCKPARENT 0x0008 /* want parent vnode returned locked */
138 #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */
139 #define NOCACHE 0x0020 /* name must not be left in cache */
140 #define FOLLOW 0x0040 /* follow symbolic links */
141 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
142 #define SHAREDLEAF 0x0080 /* OK to have shared leaf lock */
143 #define MODMASK 0x00fc /* mask of operational modifiers */
145 * Namei parameter descriptors.
147 * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
148 * If the caller of namei sets the flag (for example execve wants to
149 * know the name of the program that is being executed), then it must
150 * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
151 * be freed by either the commit routine or the VOP_ABORT routine.
152 * SAVESTART is set only by the callers of namei. It implies SAVENAME
153 * plus the addition of saving the parent directory that contains the
154 * name in ni_startdir. It allows repeated calls to lookup for the
155 * name being sought. The caller is responsible for releasing the
156 * buffer and for vrele'ing ni_startdir.
158 #define NOCROSSMOUNT 0x000100 /* do not cross mount points */
159 #define RDONLY 0x000200 /* lookup with read-only semantics */
160 #define HASBUF 0x000400 /* has allocated pathname buffer */
161 #define SAVENAME 0x000800 /* save pathanme buffer */
162 #define SAVESTART 0x001000 /* save starting directory */
163 #define ISDOTDOT 0x002000 /* current component name is .. */
164 #define MAKEENTRY 0x004000 /* entry is to be added to name cache */
165 #define ISLASTCN 0x008000 /* this is last component of pathname */
166 #define ISSYMLINK 0x010000 /* symlink needs interpretation */
167 #define ISWHITEOUT 0x020000 /* found whiteout */
168 #define DOWHITEOUT 0x040000 /* do whiteouts */
169 #define WILLBEDIR 0x080000 /* new files will be dirs; allow trailing / */
170 #define AUDITVNPATH1 0x100000 /* audit the path/vnode info */
171 #define AUDITVNPATH2 0x200000 /* audit the path/vnode info */
172 #define USEDVP 0x400000 /* start the lookup at ndp.ni_dvp */
173 #define NODELETEBUSY 0x800000 /* donot delete busy files (Carbon semantic) */
174 #define PARAMASK 0x3fff00 /* mask of parameter descriptors */
176 * Initialization of an nameidata structure.
178 #define NDINIT(ndp, op, flags, segflg, namep, p) { \
179 (ndp)->ni_cnd.cn_nameiop = op; \
180 (ndp)->ni_cnd.cn_flags = flags; \
181 (ndp)->ni_segflg = segflg; \
182 (ndp)->ni_dirp = namep; \
183 (ndp)->ni_cnd.cn_proc = p; \
188 * This structure describes the elements in the cache of recent
189 * names looked up by namei. NCHNAMLEN is sized to make structure
190 * size a power of two to optimize malloc's. Minimum reasonable
194 #define NCHNAMLEN 31 /* maximum name segment length we bother with */
197 LIST_ENTRY(namecache
) nc_hash
; /* hash chain */
198 TAILQ_ENTRY(namecache
) nc_lru
; /* LRU chain */
199 struct vnode
*nc_dvp
; /* vnode of parent of name */
200 u_long nc_dvpid
; /* capability number of nc_dvp */
201 struct vnode
*nc_vp
; /* vnode the name refers to */
202 u_long nc_vpid
; /* capability number of nc_vp */
203 char *nc_name
; /* segment name */
208 extern u_long nextvnodeid
;
209 int namei
__P((struct nameidata
*ndp
));
210 int lookup
__P((struct nameidata
*ndp
));
211 int relookup
__P((struct vnode
*dvp
, struct vnode
**vpp
,
212 struct componentname
*cnp
));
214 /* namecache function prototypes */
215 int cache_lookup
__P((struct vnode
*dvp
, struct vnode
**vpp
,
216 struct componentname
*cnp
));
217 void cache_enter
__P((struct vnode
*dvp
, struct vnode
*vpp
,
218 struct componentname
*cnp
));
219 void cache_purge
__P((struct vnode
*vp
));
220 void cache_purgevfs
__P((struct mount
*mp
));
223 // Global string-cache routines. You can pass zero for nc_hash
224 // if you don't know it (add_name() will then compute the hash).
225 // There are no flags for now but maybe someday.
227 char *add_name(const char *name
, size_t len
, u_int nc_hash
, u_int flags
);
228 int remove_name(const char *name
);
234 * Stats on usefulness of namei caches.
237 long ncs_goodhits
; /* hits that we can really use */
238 long ncs_neghits
; /* negative hits that we can use */
239 long ncs_badhits
; /* hits we must drop */
240 long ncs_falsehits
; /* hits with id mismatch */
241 long ncs_miss
; /* misses */
242 long ncs_long
; /* long names that ignore cache */
243 long ncs_pass2
; /* names found with passes == 2 */
244 long ncs_2passes
; /* number of times we attempt it */
246 #endif /* __APPLE_API_UNSTABLE */
248 #endif /* !_SYS_NAMEI_H_ */