xref: /original-bsd/sys/sys/namei.h (revision 56df853c)
1 /*
2  * Copyright (c) 1985, 1989 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)namei.h	7.9 (Berkeley) 05/03/90
18  */
19 
20 #ifndef _NAMEI_
21 #define	_NAMEI_
22 
23 #ifdef KERNEL
24 #include "../ufs/dir.h"
25 #include "uio.h"
26 #else
27 #include <sys/uio.h>
28 #include <ufs/dir.h>
29 #endif
30 
31 /*
32  * Encapsulation of namei parameters.
33  * One of these is located in the u. area to
34  * minimize space allocated on the kernel stack.
35  */
36 struct nameidata {
37 		/* arguments to namei and related context: */
38 	caddr_t	ni_dirp;		/* pathname pointer */
39 	enum	uio_seg ni_segflg;	/* location of pathname */
40 	short	ni_nameiop;		/* see below */
41 	struct	vnode *ni_cdir;		/* current directory */
42 	struct	vnode *ni_rdir;		/* root directory, if not normal root */
43 	struct	ucred *ni_cred;		/* credentials */
44 
45 		/* shared between namei, lookup routines and commit routines: */
46 	caddr_t	ni_pnbuf;		/* pathname buffer */
47 	char	*ni_ptr;		/* current location in pathname */
48 	char	*ni_next;		/* next location in pathname */
49 	u_int	ni_pathlen;		/* remaining chars in path */
50 	u_long	ni_hash;		/* hash value of current component */
51 	short	ni_namelen;		/* length of current component */
52 	short	ni_loopcnt;		/* count of symlinks encountered */
53 	char	ni_makeentry;		/* 1 => add entry to name cache */
54 	char	ni_isdotdot;		/* 1 => current component name is .. */
55 
56 		/* results: */
57 	struct	vnode *ni_vp;		/* vnode of result */
58 	struct	vnode *ni_dvp;		/* vnode of intermediate directory */
59 	struct	direct ni_dent;		/* final component name */
60 
61 		/* side effects: */
62 	/* BEGIN UFS SPECIFIC */
63 	off_t	ni_endoff;		/* end of useful directory contents */
64 	struct ndirinfo {		/* saved info for new dir entry */
65 		struct	iovec nd_iovec;		/* pointed to by ni_iov */
66 		struct	uio nd_uio;		/* directory I/O parameters */
67 	} ni_nd;
68 	/* END UFS SPECIFIC */
69 };
70 
71 #define	ni_base		ni_nd.nd_iovec.iov_base
72 #define	ni_count	ni_nd.nd_iovec.iov_len
73 #define	ni_uioseg	ni_nd.nd_uio.uio_segflg
74 #define	ni_iov		ni_nd.nd_uio.uio_iov
75 #define	ni_iovcnt	ni_nd.nd_uio.uio_iovcnt
76 #define	ni_offset	ni_nd.nd_uio.uio_offset
77 #define	ni_resid	ni_nd.nd_uio.uio_resid
78 #define	ni_rw		ni_nd.nd_uio.uio_rw
79 #define	ni_uio		ni_nd.nd_uio
80 
81 #ifdef KERNEL
82 /*
83  * namei operations and modifiers
84  */
85 #define	LOOKUP		0	/* perform name lookup only */
86 #define	CREATE		1	/* setup for file creation */
87 #define	DELETE		2	/* setup for file deletion */
88 #define	RENAME		3	/* setup for file renaming */
89 #define	OPFLAG		3	/* mask for operation */
90 #define	LOCKLEAF	0x004	/* lock inode on return */
91 #define	LOCKPARENT	0x008	/* want parent vnode returned locked */
92 #define	WANTPARENT	0x010	/* want parent vnode returned unlocked */
93 #define	NOCACHE		0x020	/* name must not be left in cache */
94 #define	FOLLOW		0x040	/* follow symbolic links */
95 #define	NOFOLLOW	0x000	/* do not follow symbolic links (pseudo) */
96 #define	NOCROSSMOUNT	0x080	/* do not cross mount points */
97 #define	REMOTE		0x100	/* lookup for remote filesystem servers */
98 #define	HASBUF		0x200	/* has preallocated pathname buffer */
99 #endif
100 
101 /*
102  * This structure describes the elements in the cache of recent
103  * names looked up by namei. NCHNAMLEN is sized to make structure
104  * size a power of two to optimize malloc's. Minimum reasonable
105  * size is 15.
106  */
107 
108 #define	NCHNAMLEN	31	/* maximum name segment length we bother with */
109 
110 struct	namecache {
111 	struct	namecache *nc_forw;	/* hash chain, MUST BE FIRST */
112 	struct	namecache *nc_back;	/* hash chain, MUST BE FIRST */
113 	struct	namecache *nc_nxt;	/* LRU chain */
114 	struct	namecache **nc_prev;	/* LRU chain */
115 	struct	vnode *nc_dvp;		/* vnode of parent of name */
116 	u_long	nc_dvpid;		/* capability number of nc_dvp */
117 	struct	vnode *nc_vp;		/* vnode the name refers to */
118 	u_long	nc_vpid;		/* capability number of nc_vp */
119 	char	nc_nlen;		/* length of name */
120 	char	nc_name[NCHNAMLEN];	/* segment name */
121 };
122 
123 #ifdef KERNEL
124 u_long	nextvnodeid;
125 #endif
126 
127 /*
128  * Stats on usefulness of namei caches.
129  */
130 struct	nchstats {
131 	long	ncs_goodhits;		/* hits that we can really use */
132 	long	ncs_neghits;		/* negative hits that we can use */
133 	long	ncs_badhits;		/* hits we must drop */
134 	long	ncs_falsehits;		/* hits with id mismatch */
135 	long	ncs_miss;		/* misses */
136 	long	ncs_long;		/* long names that ignore cache */
137 	long	ncs_pass2;		/* names found with passes == 2 */
138 	long	ncs_2passes;		/* number of times we attempt it */
139 };
140 #endif /* _NAMEI_ */
141