]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/namei.h
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / sys / namei.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 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
2d21ac55
A
78/* VFS Supports "/..namedfork/rsrc" access. */
79#define NAMEDRSRCFORK NAMEDSTREAMS
80
81
1c79356b
A
82#include <sys/queue.h>
83#include <sys/uio.h>
91447636
A
84#include <sys/vnode.h>
85#include <sys/mount.h>
86#include <sys/filedesc.h>
1c79356b 87
91447636 88#define PATHBUFLEN 256
1c79356b
A
89
90/*
91 * Encapsulation of namei parameters.
92 */
93struct nameidata {
94 /*
95 * Arguments to namei/lookup.
96 */
91447636 97 user_addr_t ni_dirp; /* pathname pointer */
1c79356b 98 enum uio_seg ni_segflg; /* location of pathname */
1c79356b
A
99 /*
100 * Arguments to lookup.
101 */
1c79356b
A
102 struct vnode *ni_startdir; /* starting directory */
103 struct vnode *ni_rootdir; /* logical root directory */
91447636 104 struct vnode *ni_usedvp; /* directory passed in via USEDVP */
1c79356b
A
105 /*
106 * Results: returned from/manipulated by lookup
107 */
108 struct vnode *ni_vp; /* vnode of result */
109 struct vnode *ni_dvp; /* vnode of intermediate directory */
110 /*
111 * Shared between namei and lookup/commit routines.
112 */
113 u_int ni_pathlen; /* remaining chars in path */
114 char *ni_next; /* next location in pathname */
91447636 115 char ni_pathbuf[PATHBUFLEN];
1c79356b 116 u_long ni_loopcnt; /* count of symlinks encountered */
91447636 117
1c79356b
A
118 struct componentname ni_cnd;
119};
120
121#ifdef KERNEL
1c79356b
A
122/*
123 * namei operational modifier flags, stored in ni_cnd.flags
2d21ac55 124 * Also includes LOCKLEAF, LOCKPARENT, and WANTPARENT flags, defined above.
1c79356b 125 */
2d21ac55
A
126#define NOCACHE 0x00000020 /* name must not be left in cache */
127#define NOFOLLOW 0x00000000 /* do not follow symbolic links (pseudo) */
128/* public FOLLOW 0x00000040 see vnode.h */
129#define SHAREDLEAF 0x00000080 /* OK to have shared leaf lock */
130/* public NOTRIGGER 0x10000000 see vnode.h */
131#define MODMASK 0x100000fc /* mask of operational modifiers */
1c79356b
A
132/*
133 * Namei parameter descriptors.
134 *
1c79356b
A
135 * SAVESTART is set only by the callers of namei. It implies SAVENAME
136 * plus the addition of saving the parent directory that contains the
137 * name in ni_startdir. It allows repeated calls to lookup for the
138 * name being sought. The caller is responsible for releasing the
139 * buffer and for vrele'ing ni_startdir.
140 */
2d21ac55 141#define SAVENAME 0 /* save pathanme buffer ***obsolete */
91447636
A
142#define NOCROSSMOUNT 0x00000100 /* do not cross mount points */
143#define RDONLY 0x00000200 /* lookup with read-only semantics */
144#define HASBUF 0x00000400 /* has allocated pathname buffer */
2d21ac55 145#define DONOTAUTH 0x00000800 /* do not authorize during lookup */
91447636 146#define SAVESTART 0x00001000 /* save starting directory */
2d21ac55
A
147/* public ISDOTDOT 0x00002000 see vnode.h */
148/* public MAKEENTRY 0x00004000 see vnode.h */
149/* public ISLASTCN 0x00008000 see vnode.h */
91447636 150#define ISSYMLINK 0x00010000 /* symlink needs interpretation */
2d21ac55
A
151/* public ISWHITEOUT 0x00020000 see vnode.h */
152/* public DOWHITEOUT 0x00040000 see vnode.h */
91447636
A
153#define WILLBEDIR 0x00080000 /* new files will be dirs; allow trailing / */
154#define AUDITVNPATH1 0x00100000 /* audit the path/vnode info */
155#define AUDITVNPATH2 0x00200000 /* audit the path/vnode info */
156#define USEDVP 0x00400000 /* start the lookup at ndp.ni_dvp */
2d21ac55 157#define CN_VOLFSPATH 0x00800000 /* user path was a volfs style path */
b0d623f7 158#ifndef __LP64__
91447636 159#define FSNODELOCKHELD 0x01000000
b0d623f7 160#endif /* __LP64__ */
2d21ac55
A
161#define UNIONCREATED 0x02000000 /* union fs creation of vnode */
162#if NAMEDRSRCFORK
163#define CN_WANTSRSRCFORK 0x04000000
164#define CN_ALLOWRSRCFORK 0x08000000
165#endif
166/* public NOTRIGGER 0x10000000 see vnode.h */
167#define CN_NBMOUNTLOOK 0x20000000 /* do not block for cross mount lookups */
91447636 168
1c79356b
A
169/*
170 * Initialization of an nameidata structure.
171 */
91447636 172#define NDINIT(ndp, op, flags, segflg, namep, ctx) { \
1c79356b
A
173 (ndp)->ni_cnd.cn_nameiop = op; \
174 (ndp)->ni_cnd.cn_flags = flags; \
91447636
A
175 if ((segflg) == UIO_USERSPACE) { \
176 (ndp)->ni_segflg = ((IS_64BIT_PROCESS(vfs_context_proc(ctx))) ? UIO_USERSPACE64 : UIO_USERSPACE32); \
177 } \
91447636
A
178 else { \
179 (ndp)->ni_segflg = segflg; \
180 } \
1c79356b 181 (ndp)->ni_dirp = namep; \
91447636 182 (ndp)->ni_cnd.cn_context = ctx; \
1c79356b
A
183}
184#endif /* KERNEL */
185
186/*
187 * This structure describes the elements in the cache of recent
91447636 188 * names looked up by namei.
1c79356b
A
189 */
190
91447636 191#define NCHASHMASK 0x7fffffff
1c79356b
A
192
193struct namecache {
91447636
A
194 TAILQ_ENTRY(namecache) nc_entry; /* chain of all entries */
195 LIST_ENTRY(namecache) nc_hash; /* hash chain */
196 LIST_ENTRY(namecache) nc_child; /* chain of ncp's that are children of a vp */
197 union {
198 LIST_ENTRY(namecache) nc_link; /* chain of ncp's that 'name' a vp */
199 TAILQ_ENTRY(namecache) nc_negentry; /* chain of ncp's that 'name' a vp */
200 } nc_un;
201 vnode_t nc_dvp; /* vnode of parent of name */
202 vnode_t nc_vp; /* vnode the name refers to */
203 unsigned int nc_whiteout:1, /* name has whiteout applied */
204 nc_hashval:31; /* hashval of stringname */
2d21ac55 205 const char *nc_name; /* pointer to segment name in string cache */
1c79356b
A
206};
207
91447636 208
1c79356b 209#ifdef KERNEL
55e303ae 210
91447636
A
211int namei(struct nameidata *ndp);
212void nameidone(struct nameidata *);
213int lookup(struct nameidata *ndp);
214int relookup(struct vnode *dvp, struct vnode **vpp,
215 struct componentname *cnp);
216
217/*
218 * namecache function prototypes
219 */
220void cache_purgevfs(mount_t mp);
221int cache_lookup_path(struct nameidata *ndp, struct componentname *cnp, vnode_t dp,
4a3eedf9 222 vfs_context_t context, int *trailing_slash, int *dp_authorized, vnode_t last_dp);
91447636 223
2d21ac55
A
224void vnode_cache_authorized_action(vnode_t vp, vfs_context_t context, kauth_action_t action);
225void vnode_uncache_authorized_action(vnode_t vp, kauth_action_t action);
226boolean_t vnode_cache_is_stale(vnode_t vp);
227boolean_t vnode_cache_is_authorized(vnode_t vp, vfs_context_t context, kauth_action_t action);
55e303ae 228
1c79356b
A
229#endif /* KERNEL */
230
231/*
232 * Stats on usefulness of namei caches.
233 */
234struct nchstats {
235 long ncs_goodhits; /* hits that we can really use */
236 long ncs_neghits; /* negative hits that we can use */
237 long ncs_badhits; /* hits we must drop */
1c79356b 238 long ncs_miss; /* misses */
1c79356b
A
239 long ncs_pass2; /* names found with passes == 2 */
240 long ncs_2passes; /* number of times we attempt it */
91447636
A
241 long ncs_stolen;
242 long ncs_enters;
243 long ncs_deletes;
244 long ncs_badvid;
1c79356b 245};
91447636 246#endif /* BSD_KERNEL_PRIVATE */
9bccf70c 247
1c79356b 248#endif /* !_SYS_NAMEI_H_ */