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