1 /* 2 * Copyright (c) 1985, 1989 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)namei.h 7.13 (Berkeley) 02/21/91 8 */ 9 10 #ifndef _NAMEI_H_ 11 #define _NAMEI_H_ 12 13 #ifdef KERNEL 14 #include "../ufs/dir.h" 15 #include "uio.h" 16 #else 17 #include <sys/uio.h> 18 #include <ufs/dir.h> 19 #endif 20 21 /* 22 * Encapsulation of namei parameters. 23 * One of these is located in the u. area to 24 * minimize space allocated on the kernel stack. 25 */ 26 struct nameidata { 27 /* arguments to namei and related context: */ 28 caddr_t ni_dirp; /* pathname pointer */ 29 enum uio_seg ni_segflg; /* location of pathname */ 30 u_long ni_nameiop; /* see below */ 31 struct ucred *ni_cred; /* credentials */ 32 struct vnode *ni_startdir; /* alternate starting directory */ 33 34 /* shared between namei, lookup routines and commit routines: */ 35 caddr_t ni_pnbuf; /* pathname buffer */ 36 char *ni_ptr; /* current location in pathname */ 37 char *ni_next; /* next location in pathname */ 38 u_int ni_pathlen; /* remaining chars in path */ 39 u_long ni_hash; /* hash value of current component */ 40 short ni_namelen; /* length of current component */ 41 short ni_loopcnt; /* count of symlinks encountered */ 42 char ni_makeentry; /* 1 => add entry to name cache */ 43 char ni_isdotdot; /* 1 => current component name is .. */ 44 45 /* results: */ 46 struct vnode *ni_vp; /* vnode of result */ 47 struct vnode *ni_dvp; /* vnode of intermediate directory */ 48 struct direct ni_dent; /* final component name */ 49 50 /* side effects: */ 51 /* BEGIN UFS SPECIFIC */ 52 off_t ni_endoff; /* end of useful directory contents */ 53 struct ndirinfo { /* saved info for new dir entry */ 54 struct iovec nd_iovec; /* pointed to by ni_iov */ 55 struct uio nd_uio; /* directory I/O parameters */ 56 } ni_nd; 57 /* END UFS SPECIFIC */ 58 }; 59 60 #define ni_base ni_nd.nd_iovec.iov_base 61 #define ni_count ni_nd.nd_iovec.iov_len 62 #define ni_uioseg ni_nd.nd_uio.uio_segflg 63 #define ni_iov ni_nd.nd_uio.uio_iov 64 #define ni_iovcnt ni_nd.nd_uio.uio_iovcnt 65 #define ni_offset ni_nd.nd_uio.uio_offset 66 #define ni_resid ni_nd.nd_uio.uio_resid 67 #define ni_rw ni_nd.nd_uio.uio_rw 68 #define ni_uio ni_nd.nd_uio 69 70 #ifdef KERNEL 71 /* 72 * namei operations 73 */ 74 #define LOOKUP 0 /* perform name lookup only */ 75 #define CREATE 1 /* setup for file creation */ 76 #define DELETE 2 /* setup for file deletion */ 77 #define RENAME 3 /* setup for file renaming */ 78 #define OPMASK 3 /* mask for operation */ 79 /* 80 * namei operational modifiers 81 */ 82 #define LOCKLEAF 0x0004 /* lock inode on return */ 83 #define LOCKPARENT 0x0008 /* want parent vnode returned locked */ 84 #define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ 85 #define NOCACHE 0x0020 /* name must not be left in cache */ 86 #define FOLLOW 0x0040 /* follow symbolic links */ 87 #define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ 88 #define MODMASK 0x00fc /* mask of operational modifiers */ 89 /* 90 * namei parameter descriptors 91 */ 92 #define NOCROSSMOUNT 0x0100 /* do not cross mount points */ 93 #define REMOTE 0x0200 /* lookup for remote filesystem servers */ 94 #define HASBUF 0x0400 /* has preallocated pathname buffer */ 95 #define STARTDIR 0x0800 /* has alternate starting directory */ 96 #define SAVESTARTDIR 0x1000 /* do not vrele alternate 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 #endif 125 126 /* 127 * Stats on usefulness of namei caches. 128 */ 129 struct nchstats { 130 long ncs_goodhits; /* hits that we can really use */ 131 long ncs_neghits; /* negative hits that we can use */ 132 long ncs_badhits; /* hits we must drop */ 133 long ncs_falsehits; /* hits with id mismatch */ 134 long ncs_miss; /* misses */ 135 long ncs_long; /* long names that ignore cache */ 136 long ncs_pass2; /* names found with passes == 2 */ 137 long ncs_2passes; /* number of times we attempt it */ 138 }; 139 #endif /* !_NAMEI_H_ */ 140