]>
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>
64 #define LOCKLEAF 0x0004 /* lock inode on return */
65 #define LOCKPARENT 0x0008 /* want parent vnode returned */
66 #define WANTPARENT 0x0010 /* want parent vnode returned */
70 #ifdef BSD_KERNEL_PRIVATE
72 #include <sys/queue.h>
74 #include <sys/vnode.h>
75 #include <sys/mount.h>
76 #include <sys/filedesc.h>
78 #define PATHBUFLEN 256
81 * Encapsulation of namei parameters.
85 * Arguments to namei/lookup.
87 user_addr_t ni_dirp
; /* pathname pointer */
88 enum uio_seg ni_segflg
; /* location of pathname */
90 * Arguments to lookup.
92 struct vnode
*ni_startdir
; /* starting directory */
93 struct vnode
*ni_rootdir
; /* logical root directory */
94 struct vnode
*ni_usedvp
; /* directory passed in via USEDVP */
96 * Results: returned from/manipulated by lookup
98 struct vnode
*ni_vp
; /* vnode of result */
99 struct vnode
*ni_dvp
; /* vnode of intermediate directory */
101 * Shared between namei and lookup/commit routines.
103 u_int ni_pathlen
; /* remaining chars in path */
104 char *ni_next
; /* next location in pathname */
105 char ni_pathbuf
[PATHBUFLEN
];
106 u_long ni_loopcnt
; /* count of symlinks encountered */
108 struct componentname ni_cnd
;
113 * namei operational modifier flags, stored in ni_cnd.flags
115 #define NOCACHE 0x0020 /* name must not be left in cache */
116 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
117 #define SHAREDLEAF 0x0080 /* OK to have shared leaf lock */
118 #define MODMASK 0x00fc /* mask of operational modifiers */
120 * Namei parameter descriptors.
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.
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
143 * Initialization of an nameidata structure.
145 #define NDINIT(ndp, op, flags, segflg, namep, ctx) { \
146 (ndp)->ni_cnd.cn_nameiop = op; \
147 (ndp)->ni_cnd.cn_flags = flags; \
148 if ((segflg) == UIO_USERSPACE) { \
149 (ndp)->ni_segflg = ((IS_64BIT_PROCESS(vfs_context_proc(ctx))) ? UIO_USERSPACE64 : UIO_USERSPACE32); \
151 else if ((segflg) == UIO_SYSSPACE) { \
152 (ndp)->ni_segflg = UIO_SYSSPACE32; \
155 (ndp)->ni_segflg = segflg; \
157 (ndp)->ni_dirp = namep; \
158 (ndp)->ni_cnd.cn_context = ctx; \
163 * This structure describes the elements in the cache of recent
164 * names looked up by namei.
167 #define NCHNAMLEN 31 /* maximum name segment length we bother with */
168 #define NCHASHMASK 0x7fffffff
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 */
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 */
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 */
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
);
195 * namecache function prototypes
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
);
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
);
209 * Stats on usefulness of namei caches.
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 */
216 long ncs_miss
; /* misses */
217 long ncs_pass2
; /* names found with passes == 2 */
218 long ncs_2passes
; /* number of times we attempt it */
224 #endif /* BSD_KERNEL_PRIVATE */
226 #endif /* !_SYS_NAMEI_H_ */