1 /* 2 * Copyright (c) 1985, 1989, 1991 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)namei.h 7.15 (Berkeley) 05/15/91 8 */ 9 10 #ifndef _NAMEI_H_ 11 #define _NAMEI_H_ 12 13 /* 14 * Encapsulation of namei parameters. 15 */ 16 struct nameidata { 17 /* 18 * Arguments to namei. 19 */ 20 caddr_t ni_dirp; /* pathname pointer */ 21 enum uio_seg ni_segflg; /* location of pathname */ 22 u_long ni_nameiop; /* see below */ 23 /* 24 * Arguments to lookup. 25 */ 26 struct ucred *ni_cred; /* credentials */ 27 struct vnode *ni_startdir; /* starting directory */ 28 struct vnode *ni_rootdir; /* logical root directory */ 29 /* 30 * Results 31 */ 32 struct vnode *ni_vp; /* vnode of result */ 33 struct vnode *ni_dvp; /* vnode of intermediate directory */ 34 /* 35 * Shared between namei, lookup routines, and commit routines. 36 */ 37 char *ni_pnbuf; /* pathname buffer */ 38 long ni_pathlen; /* remaining chars in path */ 39 char *ni_ptr; /* current location in pathname */ 40 long ni_namelen; /* length of current component */ 41 char *ni_next; /* next location in pathname */ 42 u_long ni_hash; /* hash value of current component */ 43 u_char ni_loopcnt; /* count of symlinks encountered */ 44 u_char ni_makeentry; /* 1 => add entry to name cache */ 45 u_char ni_isdotdot; /* 1 => current component name is .. */ 46 u_char ni_more; /* 1 => symlink needs interpretation */ 47 /* 48 * Side effects. 49 */ 50 struct ufs_specific { /* saved info for new dir entry */ 51 off_t ufs_endoff; /* end of useful directory contents */ 52 long ufs_offset; /* offset of free space in directory */ 53 long ufs_count; /* size of free slot in directory */ 54 ino_t ufs_ino; /* inode number of found directory */ 55 u_long ufs_reclen; /* size of found directory entry */ 56 } ni_ufs; 57 }; 58 59 #ifdef KERNEL 60 /* 61 * namei operations 62 */ 63 #define LOOKUP 0 /* perform name lookup only */ 64 #define CREATE 1 /* setup for file creation */ 65 #define DELETE 2 /* setup for file deletion */ 66 #define RENAME 3 /* setup for file renaming */ 67 #define OPMASK 3 /* mask for operation */ 68 /* 69 * namei operational modifiers 70 */ 71 #define LOCKLEAF 0x0004 /* lock inode on return */ 72 #define LOCKPARENT 0x0008 /* want parent vnode returned locked */ 73 #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ 74 #define NOCACHE 0x0020 /* name must not be left in cache */ 75 #define FOLLOW 0x0040 /* follow symbolic links */ 76 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ 77 #define MODMASK 0x00fc /* mask of operational modifiers */ 78 /* 79 * Namei parameter descriptors. 80 * 81 * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. 82 * If the caller of namei sets the flag (for example execve wants to 83 * know the name of the program that is being executed), then it must 84 * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must 85 * be freed by either the commit routine or the VOP_ABORT routine. 86 * SAVESTART is set only by the callers of namei. It implies SAVENAME 87 * plus the addition of saving the parent directory that contains the 88 * name in ni_startdir. It allows repeated calls to lookup for the 89 * name being sought. The caller is responsible for releasing the 90 * buffer and for vrele'ing ni_startdir. 91 */ 92 #define NOCROSSMOUNT 0x0100 /* do not cross mount points */ 93 #define REMOTE 0x0200 /* lookup for remote filesystem servers */ 94 #define HASBUF 0x0400 /* has allocated pathname buffer */ 95 #define SAVENAME 0x0800 /* save pathanme buffer */ 96 #define SAVESTART 0x1000 /* save starting directory */ 97 #define PARAMASK 0xff00 /* mask of parameter descriptors */ 98 #endif 99 100 /* 101 * This structure describes the elements in the cache of recent 102 * names looked up by namei. NCHNAMLEN is sized to make structure 103 * size a power of two to optimize malloc's. Minimum reasonable 104 * size is 15. 105 */ 106 107 #define NCHNAMLEN 31 /* maximum name segment length we bother with */ 108 109 struct namecache { 110 struct namecache *nc_forw; /* hash chain, MUST BE FIRST */ 111 struct namecache *nc_back; /* hash chain, MUST BE FIRST */ 112 struct namecache *nc_nxt; /* LRU chain */ 113 struct namecache **nc_prev; /* LRU chain */ 114 struct vnode *nc_dvp; /* vnode of parent of name */ 115 u_long nc_dvpid; /* capability number of nc_dvp */ 116 struct vnode *nc_vp; /* vnode the name refers to */ 117 u_long nc_vpid; /* capability number of nc_vp */ 118 char nc_nlen; /* length of name */ 119 char nc_name[NCHNAMLEN]; /* segment name */ 120 }; 121 122 #ifdef KERNEL 123 u_long nextvnodeid; 124 int namei __P((struct nameidata *ndp, struct proc *p)); 125 int lookup __P((struct nameidata *ndp, struct proc *p)); 126 #endif 127 128 /* 129 * Stats on usefulness of namei caches. 130 */ 131 struct nchstats { 132 long ncs_goodhits; /* hits that we can really use */ 133 long ncs_neghits; /* negative hits that we can use */ 134 long ncs_badhits; /* hits we must drop */ 135 long ncs_falsehits; /* hits with id mismatch */ 136 long ncs_miss; /* misses */ 137 long ncs_long; /* long names that ignore cache */ 138 long ncs_pass2; /* names found with passes == 2 */ 139 long ncs_2passes; /* number of times we attempt it */ 140 }; 141 #endif /* !_NAMEI_H_ */ 142