Annotation of src/sys/sys/namei.src, Revision 1.8.4.1
1.8.4.1 ! yamt 1: /* $NetBSD: namei.src,v 1.8 2008/04/11 15:51:25 ad Exp $ */
1.1 pooka 2:
3: /*
4: * Copyright (c) 1985, 1989, 1991, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. Neither the name of the University nor the names of its contributors
16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: *
31: * @(#)namei.h 8.5 (Berkeley) 8/20/94
32: */
33:
34: #ifndef _SYS_NAMEI_H_
35: #define _SYS_NAMEI_H_
36:
37: #include <sys/queue.h>
1.7 ad 38: #include <sys/mutex.h>
1.8 ad 39:
40: #ifdef _KERNEL
1.7 ad 41: #include <sys/kauth.h>
42:
1.1 pooka 43: /*
44: * Encapsulation of namei parameters.
45: */
46: struct nameidata {
47: /*
48: * Arguments to namei/lookup.
49: */
50: const char *ni_dirp; /* pathname pointer */
51: enum uio_seg ni_segflg; /* location of pathname */
52: /*
53: * Arguments to lookup.
54: */
55: struct vnode *ni_startdir; /* starting directory */
56: struct vnode *ni_rootdir; /* logical root directory */
57: struct vnode *ni_erootdir; /* emulation root directory */
58: /*
59: * Results: returned from/manipulated by lookup
60: */
61: struct vnode *ni_vp; /* vnode of result */
62: struct vnode *ni_dvp; /* vnode of intermediate directory */
63: /*
64: * Shared between namei and lookup/commit routines.
65: */
1.3 pooka 66: size_t ni_pathlen; /* remaining chars in path */
67: const char *ni_next; /* next location in pathname */
68: unsigned int ni_loopcnt; /* count of symlinks encountered */
1.1 pooka 69: /*
70: * Lookup parameters: this structure describes the subset of
71: * information from the nameidata structure that is passed
72: * through the VOP interface.
73: */
74: struct componentname {
75: /*
76: * Arguments to lookup.
77: */
1.3 pooka 78: uint32_t cn_nameiop; /* namei operation */
79: uint32_t cn_flags; /* flags to namei */
80: kauth_cred_t cn_cred; /* credentials */
1.1 pooka 81: /*
82: * Shared between lookup and commit routines.
83: */
1.3 pooka 84: char *cn_pnbuf; /* pathname buffer */
85: const char *cn_nameptr; /* pointer to looked up name */
86: size_t cn_namelen; /* length of looked up comp */
87: u_long cn_hash; /* hash val of looked up name */
88: size_t cn_consume; /* chars to consume in lookup */
1.1 pooka 89: } ni_cnd;
90: };
91:
92: /*
93: * namei operations
94: */
95: NAMEIFL LOOKUP 0 /* perform name lookup only */
96: NAMEIFL CREATE 1 /* setup for file creation */
97: NAMEIFL DELETE 2 /* setup for file deletion */
98: NAMEIFL RENAME 3 /* setup for file renaming */
99: NAMEIFL OPMASK 3 /* mask for operation */
100: /*
101: * namei operational modifier flags, stored in ni_cnd.cn_flags
102: */
1.8.4.1 ! yamt 103: NAMEIFL LOCKLEAF 0x00000004 /* lock inode on return */
! 104: NAMEIFL LOCKPARENT 0x00000008 /* want parent vnode returned locked */
! 105: NAMEIFL TRYEMULROOT 0x00000010 /* try relative to emulation root
! 106: first */
! 107: NAMEIFL NOCACHE 0x00000020 /* name must not be left in cache */
! 108: NAMEIFL FOLLOW 0x00000040 /* follow symbolic links */
! 109: NAMEIFL NOFOLLOW 0x00000000 /* do not follow symbolic links
! 110: (pseudo) */
! 111: NAMEIFL EMULROOTSET 0x00000080 /* emulation root already
! 112: in ni_erootdir */
! 113: NAMEIFL NOCHROOT 0x01000000 /* no chroot on abs path lookups */
! 114: NAMEIFL MODMASK 0x010000fc /* mask of operational modifiers */
1.1 pooka 115: /*
116: * Namei parameter descriptors.
117: *
118: * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
119: * If the caller of namei sets the flag (for example execve wants to
120: * know the name of the program that is being executed), then it must
121: * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
122: * be freed by either the commit routine or the VOP_ABORT routine.
123: * SAVESTART is set only by the callers of namei. It implies SAVENAME
124: * plus the addition of saving the parent directory that contains the
125: * name in ni_startdir. It allows repeated calls to lookup for the
126: * name being sought. The caller is responsible for releasing the
127: * buffer and for vrele'ing ni_startdir.
128: */
129: NAMEIFL NOCROSSMOUNT 0x0000100 /* do not cross mount points */
130: NAMEIFL RDONLY 0x0000200 /* lookup with read-only semantics */
131: NAMEIFL HASBUF 0x0000400 /* has allocated pathname buffer */
132: NAMEIFL SAVENAME 0x0000800 /* save pathname buffer */
133: NAMEIFL SAVESTART 0x0001000 /* save starting directory */
134: NAMEIFL ISDOTDOT 0x0002000 /* current component name is .. */
135: NAMEIFL MAKEENTRY 0x0004000 /* entry is to be added to name cache */
136: NAMEIFL ISLASTCN 0x0008000 /* this is last component of pathname */
137: NAMEIFL ISSYMLINK 0x0010000 /* symlink needs interpretation */
138: NAMEIFL ISWHITEOUT 0x0020000 /* found whiteout */
139: NAMEIFL DOWHITEOUT 0x0040000 /* do whiteouts */
140: NAMEIFL REQUIREDIR 0x0080000 /* must be a directory */
141: NAMEIFL CREATEDIR 0x0200000 /* trailing slashes are ok */
1.2 pooka 142: NAMEIFL PARAMASK 0x02fff00 /* mask of parameter descriptors */
1.7 ad 143:
1.1 pooka 144: /*
145: * Initialization of an nameidata structure.
146: */
1.6 pooka 147: #define NDINIT(ndp, op, flags, segflg, namep) { \
1.1 pooka 148: (ndp)->ni_cnd.cn_nameiop = op; \
149: (ndp)->ni_cnd.cn_flags = flags; \
150: (ndp)->ni_segflg = segflg; \
151: (ndp)->ni_dirp = namep; \
1.6 pooka 152: (ndp)->ni_cnd.cn_cred = kauth_cred_get(); \
1.1 pooka 153: }
154: #endif
155:
156: /*
157: * This structure describes the elements in the cache of recent
158: * names looked up by namei. NCHNAMLEN is sized to make structure
159: * size a power of two to optimize malloc's. Minimum reasonable
160: * size is 15.
161: */
162:
163: #define NCHNAMLEN 31 /* maximum name segment length we bother with */
164:
1.7 ad 165: /*
166: * Namecache entry. This structure is arranged so that frequently
167: * accessed and mostly read-only data is toward the front, with
168: * infrequently accessed data and the lock towards the rear. The
169: * lock is then more likely to be in a seperate cache line.
170: */
1.1 pooka 171: struct namecache {
172: LIST_ENTRY(namecache) nc_hash; /* hash chain */
173: LIST_ENTRY(namecache) nc_vhash; /* directory hash chain */
174: struct vnode *nc_dvp; /* vnode of parent of name */
175: struct vnode *nc_vp; /* vnode the name refers to */
176: int nc_flags; /* copy of componentname's ISWHITEOUT */
177: char nc_nlen; /* length of name */
178: char nc_name[NCHNAMLEN]; /* segment name */
1.7 ad 179: void *nc_gcqueue; /* queue for garbage collection */
180: TAILQ_ENTRY(namecache) nc_lru; /* psuedo-lru chain */
181: LIST_ENTRY(namecache) nc_dvlist;
182: LIST_ENTRY(namecache) nc_vlist;
183: kmutex_t nc_lock; /* lock on this entry */
184: int nc_hittime; /* last time scored a hit */
1.1 pooka 185: };
186:
187: #ifdef _KERNEL
188: #include <sys/mallocvar.h>
189: #include <sys/pool.h>
190:
191: struct mount;
1.7 ad 192: struct cpu_info;
1.1 pooka 193:
1.4 pooka 194: extern pool_cache_t pnbuf_cache; /* pathname buffer cache */
1.1 pooka 195:
1.4 pooka 196: #define PNBUF_GET() pool_cache_get(pnbuf_cache, PR_WAITOK)
197: #define PNBUF_PUT(pnb) pool_cache_put(pnbuf_cache, (pnb))
1.1 pooka 198:
199: int namei(struct nameidata *);
200: uint32_t namei_hash(const char *, const char **);
201: int lookup(struct nameidata *);
202: int relookup(struct vnode *, struct vnode **, struct componentname *);
203: void cache_purge1(struct vnode *, const struct componentname *, int);
204: #define PURGE_PARENTS 1
205: #define PURGE_CHILDREN 2
206: #define cache_purge(vp) cache_purge1((vp), NULL, PURGE_PARENTS|PURGE_CHILDREN)
207: int cache_lookup(struct vnode *, struct vnode **, struct componentname *);
208: int cache_lookup_raw(struct vnode *, struct vnode **,
209: struct componentname *);
210: int cache_revlookup(struct vnode *, struct vnode **, char **, char *);
211: void cache_enter(struct vnode *, struct vnode *, struct componentname *);
212: void nchinit(void);
213: void nchreinit(void);
1.7 ad 214: void cache_cpu_init(struct cpu_info *);
1.1 pooka 215: void cache_purgevfs(struct mount *);
216: void namecache_print(struct vnode *, void (*)(const char *, ...));
217:
218: #endif
219:
220: /*
221: * Stats on usefulness of namei caches.
222: * XXX: should be 64-bit counters.
223: */
224: struct nchstats {
225: long ncs_goodhits; /* hits that we can really use */
226: long ncs_neghits; /* negative hits that we can use */
227: long ncs_badhits; /* hits we must drop */
228: long ncs_falsehits; /* hits with id mismatch */
229: long ncs_miss; /* misses */
230: long ncs_long; /* long names that ignore cache */
231: long ncs_pass2; /* names found with passes == 2 */
232: long ncs_2passes; /* number of times we attempt it */
233: long ncs_revhits; /* reverse-cache hits */
234: long ncs_revmiss; /* reverse-cache misses */
235: };
236:
237: #ifdef _KERNEL
238: extern struct nchstats nchstats;
239: #endif
240: /* #endif !_SYS_NAMEI_H_ (generated by gennameih.awk) */
CVSweb <webmaster@jp.NetBSD.org>