1 /* $NetBSD: namei.h,v 1.64 2009/02/11 00:20:18 enami Exp $ */ 2 3 4 /* 5 * WARNING: GENERATED FILE. DO NOT EDIT 6 * (edit namei.src and run make namei in src/sys/sys) 7 * by: NetBSD: gennameih.awk,v 1.4 2008/12/03 10:54:27 ad Exp 8 * from: NetBSD: namei.src,v 1.10 2009/02/11 00:19:11 enami Exp 9 */ 10 11 /* 12 * Copyright (c) 1985, 1989, 1991, 1993 13 * The Regents of the University of California. All rights reserved. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 3. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)namei.h 8.5 (Berkeley) 8/20/94 40 */ 41 42 #ifndef _SYS_NAMEI_H_ 43 #define _SYS_NAMEI_H_ 44 45 #include <sys/queue.h> 46 #include <sys/mutex.h> 47 48 #ifdef _KERNEL 49 #include <sys/kauth.h> 50 51 /* 52 * Encapsulation of namei parameters. 53 */ 54 struct nameidata { 55 /* 56 * Arguments to namei/lookup. 57 */ 58 const char *ni_dirp; /* pathname pointer */ 59 enum uio_seg ni_segflg; /* location of pathname */ 60 /* 61 * Arguments to lookup. 62 */ 63 struct vnode *ni_startdir; /* starting directory */ 64 struct vnode *ni_rootdir; /* logical root directory */ 65 struct vnode *ni_erootdir; /* emulation root directory */ 66 /* 67 * Results: returned from/manipulated by lookup 68 */ 69 struct vnode *ni_vp; /* vnode of result */ 70 struct vnode *ni_dvp; /* vnode of intermediate directory */ 71 /* 72 * Shared between namei and lookup/commit routines. 73 */ 74 size_t ni_pathlen; /* remaining chars in path */ 75 const char *ni_next; /* next location in pathname */ 76 unsigned int ni_loopcnt; /* count of symlinks encountered */ 77 /* 78 * Lookup parameters: this structure describes the subset of 79 * information from the nameidata structure that is passed 80 * through the VOP interface. 81 */ 82 struct componentname { 83 /* 84 * Arguments to lookup. 85 */ 86 uint32_t cn_nameiop; /* namei operation */ 87 uint32_t cn_flags; /* flags to namei */ 88 kauth_cred_t cn_cred; /* credentials */ 89 /* 90 * Shared between lookup and commit routines. 91 */ 92 char *cn_pnbuf; /* pathname buffer */ 93 const char *cn_nameptr; /* pointer to looked up name */ 94 size_t cn_namelen; /* length of looked up comp */ 95 u_long cn_hash; /* hash val of looked up name */ 96 size_t cn_consume; /* chars to consume in lookup */ 97 } ni_cnd; 98 }; 99 100 /* 101 * namei operations 102 */ 103 #define LOOKUP 0 /* perform name lookup only */ 104 #define CREATE 1 /* setup for file creation */ 105 #define DELETE 2 /* setup for file deletion */ 106 #define RENAME 3 /* setup for file renaming */ 107 #define OPMASK 3 /* mask for operation */ 108 /* 109 * namei operational modifier flags, stored in ni_cnd.cn_flags 110 */ 111 #define LOCKLEAF 0x00000004 /* lock inode on return */ 112 #define LOCKPARENT 0x00000008 /* want parent vnode returned locked */ 113 #define TRYEMULROOT 0x00000010 /* try relative to emulation root 114 first */ 115 #define NOCACHE 0x00000020 /* name must not be left in cache */ 116 #define FOLLOW 0x00000040 /* follow symbolic links */ 117 #define NOFOLLOW 0x00000000 /* do not follow symbolic links 118 (pseudo) */ 119 #define EMULROOTSET 0x00000080 /* emulation root already 120 in ni_erootdir */ 121 #define NOCHROOT 0x01000000 /* no chroot on abs path lookups */ 122 #define MODMASK 0x010000fc /* mask of operational modifiers */ 123 /* 124 * Namei parameter descriptors. 125 * 126 * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. 127 * If the caller of namei sets the flag (for example execve wants to 128 * know the name of the program that is being executed), then it must 129 * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must 130 * be freed by either the commit routine or the VOP_ABORT routine. 131 * SAVESTART is set only by the callers of namei. It implies SAVENAME 132 * plus the addition of saving the parent directory that contains the 133 * name in ni_startdir. It allows repeated calls to lookup for the 134 * name being sought. The caller is responsible for releasing the 135 * buffer and for vrele'ing ni_startdir. 136 */ 137 #define NOCROSSMOUNT 0x0000100 /* do not cross mount points */ 138 #define RDONLY 0x0000200 /* lookup with read-only semantics */ 139 #define HASBUF 0x0000400 /* has allocated pathname buffer */ 140 #define SAVENAME 0x0000800 /* save pathname buffer */ 141 #define SAVESTART 0x0001000 /* save starting directory */ 142 #define ISDOTDOT 0x0002000 /* current component name is .. */ 143 #define MAKEENTRY 0x0004000 /* entry is to be added to name cache */ 144 #define ISLASTCN 0x0008000 /* this is last component of pathname */ 145 #define ISSYMLINK 0x0010000 /* symlink needs interpretation */ 146 #define ISWHITEOUT 0x0020000 /* found whiteout */ 147 #define DOWHITEOUT 0x0040000 /* do whiteouts */ 148 #define REQUIREDIR 0x0080000 /* must be a directory */ 149 #define CREATEDIR 0x0200000 /* trailing slashes are ok */ 150 #define PARAMASK 0x02fff00 /* mask of parameter descriptors */ 151 152 /* 153 * Initialization of an nameidata structure. 154 */ 155 #define NDINIT(ndp, op, flags, segflg, namep) { \ 156 (ndp)->ni_cnd.cn_nameiop = op; \ 157 (ndp)->ni_cnd.cn_flags = flags; \ 158 (ndp)->ni_segflg = segflg; \ 159 (ndp)->ni_dirp = namep; \ 160 (ndp)->ni_cnd.cn_cred = kauth_cred_get(); \ 161 } 162 #endif 163 164 /* 165 * This structure describes the elements in the cache of recent 166 * names looked up by namei. NCHNAMLEN is sized to make structure 167 * size a power of two to optimize malloc's. Minimum reasonable 168 * size is 15. 169 */ 170 171 #define NCHNAMLEN 31 /* maximum name segment length we bother with */ 172 173 /* 174 * Namecache entry. This structure is arranged so that frequently 175 * accessed and mostly read-only data is toward the front, with 176 * infrequently accessed data and the lock towards the rear. The 177 * lock is then more likely to be in a seperate cache line. 178 */ 179 struct namecache { 180 LIST_ENTRY(namecache) nc_hash; /* hash chain */ 181 LIST_ENTRY(namecache) nc_vhash; /* directory hash chain */ 182 struct vnode *nc_dvp; /* vnode of parent of name */ 183 struct vnode *nc_vp; /* vnode the name refers to */ 184 int nc_flags; /* copy of componentname's ISWHITEOUT */ 185 char nc_nlen; /* length of name */ 186 char nc_name[NCHNAMLEN]; /* segment name */ 187 void *nc_gcqueue; /* queue for garbage collection */ 188 TAILQ_ENTRY(namecache) nc_lru; /* psuedo-lru chain */ 189 LIST_ENTRY(namecache) nc_dvlist; 190 LIST_ENTRY(namecache) nc_vlist; 191 kmutex_t nc_lock; /* lock on this entry */ 192 int nc_hittime; /* last time scored a hit */ 193 }; 194 195 #ifdef _KERNEL 196 #include <sys/mallocvar.h> 197 #include <sys/pool.h> 198 199 struct mount; 200 struct cpu_info; 201 202 extern pool_cache_t pnbuf_cache; /* pathname buffer cache */ 203 204 #define PNBUF_GET() pool_cache_get(pnbuf_cache, PR_WAITOK) 205 #define PNBUF_PUT(pnb) pool_cache_put(pnbuf_cache, (pnb)) 206 207 int namei(struct nameidata *); 208 uint32_t namei_hash(const char *, const char **); 209 int lookup(struct nameidata *); 210 int relookup(struct vnode *, struct vnode **, struct componentname *); 211 void cache_purge1(struct vnode *, const struct componentname *, int); 212 #define PURGE_PARENTS 1 213 #define PURGE_CHILDREN 2 214 #define cache_purge(vp) cache_purge1((vp), NULL, PURGE_PARENTS|PURGE_CHILDREN) 215 int cache_lookup(struct vnode *, struct vnode **, struct componentname *); 216 int cache_lookup_raw(struct vnode *, struct vnode **, 217 struct componentname *); 218 int cache_revlookup(struct vnode *, struct vnode **, char **, char *); 219 void cache_enter(struct vnode *, struct vnode *, struct componentname *); 220 void nchinit(void); 221 void nchreinit(void); 222 void cache_cpu_init(struct cpu_info *); 223 void cache_purgevfs(struct mount *); 224 void namecache_print(struct vnode *, void (*)(const char *, ...)); 225 226 #endif 227 228 /* 229 * Stats on usefulness of namei caches. 230 * XXX: should be 64-bit counters. 231 */ 232 struct nchstats { 233 long ncs_goodhits; /* hits that we can really use */ 234 long ncs_neghits; /* negative hits that we can use */ 235 long ncs_badhits; /* hits we must drop */ 236 long ncs_falsehits; /* hits with id mismatch */ 237 long ncs_miss; /* misses */ 238 long ncs_long; /* long names that ignore cache */ 239 long ncs_pass2; /* names found with passes == 2 */ 240 long ncs_2passes; /* number of times we attempt it */ 241 long ncs_revhits; /* reverse-cache hits */ 242 long ncs_revmiss; /* reverse-cache misses */ 243 }; 244 245 #ifdef _KERNEL 246 extern struct nchstats nchstats; 247 #endif 248 /* #endif !_SYS_NAMEI_H_ (generated by gennameih.awk) */ 249 250 /* Definitions match above, but with NAMEI_ prefix */ 251 #define NAMEI_LOOKUP 0 252 #define NAMEI_CREATE 1 253 #define NAMEI_DELETE 2 254 #define NAMEI_RENAME 3 255 #define NAMEI_OPMASK 3 256 #define NAMEI_LOCKLEAF 0x00000004 257 #define NAMEI_LOCKPARENT 0x00000008 258 #define NAMEI_TRYEMULROOT 0x00000010 259 #define NAMEI_NOCACHE 0x00000020 260 #define NAMEI_FOLLOW 0x00000040 261 #define NAMEI_NOFOLLOW 0x00000000 262 #define NAMEI_EMULROOTSET 0x00000080 263 #define NAMEI_NOCHROOT 0x01000000 264 #define NAMEI_MODMASK 0x010000fc 265 #define NAMEI_NOCROSSMOUNT 0x0000100 266 #define NAMEI_RDONLY 0x0000200 267 #define NAMEI_HASBUF 0x0000400 268 #define NAMEI_SAVENAME 0x0000800 269 #define NAMEI_SAVESTART 0x0001000 270 #define NAMEI_ISDOTDOT 0x0002000 271 #define NAMEI_MAKEENTRY 0x0004000 272 #define NAMEI_ISLASTCN 0x0008000 273 #define NAMEI_ISSYMLINK 0x0010000 274 #define NAMEI_ISWHITEOUT 0x0020000 275 #define NAMEI_DOWHITEOUT 0x0040000 276 #define NAMEI_REQUIREDIR 0x0080000 277 #define NAMEI_CREATEDIR 0x0200000 278 #define NAMEI_PARAMASK 0x02fff00 279 280 #endif /* !_SYS_NAMEI_H_ */ 281