Node: vfs interface integration, Previous: lower layer code, Up: Implementation



vfs interface integration

We will now plug your new filesystem into the vfs kernel interface. This will be simply to put the corresponding information in files seen at the beginning. The first step will be to add our new vnode type into sys/vnode.h. In the vtagtype enum we will add our tag type at the end.

     
     enum vtagtype	{
     	VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS, VT_LOFS, VT_FDESC,
     	VT_PORTAL, VT_NULL, VT_UMAP, VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS,
     	VT_UNION, VT_ADOSFS, VT_EXT2FS, VT_NCPFS, VT_VFS, VT_XFS, VT_MYFS
     };
     

Next sys/mount.h must be modified to be able to mount your filesystem. This is done by adding a proper define for the filesystem. This define is important because it's this name that will appear to users of the filesystem. After that you must make a new mount_myfs program based on mount to be able to mount in user land the filesystem. This program will simply be a wrapper around mount that specify the options supported by the filesystem and the type of it (in our case MOUNT_MYFS).
#define	MOUNT_XFS	"xfs"		/* xfs */
#define	MOUNT_MYFS	"myfs"		/* MYFS The future best
                                           filesystem in the world */

The next define must be done in sys/malloc.h. It will represent the type of node to malloc when the system or you want to malloc a myfs vnode. It's not necessary because you can for example, use your proper tags but it's the easiest way to do it. You must use a value not yet used by another filesystem. For example, 73 should be fine.
/*
 * Types of memory to be allocated
 */
#define	M_FREE		0	/* should be on free list */
...
#define	M_MYFSNODE	73	/* myfs vnode private part */

Now the last part of the integration, the vfs interface configuration. As seeing before the vfs configuration is done in kern/vfs_conf.c. The first thing to do is to include the myfs_extern.h where you have all the definitions. Take care that all the following codes must be inner #ifdef MYFS blocks, because you only want to compile this part of the kernel and not the entire myfs code. Otherwise if you include this code without defining MYFS in the kernel configuration, your kernel won't compile because of unresolved symbols.
...
#ifdef MYFS
# include <ufs/myfs/myfs_extern.h>
#endif
...

/*
 * Set up the filesystem operations for vnodes.
 * The types are defined in mount.h.
 */
#ifdef MYFS
 extern	struct vfsops myfs_vfsops;
#endif
...

/*
 * Set up the filesystem operations for vnodes.
 */
static struct vfsconf vfsconflist[] = {
...
        /* my filesystem */
#ifdef MYFS
	{ &myfs_vfsops, MOUNT_MYFS, 18, 0, MNT_LOCAL, myfs_mountroot, NULL },
#endif
...
};

/*
 * vfs_opv_descs enumerates the list of vnode classes, each with it's own
 * vnode operation vector.  It is consulted at system boot to build operation
 * vectors.  It is NULL terminated.
 */

extern struct vnodeopv_desc myfs_vnodeop_opv_desc;
...
struct vnodeopv_desc *vfs_opv_descs[] = {
	&sync_vnodeop_opv_desc,

#ifdef SRSFS
	&srsfs_vnodeop_opv_desc,
#endif

	NULL
};
This is simple. All you need to do is to insert your structures into the needed vectors. Beware to not forget a part or the system will crash at the first access of your filesystem. All this part is explained in the comments, this will normally not cause any problems.