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.5 (Berkeley) 01/09/95 8 */ 9 10 #ifndef _SYS_NAMEI_H_ 11 #define _SYS_NAMEI_H_ 12 13 #include <sys/queue.h> 14 15 /* 16 * Encapsulation of namei parameters. 17 */ 18 struct nameidata { 19 /* 20 * Arguments to namei/lookup. 21 */ 22 caddr_t ni_dirp; /* pathname pointer */ 23 enum uio_seg ni_segflg; /* location of pathname */ 24 /* u_long ni_nameiop; namei operation */ 25 /* u_long ni_flags; flags to namei */ 26 /* struct proc *ni_proc; process requesting lookup */ 27 /* 28 * Arguments to lookup. 29 */ 30 /* struct ucred *ni_cred; credentials */ 31 struct vnode *ni_startdir; /* starting directory */ 32 struct vnode *ni_rootdir; /* logical root directory */ 33 /* 34 * Results: returned from/manipulated by lookup 35 */ 36 struct vnode *ni_vp; /* vnode of result */ 37 struct vnode *ni_dvp; /* vnode of intermediate directory */ 38 /* 39 * Shared between namei and lookup/commit routines. 40 */ 41 long ni_pathlen; /* remaining chars in path */ 42 char *ni_next; /* next location in pathname */ 43 u_long ni_loopcnt; /* count of symlinks encountered */ 44 /* 45 * Lookup parameters: this structure describes the subset of 46 * information from the nameidata structure that is passed 47 * through the VOP interface. 48 */ 49 struct componentname { 50 /* 51 * Arguments to lookup. 52 */ 53 u_long cn_nameiop; /* namei operation */ 54 u_long cn_flags; /* flags to namei */ 55 struct proc *cn_proc; /* process requesting lookup */ 56 struct ucred *cn_cred; /* credentials */ 57 /* 58 * Shared between lookup and commit routines. 59 */ 60 char *cn_pnbuf; /* pathname buffer */ 61 char *cn_nameptr; /* pointer to looked up name */ 62 long cn_namelen; /* length of looked up component */ 63 u_long cn_hash; /* hash value of looked up name */ 64 long cn_consume; /* chars to consume in lookup() */ 65 } ni_cnd; 66 }; 67 68 #ifdef KERNEL 69 /* 70 * namei operations 71 */ 72 #define LOOKUP 0 /* perform name lookup only */ 73 #define CREATE 1 /* setup for file creation */ 74 #define DELETE 2 /* setup for file deletion */ 75 #define RENAME 3 /* setup for file renaming */ 76 #define OPMASK 3 /* mask for operation */ 77 /* 78 * namei operational modifier flags, stored in ni_cnd.flags 79 */ 80 #define LOCKLEAF 0x0004 /* lock inode on return */ 81 #define LOCKPARENT 0x0008 /* want parent vnode returned locked */ 82 #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ 83 #define NOCACHE 0x0020 /* name must not be left in cache */ 84 #define FOLLOW 0x0040 /* follow symbolic links */ 85 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ 86 #define MODMASK 0x00fc /* mask of operational modifiers */ 87 /* 88 * Namei parameter descriptors. 89 * 90 * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. 91 * If the caller of namei sets the flag (for example execve wants to 92 * know the name of the program that is being executed), then it must 93 * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must 94 * be freed by either the commit routine or the VOP_ABORT routine. 95 * SAVESTART is set only by the callers of namei. It implies SAVENAME 96 * plus the addition of saving the parent directory that contains the 97 * name in ni_startdir. It allows repeated calls to lookup for the 98 * name being sought. The caller is responsible for releasing the 99 * buffer and for vrele'ing ni_startdir. 100 */ 101 #define NOCROSSMOUNT 0x00100 /* do not cross mount points */ 102 #define RDONLY 0x00200 /* lookup with read-only semantics */ 103 #define HASBUF 0x00400 /* has allocated pathname buffer */ 104 #define SAVENAME 0x00800 /* save pathanme buffer */ 105 #define SAVESTART 0x01000 /* save starting directory */ 106 #define ISDOTDOT 0x02000 /* current component name is .. */ 107 #define MAKEENTRY 0x04000 /* entry is to be added to name cache */ 108 #define ISLASTCN 0x08000 /* this is last component of pathname */ 109 #define ISSYMLINK 0x10000 /* symlink needs interpretation */ 110 #define ISWHITEOUT 0x20000 /* found whiteout */ 111 #define DOWHITEOUT 0x40000 /* do whiteouts */ 112 #define PARAMASK 0xfff00 /* mask of parameter descriptors */ 113 /* 114 * Initialization of an nameidata structure. 115 */ 116 #define NDINIT(ndp, op, flags, segflg, namep, p) { \ 117 (ndp)->ni_cnd.cn_nameiop = op; \ 118 (ndp)->ni_cnd.cn_flags = flags; \ 119 (ndp)->ni_segflg = segflg; \ 120 (ndp)->ni_dirp = namep; \ 121 (ndp)->ni_cnd.cn_proc = p; \ 122 } 123 #endif 124 125 /* 126 * This structure describes the elements in the cache of recent 127 * names looked up by namei. NCHNAMLEN is sized to make structure 128 * size a power of two to optimize malloc's. Minimum reasonable 129 * size is 15. 130 */ 131 132 #define NCHNAMLEN 31 /* maximum name segment length we bother with */ 133 134 struct namecache { 135 LIST_ENTRY(namecache) nc_hash; /* hash chain */ 136 TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */ 137 struct vnode *nc_dvp; /* vnode of parent of name */ 138 u_long nc_dvpid; /* capability number of nc_dvp */ 139 struct vnode *nc_vp; /* vnode the name refers to */ 140 u_long nc_vpid; /* capability number of nc_vp */ 141 char nc_nlen; /* length of name */ 142 char nc_name[NCHNAMLEN]; /* segment name */ 143 }; 144 145 #ifdef KERNEL 146 u_long nextvnodeid; 147 int namei __P((struct nameidata *ndp)); 148 int lookup __P((struct nameidata *ndp)); 149 int relookup __P((struct vnode *dvp, struct vnode **vpp, 150 struct componentname *cnp)); 151 #endif 152 153 /* 154 * Stats on usefulness of namei caches. 155 */ 156 struct nchstats { 157 long ncs_goodhits; /* hits that we can really use */ 158 long ncs_neghits; /* negative hits that we can use */ 159 long ncs_badhits; /* hits we must drop */ 160 long ncs_falsehits; /* hits with id mismatch */ 161 long ncs_miss; /* misses */ 162 long ncs_long; /* long names that ignore cache */ 163 long ncs_pass2; /* names found with passes == 2 */ 164 long ncs_2passes; /* number of times we attempt it */ 165 }; 166 #endif /* !_SYS_NAMEI_H_ */ 167