|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26: /*
27: * Copyright (c) 1985, 1989, 1991, 1993
28: * The Regents of the University of California. All rights reserved.
29: *
30: * Redistribution and use in source and binary forms, with or without
31: * modification, are permitted provided that the following conditions
32: * are met:
33: * 1. Redistributions of source code must retain the above copyright
34: * notice, this list of conditions and the following disclaimer.
35: * 2. Redistributions in binary form must reproduce the above copyright
36: * notice, this list of conditions and the following disclaimer in the
37: * documentation and/or other materials provided with the distribution.
38: * 3. All advertising materials mentioning features or use of this software
39: * must display the following acknowledgement:
40: * This product includes software developed by the University of
41: * California, Berkeley and its contributors.
42: * 4. Neither the name of the University nor the names of its contributors
43: * may be used to endorse or promote products derived from this software
44: * without specific prior written permission.
45: *
46: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56: * SUCH DAMAGE.
57: *
58: * @(#)namei.h 8.5 (Berkeley) 1/9/95
59: */
60:
61: #ifndef _SYS_NAMEI_H_
62: #define _SYS_NAMEI_H_
63:
64: #include <sys/queue.h>
65: #include <sys/uio.h>
66:
67: /*
68: * Encapsulation of namei parameters.
69: */
70: struct nameidata {
71: /*
72: * Arguments to namei/lookup.
73: */
74: caddr_t ni_dirp; /* pathname pointer */
75: enum uio_seg ni_segflg; /* location of pathname */
76: /* u_long ni_nameiop; namei operation */
77: /* u_long ni_flags; flags to namei */
78: /* struct proc *ni_proc; process requesting lookup */
79: /*
80: * Arguments to lookup.
81: */
82: /* struct ucred *ni_cred; credentials */
83: struct vnode *ni_startdir; /* starting directory */
84: struct vnode *ni_rootdir; /* logical root directory */
85: /*
86: * Results: returned from/manipulated by lookup
87: */
88: struct vnode *ni_vp; /* vnode of result */
89: struct vnode *ni_dvp; /* vnode of intermediate directory */
90: /*
91: * Shared between namei and lookup/commit routines.
92: */
93: u_int ni_pathlen; /* remaining chars in path */
94: char *ni_next; /* next location in pathname */
95: u_long ni_loopcnt; /* count of symlinks encountered */
96: /*
97: * Lookup parameters: this structure describes the subset of
98: * information from the nameidata structure that is passed
99: * through the VOP interface.
100: */
101: struct componentname {
102: /*
103: * Arguments to lookup.
104: */
105: u_long cn_nameiop; /* namei operation */
106: u_long cn_flags; /* flags to namei */
107: struct proc *cn_proc; /* process requesting lookup */
108: struct ucred *cn_cred; /* credentials */
109: /*
110: * Shared between lookup and commit routines.
111: */
112: char *cn_pnbuf; /* pathname buffer */
113: long cn_pnlen; /* length of allocated buffer */
114: char *cn_nameptr; /* pointer to looked up name */
115: long cn_namelen; /* length of looked up component */
116: u_long cn_hash; /* hash value of looked up name */
117: long cn_consume; /* chars to consume in lookup() */
118: } ni_cnd;
119: };
120:
121: #ifdef _KERNEL
122: /*
123: * namei operations
124: */
125: #define LOOKUP 0 /* perform name lookup only */
126: #define CREATE 1 /* setup for file creation */
127: #define DELETE 2 /* setup for file deletion */
128: #define RENAME 3 /* setup for file renaming */
129: #define OPMASK 3 /* mask for operation */
130: /*
131: * namei operational modifier flags, stored in ni_cnd.flags
132: */
133: #define LOCKLEAF 0x0004 /* lock inode on return */
134: #define LOCKPARENT 0x0008 /* want parent vnode returned locked */
135: #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */
136: #define NOCACHE 0x0020 /* name must not be left in cache */
137: #define FOLLOW 0x0040 /* follow symbolic links */
138: #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
139: #define MODMASK 0x00fc /* mask of operational modifiers */
140: /*
141: * Namei parameter descriptors.
142: *
143: * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
144: * If the caller of namei sets the flag (for example execve wants to
145: * know the name of the program that is being executed), then it must
146: * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
147: * be freed by either the commit routine or the VOP_ABORT routine.
148: * SAVESTART is set only by the callers of namei. It implies SAVENAME
149: * plus the addition of saving the parent directory that contains the
150: * name in ni_startdir. It allows repeated calls to lookup for the
151: * name being sought. The caller is responsible for releasing the
152: * buffer and for vrele'ing ni_startdir.
153: */
154: #define NOCROSSMOUNT 0x00100 /* do not cross mount points */
155: #define RDONLY 0x00200 /* lookup with read-only semantics */
156: #define HASBUF 0x00400 /* has allocated pathname buffer */
157: #define SAVENAME 0x00800 /* save pathanme buffer */
158: #define SAVESTART 0x01000 /* save starting directory */
159: #define ISDOTDOT 0x02000 /* current component name is .. */
160: #define MAKEENTRY 0x04000 /* entry is to be added to name cache */
161: #define ISLASTCN 0x08000 /* this is last component of pathname */
162: #define ISSYMLINK 0x10000 /* symlink needs interpretation */
163: #define ISWHITEOUT 0x20000 /* found whiteout */
164: #define DOWHITEOUT 0x40000 /* do whiteouts */
165: #define PARAMASK 0xfff00 /* mask of parameter descriptors */
166: /*
167: * Initialization of an nameidata structure.
168: */
169: #define NDINIT(ndp, op, flags, segflg, namep, p) { \
170: (ndp)->ni_cnd.cn_nameiop = op; \
171: (ndp)->ni_cnd.cn_flags = flags; \
172: (ndp)->ni_segflg = segflg; \
173: (ndp)->ni_dirp = namep; \
174: (ndp)->ni_cnd.cn_proc = p; \
175: }
176: #endif /* _KERNEL */
177:
178: /*
179: * This structure describes the elements in the cache of recent
180: * names looked up by namei. NCHNAMLEN is sized to make structure
181: * size a power of two to optimize malloc's. Minimum reasonable
182: * size is 15.
183: */
184:
185: #define NCHNAMLEN 31 /* maximum name segment length we bother with */
186:
187: struct namecache {
188: LIST_ENTRY(namecache) nc_hash; /* hash chain */
189: TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */
190: struct vnode *nc_dvp; /* vnode of parent of name */
191: u_long nc_dvpid; /* capability number of nc_dvp */
192: struct vnode *nc_vp; /* vnode the name refers to */
193: u_long nc_vpid; /* capability number of nc_vp */
194: char nc_nlen; /* length of name */
195: char nc_name[NCHNAMLEN]; /* segment name */
196: };
197:
198: #ifdef _KERNEL
199: extern u_long nextvnodeid;
200: int namei __P((struct nameidata *ndp));
201: int lookup __P((struct nameidata *ndp));
202: int relookup __P((struct vnode *dvp, struct vnode **vpp,
203: struct componentname *cnp));
204: #endif /* _KERNEL */
205:
206: /*
207: * Stats on usefulness of namei caches.
208: */
209: struct nchstats {
210: long ncs_goodhits; /* hits that we can really use */
211: long ncs_neghits; /* negative hits that we can use */
212: long ncs_badhits; /* hits we must drop */
213: long ncs_falsehits; /* hits with id mismatch */
214: long ncs_miss; /* misses */
215: long ncs_long; /* long names that ignore cache */
216: long ncs_pass2; /* names found with passes == 2 */
217: long ncs_2passes; /* number of times we attempt it */
218: };
219: #endif /* !_SYS_NAMEI_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.