xref: /freebsd/share/man/man9/vnode.9 (revision 2e14815b84df9657a3c6d3c1b0b290317c53591a)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 1996 Doug Rabson
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" $Id: vnode.9,v 1.2 1997/03/22 22:47:31 mpp Exp $
30.\"
31.Dd July 24, 1996
32.Os
33.Dt VNODE 9
34.Sh NAME
35.Nm vnode
36.Nd internal representation of a file or directory
37.Sh SYNOPSIS
38.Fd #include <sys/param.h>
39.Fd #include <sys/vnode.h>
40.Pp
41.Bd -literal
42/*
43 * Vnode types.  VNON means no type.
44 */
45enum vtype	{ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
46
47/*
48 * Vnode tag types.
49 * These are for the benefit of external programs only (e.g., pstat)
50 * and should NEVER be inspected by the kernel.
51 */
52enum vtagtype	{
53	VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_PC, VT_LFS, VT_LOFS, VT_FDESC,
54	VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
55	VT_UNION, VT_MSDOSFS, VT_DEVFS
56};
57
58/*
59 * Each underlying filesystem allocates its own private area and hangs
60 * it from v_data.  If non-null, this area is freed in getnewvnode().
61 */
62LIST_HEAD(buflists, buf);
63
64typedef	int 	vop_t __P((void *));
65
66struct vnode {
67	u_long	v_flag;			/* vnode flags (see below) */
68	int	v_usecount;		/* reference count of users */
69	int	v_writecount;		/* reference count of writers */
70	int	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	vop_t	**v_op;			/* vnode operations vector */
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 */
79	long	v_numoutput;		/* num of writes in progress */
80	enum	vtype v_type;		/* vnode type */
81	union {
82		struct mount	*vu_mountedhere;/* ptr to mounted vfs (VDIR) */
83		struct socket	*vu_socket;	/* unix ipc (VSOCK) */
84		struct specinfo	*vu_specinfo;	/* device (VCHR, VBLK) */
85		struct fifoinfo	*vu_fifoinfo;	/* fifo (VFIFO) */
86	} v_un;
87	struct	nqlease *v_lease;	/* Soft reference to lease */
88	daddr_t	v_lastw;		/* last write (write cluster) */
89	daddr_t	v_cstart;		/* start block of cluster */
90	daddr_t	v_lasta;		/* last allocation */
91	int	v_clen;			/* length of current cluster */
92	int	v_ralen;		/* Read-ahead length */
93	int	v_usage;		/* Vnode usage counter */
94	daddr_t	v_maxra;		/* last readahead block */
95	void	*v_object;		/* Place to store VM object */
96	enum	vtagtype v_tag;		/* type of underlying data */
97	void 	*v_data;		/* private data for fs */
98};
99#define	v_mountedhere	v_un.vu_mountedhere
100#define	v_socket	v_un.vu_socket
101#define	v_specinfo	v_un.vu_specinfo
102#define	v_fifoinfo	v_un.vu_fifoinfo
103
104/*
105 * Vnode flags.
106 */
107#define	VROOT	0x0001	/* root of its file system */
108#define	VTEXT	0x0002	/* vnode is a pure text prototype */
109#define	VSYSTEM	0x0004	/* vnode being used by kernel */
110#define	VOLOCK	0x0008	/* vnode is locked waiting for an object */
111#define	VOWANT	0x0010	/* a process is waiting for VOLOCK */
112#define	VXLOCK	0x0100	/* vnode is locked to change underlying type */
113#define	VXWANT	0x0200	/* process is waiting for vnode */
114#define	VBWAIT	0x0400	/* waiting for output to complete */
115#define	VALIASED 0x0800	/* vnode has an alias */
116#define	VDIROP	0x1000	/* LFS: vnode is involved in a directory op */
117#define	VVMIO	0x2000	/* VMIO flag */
118#define	VNINACT	0x4000	/* LFS: skip ufs_inactive() in lfs_vunref */
119#define	VAGE	0x8000	/* Insert vnode at head of free list */
120.Ed
121.Sh DESCRIPTION
122The vnode is the focus of all file activity in UNIX.  There is a
123unique vnode allocated for each active file, each current directory,
124each mounted-on file, text file, and the root.
125.Pp
126Each vnode has two reference counts,
127.Dv v_usecount
128and
129.Dv v_writecount .
130The first is the number of clients within the kernel which are
131using this vnode.  This count is maintained by
132.Xr vref 9 ,
133.Xr vrele 9 and
134.Xr vput 9 .
135When the
136.Dv v_usecount
137of a vnode reaches zero then the vnode may be reused for another
138file, possibly in another filesystem.
139The second is a count of the number of clients which are writing into
140the file.  It is maintained by the
141.Xr open 2
142and
143.Xr close 2
144system calls.
145.Pp
146Any call which returns a vnode (e.g.
147.Xr VFS_GET 9 ,
148.Xr VOP_LOOKUP 9
149etc.)
150will increase the
151.Dv v_usecount
152of the vnode by one.  When the caller is finished with the vnode, it
153should release this reference by calling
154.Xr vrele 9
155(or
156.Xr vput 9
157if the vnode is locked).
158.Pp
159Other commonly used members of the vnode structure are
160.Dv v_id
161which is used to maintain consistency in the name cache,
162.Dv v_mount
163which points at the filesystem which owns the vnode,
164.Dv v_type
165which contains the type of object the vnode represents and
166.Dv v_data
167which is used by filesystems to store filesystem specific data with
168the vnode.
169The
170.Dv v_op
171field is used by the
172.Dv VOP_*
173macros to call functions in the filesystem which implement the vnode's
174functionality.
175.Sh SEE ALSO
176.Xr VFS 9
177.Sh AUTHORS
178This man page was written by Doug Rabson.
179
180