Next: 8.4 struct vnodeops
Up: 8. Appendix: Vnode Interface
Previous: 8.2 struct vfsops
8.3 struct vnode
An instance of struct vnode (Figure 25) exists in a
running system for every opened (in-use) file, directory, symbolic-link,
hard-link, block or character device, a socket, a Unix pipe, etc.
Figure:
SunOS 5.x Vnode Interface
Figure:
SunOS 5.x Vnode Interface
typedef struct vnode {
kmutex_t v_lock; /* protects vnode fields */
u_short v_flag; /* vnode flags (see below) */
u_long v_count; /* reference count */
struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */
struct vnodeops *v_op; /* vnode operations */
struct vfs *v_vfsp; /* ptr to containing VFS */
struct stdata *v_stream; /* associated stream */
struct page *v_pages; /* vnode pages list */
enum vtype v_type; /* vnode type */
dev_t v_rdev; /* device (VCHR, VBLK) */
caddr_t v_data; /* private data for fs */
struct filock *v_filocks; /* ptr to filock list */
kcondvar_t v_cv; /* synchronize locking */
} vnode_t;
|
5.2in
typedef struct vnode {
kmutex_t v_lock; /* protects vnode fields */
u_short v_flag; /* vnode flags (see below) */
u_long v_count; /* reference count */
struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */
struct vnodeops *v_op; /* vnode operations */
struct vfs *v_vfsp; /* ptr to containing VFS */
struct stdata *v_stream; /* associated stream */
struct page *v_pages; /* vnode pages list */
enum vtype v_type; /* vnode type */
dev_t v_rdev; /* device (VCHR, VBLK) */
caddr_t v_data; /* private data for fs */
struct filock *v_filocks; /* ptr to filock list */
kcondvar_t v_cv; /* synchronize locking */
} vnode_t;
|
Structure fields relevant to our work are:
- v_lock is a mutual exclusion variable used by locking functions
that need to perform changes to values of certain fields in the vnode
structure.
- v_flag contains bit flags for characteristics such as whether
this vnode is the root of its file system, if it has a shared or exclusive
lock, whether pages should be cached, if it is a swap device, etc.
- v_count is incremented each time a new process opens the same
vnode.
- v_vfsmountedhere, if non-null, contains a pointer to the vfs
that is mounted on this vnode. This vnode thus is a directory that is a
mount point for a mounted file system.
- v_op is a pointer to a function-pointer table. That is,
this v_op can hold pointers to UFS functions, NFS, PCFS, HSFS, etc.
For example, if the vnode interface calls the function to open a file, it
will call whatever subfield of struct vnodeops (See Section
sec-appendix-vnode-vnodeops) is designated for the open function.
That is how the transition from the vnode level to a file system-specific
level is made.
- v_vfsp is a pointer to the vfs that this vnode belongs to. If
the value of the field v_vfsmountedhere is non-null, it is also said
that v_vfsp is the parent file system of the one mounted here.
- v_type is used to distinguish between a regular file, a
directory, a symbolic link, a block/character device, a socket, a Unix pipe
(fifo), etc.
- v_data is a pointer to opaque data specific to this vnode. For
an NFS vfs, this might be a pointer to struct rnode (located in <nfs/rnode.h>) -- a remote file system-specific structure containing such
information as the file-handle, owner, user credentials, file size (from the
client's view), and more.
Next: 8.4 struct vnodeops
Up: 8. Appendix: Vnode Interface
Previous: 8.2 struct vfsops
Erez Zadok
1999-12-07