1 /* $NetBSD: v7fs_extern.c,v 1.9 2021/07/18 23:56:13 dholland Exp $ */
2
3 /*-
4 * Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: v7fs_extern.c,v 1.9 2021/07/18 23:56:13 dholland Exp $");
34
35 #if defined _KERNEL_OPT
36 #include "opt_v7fs.h"
37 #endif
38 #include <sys/resource.h>
39 #include <sys/param.h>
40 #include <sys/vnode.h>
41 #include <sys/mount.h>
42 #include <sys/module.h>
43
44 #include <miscfs/fifofs/fifo.h>
45 #include <miscfs/genfs/genfs.h>
46 #include <miscfs/genfs/genfs_node.h>
47
48 #include <fs/v7fs/v7fs_extern.h>
49
50 MODULE(MODULE_CLASS_VFS, v7fs, NULL);
51
52 /* External interfaces */
53
54 int (**v7fs_vnodeop_p)(void *); /* filled by getnewvnode (vnode.h) */
55
56 const struct vnodeopv_entry_desc v7fs_vnodeop_entries[] = {
57 { &vop_default_desc, vn_default_error },
58 { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */
59 { &vop_lookup_desc, v7fs_lookup }, /* lookup */
60 { &vop_create_desc, v7fs_create }, /* create */
61 { &vop_mknod_desc, v7fs_mknod }, /* mknod */
62 { &vop_open_desc, v7fs_open }, /* open */
63 { &vop_close_desc, v7fs_close }, /* close */
64 { &vop_access_desc, v7fs_access }, /* access */
65 { &vop_accessx_desc, genfs_accessx }, /* accessx */
66 { &vop_getattr_desc, v7fs_getattr }, /* getattr */
67 { &vop_setattr_desc, v7fs_setattr }, /* setattr */
68 { &vop_read_desc, v7fs_read }, /* read */
69 { &vop_write_desc, v7fs_write }, /* write */
70 { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
71 { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
72 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
73 { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */
74 { &vop_poll_desc, genfs_poll }, /* poll */
75 { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
76 { &vop_revoke_desc, genfs_revoke }, /* revoke */
77 { &vop_mmap_desc, genfs_mmap }, /* mmap */
78 { &vop_fsync_desc, v7fs_fsync }, /* fsync */
79 { &vop_seek_desc, genfs_seek }, /* seek */
80 { &vop_remove_desc, v7fs_remove }, /* remove */
81 { &vop_link_desc, v7fs_link }, /* link */
82 { &vop_rename_desc, v7fs_rename }, /* rename */
83 { &vop_mkdir_desc, v7fs_mkdir }, /* mkdir */
84 { &vop_rmdir_desc, v7fs_rmdir }, /* rmdir */
85 { &vop_symlink_desc, v7fs_symlink }, /* symlink */
86 { &vop_readdir_desc, v7fs_readdir }, /* readdir */
87 { &vop_readlink_desc, v7fs_readlink }, /* readlink */
88 { &vop_abortop_desc, genfs_abortop }, /* abortop */
89 { &vop_inactive_desc, v7fs_inactive }, /* inactive */
90 { &vop_reclaim_desc, v7fs_reclaim }, /* reclaim */
91 { &vop_lock_desc, genfs_lock }, /* lock */
92 { &vop_unlock_desc, genfs_unlock }, /* unlock */
93 { &vop_bmap_desc, v7fs_bmap }, /* bmap */
94 { &vop_strategy_desc, v7fs_strategy }, /* strategy */
95 { &vop_print_desc, v7fs_print }, /* print */
96 { &vop_islocked_desc, genfs_islocked }, /* islocked */
97 { &vop_pathconf_desc, v7fs_pathconf }, /* pathconf */
98 { &vop_advlock_desc, v7fs_advlock }, /* advlock */
99 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
100 { &vop_getpages_desc, genfs_getpages }, /* getpages */
101 { &vop_putpages_desc, genfs_putpages }, /* putpages */
102 { NULL, NULL }
103 };
104
105
106 int (**v7fs_specop_p)(void *);
107 const struct vnodeopv_entry_desc v7fs_specop_entries[] = {
108 { &vop_default_desc, vn_default_error },
109 GENFS_SPECOP_ENTRIES,
110 { &vop_close_desc, spec_close }, /* close */
111 { &vop_access_desc, v7fs_access }, /* access */
112 { &vop_accessx_desc, genfs_accessx }, /* accessx */
113 { &vop_getattr_desc, v7fs_getattr }, /* getattr */
114 { &vop_setattr_desc, v7fs_setattr }, /* setattr */
115 { &vop_read_desc, spec_read }, /* read */
116 { &vop_write_desc, spec_write }, /* write */
117 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
118 { &vop_fsync_desc, spec_fsync }, /* fsync */
119 { &vop_inactive_desc, v7fs_inactive }, /* inactive */
120 { &vop_reclaim_desc, v7fs_reclaim }, /* reclaim */
121 { &vop_lock_desc, genfs_lock }, /* lock */
122 { &vop_unlock_desc, genfs_unlock }, /* unlock */
123 { &vop_print_desc, spec_print }, /* print */
124 { &vop_islocked_desc, genfs_islocked }, /* islocked */
125 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
126 { NULL, NULL }
127 };
128
129 int (**v7fs_fifoop_p)(void *);
130 const struct vnodeopv_entry_desc v7fs_fifoop_entries[] = {
131 { &vop_default_desc, vn_default_error },
132 GENFS_FIFOOP_ENTRIES,
133 { &vop_close_desc, vn_fifo_bypass }, /* close */
134 { &vop_access_desc, v7fs_access }, /* access */
135 { &vop_accessx_desc, genfs_accessx }, /* accessx */
136 { &vop_getattr_desc, v7fs_getattr }, /* getattr */
137 { &vop_setattr_desc, v7fs_setattr }, /* setattr */
138 { &vop_read_desc, vn_fifo_bypass }, /* read */
139 { &vop_write_desc, vn_fifo_bypass }, /* write */
140 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
141 { &vop_fsync_desc, vn_fifo_bypass }, /* fsync */
142 { &vop_inactive_desc, v7fs_inactive }, /* inactive */
143 { &vop_reclaim_desc, v7fs_reclaim }, /* reclaim */
144 { &vop_lock_desc, vn_fifo_bypass }, /* lock */
145 { &vop_unlock_desc, vn_fifo_bypass }, /* unlock */
146 { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */
147 { &vop_print_desc, vn_fifo_bypass }, /* print */
148 { &vop_islocked_desc, vn_fifo_bypass }, /* islocked */
149 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
150 { NULL, NULL }
151 };
152
153 const struct vnodeopv_desc v7fs_fifoop_opv_desc = {
154 &v7fs_fifoop_p,
155 v7fs_fifoop_entries
156 };
157
158 const struct vnodeopv_desc v7fs_vnodeop_opv_desc = {
159 &v7fs_vnodeop_p,
160 v7fs_vnodeop_entries
161 };
162
163 const struct vnodeopv_desc v7fs_specop_opv_desc = {
164 &v7fs_specop_p,
165 v7fs_specop_entries
166 };
167
168 const struct vnodeopv_desc *v7fs_vnodeopv_descs[] = {
169 &v7fs_vnodeop_opv_desc,
170 &v7fs_specop_opv_desc,
171 &v7fs_fifoop_opv_desc,
172 NULL,
173 };
174
175 const struct genfs_ops v7fs_genfsops = {
176 .gop_size = genfs_size,
177 .gop_alloc = v7fs_gop_alloc,
178 .gop_write = genfs_gop_write,
179 .gop_putrange = genfs_gop_putrange,
180 };
181
182 struct vfsops v7fs_vfsops = {
183 .vfs_name = MOUNT_V7FS,
184 .vfs_min_mount_data = sizeof(struct v7fs_args),
185 .vfs_mount = v7fs_mount,
186 .vfs_start = v7fs_start,
187 .vfs_unmount = v7fs_unmount,
188 .vfs_root = v7fs_root,
189 .vfs_quotactl = (void *)eopnotsupp,
190 .vfs_statvfs = v7fs_statvfs,
191 .vfs_sync = v7fs_sync,
192 .vfs_vget = v7fs_vget,
193 .vfs_loadvnode = v7fs_loadvnode,
194 .vfs_fhtovp = v7fs_fhtovp,
195 .vfs_vptofh = v7fs_vptofh,
196 .vfs_init = v7fs_init,
197 .vfs_reinit = v7fs_reinit,
198 .vfs_done = v7fs_done,
199 .vfs_mountroot = v7fs_mountroot,
200 .vfs_snapshot = (void *)eopnotsupp,
201 .vfs_extattrctl = vfs_stdextattrctl,
202 .vfs_suspendctl = genfs_suspendctl,
203 .vfs_renamelock_enter = genfs_renamelock_enter,
204 .vfs_renamelock_exit = genfs_renamelock_exit,
205 .vfs_fsync = (void *)eopnotsupp,
206 .vfs_opv_descs = v7fs_vnodeopv_descs
207 };
208
209 static int
v7fs_modcmd(modcmd_t cmd,void * arg)210 v7fs_modcmd(modcmd_t cmd, void *arg)
211 {
212
213 switch (cmd) {
214 case MODULE_CMD_INIT:
215 return vfs_attach(&v7fs_vfsops);
216 case MODULE_CMD_FINI:
217 return vfs_detach(&v7fs_vfsops);
218 default:
219 return ENOTTY;
220 }
221 }
222