1 /* $NetBSD: kernfs_vfsops.c,v 1.89 2009/03/15 17:22:38 cegger Exp $ */
4 * Copyright (c) 1992, 1993, 1995
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software donated to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)kernfs_vfsops.c 8.10 (Berkeley) 5/14/95
38 * Kernel params Filesystem
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.89 2009/03/15 17:22:38 cegger Exp $");
45 #include "opt_compat_netbsd.h"
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/sysctl.h>
53 #include <sys/vnode.h>
54 #include <sys/mount.h>
55 #include <sys/namei.h>
56 #include <sys/dirent.h>
57 #include <sys/malloc.h>
58 #include <sys/syslog.h>
59 #include <sys/kauth.h>
60 #include <sys/module.h>
62 #include <miscfs/genfs/genfs.h>
63 #include <miscfs/specfs/specdev.h>
64 #include <miscfs/kernfs/kernfs.h>
66 MODULE(MODULE_CLASS_VFS
, kernfs
, NULL
);
68 MALLOC_JUSTDEFINE(M_KERNFSMNT
, "kernfs mount", "kernfs mount structures");
70 dev_t rrootdev
= NODEV
;
74 void kernfs_get_rrootdev(void);
76 static struct sysctllog
*kernfs_sysctl_log
;
82 malloc_type_attach(M_KERNFSMNT
);
97 malloc_type_detach(M_KERNFSMNT
);
101 kernfs_get_rrootdev(void)
103 static int tried
= 0;
106 /* Already did it once. */
111 if (rootdev
== NODEV
)
113 rrootdev
= devsw_blk2chr(rootdev
);
114 if (rrootdev
!= NODEV
)
117 printf("kernfs_get_rrootdev: no raw root device\n");
121 * Mount the Kernel params filesystem
124 kernfs_mount(struct mount
*mp
, const char *path
, void *data
, size_t *data_len
)
126 struct lwp
*l
= curlwp
;
128 struct kernfs_mount
*fmp
;
130 if (UIO_MX
& (UIO_MX
- 1)) {
131 log(LOG_ERR
, "kernfs: invalid directory entry size");
135 if (mp
->mnt_flag
& MNT_GETARGS
) {
142 if (mp
->mnt_flag
& MNT_UPDATE
)
145 fmp
= malloc(sizeof(struct kernfs_mount
), M_KERNFSMNT
, M_WAITOK
|M_ZERO
);
146 TAILQ_INIT(&fmp
->nodelist
);
148 mp
->mnt_stat
.f_namemax
= MAXNAMLEN
;
149 mp
->mnt_flag
|= MNT_LOCAL
;
153 if ((error
= set_statvfs_info(path
, UIO_USERSPACE
, "kernfs",
154 UIO_SYSSPACE
, mp
->mnt_op
->vfs_name
, mp
, l
)) != 0) {
155 free(fmp
, M_KERNFSMNT
);
159 kernfs_get_rrootdev();
164 kernfs_start(struct mount
*mp
, int flags
)
171 kernfs_unmount(struct mount
*mp
, int mntflags
)
176 if (mntflags
& MNT_FORCE
)
179 if ((error
= vflush(mp
, 0, flags
)) != 0)
183 * Finally, throw away the kernfs_mount structure
185 free(mp
->mnt_data
, M_KERNFSMNT
);
191 kernfs_root(struct mount
*mp
, struct vnode
**vpp
)
195 return (kernfs_allocvp(mp
, vpp
, KFSkern
, &kern_targets
[0], 0));
200 kernfs_sync(struct mount
*mp
, int waitfor
,
208 * Kernfs flat namespace lookup.
209 * Currently unsupported.
212 kernfs_vget(struct mount
*mp
, ino_t ino
,
219 extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc
;
221 const struct vnodeopv_desc
* const kernfs_vnodeopv_descs
[] = {
222 &kernfs_vnodeop_opv_desc
,
226 struct vfsops kernfs_vfsops
= {
233 (void *)eopnotsupp
, /* vfs_quotactl */
237 (void *)eopnotsupp
, /* vfs_fhtovp */
238 (void *)eopnotsupp
, /* vfs_vptofh */
242 NULL
, /* vfs_mountroot */
243 (int (*)(struct mount
*, struct vnode
*, struct timespec
*)) eopnotsupp
,
245 (void *)eopnotsupp
, /* vfs_suspendctl */
246 genfs_renamelock_enter
,
247 genfs_renamelock_exit
,
249 kernfs_vnodeopv_descs
,
255 kernfs_modcmd(modcmd_t cmd
, void *arg
)
260 case MODULE_CMD_INIT
:
261 error
= vfs_attach(&kernfs_vfsops
);
264 sysctl_createv(&kernfs_sysctl_log
, 0, NULL
, NULL
,
266 CTLTYPE_NODE
, "vfs", NULL
,
269 sysctl_createv(&kernfs_sysctl_log
, 0, NULL
, NULL
,
271 CTLTYPE_NODE
, "kernfs",
272 SYSCTL_DESCR("/kern file system"),
274 CTL_VFS
, 11, CTL_EOL
);
276 * XXX the "11" above could be dynamic, thereby eliminating one
277 * more instance of the "number to vfs" mapping problem, but
278 * "11" is the order as taken from sys/mount.h
281 case MODULE_CMD_FINI
:
282 error
= vfs_detach(&kernfs_vfsops
);
285 sysctl_teardown(&kernfs_sysctl_log
);