|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ ! 23: /* ! 24: * Copyright (c) 1985, 1989, 1991, 1993 ! 25: * The Regents of the University of California. All rights reserved. ! 26: * ! 27: * Redistribution and use in source and binary forms, with or without ! 28: * modification, are permitted provided that the following conditions ! 29: * are met: ! 30: * 1. Redistributions of source code must retain the above copyright ! 31: * notice, this list of conditions and the following disclaimer. ! 32: * 2. Redistributions in binary form must reproduce the above copyright ! 33: * notice, this list of conditions and the following disclaimer in the ! 34: * documentation and/or other materials provided with the distribution. ! 35: * 3. All advertising materials mentioning features or use of this software ! 36: * must display the following acknowledgement: ! 37: * This product includes software developed by the University of ! 38: * California, Berkeley and its contributors. ! 39: * 4. Neither the name of the University nor the names of its contributors ! 40: * may be used to endorse or promote products derived from this software ! 41: * without specific prior written permission. ! 42: * ! 43: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 44: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 45: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 46: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 47: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 48: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 49: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 50: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 51: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 52: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 53: * SUCH DAMAGE. ! 54: * ! 55: * @(#)namei.h 8.4 (Berkeley) 8/20/94 ! 56: */ ! 57: ! 58: #ifndef _SYS_NAMEI_H_ ! 59: #define _SYS_NAMEI_H_ ! 60: ! 61: #include <sys/queue.h> ! 62: #include <sys/uio.h> ! 63: ! 64: /* ! 65: * Encapsulation of namei parameters. ! 66: */ ! 67: struct nameidata { ! 68: /* ! 69: * Arguments to namei/lookup. ! 70: */ ! 71: caddr_t ni_dirp; /* pathname pointer */ ! 72: enum uio_seg ni_segflg; /* location of pathname */ ! 73: /* u_long ni_nameiop; namei operation */ ! 74: /* u_long ni_flags; flags to namei */ ! 75: /* struct proc *ni_proc; process requesting lookup */ ! 76: /* ! 77: * Arguments to lookup. ! 78: */ ! 79: /* struct ucred *ni_cred; credentials */ ! 80: struct vnode *ni_startdir; /* starting directory */ ! 81: struct vnode *ni_rootdir; /* logical root directory */ ! 82: /* ! 83: * Results: returned from/manipulated by lookup ! 84: */ ! 85: struct vnode *ni_vp; /* vnode of result */ ! 86: struct vnode *ni_dvp; /* vnode of intermediate directory */ ! 87: /* ! 88: * Shared between namei and lookup/commit routines. ! 89: */ ! 90: u_int ni_pathlen; /* remaining chars in path */ ! 91: char *ni_next; /* next location in pathname */ ! 92: u_long ni_loopcnt; /* count of symlinks encountered */ ! 93: /* ! 94: * Lookup parameters: this structure describes the subset of ! 95: * information from the nameidata structure that is passed ! 96: * through the VOP interface. ! 97: */ ! 98: struct componentname { ! 99: /* ! 100: * Arguments to lookup. ! 101: */ ! 102: u_long cn_nameiop; /* namei operation */ ! 103: u_long cn_flags; /* flags to namei */ ! 104: struct proc *cn_proc; /* process requesting lookup */ ! 105: struct ucred *cn_cred; /* credentials */ ! 106: /* ! 107: * Shared between lookup and commit routines. ! 108: */ ! 109: char *cn_pnbuf; /* pathname buffer */ ! 110: long cn_pnlen; /* length of allocated buffer */ ! 111: char *cn_nameptr; /* pointer to looked up name */ ! 112: long cn_namelen; /* length of looked up component */ ! 113: u_long cn_hash; /* hash value of looked up name */ ! 114: long cn_consume; /* chars to consume in lookup() */ ! 115: } ni_cnd; ! 116: }; ! 117: ! 118: #ifdef KERNEL ! 119: /* ! 120: * namei operations ! 121: */ ! 122: #define LOOKUP 0 /* perform name lookup only */ ! 123: #define CREATE 1 /* setup for file creation */ ! 124: #define DELETE 2 /* setup for file deletion */ ! 125: #define RENAME 3 /* setup for file renaming */ ! 126: #define OPMASK 3 /* mask for operation */ ! 127: /* ! 128: * namei operational modifier flags, stored in ni_cnd.flags ! 129: */ ! 130: #define LOCKLEAF 0x0004 /* lock inode on return */ ! 131: #define LOCKPARENT 0x0008 /* want parent vnode returned locked */ ! 132: #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ ! 133: #define NOCACHE 0x0020 /* name must not be left in cache */ ! 134: #define FOLLOW 0x0040 /* follow symbolic links */ ! 135: #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ ! 136: #define MODMASK 0x00fc /* mask of operational modifiers */ ! 137: /* ! 138: * Namei parameter descriptors. ! 139: * ! 140: * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. ! 141: * If the caller of namei sets the flag (for example execve wants to ! 142: * know the name of the program that is being executed), then it must ! 143: * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must ! 144: * be freed by either the commit routine or the VOP_ABORT routine. ! 145: * SAVESTART is set only by the callers of namei. It implies SAVENAME ! 146: * plus the addition of saving the parent directory that contains the ! 147: * name in ni_startdir. It allows repeated calls to lookup for the ! 148: * name being sought. The caller is responsible for releasing the ! 149: * buffer and for vrele'ing ni_startdir. ! 150: */ ! 151: #define NOCROSSMOUNT 0x000100 /* do not cross mount points */ ! 152: #define RDONLY 0x000200 /* lookup with read-only semantics */ ! 153: #define HASBUF 0x000400 /* has allocated pathname buffer */ ! 154: #define SAVENAME 0x000800 /* save pathanme buffer */ ! 155: #define SAVESTART 0x001000 /* save starting directory */ ! 156: #define ISDOTDOT 0x002000 /* current component name is .. */ ! 157: #define MAKEENTRY 0x004000 /* entry is to be added to name cache */ ! 158: #define ISLASTCN 0x008000 /* this is last component of pathname */ ! 159: #define ISSYMLINK 0x010000 /* symlink needs interpretation */ ! 160: #define ISWHITEOUT 0x020000 /* found whiteout */ ! 161: #define DOWHITEOUT 0x040000 /* do whiteouts */ ! 162: #define NODELETEBUSY 0x800000 /* do not delete busy files (HFS semantic) */ ! 163: #define PARAMASK 0x0fff00 /* mask of parameter descriptors */ ! 164: /* ! 165: * Initialization of an nameidata structure. ! 166: */ ! 167: #define NDINIT(ndp, op, flags, segflg, namep, p) { \ ! 168: (ndp)->ni_cnd.cn_nameiop = op; \ ! 169: (ndp)->ni_cnd.cn_flags = flags; \ ! 170: (ndp)->ni_segflg = segflg; \ ! 171: (ndp)->ni_dirp = namep; \ ! 172: (ndp)->ni_cnd.cn_proc = p; \ ! 173: } ! 174: #endif /* KERNEL */ ! 175: ! 176: /* ! 177: * This structure describes the elements in the cache of recent ! 178: * names looked up by namei. NCHNAMLEN is sized to make structure ! 179: * size a power of two to optimize malloc's. Minimum reasonable ! 180: * size is 15. ! 181: */ ! 182: ! 183: #define NCHNAMLEN 31 /* maximum name segment length we bother with */ ! 184: ! 185: struct namecache { ! 186: LIST_ENTRY(namecache) nc_hash; /* hash chain */ ! 187: TAILQ_ENTRY(namecache) nc_lru; /* LRU chain */ ! 188: struct vnode *nc_dvp; /* vnode of parent of name */ ! 189: u_long nc_dvpid; /* capability number of nc_dvp */ ! 190: struct vnode *nc_vp; /* vnode the name refers to */ ! 191: u_long nc_vpid; /* capability number of nc_vp */ ! 192: char nc_nlen; /* length of name */ ! 193: char nc_name[NCHNAMLEN]; /* segment name */ ! 194: }; ! 195: ! 196: #ifdef KERNEL ! 197: extern u_long nextvnodeid; ! 198: int namei __P((struct nameidata *ndp)); ! 199: int lookup __P((struct nameidata *ndp)); ! 200: int relookup __P((struct vnode *dvp, struct vnode **vpp, ! 201: struct componentname *cnp)); ! 202: #endif /* KERNEL */ ! 203: ! 204: /* ! 205: * Stats on usefulness of namei caches. ! 206: */ ! 207: struct nchstats { ! 208: long ncs_goodhits; /* hits that we can really use */ ! 209: long ncs_neghits; /* negative hits that we can use */ ! 210: long ncs_badhits; /* hits we must drop */ ! 211: long ncs_falsehits; /* hits with id mismatch */ ! 212: long ncs_miss; /* misses */ ! 213: long ncs_long; /* long names that ignore cache */ ! 214: long ncs_pass2; /* names found with passes == 2 */ ! 215: long ncs_2passes; /* number of times we attempt it */ ! 216: }; ! 217: #endif /* !_SYS_NAMEI_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.