xref: /original-bsd/sys/sys/namei.h (revision 792e4f5f)
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.4 (Berkeley) 05/09/89
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 	short	ni_namelen;		/* length of current component */
51 	short	ni_loopcnt;		/* count of symlinks encountered */
52 	char	ni_makeentry;		/* 1 => add entry to name cache */
53 	char	ni_isdotdot;		/* 1 => current component name is .. */
54 
55 		/* results: */
56 	struct	vnode *ni_vp;		/* vnode of result */
57 	struct	vnode *ni_dvp;		/* vnode of intermediate directory */
58 
59 		/* side effects: */
60 	struct	direct ni_dent;		/* current directory entry */
61 
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 		u_long	nd_hash;		/* hash value of nd_dent */
68 	} ni_nd;
69 	/* END UFS SPECIFIC */
70 };
71 
72 #define	ni_base		ni_nd.nd_iovec.iov_base
73 #define	ni_count	ni_nd.nd_iovec.iov_len
74 #define	ni_segflg	ni_nd.nd_uio.uio_segflg
75 #define	ni_iov		ni_nd.nd_uio.uio_iov
76 #define	ni_iovcnt	ni_nd.nd_uio.uio_iovcnt
77 #define	ni_offset	ni_nd.nd_uio.uio_offset
78 #define	ni_resid	ni_nd.nd_uio.uio_resid
79 #define ni_hash		ni_nd.nd_hash
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	0x04	/* lock inode on return */
91 #define	LOCKPARENT	0x08	/* want parent vnode returned locked */
92 #define	WANTPARENT	0x10	/* want parent vnode returned unlocked */
93 #define NOCACHE		0x20	/* name must not be left in cache */
94 #define FOLLOW		0x40	/* follow symbolic links */
95 #define	NOFOLLOW	0x0	/* don't follow symbolic links (pseudo) */
96 #define	NOMOUNT		0x80	/* don't cross mount points */
97 #endif
98 
99 /*
100  * This structure describes the elements in the cache of recent
101  * names looked up by namei.
102  */
103 
104 #define	NCHNAMLEN	15	/* maximum name segment length we bother with */
105 
106 struct	namecache {
107 	struct	namecache *nc_forw;	/* hash chain, MUST BE FIRST */
108 	struct	namecache *nc_back;	/* hash chain, MUST BE FIRST */
109 	struct	namecache *nc_nxt;	/* LRU chain */
110 	struct	namecache **nc_prev;	/* LRU chain */
111 	struct	vnode *nc_vp;		/* vnode the name refers to */
112 	struct	vnode *nc_dp;		/* vnode of parent of name */
113 	char	nc_nlen;		/* length of name */
114 	char	nc_name[NCHNAMLEN];	/* segment name */
115 	struct	ucred *nc_cred;		/* ??? credentials */
116 };
117 
118 #define ANYCRED ((struct ucred *) -1)
119 #define NOCRED  ((struct ucred *) 0)
120 
121 #ifdef KERNEL
122 struct	namecache *namecache;
123 int	nchsize;
124 #endif
125 
126 /*
127  * Stats on usefulness of namei caches.
128  */
129 struct	nchstats {
130 	long	ncs_goodhits;		/* hits that we can reall use */
131 	long	ncs_badhits;		/* hits we must drop */
132 	long	ncs_falsehits;		/* hits with id mismatch */
133 	long	ncs_miss;		/* misses */
134 	long	ncs_long;		/* long names that ignore cache */
135 	long	ncs_pass2;		/* names found with passes == 2 */
136 	long	ncs_2passes;		/* number of times we attempt it */
137 };
138 #endif
139