next up previous contents
Next: 8.3 struct vnode Up: 8. Appendix: Vnode Interface Previous: 8.1 struct vfs

   
8.2 struct vfsops

The vfs operations structure (struct vfsops, seen in Figure fig-vfsops-h) is constant for each type of file system. For every instance of a file system, the vfs field vfs_op is set to the pointer of the operations vector of the underlying file system.


  
Figure: SunOS 5.x VFS Operations Interface

Figure: SunOS 5.x VFS Operations Interface


typedef struct vfsops {
  int     (*vfs_mount)();
  int     (*vfs_unmount)();
  int     (*vfs_root)();
  int     (*vfs_statvfs)();
  int     (*vfs_sync)();
  int     (*vfs_vget)();
  int     (*vfs_mountroot)();
  int     (*vfs_swapvp)();
} vfsops_t;





2.1in


typedef struct vfsops {
  int     (*vfs_mount)();
  int     (*vfs_unmount)();
  int     (*vfs_root)();
  int     (*vfs_statvfs)();
  int     (*vfs_sync)();
  int     (*vfs_vget)();
  int     (*vfs_mountroot)();
  int     (*vfs_swapvp)();
} vfsops_t;

Each field of the structure is assigned a pointer to a function that implements a particular operation for the file system in question:

The VFS operations get invoked transparently via macros that dereference the operations vector's field for that operation, and pass along the vfs and the arguments it needs. Each VFS operation has a macro associated with it, located in <sys/vfs.h>. Figure fig-vfs-mac shows the definitions for these macros.


  
Figure: VFS Macros

Figure: VFS Macros


#define VFS_MOUNT(vfsp, mvp, uap, cr) (*(vfsp)->vfs_op->vfs_mount)(vfsp, mvp, uap, cr)
#define VFS_UNMOUNT(vfsp, cr)         (*(vfsp)->vfs_op->vfs_unmount)(vfsp, cr)
#define VFS_ROOT(vfsp, vpp)           (*(vfsp)->vfs_op->vfs_root)(vfsp, vpp)
#define VFS_STATVFS(vfsp, sp)         (*(vfsp)->vfs_op->vfs_statvfs)(vfsp, sp)
#define VFS_SYNC(vfsp, flag, cr)      (*(vfsp)->vfs_op->vfs_sync)(vfsp, flag, cr)
#define VFS_VGET(vfsp, vpp, fidp)     (*(vfsp)->vfs_op->vfs_vget)(vfsp, vpp, fidp)
#define VFS_MOUNTROOT(vfsp, init)     (*(vfsp)->vfs_op->vfs_mountroot)(vfsp, init)
#define VFS_SWAPVP(vfsp, vpp, nm)     (*(vfsp)->vfs_op->vfs_swapvp)(vfsp, vpp, nm)





6.4in


#define VFS_MOUNT(vfsp, mvp, uap, cr) (*(vfsp)->vfs_op->vfs_mount)(vfsp, mvp, uap, cr)
#define VFS_UNMOUNT(vfsp, cr)         (*(vfsp)->vfs_op->vfs_unmount)(vfsp, cr)
#define VFS_ROOT(vfsp, vpp)           (*(vfsp)->vfs_op->vfs_root)(vfsp, vpp)
#define VFS_STATVFS(vfsp, sp)         (*(vfsp)->vfs_op->vfs_statvfs)(vfsp, sp)
#define VFS_SYNC(vfsp, flag, cr)      (*(vfsp)->vfs_op->vfs_sync)(vfsp, flag, cr)
#define VFS_VGET(vfsp, vpp, fidp)     (*(vfsp)->vfs_op->vfs_vget)(vfsp, vpp, fidp)
#define VFS_MOUNTROOT(vfsp, init)     (*(vfsp)->vfs_op->vfs_mountroot)(vfsp, init)
#define VFS_SWAPVP(vfsp, vpp, nm)     (*(vfsp)->vfs_op->vfs_swapvp)(vfsp, vpp, nm)

When any piece of file system code, that has a handle on a vfs, wants to call a vfs operation on that vfs, they simply dereference the macro, as depicted in Figure fig-vfs-mac-ex.


  
Figure: VFS Macros Usage Example

Figure: VFS Macros Usage Example


int foo(const vfs_t *vfsp, vnode_t **vpp)
{
  int error;

  error = VFS_ROOT(vfsp, vpp);
  if (error)
    return (error);
}





2.9in


int foo(const vfs_t *vfsp, vnode_t **vpp)
{
  int error;

  error = VFS_ROOT(vfsp, vpp);
  if (error)
    return (error);
}


next up previous contents
Next: 8.3 struct vnode Up: 8. Appendix: Vnode Interface Previous: 8.1 struct vfs
Erez Zadok
1999-12-07