Commit | Line | Data |
---|---|---|
d1927135 | 1 | /* |
56559b70 KB |
2 | * Copyright (c) 1989, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
d1927135 | 4 | * |
ad787160 C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
d1927135 | 20 | * |
ad787160 C |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
ed554bc5 | 33 | * @(#)vnode.h 8.7 (Berkeley) 2/4/94 |
d1927135 KM |
34 | */ |
35 | ||
907fd47e | 36 | #include <sys/queue.h> |
8fae943a | 37 | |
d1927135 | 38 | /* |
ad1e7e0e KB |
39 | * The vnode is the focus of all file activity in UNIX. There is a |
40 | * unique vnode allocated for each active file, each current directory, | |
41 | * each mounted-on file, text file, and the root. | |
d1927135 KM |
42 | */ |
43 | ||
44 | /* | |
ad1e7e0e | 45 | * Vnode types. VNON means no type. |
d1927135 | 46 | */ |
ad1e7e0e | 47 | enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; |
d1927135 | 48 | |
94c33299 KM |
49 | /* |
50 | * Vnode tag types. | |
51 | * These are for the benefit of external programs only (e.g., pstat) | |
ad1e7e0e | 52 | * and should NEVER be inspected by the kernel. |
94c33299 | 53 | */ |
ce6f728f JSP |
54 | enum vtagtype { |
55 | VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_PC, VT_LFS, VT_LOFS, VT_FDESC, | |
95027046 JSP |
56 | VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS, |
57 | VT_UNION | |
ce6f728f | 58 | }; |
94c33299 KM |
59 | |
60 | /* | |
eb0a621f | 61 | * Each underlying filesystem allocates its own private area and hangs |
95084395 | 62 | * it from v_data. If non-null, this area is freed in getnewvnode(). |
94c33299 | 63 | */ |
95084395 KM |
64 | LIST_HEAD(buflists, buf); |
65 | ||
d1927135 | 66 | struct vnode { |
907fd47e KM |
67 | u_long v_flag; /* vnode flags (see below) */ |
68 | short v_usecount; /* reference count of users */ | |
69 | short v_writecount; /* reference count of writers */ | |
70 | long v_holdcnt; /* page & buffer references */ | |
71 | daddr_t v_lastr; /* last read (read-ahead) */ | |
72 | u_long v_id; /* capability identifier */ | |
73 | struct mount *v_mount; /* ptr to vfs we are in */ | |
74 | int (**v_op)(); /* vnode operations vector */ | |
95084395 KM |
75 | TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ |
76 | LIST_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ | |
77 | struct buflists v_cleanblkhd; /* clean blocklist head */ | |
78 | struct buflists v_dirtyblkhd; /* dirty blocklist head */ | |
907fd47e KM |
79 | long v_numoutput; /* num of writes in progress */ |
80 | enum vtype v_type; /* vnode type */ | |
d1927135 KM |
81 | union { |
82 | struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ | |
83 | struct socket *vu_socket; /* unix ipc (VSOCK) */ | |
0871b2b8 | 84 | caddr_t vu_vmdata; /* private data for vm (VREG) */ |
03709bc7 | 85 | struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ |
59547b09 | 86 | struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ |
d1927135 | 87 | } v_un; |
907fd47e | 88 | struct nqlease *v_lease; /* Soft reference to lease */ |
10cadfbc MS |
89 | daddr_t v_lastw; /* last write (write cluster) */ |
90 | daddr_t v_cstart; /* start block of cluster */ | |
91 | daddr_t v_lasta; /* last allocation */ | |
92 | int v_clen; /* length of current cluster */ | |
93 | int v_ralen; /* Read-ahead length */ | |
dc7ee83c MH |
94 | daddr_t v_maxra; /* last readahead block */ |
95 | long v_spare[7]; /* round to 128 bytes */ | |
907fd47e KM |
96 | enum vtagtype v_tag; /* type of underlying data */ |
97 | void *v_data; /* private data for fs */ | |
d1927135 | 98 | }; |
075eef37 MK |
99 | #define v_mountedhere v_un.vu_mountedhere |
100 | #define v_socket v_un.vu_socket | |
101 | #define v_vmdata v_un.vu_vmdata | |
102 | #define v_specinfo v_un.vu_specinfo | |
103 | #define v_fifoinfo v_un.vu_fifoinfo | |
d1927135 KM |
104 | |
105 | /* | |
ad1e7e0e | 106 | * Vnode flags. |
d1927135 | 107 | */ |
ebb1929c KM |
108 | #define VROOT 0x0001 /* root of its file system */ |
109 | #define VTEXT 0x0002 /* vnode is a pure text prototype */ | |
d0c771ff | 110 | #define VSYSTEM 0x0004 /* vnode being used by kernel */ |
d0c771ff KM |
111 | #define VXLOCK 0x0100 /* vnode is locked to change underlying type */ |
112 | #define VXWANT 0x0200 /* process is waiting for vnode */ | |
113 | #define VBWAIT 0x0400 /* waiting for output to complete */ | |
114 | #define VALIASED 0x0800 /* vnode has an alias */ | |
8a1f291b | 115 | #define VDIROP 0x1000 /* LFS: vnode is involved in a directory op */ |
d1927135 | 116 | |
d1927135 | 117 | /* |
ed54235b KB |
118 | * Vnode attributes. A field value of VNOVAL represents a field whose value |
119 | * is unavailable (getattr) or which is not to be changed (setattr). | |
d1927135 KM |
120 | */ |
121 | struct vattr { | |
122 | enum vtype va_type; /* vnode type (for create) */ | |
123 | u_short va_mode; /* files access mode and type */ | |
124 | short va_nlink; /* number of references to file */ | |
125 | uid_t va_uid; /* owner user id */ | |
126 | gid_t va_gid; /* owner group id */ | |
127 | long va_fsid; /* file system id (dev for now) */ | |
128 | long va_fileid; /* file id */ | |
19ae0f1d | 129 | u_quad_t va_size; /* file size in bytes */ |
d1927135 | 130 | long va_blocksize; /* blocksize preferred for i/o */ |
f9c05f63 KM |
131 | struct timespec va_atime; /* time of last access */ |
132 | struct timespec va_mtime; /* time of last modification */ | |
133 | struct timespec va_ctime; /* time file changed */ | |
3d565337 KM |
134 | u_long va_gen; /* generation number of file */ |
135 | u_long va_flags; /* flags defined for file */ | |
d1927135 | 136 | dev_t va_rdev; /* device the special file represents */ |
19ae0f1d | 137 | u_quad_t va_bytes; /* bytes of disk space held by file */ |
46fc8b00 | 138 | u_quad_t va_filerev; /* file modification number */ |
fcba749b | 139 | u_int va_vaflags; /* operations flags, see below */ |
8f262660 | 140 | long va_spare; /* remain quad aligned */ |
d1927135 KM |
141 | }; |
142 | ||
f8ee9a49 KB |
143 | /* |
144 | * Flags for va_cflags. | |
145 | */ | |
146 | #define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ | |
147 | ||
0871b2b8 | 148 | /* |
ad1e7e0e | 149 | * Flags for ioflag. |
0871b2b8 | 150 | */ |
075eef37 MK |
151 | #define IO_UNIT 0x01 /* do I/O as atomic unit */ |
152 | #define IO_APPEND 0x02 /* append write to end */ | |
153 | #define IO_SYNC 0x04 /* do I/O synchronously */ | |
0871b2b8 KM |
154 | #define IO_NODELOCKED 0x08 /* underlying node already locked */ |
155 | #define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ | |
156 | ||
d1927135 | 157 | /* |
ad1e7e0e | 158 | * Modes. Some values same as Ixxx entries from inode.h for now. |
d1927135 KM |
159 | */ |
160 | #define VSUID 04000 /* set user id on execution */ | |
161 | #define VSGID 02000 /* set group id on execution */ | |
162 | #define VSVTX 01000 /* save swapped text even after use */ | |
ad1e7e0e KB |
163 | #define VREAD 00400 /* read, write, execute permissions */ |
164 | #define VWRITE 00200 | |
165 | #define VEXEC 00100 | |
94c33299 | 166 | |
d1927135 | 167 | /* |
ad1e7e0e | 168 | * Token indicating no attribute value yet assigned. |
d1927135 | 169 | */ |
46fc8b00 | 170 | #define VNOVAL (-1) |
d1927135 KM |
171 | |
172 | #ifdef KERNEL | |
5619f568 KM |
173 | /* |
174 | * Convert between vnode types and inode formats (since POSIX.1 | |
175 | * defines mode word of stat structure in terms of inode formats). | |
176 | */ | |
177 | extern enum vtype iftovt_tab[]; | |
178 | extern int vttoif_tab[]; | |
688bb869 | 179 | #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) |
5619f568 KM |
180 | #define VTTOIF(indx) (vttoif_tab[(int)(indx)]) |
181 | #define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) | |
182 | ||
d0c771ff KM |
183 | /* |
184 | * Flags to various vnode functions. | |
185 | */ | |
186 | #define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ | |
187 | #define FORCECLOSE 0x0002 /* vflush: force file closeure */ | |
1e15b6fc KM |
188 | #define WRITECLOSE 0x0004 /* vflush: only close writeable files */ |
189 | #define DOCLOSE 0x0008 /* vclean: close active files */ | |
06dd4b9a MS |
190 | #define V_SAVE 0x0001 /* vinvalbuf: sync file first */ |
191 | #define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */ | |
d0c771ff | 192 | |
ad1e7e0e | 193 | #ifdef DIAGNOSTIC |
075eef37 MK |
194 | #define HOLDRELE(vp) holdrele(vp) |
195 | #define VATTR_NULL(vap) vattr_null(vap) | |
ad1e7e0e KB |
196 | #define VHOLD(vp) vhold(vp) |
197 | #define VREF(vp) vref(vp) | |
cdfa4fa3 KM |
198 | |
199 | void holdrele __P((struct vnode *)); | |
200 | void vattr_null __P((struct vattr *)); | |
201 | void vhold __P((struct vnode *)); | |
202 | void vref __P((struct vnode *)); | |
ad1e7e0e KB |
203 | #else |
204 | #define HOLDRELE(vp) (vp)->v_holdcnt-- /* decrease buf or page ref */ | |
205 | #define VATTR_NULL(vap) (*(vap) = va_null) /* initialize a vattr */ | |
206 | #define VHOLD(vp) (vp)->v_holdcnt++ /* increase buf or page ref */ | |
207 | #define VREF(vp) (vp)->v_usecount++ /* increase reference */ | |
5bbeeaec | 208 | #endif |
d1927135 | 209 | |
075eef37 | 210 | #define NULLVP ((struct vnode *)NULL) |
d0c771ff | 211 | |
d1927135 KM |
212 | /* |
213 | * Global vnode data. | |
214 | */ | |
5685f766 | 215 | extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ |
be304f9f | 216 | extern int desiredvnodes; /* number of vnodes desired */ |
97efb212 | 217 | extern struct vattr va_null; /* predefined null vattr structure */ |
d7cecd93 KM |
218 | |
219 | /* | |
220 | * Macro/function to check for client cache inconsistency w.r.t. leasing. | |
221 | */ | |
222 | #define LEASE_READ 0x1 /* Check lease for readers */ | |
223 | #define LEASE_WRITE 0x2 /* Check lease for modifiers */ | |
224 | ||
225 | #ifdef NFS | |
226 | void lease_check __P((struct vnode *vp, struct proc *p, | |
ad1e7e0e | 227 | struct ucred *ucred, int flag)); |
d7cecd93 KM |
228 | void lease_updatetime __P((int deltat)); |
229 | #define LEASE_CHECK(vp, p, cred, flag) lease_check((vp), (p), (cred), (flag)) | |
230 | #define LEASE_UPDATETIME(dt) lease_updatetime(dt) | |
231 | #else | |
232 | #define LEASE_CHECK(vp, p, cred, flag) | |
233 | #define LEASE_UPDATETIME(dt) | |
234 | #endif /* NFS */ | |
11127818 | 235 | #endif /* KERNEL */ |
4a7f0e14 JH |
236 | |
237 | ||
238 | /* | |
239 | * Mods for exensibility. | |
240 | */ | |
241 | ||
242 | /* | |
ad1e7e0e | 243 | * Flags for vdesc_flags: |
4a7f0e14 JH |
244 | */ |
245 | #define VDESC_MAX_VPS 16 | |
83cc0aab JH |
246 | /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */ |
247 | #define VDESC_VP0_WILLRELE 0x0001 | |
248 | #define VDESC_VP1_WILLRELE 0x0002 | |
249 | #define VDESC_VP2_WILLRELE 0x0004 | |
250 | #define VDESC_VP3_WILLRELE 0x0008 | |
4a7f0e14 | 251 | #define VDESC_NOMAP_VPP 0x0100 |
83cc0aab | 252 | #define VDESC_VPP_WILLRELE 0x0200 |
4a7f0e14 JH |
253 | |
254 | /* | |
255 | * VDESC_NO_OFFSET is used to identify the end of the offset list | |
256 | * and in places where no such field exists. | |
257 | */ | |
258 | #define VDESC_NO_OFFSET -1 | |
259 | ||
260 | /* | |
261 | * This structure describes the vnode operation taking place. | |
262 | */ | |
263 | struct vnodeop_desc { | |
264 | int vdesc_offset; /* offset in vector--first for speed */ | |
265 | char *vdesc_name; /* a readable name for debugging */ | |
266 | int vdesc_flags; /* VDESC_* flags */ | |
267 | ||
268 | /* | |
ad1e7e0e KB |
269 | * These ops are used by bypass routines to map and locate arguments. |
270 | * Creds and procs are not needed in bypass routines, but sometimes | |
271 | * they are useful to (for example) transport layers. | |
83cc0aab | 272 | * Nameidata is useful because it has a cred in it. |
4a7f0e14 JH |
273 | */ |
274 | int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */ | |
275 | int vdesc_vpp_offset; /* return vpp location */ | |
276 | int vdesc_cred_offset; /* cred location, if any */ | |
277 | int vdesc_proc_offset; /* proc location, if any */ | |
83cc0aab | 278 | int vdesc_componentname_offset; /* if any */ |
4a7f0e14 | 279 | /* |
ad1e7e0e KB |
280 | * Finally, we've got a list of private data (about each operation) |
281 | * for each transport layer. (Support to manage this list is not | |
282 | * yet part of BSD.) | |
4a7f0e14 JH |
283 | */ |
284 | caddr_t *vdesc_transports; | |
285 | }; | |
286 | ||
11127818 | 287 | #ifdef KERNEL |
4a7f0e14 JH |
288 | /* |
289 | * A list of all the operation descs. | |
290 | */ | |
291 | extern struct vnodeop_desc *vnodeop_descs[]; | |
292 | ||
293 | ||
294 | /* | |
295 | * This macro is very helpful in defining those offsets in the vdesc struct. | |
296 | * | |
297 | * This is stolen from X11R4. I ingored all the fancy stuff for | |
298 | * Crays, so if you decide to port this to such a serious machine, | |
299 | * you might want to consult Intrisics.h's XtOffset{,Of,To}. | |
300 | */ | |
301 | #define VOPARG_OFFSET(p_type,field) \ | |
302 | ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) | |
303 | #define VOPARG_OFFSETOF(s_type,field) \ | |
304 | VOPARG_OFFSET(s_type*,field) | |
305 | #define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \ | |
306 | ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET))) | |
307 | ||
308 | ||
309 | /* | |
310 | * This structure is used to configure the new vnodeops vector. | |
311 | */ | |
312 | struct vnodeopv_entry_desc { | |
313 | struct vnodeop_desc *opve_op; /* which operation this is */ | |
ad1e7e0e | 314 | int (*opve_impl)(); /* code implementing this operation */ |
4a7f0e14 JH |
315 | }; |
316 | struct vnodeopv_desc { | |
4a7f0e14 | 317 | /* ptr to the ptr to the vector where op should go */ |
ad1e7e0e | 318 | int (***opv_desc_vector_p)(); |
4a7f0e14 JH |
319 | struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */ |
320 | }; | |
321 | ||
322 | /* | |
323 | * A default routine which just returns an error. | |
324 | */ | |
ad1e7e0e | 325 | int vn_default_error __P((void)); |
4a7f0e14 JH |
326 | |
327 | /* | |
328 | * A generic structure. | |
329 | * This can be used by bypass routines to identify generic arguments. | |
330 | */ | |
331 | struct vop_generic_args { | |
332 | struct vnodeop_desc *a_desc; | |
333 | /* other random data follows, presumably */ | |
334 | }; | |
335 | ||
336 | /* | |
ad1e7e0e KB |
337 | * VOCALL calls an op given an ops vector. We break it out because BSD's |
338 | * vclean changes the ops vector and then wants to call ops with the old | |
339 | * vector. | |
4a7f0e14 JH |
340 | */ |
341 | #define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP)) | |
ad1e7e0e | 342 | |
4a7f0e14 JH |
343 | /* |
344 | * This call works for vnodes in the kernel. | |
345 | */ | |
346 | #define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP)) | |
ad1e7e0e | 347 | #define VDESC(OP) (& __CONCAT(OP,_desc)) |
4a7f0e14 JH |
348 | #define VOFFSET(OP) (VDESC(OP)->vdesc_offset) |
349 | ||
350 | /* | |
351 | * Finally, include the default set of vnode operations. | |
352 | */ | |
b36df905 | 353 | #include <vnode_if.h> |
4a7f0e14 JH |
354 | |
355 | /* | |
ad1e7e0e | 356 | * Public vnode manipulation functions. |
4a7f0e14 | 357 | */ |
ad1e7e0e KB |
358 | struct file; |
359 | struct mount; | |
360 | struct nameidata; | |
361 | struct proc; | |
925b3205 | 362 | struct stat; |
ad1e7e0e KB |
363 | struct ucred; |
364 | struct uio; | |
365 | struct vattr; | |
366 | struct vnode; | |
367 | struct vop_bwrite_args; | |
368 | ||
369 | int bdevvp __P((dev_t dev, struct vnode **vpp)); | |
370 | int getnewvnode __P((enum vtagtype tag, | |
371 | struct mount *mp, int (**vops)(), struct vnode **vpp)); | |
688bb869 | 372 | int vinvalbuf __P((struct vnode *vp, int save, struct ucred *cred, |
25bdc8b5 | 373 | struct proc *p, int slpflag, int slptimeo)); |
ad1e7e0e KB |
374 | void vattr_null __P((struct vattr *vap)); |
375 | int vcount __P((struct vnode *vp)); | |
82975a86 | 376 | int vget __P((struct vnode *vp, int lockflag)); |
ad1e7e0e KB |
377 | void vgone __P((struct vnode *vp)); |
378 | void vgoneall __P((struct vnode *vp)); | |
379 | int vn_bwrite __P((struct vop_bwrite_args *ap)); | |
380 | int vn_close __P((struct vnode *vp, | |
381 | int flags, struct ucred *cred, struct proc *p)); | |
382 | int vn_closefile __P((struct file *fp, struct proc *p)); | |
383 | int vn_ioctl __P((struct file *fp, int com, caddr_t data, struct proc *p)); | |
4a7f0e14 | 384 | int vn_open __P((struct nameidata *ndp, int fmode, int cmode)); |
4a7f0e14 JH |
385 | int vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base, |
386 | int len, off_t offset, enum uio_seg segflg, int ioflg, | |
387 | struct ucred *cred, int *aresid, struct proc *p)); | |
388 | int vn_read __P((struct file *fp, struct uio *uio, struct ucred *cred)); | |
4a7f0e14 | 389 | int vn_select __P((struct file *fp, int which, struct proc *p)); |
b36df905 | 390 | int vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p)); |
ad1e7e0e KB |
391 | int vn_write __P((struct file *fp, struct uio *uio, struct ucred *cred)); |
392 | struct vnode * | |
393 | checkalias __P((struct vnode *vp, dev_t nvp_rdev, struct mount *mp)); | |
394 | void vput __P((struct vnode *vp)); | |
395 | void vref __P((struct vnode *vp)); | |
396 | void vrele __P((struct vnode *vp)); | |
11127818 | 397 | #endif /* KERNEL */ |