1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)vnode.h 7.32 (Berkeley) 02/01/91 8 */ 9 10 #include <machine/endian.h> 11 12 /* 13 * The vnode is the focus of all file activity in UNIX. 14 * There is a unique vnode allocated for each active file, 15 * each current directory, each mounted-on file, text file, and the root. 16 */ 17 18 /* 19 * vnode types. VNON means no type. 20 */ 21 enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; 22 23 /* 24 * Vnode tag types. 25 * These are for the benefit of external programs only (e.g., pstat) 26 * and should NEVER be inspected inside the kernel. 27 */ 28 enum vtagtype { VT_NON, VT_UFS, VT_NFS, VT_MFS }; 29 30 /* 31 * This defines the maximum size of the private data area 32 * permitted for any file system type. A defined constant 33 * is used rather than a union structure to cut down on the 34 * number of header files that must be included. 35 */ 36 #define VN_MAXPRIVATE 188 37 38 struct vnode { 39 u_long v_flag; /* vnode flags (see below) */ 40 long v_usecount; /* reference count of users */ 41 long v_holdcnt; /* page & buffer references */ 42 off_t v_lastr; /* last read (read-ahead) */ 43 u_long v_id; /* capability identifier */ 44 struct mount *v_mount; /* ptr to vfs we are in */ 45 struct vnodeops *v_op; /* vnode operations */ 46 struct vnode *v_freef; /* vnode freelist forward */ 47 struct vnode **v_freeb; /* vnode freelist back */ 48 struct vnode *v_mountf; /* vnode mountlist forward */ 49 struct vnode **v_mountb; /* vnode mountlist back */ 50 struct buf *v_cleanblkhd; /* clean blocklist head */ 51 struct buf *v_dirtyblkhd; /* dirty blocklist head */ 52 long v_numoutput; /* num of writes in progress */ 53 enum vtype v_type; /* vnode type */ 54 union { 55 struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ 56 struct socket *vu_socket; /* unix ipc (VSOCK) */ 57 caddr_t vu_vmdata; /* private data for vm */ 58 struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ 59 struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ 60 } v_un; 61 enum vtagtype v_tag; /* type of underlying data */ 62 char v_data[VN_MAXPRIVATE]; /* private data for fs */ 63 }; 64 #define v_mountedhere v_un.vu_mountedhere 65 #define v_socket v_un.vu_socket 66 #define v_vmdata v_un.vu_vmdata 67 #define v_specinfo v_un.vu_specinfo 68 #define v_fifoinfo v_un.vu_fifoinfo 69 70 /* 71 * vnode flags. 72 */ 73 #define VROOT 0x0001 /* root of its file system */ 74 #define VTEXT 0x0002 /* vnode is a pure text prototype */ 75 #define VSYSTEM 0x0004 /* vnode being used by kernel */ 76 #define VXLOCK 0x0100 /* vnode is locked to change underlying type */ 77 #define VXWANT 0x0200 /* process is waiting for vnode */ 78 #define VBWAIT 0x0400 /* waiting for output to complete */ 79 #define VALIASED 0x0800 /* vnode has an alias */ 80 81 /* 82 * Operations on vnodes. 83 */ 84 struct vnodeops { 85 int (*vn_lookup)( /* ndp */ ); 86 int (*vn_create)( /* ndp, fflags, vap, cred */ ); 87 int (*vn_mknod)( /* ndp, vap, cred */ ); 88 int (*vn_open)( /* vp, fflags, cred */ ); 89 int (*vn_close)( /* vp, fflags, cred */ ); 90 int (*vn_access)( /* vp, fflags, cred */ ); 91 int (*vn_getattr)( /* vp, vap, cred */ ); 92 int (*vn_setattr)( /* vp, vap, cred */ ); 93 94 int (*vn_read)( /* vp, uiop, offp, ioflag, cred */ ); 95 int (*vn_write)( /* vp, uiop, offp, ioflag, cred */ ); 96 int (*vn_ioctl)( /* vp, com, data, fflag, cred */ ); 97 int (*vn_select)( /* vp, which, cred */ ); 98 int (*vn_mmap)( /* vp, ..., cred */ ); 99 int (*vn_fsync)( /* vp, fflags, cred */ ); 100 int (*vn_seek)( /* vp, (old)offp, off, whence */ ); 101 102 int (*vn_remove)( /* ndp */ ); 103 int (*vn_link)( /* vp, ndp */ ); 104 int (*vn_rename)( /* ndp, ndp */ ); 105 int (*vn_mkdir)( /* ndp, vap */ ); 106 int (*vn_rmdir)( /* ndp */ ); 107 int (*vn_symlink)( /* ndp, vap, nm */ ); 108 int (*vn_readdir)( /* vp, uiop, cred, eofflagp */ ); 109 int (*vn_readlink)( /* vp, uiop, cred */ ); 110 111 int (*vn_abortop)( /* ndp */ ); 112 int (*vn_inactive)( /* vp */ ); 113 int (*vn_reclaim)( /* vp */ ); 114 int (*vn_lock)( /* vp */ ); 115 int (*vn_unlock)( /* vp */ ); 116 117 int (*vn_bmap)( /* vp, bn, vpp, bnp */ ); 118 int (*vn_strategy)( /* bp */ ); 119 120 int (*vn_print)( /* vp */ ); 121 int (*vn_islocked)( /* vp */ ); 122 int (*vn_advlock)( /* vp, proc, op, lck, flg */ ); 123 }; 124 125 /* Macros to call the vnode ops */ 126 #define VOP_LOOKUP(v,n) (*((v)->v_op->vn_lookup))((v),(n)) 127 #define VOP_CREATE(n,a) (*((n)->ni_dvp->v_op->vn_create))((n),(a)) 128 #define VOP_MKNOD(n,a,c) (*((n)->ni_dvp->v_op->vn_mknod))((n),(a),(c)) 129 #define VOP_OPEN(v,f,c) (*((v)->v_op->vn_open))((v),(f),(c)) 130 #define VOP_CLOSE(v,f,c) (*((v)->v_op->vn_close))((v),(f),(c)) 131 #define VOP_ACCESS(v,f,c) (*((v)->v_op->vn_access))((v),(f),(c)) 132 #define VOP_GETATTR(v,a,c) (*((v)->v_op->vn_getattr))((v),(a),(c)) 133 #define VOP_SETATTR(v,a,c) (*((v)->v_op->vn_setattr))((v),(a),(c)) 134 #define VOP_READ(v,u,i,c) (*((v)->v_op->vn_read))((v),(u),(i),(c)) 135 #define VOP_WRITE(v,u,i,c) (*((v)->v_op->vn_write))((v),(u),(i),(c)) 136 #define VOP_IOCTL(v,o,d,f,c) (*((v)->v_op->vn_ioctl))((v),(o),(d),(f),(c)) 137 #define VOP_SELECT(v,w,f,c) (*((v)->v_op->vn_select))((v),(w),(f),(c)) 138 #define VOP_MMAP(v,c) (*((v)->v_op->vn_mmap))((v),(c)) 139 #define VOP_FSYNC(v,f,c,w) (*((v)->v_op->vn_fsync))((v),(f),(c),(w)) 140 #define VOP_SEEK(v,p,o,w) (*((v)->v_op->vn_seek))((v),(p),(o),(w)) 141 #define VOP_REMOVE(n) (*((n)->ni_dvp->v_op->vn_remove))(n) 142 #define VOP_LINK(v,n) (*((n)->ni_dvp->v_op->vn_link))((v),(n)) 143 #define VOP_RENAME(s,t) (*((s)->ni_dvp->v_op->vn_rename))((s),(t)) 144 #define VOP_MKDIR(n,a) (*((n)->ni_dvp->v_op->vn_mkdir))((n),(a)) 145 #define VOP_RMDIR(n) (*((n)->ni_dvp->v_op->vn_rmdir))(n) 146 #define VOP_SYMLINK(n,a,m) (*((n)->ni_dvp->v_op->vn_symlink))((n),(a),(m)) 147 #define VOP_READDIR(v,u,c,e) (*((v)->v_op->vn_readdir))((v),(u),(c),(e)) 148 #define VOP_READLINK(v,u,c) (*((v)->v_op->vn_readlink))((v),(u),(c)) 149 #define VOP_ABORTOP(n) (*((n)->ni_dvp->v_op->vn_abortop))(n) 150 #define VOP_INACTIVE(v) (*((v)->v_op->vn_inactive))(v) 151 #define VOP_RECLAIM(v) (*((v)->v_op->vn_reclaim))(v) 152 #define VOP_LOCK(v) (*((v)->v_op->vn_lock))(v) 153 #define VOP_UNLOCK(v) (*((v)->v_op->vn_unlock))(v) 154 #define VOP_BMAP(v,s,p,n) (*((v)->v_op->vn_bmap))((v),(s),(p),(n)) 155 #define VOP_STRATEGY(b) (*((b)->b_vp->v_op->vn_strategy))(b) 156 #define VOP_PRINT(v) (*((v)->v_op->vn_print))(v) 157 #define VOP_ISLOCKED(v) (*((v)->v_op->vn_islocked))(v) 158 #define VOP_ADVLOCK(v,p,o,l,f) (*((v)->v_op->vn_advlock))((v),(p),(o),(l),(f)) 159 160 /* 161 * flags for ioflag 162 */ 163 #define IO_UNIT 0x01 /* do I/O as atomic unit */ 164 #define IO_APPEND 0x02 /* append write to end */ 165 #define IO_SYNC 0x04 /* do I/O synchronously */ 166 #define IO_NODELOCKED 0x08 /* underlying node already locked */ 167 #define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ 168 169 /* 170 * Vnode attributes. A field value of VNOVAL 171 * represents a field whose value is unavailable 172 * (getattr) or which is not to be changed (setattr). 173 */ 174 struct vattr { 175 enum vtype va_type; /* vnode type (for create) */ 176 u_short va_mode; /* files access mode and type */ 177 short va_nlink; /* number of references to file */ 178 uid_t va_uid; /* owner user id */ 179 gid_t va_gid; /* owner group id */ 180 long va_fsid; /* file system id (dev for now) */ 181 long va_fileid; /* file id */ 182 u_quad va_qsize; /* file size in bytes */ 183 long va_blocksize; /* blocksize preferred for i/o */ 184 struct timeval va_atime; /* time of last access */ 185 struct timeval va_mtime; /* time of last modification */ 186 struct timeval va_ctime; /* time file changed */ 187 u_long va_gen; /* generation number of file */ 188 u_long va_flags; /* flags defined for file */ 189 dev_t va_rdev; /* device the special file represents */ 190 u_quad va_qbytes; /* bytes of disk space held by file */ 191 }; 192 #if BYTE_ORDER == LITTLE_ENDIAN 193 #define va_size va_qsize.val[0] 194 #define va_size_rsv va_qsize.val[1] 195 #define va_bytes va_qbytes.val[0] 196 #define va_bytes_rsv va_qbytes.val[1] 197 #else 198 #define va_size va_qsize.val[1] 199 #define va_size_rsv va_qsize.val[0] 200 #define va_bytes va_qbytes.val[1] 201 #define va_bytes_rsv va_qbytes.val[0] 202 #endif 203 204 /* 205 * Modes. Some values same as Ixxx entries from inode.h for now 206 */ 207 #define VSUID 04000 /* set user id on execution */ 208 #define VSGID 02000 /* set group id on execution */ 209 #define VSVTX 01000 /* save swapped text even after use */ 210 #define VREAD 0400 /* read, write, execute permissions */ 211 #define VWRITE 0200 212 #define VEXEC 0100 213 214 /* 215 * Token indicating no attribute value yet assigned 216 */ 217 #define VNOVAL ((unsigned)0xffffffff) 218 219 #ifdef KERNEL 220 /* 221 * public vnode manipulation functions 222 */ 223 extern int vn_open(); /* open vnode */ 224 extern int vn_rdwr(); /* read or write vnode */ 225 extern int vn_close(); /* close vnode */ 226 extern void vattr_null(); /* set attributes to null */ 227 extern int getnewvnode(); /* allocate a new vnode */ 228 extern int bdevvp(); /* allocate a new special dev vnode */ 229 extern struct vnode *checkalias(); /* check for special device aliases */ 230 extern int vcount(); /* total references to a device */ 231 extern int vget(); /* get first reference to a vnode */ 232 extern void vref(); /* increase reference to a vnode */ 233 extern void vput(); /* unlock and release vnode */ 234 extern void vrele(); /* release vnode */ 235 extern void vgone(); /* completely recycle vnode */ 236 extern void vgoneall(); /* recycle vnode and all its aliases */ 237 238 /* 239 * Flags to various vnode functions. 240 */ 241 #define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ 242 #define FORCECLOSE 0x0002 /* vflush: force file closeure */ 243 #define DOCLOSE 0x0004 /* vclean: close active files */ 244 245 #ifndef DIAGNOSTIC 246 #define VREF(vp) (vp)->v_usecount++ /* increase reference to a vnode */ 247 #define VHOLD(vp) (vp)->v_holdcnt++ /* increase buf or page ref to vnode */ 248 #define HOLDRELE(vp) (vp)->v_holdcnt-- /* decrease buf or page ref to vnode */ 249 #define VATTR_NULL(vap) *(vap) = va_null /* initialize a vattr stucture */ 250 #else /* DIAGNOSTIC */ 251 #define VREF(vp) vref(vp) 252 #define VHOLD(vp) vhold(vp) 253 #define HOLDRELE(vp) holdrele(vp) 254 #define VATTR_NULL(vap) vattr_null(vap) 255 #endif 256 257 #define NULLVP ((struct vnode *)0) 258 259 /* 260 * Global vnode data. 261 */ 262 extern struct vnode *rootdir; /* root (i.e. "/") vnode */ 263 extern int desiredvnodes; /* number of vnodes desired */ 264 extern struct vattr va_null; /* predefined null vattr structure */ 265 #endif 266