xref: /original-bsd/sys/sys/namei.h (revision 68549010)
1 /*
2  * Copyright (c) 1985, 1989, 1991 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)namei.h	7.18 (Berkeley) 02/04/92
8  */
9 
10 #ifndef _NAMEI_H_
11 #define	_NAMEI_H_
12 
13 /*
14  * Encapsulation of namei parameters.
15  */
16 struct nameidata {
17 	/*
18 	 * Arguments to namei/lookup.
19 	 */
20 	caddr_t	ni_dirp;		/* pathname pointer */
21 	enum	uio_seg ni_segflg;	/* location of pathname */
22      /* u_long	ni_nameiop;		/* namei operation */
23      /* u_long	ni_flags;		/* flags to namei */
24      /* struct	proc *ni_proc;		/* process requesting lookup */
25 	/*
26 	 * Arguments to lookup.
27 	 */
28      /* struct	ucred *ni_cred;		/* credentials */
29 	struct	vnode *ni_startdir;	/* starting directory */
30 	struct	vnode *ni_rootdir;	/* logical root directory */
31 	/*
32 	 * Results: returned from/manipulated by lookup
33 	 */
34 	struct	vnode *ni_vp;		/* vnode of result */
35 	struct	vnode *ni_dvp;		/* vnode of intermediate directory */
36 	/*
37 	 * Shared between namei and lookup/commit routines.
38 	 */
39 	long	ni_pathlen;		/* remaining chars in path */
40 	char	*ni_next;		/* next location in pathname */
41 	u_long	ni_loopcnt;		/* count of symlinks encountered */
42 	/*
43 	 * Lookup parameters: this structure describes the subset of
44 	 * information from the nameidata structure that is passed
45 	 * through the VOP interface.
46 	 */
47 	struct componentname {
48 		/*
49 		 * Arguments to lookup.
50 		 */
51 		u_long	cn_nameiop;	/* namei operation */
52 		u_long	cn_flags;	/* flags to namei */
53 		struct	proc *cn_proc;	/* process requesting lookup */
54 		struct	ucred *cn_cred;	/* credentials */
55 		/*
56 		 * Shared between lookup and commit routines.
57 		 */
58 		char	*cn_pnbuf;	/* pathname buffer */
59 		char	*cn_nameptr;	/* pointer to looked up name */
60 		long	cn_namelen;	/* length of looked up component */
61 		u_long	cn_hash;	/* hash value of looked up name */
62 	} ni_cnd;
63 };
64 
65 #ifdef KERNEL
66 /*
67  * namei operations
68  */
69 #define	LOOKUP		0	/* perform name lookup only */
70 #define	CREATE		1	/* setup for file creation */
71 #define	DELETE		2	/* setup for file deletion */
72 #define	RENAME		3	/* setup for file renaming */
73 #define	OPMASK		3	/* mask for operation */
74 /*
75  * namei operational modifier flags, stored in ni_cnd.flags
76  */
77 #define	LOCKLEAF	0x0004	/* lock inode on return */
78 #define	LOCKPARENT	0x0008	/* want parent vnode returned locked */
79 #define	WANTPARENT	0x0010	/* want parent vnode returned unlocked */
80 #define	NOCACHE		0x0020	/* name must not be left in cache */
81 #define	FOLLOW		0x0040	/* follow symbolic links */
82 #define	NOFOLLOW	0x0000	/* do not follow symbolic links (pseudo) */
83 #define	MODMASK		0x00fc	/* mask of operational modifiers */
84 /*
85  * Namei parameter descriptors.
86  *
87  * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
88  * If the caller of namei sets the flag (for example execve wants to
89  * know the name of the program that is being executed), then it must
90  * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
91  * be freed by either the commit routine or the VOP_ABORT routine.
92  * SAVESTART is set only by the callers of namei. It implies SAVENAME
93  * plus the addition of saving the parent directory that contains the
94  * name in ni_startdir. It allows repeated calls to lookup for the
95  * name being sought. The caller is responsible for releasing the
96  * buffer and for vrele'ing ni_startdir.
97  */
98 #define	NOCROSSMOUNT	0x00100	/* do not cross mount points */
99 #define	RDONLY		0x00200	/* lookup with read-only semantics */
100 #define	HASBUF		0x00400	/* has allocated pathname buffer */
101 #define	SAVENAME	0x00800	/* save pathanme buffer */
102 #define	SAVESTART	0x01000	/* save starting directory */
103 #define ISDOTDOT	0x02000	/* current component name is .. */
104 #define MAKEENTRY	0x04000	/* entry is to be added to name cache */
105 #define ISLASTCN	0x08000	/* this is last component of pathname */
106 #define ISSYMLINK	0x10000	/* symlink needs interpretation */
107 #define PARAMASK	0xfff00	/* mask of parameter descriptors */
108 /*
109  * Initialization of an nameidata structure.
110  */
111 #define NDINIT(ndp, op, flags, segflg, namep, p) { \
112 	(ndp)->ni_cnd.cn_nameiop = op; \
113 	(ndp)->ni_cnd.cn_flags = flags; \
114 	(ndp)->ni_segflg = segflg; \
115 	(ndp)->ni_dirp = namep; \
116 	(ndp)->ni_cnd.cn_proc = p; \
117 }
118 #endif
119 
120 /*
121  * This structure describes the elements in the cache of recent
122  * names looked up by namei. NCHNAMLEN is sized to make structure
123  * size a power of two to optimize malloc's. Minimum reasonable
124  * size is 15.
125  */
126 
127 #define	NCHNAMLEN	31	/* maximum name segment length we bother with */
128 
129 struct	namecache {
130 	struct	namecache *nc_forw;	/* hash chain, MUST BE FIRST */
131 	struct	namecache *nc_back;	/* hash chain, MUST BE FIRST */
132 	struct	namecache *nc_nxt;	/* LRU chain */
133 	struct	namecache **nc_prev;	/* LRU chain */
134 	struct	vnode *nc_dvp;		/* vnode of parent of name */
135 	u_long	nc_dvpid;		/* capability number of nc_dvp */
136 	struct	vnode *nc_vp;		/* vnode the name refers to */
137 	u_long	nc_vpid;		/* capability number of nc_vp */
138 	char	nc_nlen;		/* length of name */
139 	char	nc_name[NCHNAMLEN];	/* segment name */
140 };
141 
142 #ifdef KERNEL
143 u_long	nextvnodeid;
144 int	namei __P((struct nameidata *ndp));
145 int	lookup __P((struct nameidata *ndp));
146 #endif
147 
148 /*
149  * Stats on usefulness of namei caches.
150  */
151 struct	nchstats {
152 	long	ncs_goodhits;		/* hits that we can really use */
153 	long	ncs_neghits;		/* negative hits that we can use */
154 	long	ncs_badhits;		/* hits we must drop */
155 	long	ncs_falsehits;		/* hits with id mismatch */
156 	long	ncs_miss;		/* misses */
157 	long	ncs_long;		/* long names that ignore cache */
158 	long	ncs_pass2;		/* names found with passes == 2 */
159 	long	ncs_2passes;		/* number of times we attempt it */
160 };
161 #endif /* !_NAMEI_H_ */
162