xref: /original-bsd/sys/sys/namei.h (revision 82ad9df5)
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.5 (Berkeley) 06/06/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_rw		ni_nd.nd_uio.uio_rw
80 #define	ni_uio		ni_nd.nd_uio
81 #define ni_hash		ni_nd.nd_hash
82 
83 #ifdef KERNEL
84 /*
85  * namei operations and modifiers
86  */
87 #define	LOOKUP		0	/* perform name lookup only */
88 #define	CREATE		1	/* setup for file creation */
89 #define	DELETE		2	/* setup for file deletion */
90 #define	RENAME		3	/* setup for file renaming */
91 #define	OPFLAG		3	/* mask for operation */
92 #define	LOCKLEAF	0x04	/* lock inode on return */
93 #define	LOCKPARENT	0x08	/* want parent vnode returned locked */
94 #define	WANTPARENT	0x10	/* want parent vnode returned unlocked */
95 #define NOCACHE		0x20	/* name must not be left in cache */
96 #define FOLLOW		0x40	/* follow symbolic links */
97 #define	NOFOLLOW	0x0	/* don't follow symbolic links (pseudo) */
98 #define	NOMOUNT		0x80	/* don't cross mount points */
99 #endif
100 
101 /*
102  * This structure describes the elements in the cache of recent
103  * names looked up by namei.
104  */
105 
106 #define	NCHNAMLEN	15	/* maximum name segment length we bother with */
107 
108 struct	namecache {
109 	struct	namecache *nc_forw;	/* hash chain, MUST BE FIRST */
110 	struct	namecache *nc_back;	/* hash chain, MUST BE FIRST */
111 	struct	namecache *nc_nxt;	/* LRU chain */
112 	struct	namecache **nc_prev;	/* LRU chain */
113 	struct	vnode *nc_vp;		/* vnode the name refers to */
114 	struct	vnode *nc_dp;		/* vnode of parent of name */
115 	char	nc_nlen;		/* length of name */
116 	char	nc_name[NCHNAMLEN];	/* segment name */
117 	struct	ucred *nc_cred;		/* ??? credentials */
118 };
119 
120 #define ANYCRED ((struct ucred *) -1)
121 #define NOCRED  ((struct ucred *) 0)
122 
123 #ifdef KERNEL
124 struct	namecache *namecache;
125 int	nchsize;
126 #endif
127 
128 /*
129  * Stats on usefulness of namei caches.
130  */
131 struct	nchstats {
132 	long	ncs_goodhits;		/* hits that we can reall 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
141