1 /* 2 * Copyright (c) 1985, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)namei.h 8.2 (Berkeley) 01/04/94 8 */ 9 10 #ifndef _SYS_NAMEI_H_ 11 #define _SYS_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 long cn_consume; /* chars to consume in lookup() */ 63 } ni_cnd; 64 }; 65 66 #ifdef KERNEL 67 /* 68 * namei operations 69 */ 70 #define LOOKUP 0 /* perform name lookup only */ 71 #define CREATE 1 /* setup for file creation */ 72 #define DELETE 2 /* setup for file deletion */ 73 #define RENAME 3 /* setup for file renaming */ 74 #define OPMASK 3 /* mask for operation */ 75 /* 76 * namei operational modifier flags, stored in ni_cnd.flags 77 */ 78 #define LOCKLEAF 0x0004 /* lock inode on return */ 79 #define LOCKPARENT 0x0008 /* want parent vnode returned locked */ 80 #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ 81 #define NOCACHE 0x0020 /* name must not be left in cache */ 82 #define FOLLOW 0x0040 /* follow symbolic links */ 83 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ 84 #define MODMASK 0x00fc /* mask of operational modifiers */ 85 /* 86 * Namei parameter descriptors. 87 * 88 * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. 89 * If the caller of namei sets the flag (for example execve wants to 90 * know the name of the program that is being executed), then it must 91 * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must 92 * be freed by either the commit routine or the VOP_ABORT routine. 93 * SAVESTART is set only by the callers of namei. It implies SAVENAME 94 * plus the addition of saving the parent directory that contains the 95 * name in ni_startdir. It allows repeated calls to lookup for the 96 * name being sought. The caller is responsible for releasing the 97 * buffer and for vrele'ing ni_startdir. 98 */ 99 #define NOCROSSMOUNT 0x00100 /* do not cross mount points */ 100 #define RDONLY 0x00200 /* lookup with read-only semantics */ 101 #define HASBUF 0x00400 /* has allocated pathname buffer */ 102 #define SAVENAME 0x00800 /* save pathanme buffer */ 103 #define SAVESTART 0x01000 /* save starting directory */ 104 #define ISDOTDOT 0x02000 /* current component name is .. */ 105 #define MAKEENTRY 0x04000 /* entry is to be added to name cache */ 106 #define ISLASTCN 0x08000 /* this is last component of pathname */ 107 #define ISSYMLINK 0x10000 /* symlink needs interpretation */ 108 #define PARAMASK 0xfff00 /* mask of parameter descriptors */ 109 /* 110 * Initialization of an nameidata structure. 111 */ 112 #define NDINIT(ndp, op, flags, segflg, namep, p) { \ 113 (ndp)->ni_cnd.cn_nameiop = op; \ 114 (ndp)->ni_cnd.cn_flags = flags; \ 115 (ndp)->ni_segflg = segflg; \ 116 (ndp)->ni_dirp = namep; \ 117 (ndp)->ni_cnd.cn_proc = p; \ 118 } 119 #endif 120 121 /* 122 * This structure describes the elements in the cache of recent 123 * names looked up by namei. NCHNAMLEN is sized to make structure 124 * size a power of two to optimize malloc's. Minimum reasonable 125 * size is 15. 126 */ 127 128 #define NCHNAMLEN 31 /* maximum name segment length we bother with */ 129 130 struct namecache { 131 struct namecache *nc_forw; /* hash chain */ 132 struct namecache **nc_back; /* hash chain */ 133 struct namecache *nc_nxt; /* LRU chain */ 134 struct namecache **nc_prev; /* LRU chain */ 135 struct vnode *nc_dvp; /* vnode of parent of name */ 136 u_long nc_dvpid; /* capability number of nc_dvp */ 137 struct vnode *nc_vp; /* vnode the name refers to */ 138 u_long nc_vpid; /* capability number of nc_vp */ 139 char nc_nlen; /* length of name */ 140 char nc_name[NCHNAMLEN]; /* segment name */ 141 }; 142 143 #ifdef KERNEL 144 u_long nextvnodeid; 145 int namei __P((struct nameidata *ndp)); 146 int lookup __P((struct nameidata *ndp)); 147 #endif 148 149 /* 150 * Stats on usefulness of namei caches. 151 */ 152 struct nchstats { 153 long ncs_goodhits; /* hits that we can really use */ 154 long ncs_neghits; /* negative hits that we can use */ 155 long ncs_badhits; /* hits we must drop */ 156 long ncs_falsehits; /* hits with id mismatch */ 157 long ncs_miss; /* misses */ 158 long ncs_long; /* long names that ignore cache */ 159 long ncs_pass2; /* names found with passes == 2 */ 160 long ncs_2passes; /* number of times we attempt it */ 161 }; 162 #endif /* !_SYS_NAMEI_H_ */ 163