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