Download A File System Component Compiler

Transcript
47
A
Appendix: Vnode Interface Tutorial
This section provides a simple introduction to the vnode interface. The information herein is gathered from pivotal papers on the subject [Kleiman86, Rosenthal90] and from system C header files —
specifically <sys/vfs.h> and <sys/vnode.h>.
The two important data structures used in the vnode interface are struct vfs and struct vnode,
depicted in Figures 21 and 25, respectively.
A.1
struct vfs
An instance of the vfs structure exists in a running kernel for each mounted file system. All of these
instances are chained together in a singly-linked list. The head of the list is a global variable called
root vp, which contains the vfs for the root device. The field vfs next links one vfs structure to the
following one in the list.
typedef struct vfs {
struct vfs
*vfs_next;
struct vfsops
*vfs_op;
struct vnode
*vfs_vnodecovered;
u_long
vfs_flag;
u_long
vfs_bsize;
int
vfs_fstype;
fsid_t
vfs_fsid;
caddr_t
vfs_data;
dev_t
vfs_dev;
u_long
vfs_bcount;
u_short
vfs_nsubmounts;
struct vfs
*vfs_list;
struct vfs
*vfs_hash;
kmutex_t
vfs_reflock;
} vfs_t;
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
next VFS in VFS list */
operations on VFS */
vnode mounted on */
flags */
native block size */
file system type index */
file system id */
private data */
device of mounted VFS */
I/O count (accounting) */
immediate sub-mount count */
sync list pointer */
hash list pointer */
mount/unmount/sync lock */
Figure 21: SunOS 5.x VFS Interface
The fields relevant to this proposal are as follows:
• vfs next is a pointer to the next vfs in the linked list.
• vfs op is a pointer to a function-pointer table. That is, this vfs op can hold pointers to UFS
functions, NFS, PCFS, HSFS, etc. For example, if the vnode interface calls the function to mount
the file system, it will call whatever subfield of struct vfsops (See Section A.2) is designated
for the mount function. That is how the transition from the vnode level to a file system-specific
level is made.
• vfs vnodecovered is the vnode on which this file system is mounted (the mount point).