1997-03-03 18:01:01 +00:00
|
|
|
.\" Copyright (c) 1996 Doug Rabson
|
|
|
|
.\"
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This program is free software.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1997-03-03 18:01:01 +00:00
|
|
|
.\"
|
2003-05-24 18:19:11 +00:00
|
|
|
.Dd May 20, 2003
|
1997-03-03 18:01:01 +00:00
|
|
|
.Os
|
1997-03-22 22:47:34 +00:00
|
|
|
.Dt VNODE 9
|
1997-03-03 18:01:01 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm vnode
|
|
|
|
.Nd internal representation of a file or directory
|
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In sys/param.h
|
|
|
|
.In sys/vnode.h
|
1997-03-03 18:01:01 +00:00
|
|
|
.Sh DESCRIPTION
|
2002-03-18 10:43:49 +00:00
|
|
|
The vnode is the focus of all file activity in
|
|
|
|
.Ux .
|
2003-05-24 18:19:11 +00:00
|
|
|
A vnode is described by
|
|
|
|
.Vt "struct vnode" .
|
2002-03-18 10:43:49 +00:00
|
|
|
There is a
|
1997-03-03 18:01:01 +00:00
|
|
|
unique vnode allocated for each active file, each current directory,
|
|
|
|
each mounted-on file, text file, and the root.
|
|
|
|
.Pp
|
1997-10-11 07:39:45 +00:00
|
|
|
Each vnode has three reference counts,
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_usecount ,
|
|
|
|
.Va v_holdcnt
|
1997-03-03 18:01:01 +00:00
|
|
|
and
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_writecount .
|
1997-03-03 18:01:01 +00:00
|
|
|
The first is the number of clients within the kernel which are
|
2003-10-23 02:22:07 +00:00
|
|
|
using this vnode.
|
|
|
|
This count is maintained by
|
1997-03-03 18:01:01 +00:00
|
|
|
.Xr vref 9 ,
|
2001-07-14 19:41:16 +00:00
|
|
|
.Xr vrele 9
|
1997-10-11 07:39:45 +00:00
|
|
|
and
|
1997-03-03 18:01:01 +00:00
|
|
|
.Xr vput 9 .
|
1998-02-28 15:37:25 +00:00
|
|
|
The second is the number of clients within the kernel who veto
|
2003-10-23 02:22:07 +00:00
|
|
|
the recycling of this vnode.
|
|
|
|
This count is
|
1997-10-11 07:39:45 +00:00
|
|
|
maintained by
|
2001-07-14 19:41:16 +00:00
|
|
|
.Xr vhold 9
|
1997-10-11 07:39:45 +00:00
|
|
|
and
|
|
|
|
.Xr vdrop 9 .
|
|
|
|
When both the
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_usecount
|
1997-10-11 07:39:45 +00:00
|
|
|
and the
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_holdcnt
|
1997-10-11 07:39:45 +00:00
|
|
|
of a vnode reaches zero then the vnode will be put on the freelist
|
2002-12-12 17:26:04 +00:00
|
|
|
and may be reused for another file, possibly in another file system.
|
1998-02-28 15:37:25 +00:00
|
|
|
The transition to and from the freelist is handled by
|
1998-09-28 23:36:35 +00:00
|
|
|
.Xr getnewvnode 9 ,
|
2001-07-14 19:41:16 +00:00
|
|
|
.Xr vfree 9
|
1997-10-11 07:39:45 +00:00
|
|
|
and
|
|
|
|
.Xr vbusy 9 .
|
|
|
|
The third is a count of the number of clients which are writing into
|
2003-10-23 02:22:07 +00:00
|
|
|
the file.
|
|
|
|
It is maintained by the
|
1997-03-03 18:01:01 +00:00
|
|
|
.Xr open 2
|
|
|
|
and
|
|
|
|
.Xr close 2
|
|
|
|
system calls.
|
|
|
|
.Pp
|
2001-08-10 13:45:36 +00:00
|
|
|
Any call which returns a vnode (e.g.\&
|
2003-05-31 14:20:30 +00:00
|
|
|
.Xr vget 9 ,
|
1997-03-03 18:01:01 +00:00
|
|
|
.Xr VOP_LOOKUP 9
|
|
|
|
etc.)
|
|
|
|
will increase the
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_usecount
|
2003-10-23 02:22:07 +00:00
|
|
|
of the vnode by one.
|
|
|
|
When the caller is finished with the vnode, it
|
1997-03-03 18:01:01 +00:00
|
|
|
should release this reference by calling
|
|
|
|
.Xr vrele 9
|
|
|
|
(or
|
|
|
|
.Xr vput 9
|
|
|
|
if the vnode is locked).
|
|
|
|
.Pp
|
|
|
|
Other commonly used members of the vnode structure are
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_id
|
1997-03-03 18:01:01 +00:00
|
|
|
which is used to maintain consistency in the name cache,
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_mount
|
2002-12-12 17:26:04 +00:00
|
|
|
which points at the file system which owns the vnode,
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_type
|
1997-03-03 18:01:01 +00:00
|
|
|
which contains the type of object the vnode represents and
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_data
|
2002-12-12 17:26:04 +00:00
|
|
|
which is used by file systems to store file system specific data with
|
1997-03-03 18:01:01 +00:00
|
|
|
the vnode.
|
|
|
|
The
|
2003-05-24 18:19:11 +00:00
|
|
|
.Va v_op
|
1997-03-03 18:01:01 +00:00
|
|
|
field is used by the
|
|
|
|
.Dv VOP_*
|
2002-12-12 17:26:04 +00:00
|
|
|
macros to call functions in the file system which implement the vnode's
|
1997-03-03 18:01:01 +00:00
|
|
|
functionality.
|
1998-09-28 23:36:35 +00:00
|
|
|
.Sh VNODE TYPES
|
|
|
|
.Bl -tag -width VSOCK
|
|
|
|
.It Dv VNON
|
|
|
|
No type.
|
|
|
|
.It Dv VREG
|
2003-10-23 02:22:07 +00:00
|
|
|
A regular file; may be with or without VM object backing.
|
|
|
|
If you want to make sure this get a backing object, call
|
1998-09-28 23:36:35 +00:00
|
|
|
.Xr vfs_object_create 9 .
|
|
|
|
.It Dv VDIR
|
|
|
|
A directory.
|
|
|
|
.It Dv VBLK
|
2003-10-23 02:22:07 +00:00
|
|
|
A block device; may be with or without VM object backing.
|
|
|
|
If you want to make sure this get a backing object, call
|
1998-09-28 23:36:35 +00:00
|
|
|
.Xr vfs_object_create 9 .
|
|
|
|
.It Dv VCHR
|
|
|
|
A character device.
|
|
|
|
.It Dv VLNK
|
|
|
|
A symbolic link.
|
|
|
|
.It Dv VSOCK
|
2003-10-23 02:22:07 +00:00
|
|
|
A socket.
|
2005-02-13 22:25:33 +00:00
|
|
|
Advisory locking will not work on this.
|
1998-09-28 23:36:35 +00:00
|
|
|
.It Dv VFIFO
|
2003-10-23 02:22:07 +00:00
|
|
|
A FIFO (named pipe).
|
2005-02-13 22:25:33 +00:00
|
|
|
Advisory locking will not work on this.
|
1998-09-28 23:36:35 +00:00
|
|
|
.It Dv VBAD
|
|
|
|
An old style bad sector map
|
|
|
|
.El
|
2003-01-18 19:51:52 +00:00
|
|
|
.Sh IMPLEMENTATION NOTES
|
2001-07-14 19:41:16 +00:00
|
|
|
VFIFO uses the "struct fileops" from
|
1998-09-28 23:36:35 +00:00
|
|
|
.Pa /sys/kern/sys_pipe.c .
|
|
|
|
VSOCK uses the "struct fileops" from
|
|
|
|
.Pa /sys/kern/sys_socket.c .
|
|
|
|
Everything else uses the one from
|
|
|
|
.Pa /sys/kern/vfs_vnops.c .
|
2000-12-29 09:18:45 +00:00
|
|
|
.Pp
|
1998-09-28 23:36:35 +00:00
|
|
|
The VFIFO/VSOCK code, which is why "struct fileops" is used at all, is
|
|
|
|
an artifact of an incomplete integration of the VFS code into the
|
|
|
|
kernel.
|
2003-01-18 19:51:52 +00:00
|
|
|
.Pp
|
|
|
|
Calls to
|
|
|
|
.Xr malloc 9
|
|
|
|
or
|
|
|
|
.Xr free 9
|
|
|
|
when holding a
|
|
|
|
.Nm
|
|
|
|
interlock, will cause a LOR (Lock Order Reversal) due to the
|
2003-03-06 23:55:51 +00:00
|
|
|
intertwining of VM Objects and Vnodes.
|
1997-03-03 18:01:01 +00:00
|
|
|
.Sh SEE ALSO
|
2003-01-19 15:44:32 +00:00
|
|
|
.Xr malloc 9 ,
|
1997-03-03 18:01:01 +00:00
|
|
|
.Xr VFS 9
|
|
|
|
.Sh AUTHORS
|
2005-06-28 20:15:19 +00:00
|
|
|
This manual page was written by
|
1998-03-12 07:31:21 +00:00
|
|
|
.An Doug Rabson .
|