xref: /original-bsd/sys/sys/vnode.h (revision 1be78126)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)vnode.h	7.4 (Berkeley) 08/25/89
18  */
19 
20 /*
21  * The vnode is the focus of all file activity in UNIX.
22  * There is a unique vnode allocated for each active file,
23  * each current directory, each mounted-on file, text file, and the root.
24  */
25 
26 /*
27  * vnode types. VNON means no type.
28  */
29 enum vtype 	{ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VBAD };
30 
31 struct vnode {
32 	u_long		v_flag;			/* vnode flags (see below) */
33 	long		v_count;		/* reference count */
34 	u_short		v_shlockc;		/* count of shared locks */
35 	u_short		v_exlockc;		/* count of exclusive locks */
36 	struct mount	*v_mount;		/* ptr to vfs we are in */
37 	struct vnodeops	*v_op;			/* vnode operations */
38 	u_long		v_id;			/* capability identifier */
39 	enum vtype	v_type;			/* vnode type */
40 	union {
41 		struct mount	*vu_mountedhere;/* ptr to mounted vfs (VDIR) */
42 		struct socket	*vu_socket;	/* unix ipc (VSOCK) */
43 		struct text	*vu_text;	/* text/mapped region (VREG) */
44 		dev_t		vu_rdev;	/* device (VCHR, VBLK) */
45 	} v_un;
46 	qaddr_t		v_data;			/* private data for fs */
47 };
48 #define v_mountedhere v_un.vu_mountedhere
49 #define v_socket v_un.vu_socket
50 #define v_text v_un.vu_text
51 #define v_rdev v_un.vu_rdev
52 
53 /*
54  * vnode flags.
55  */
56 #define	VROOT		0x01	/* root of its file system */
57 #define	VTEXT		0x02	/* vnode is a pure text prototype */
58 #define	VEXLOCK		0x10	/* exclusive lock */
59 #define	VSHLOCK		0x20	/* shared lock */
60 #define	VLWAIT		0x40	/* proc is waiting on shared or excl. lock */
61 
62 /*
63  * Operations on vnodes.
64  */
65 struct vnodeops {
66 	int	(*vn_lookup)(		/* ndp */ );
67 	int	(*vn_create)(		/* ndp, fflags, vap, cred */ );
68 	int	(*vn_mknod)(		/* ndp, vap, cred */ );
69 	int	(*vn_open)(		/* vp, fflags, cred */ );
70 	int	(*vn_close)(		/* vp, fflags, cred */ );
71 	int	(*vn_access)(		/* vp, fflags, cred */ );
72 	int	(*vn_getattr)(		/* vp, vap, cred */ );
73 	int	(*vn_setattr)(		/* vp, vap, cred */ );
74 
75 	int	(*vn_read)(		/* vp, uiop, offp, ioflag, cred */ );
76 	int	(*vn_write)(		/* vp, uiop, offp, ioflag, cred */ );
77 	int	(*vn_ioctl)(		/* vp, com, data, fflag, cred */ );
78 	int	(*vn_select)(		/* vp, which, cred */ );
79 	int	(*vn_mmap)(		/* vp, ..., cred */ );
80 	int	(*vn_fsync)(		/* vp, fflags, cred */ );
81 	int	(*vn_seek)(		/* vp, (old)offp, off, whence */ );
82 
83 	int	(*vn_remove)(		/* ndp */ );
84 	int	(*vn_link)(		/* vp, ndp */ );
85 	int	(*vn_rename)(		/* ndp, ndp */ );
86 	int	(*vn_mkdir)(		/* ndp, vap */ );
87 	int	(*vn_rmdir)(		/* ndp */ );
88 	int	(*vn_symlink)(		/* ndp, vap, nm */ );
89 	int	(*vn_readdir)(		/* vp, uiop, ioflag, cred */ );
90 	int	(*vn_readlink)(		/* vp, uiop, cred */ );
91 
92 	int	(*vn_abortop)(		/* ndp */ );
93 	int	(*vn_inactive)(		/* vp */ );
94 	int	(*vn_lock)(		/* vp */ );
95 	int	(*vn_unlock)(		/* vp */ );
96 
97 	int	(*vn_bmap)(		/* vp, bn, vpp, bnp */ );
98 	int	(*vn_strategy)(		/* bp */ );
99 };
100 
101 /* Macros to call the vnode ops */
102 #define	VOP_LOOKUP(v,n)		(*((v)->v_op->vn_lookup))((v),(n))
103 #define	VOP_CREATE(n,a)		(*((n)->ni_dvp->v_op->vn_create))((n),(a))
104 #define	VOP_MKNOD(n,a,c)	(*((n)->ni_dvp->v_op->vn_mknod))((n),(a),(c))
105 #define	VOP_OPEN(v,f,c)		(*((v)->v_op->vn_open))((v),(f),(c))
106 #define	VOP_CLOSE(v,f,c)	(*((v)->v_op->vn_close))((v),(f),(c))
107 #define	VOP_ACCESS(v,f,c)	(*((v)->v_op->vn_access))((v),(f),(c))
108 #define	VOP_GETATTR(v,a,c)	(*((v)->v_op->vn_getattr))((v),(a),(c))
109 #define	VOP_SETATTR(v,a,c)	(*((v)->v_op->vn_setattr))((v),(a),(c))
110 #define	VOP_READ(v,u,o,i,c)	(*((v)->v_op->vn_read))((v),(u),(o),(i),(c))
111 #define	VOP_WRITE(v,u,o,i,c)	(*((v)->v_op->vn_write))((v),(u),(o),(i),(c))
112 #define	VOP_IOCTL(v,o,d,f,c)	(*((v)->v_op->vn_ioctl))((v),(o),(d),(f),(c))
113 #define	VOP_SELECT(v,w,c)	(*((v)->v_op->vn_select))((v),(w),(c))
114 #define	VOP_MMAP(v,c)		(*((v)->v_op->vn_mmap))((v),(c))
115 #define	VOP_FSYNC(v,f,c)	(*((v)->v_op->vn_fsync))((v),(f),(c))
116 #define	VOP_SEEK(v,p,o,w)	(*((v)->v_op->vn_seek))((v),(p),(o),(w))
117 #define	VOP_REMOVE(n)		(*((n)->ni_dvp->v_op->vn_remove))(n)
118 #define	VOP_LINK(v,n)		(*((n)->ni_dvp->v_op->vn_link))((v),(n))
119 #define	VOP_RENAME(s,t)		(*((s)->ni_dvp->v_op->vn_rename))((s),(t))
120 #define	VOP_MKDIR(n,a)		(*((n)->ni_dvp->v_op->vn_mkdir))((n),(a))
121 #define	VOP_RMDIR(n)		(*((n)->ni_dvp->v_op->vn_rmdir))(n)
122 #define	VOP_SYMLINK(n,a,m)	(*((n)->ni_dvp->v_op->vn_symlink))((n),(a),(m))
123 #define	VOP_READDIR(v,u,i,c)	(*((v)->v_op->vn_readdir))((v),(u),(i),(c))
124 #define	VOP_READLINK(v,u,c)	(*((v)->v_op->vn_readlink))((v),(u),(c))
125 #define	VOP_ABORTOP(n)		(*((n)->ni_dvp->v_op->vn_abortop))(n)
126 #define	VOP_INACTIVE(v)		(*((v)->v_op->vn_inactive))(v)
127 #define	VOP_LOCK(v)		(*((v)->v_op->vn_lock))(v)
128 #define	VOP_UNLOCK(v)		(*((v)->v_op->vn_unlock))(v)
129 #define	VOP_BMAP(v,s,p,n)	(*((v)->v_op->vn_bmap))((v),(s),(p),(n))
130 #define	VOP_STRATEGY(b)		(*((b)->b_vp->v_op->vn_strategy))(b)
131 
132 /*
133  * flags for ioflag
134  */
135 #define IO_ATOMIC	0x01		/* do io as atomic unit for VOP_RDWR */
136 #define IO_APPEND	0x02		/* append write for VOP_RDWR */
137 #define IO_SYNC		0x04		/* sync io for VOP_RDWR */
138 #define	IO_NODELOCKED	0x08		/* underlying node already locked */
139 #define	IO_NDELAY	0x10		/* FNDELAY flag set in file table */
140 
141 #define IO_UNIT		IO_ATOMIC	/* compat */
142 
143 /*
144  * Vnode attributes.  A field value of VNOVAL
145  * represents a field whose value is unavailable
146  * (getattr) or which is not to be changed (setattr).
147  */
148 struct vattr {
149 	enum vtype	va_type;	/* vnode type (for create) */
150 	u_short		va_mode;	/* files access mode and type */
151 	short		va_nlink;	/* number of references to file */
152 	uid_t		va_uid;		/* owner user id */
153 	gid_t		va_gid;		/* owner group id */
154 	long		va_fsid;	/* file system id (dev for now) */
155 	long		va_fileid;	/* file id */
156 	u_long		va_size;	/* file size in bytes (quad?) */
157 	u_long		va_size1;	/* reserved if not quad */
158 	long		va_blocksize;	/* blocksize preferred for i/o */
159 	struct timeval	va_atime;	/* time of last access */
160 	struct timeval	va_mtime;	/* time of last modification */
161 	struct timeval	va_ctime;	/* time file changed */
162 	u_long		va_gen;		/* generation number of file */
163 	u_long		va_flags;	/* flags defined for file */
164 	dev_t		va_rdev;	/* device the special file represents */
165 	u_long		va_bytes;	/* bytes of disk space held by file */
166 	u_long		va_bytes1;	/* reserved if va_bytes not a quad */
167 };
168 
169 /*
170  *  Modes. Some values same as Ixxx entries from inode.h for now
171  */
172 #define	VSUID	04000		/* set user id on execution */
173 #define	VSGID	02000		/* set group id on execution */
174 #define	VSVTX	01000		/* save swapped text even after use */
175 #define	VREAD	0400		/* read, write, execute permissions */
176 #define	VWRITE	0200
177 #define	VEXEC	0100
178 /*
179  * Token indicating no attribute value yet assigned
180  */
181 #define VNOVAL	((unsigned)0xffffffff)
182 
183 #ifdef KERNEL
184 /*
185  * public vnode manipulation functions
186  */
187 extern int vn_open();			/* open vnode */
188 extern int vn_rdwr();			/* read or write vnode */
189 extern int vn_close();			/* close vnode */
190 extern void vrele();			/* release vnode */
191 extern void vattr_null();		/* set attributes to null */
192 #define VREF(vp)	(vp)->v_count++;/* increment vnode reference count */
193 
194 #define vinit(vp, mountp, type, vops)	{ \
195 	(vp)->v_flag = 0; \
196 	(vp)->v_count++; \
197 	(vp)->v_shlockc = (vp)->v_exlockc = 0; \
198 	(vp)->v_mount = (mountp); \
199 	(vp)->v_type = (type); \
200 	(vp)->v_op = (vops); \
201 	(vp)->v_socket = 0; \
202 }
203 
204 /*
205  * Global vnode data.
206  */
207 extern struct vnode	*rootdir;		/* root (i.e. "/") vnode */
208 
209 #endif
210