xref: /original-bsd/sys/sys/namei.h (revision 1ff91bf0)
1 /*
2  * Copyright (c) 1985, 1989 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)namei.h	7.14 (Berkeley) 03/17/91
8  */
9 
10 #ifndef _NAMEI_H_
11 #define	_NAMEI_H_
12 
13 #include <ufs/dir.h>		/* XXX */
14 
15 /*
16  * Encapsulation of namei parameters.
17  * One of these is located in the u. area to
18  * minimize space allocated on the kernel stack.
19  */
20 struct nameidata {
21 		/* arguments to namei and related context: */
22 	caddr_t	ni_dirp;		/* pathname pointer */
23 	enum	uio_seg ni_segflg;	/* location of pathname */
24 	u_long	ni_nameiop;		/* see below */
25 	struct	ucred *ni_cred;		/* credentials */
26 	struct	vnode *ni_startdir;	/* alternate starting directory */
27 
28 		/* shared between namei, lookup routines and commit routines: */
29 	caddr_t	ni_pnbuf;		/* pathname buffer */
30 	char	*ni_ptr;		/* current location in pathname */
31 	char	*ni_next;		/* next location in pathname */
32 	u_int	ni_pathlen;		/* remaining chars in path */
33 	u_long	ni_hash;		/* hash value of current component */
34 	short	ni_namelen;		/* length of current component */
35 	short	ni_loopcnt;		/* count of symlinks encountered */
36 	char	ni_makeentry;		/* 1 => add entry to name cache */
37 	char	ni_isdotdot;		/* 1 => current component name is .. */
38 
39 		/* results: */
40 	struct	vnode *ni_vp;		/* vnode of result */
41 	struct	vnode *ni_dvp;		/* vnode of intermediate directory */
42 	struct	direct ni_dent;		/* final component name */
43 
44 		/* side effects: */
45 	/* BEGIN UFS SPECIFIC */
46 	off_t	ni_endoff;		/* end of useful directory contents */
47 	struct ndirinfo {		/* saved info for new dir entry */
48 		struct	iovec nd_iovec;		/* pointed to by ni_iov */
49 		struct	uio nd_uio;		/* directory I/O parameters */
50 	} ni_nd;
51 	/* END UFS SPECIFIC */
52 };
53 
54 #define	ni_base		ni_nd.nd_iovec.iov_base
55 #define	ni_count	ni_nd.nd_iovec.iov_len
56 #define	ni_uioseg	ni_nd.nd_uio.uio_segflg
57 #define	ni_iov		ni_nd.nd_uio.uio_iov
58 #define	ni_iovcnt	ni_nd.nd_uio.uio_iovcnt
59 #define	ni_offset	ni_nd.nd_uio.uio_offset
60 #define	ni_resid	ni_nd.nd_uio.uio_resid
61 #define	ni_rw		ni_nd.nd_uio.uio_rw
62 #define	ni_uio		ni_nd.nd_uio
63 
64 #ifdef KERNEL
65 /*
66  * namei operations
67  */
68 #define	LOOKUP		0	/* perform name lookup only */
69 #define	CREATE		1	/* setup for file creation */
70 #define	DELETE		2	/* setup for file deletion */
71 #define	RENAME		3	/* setup for file renaming */
72 #define	OPMASK		3	/* mask for operation */
73 /*
74  * namei operational modifiers
75  */
76 #define	LOCKLEAF	0x0004	/* lock inode on return */
77 #define	LOCKPARENT	0x0008	/* want parent vnode returned locked */
78 #define	WANTPARENT	0x0010	/* want parent vnode returned unlocked */
79 #define	NOCACHE		0x0020	/* name must not be left in cache */
80 #define	FOLLOW		0x0040	/* follow symbolic links */
81 #define	NOFOLLOW	0x0000	/* do not follow symbolic links (pseudo) */
82 #define	MODMASK		0x00fc	/* mask of operational modifiers */
83 /*
84  * namei parameter descriptors
85  */
86 #define	NOCROSSMOUNT	0x0100	/* do not cross mount points */
87 #define	REMOTE		0x0200	/* lookup for remote filesystem servers */
88 #define	HASBUF		0x0400	/* has preallocated pathname buffer */
89 #define	STARTDIR	0x0800	/* has alternate starting directory */
90 #define	SAVESTARTDIR	0x1000	/* do not vrele alternate starting directory */
91 #define PARAMASK	0xff00	/* mask of parameter descriptors */
92 #endif
93 
94 /*
95  * This structure describes the elements in the cache of recent
96  * names looked up by namei. NCHNAMLEN is sized to make structure
97  * size a power of two to optimize malloc's. Minimum reasonable
98  * size is 15.
99  */
100 
101 #define	NCHNAMLEN	31	/* maximum name segment length we bother with */
102 
103 struct	namecache {
104 	struct	namecache *nc_forw;	/* hash chain, MUST BE FIRST */
105 	struct	namecache *nc_back;	/* hash chain, MUST BE FIRST */
106 	struct	namecache *nc_nxt;	/* LRU chain */
107 	struct	namecache **nc_prev;	/* LRU chain */
108 	struct	vnode *nc_dvp;		/* vnode of parent of name */
109 	u_long	nc_dvpid;		/* capability number of nc_dvp */
110 	struct	vnode *nc_vp;		/* vnode the name refers to */
111 	u_long	nc_vpid;		/* capability number of nc_vp */
112 	char	nc_nlen;		/* length of name */
113 	char	nc_name[NCHNAMLEN];	/* segment name */
114 };
115 
116 #ifdef KERNEL
117 u_long	nextvnodeid;
118 int	namei __P((struct nameidata *ndp, struct proc *p));
119 #endif
120 
121 /*
122  * Stats on usefulness of namei caches.
123  */
124 struct	nchstats {
125 	long	ncs_goodhits;		/* hits that we can really use */
126 	long	ncs_neghits;		/* negative hits that we can use */
127 	long	ncs_badhits;		/* hits we must drop */
128 	long	ncs_falsehits;		/* hits with id mismatch */
129 	long	ncs_miss;		/* misses */
130 	long	ncs_long;		/* long names that ignore cache */
131 	long	ncs_pass2;		/* names found with passes == 2 */
132 	long	ncs_2passes;		/* number of times we attempt it */
133 };
134 #endif /* !_NAMEI_H_ */
135