2 * Copyright 2017 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _SYS_VFS_DISPATCH_H
18 #define _SYS_VFS_DISPATCH_H
21 #include <sys/stdbool.h>
25 * Ideally these static inlines could be just inline statements in the
26 * corresponding fsop_*() functions. Unfortunately, fem gets in the way and
27 * we have to make these to centralize the damage.
29 * See comment in sys/vnode_dispatch.h for more details and an example.
32 #define VFS_DISPATCH(fname, opname, vheadname, args, callargs) \
33 static inline int fname args \
35 if (check_fem && vfs->vfs_femhead != NULL) \
36 return vheadname callargs; \
37 if (vfs->vfs_op->opname == NULL) \
39 return vfs->vfs_op->opname callargs; \
42 VFS_DISPATCH(fsop_mount_dispatch
, vfs_mount
, fshead_mount
,
43 (struct vfs
*vfs
, struct vnode
*mvnode
, struct mounta
*uap
, cred_t
*cr
,
45 (vfs
, mvnode
, uap
, cr
))
46 VFS_DISPATCH(fsop_unmount_dispatch
, vfs_unmount
, fshead_unmount
,
47 (struct vfs
*vfs
, int flag
, cred_t
*cr
, bool check_fem
),
49 VFS_DISPATCH(fsop_root_dispatch
, vfs_root
, fshead_root
,
50 (struct vfs
*vfs
, struct vnode
**vnode
, bool check_fem
),
52 VFS_DISPATCH(fsop_statfs_dispatch
, vfs_statvfs
, fshead_statvfs
,
53 (struct vfs
*vfs
, statvfs64_t
*sp
, bool check_fem
),
56 /* no-op by default, so it is hand-coded */
57 static inline int fsop_sync_dispatch(struct vfs
*vfs
, short flag
, cred_t
*cr
,
60 if (check_fem
&& vfs
->vfs_femhead
!= NULL
)
61 return fshead_sync(vfs
, flag
, cr
);
63 if (vfs
->vfs_op
->vfs_sync
== NULL
)
66 return vfs
->vfs_op
->vfs_sync(vfs
, flag
, cr
);
69 VFS_DISPATCH(fsop_vget_dispatch
, vfs_vget
, fshead_vget
,
70 (struct vfs
*vfs
, struct vnode
**vnode
, fid_t
*fid
, bool check_fem
),
72 VFS_DISPATCH(fsop_mountroot_dispatch
, vfs_mountroot
, fshead_mountroot
,
73 (struct vfs
*vfs
, enum whymountroot reason
, bool check_fem
),
76 /* returns void, so it is hand-coded */
77 static inline void fsop_freefs_dispatch(struct vfs
*vfs
, bool check_fem
)
79 if (check_fem
&& vfs
->vfs_femhead
!= NULL
)
81 else if (vfs
->vfs_op
->vfs_freevfs
!= NULL
)
82 vfs
->vfs_op
->vfs_freevfs(vfs
);
85 VFS_DISPATCH(fsop_vnstate_dispatch
, vfs_vnstate
, fshead_vnstate
,
86 (struct vfs
*vfs
, struct vnode
*vnode
, vntrans_t nstate
, bool check_fem
),