2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/mount.h>
38 #include <sys/vnode.h>
40 #include <vfs/devfs/devfs.h>
42 MALLOC_DECLARE(M_DEVFS);
44 extern struct vop_ops devfs_vnode_norm_vops;
45 extern struct vop_ops devfs_vnode_dev_vops;
46 extern struct lock devfs_lock;
48 static int devfs_mount (struct mount *mp, char *path, caddr_t data,
50 static int devfs_statfs (struct mount *mp, struct statfs *sbp,
52 static int devfs_unmount (struct mount *mp, int mntflags);
53 int devfs_root(struct mount *mp, struct vnode **vpp);
62 devfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
64 struct devfs_mnt_data *mnt;
67 devfs_debug(DEVFS_DEBUG_DEBUG, "(vfsops) devfs_mount() called!\n");
69 if (mp->mnt_flag & MNT_UPDATE)
73 mp->mnt_flag |= MNT_LOCAL;
74 mp->mnt_kern_flag |= MNTK_NOSTKMNT;
78 size = sizeof("devfs") - 1;
79 bcopy("devfs", mp->mnt_stat.f_mntfromname, size);
80 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
81 devfs_statfs(mp, &mp->mnt_stat, cred);
83 //XXX: save other mount info passed from userland or so.
84 mnt = kmalloc(sizeof(*mnt), M_DEVFS, M_WAITOK | M_ZERO);
86 lockmgr(&devfs_lock, LK_EXCLUSIVE);
87 mp->mnt_data = (qaddr_t)mnt;
88 mnt->jailed = jailed(cred);
91 TAILQ_INIT(&mnt->orphan_list);
92 mnt->mntonnamelen = strlen(mp->mnt_stat.f_mntonname);
93 mnt->root_node = devfs_allocp(Proot, "", NULL, mp, NULL);
94 KKASSERT(mnt->root_node);
95 lockmgr(&devfs_lock, LK_RELEASE);
97 vfs_add_vnodeops(mp, &devfs_vnode_norm_vops, &mp->mnt_vn_norm_ops);
98 vfs_add_vnodeops(mp, &devfs_vnode_dev_vops, &mp->mnt_vn_spec_ops);
100 devfs_debug(DEVFS_DEBUG_DEBUG, "calling devfs_mount_add\n");
101 devfs_mount_add(mnt);
107 * unmount system call
110 devfs_unmount(struct mount *mp, int mntflags)
115 devfs_debug(DEVFS_DEBUG_DEBUG, "(vfsops) devfs_unmount() called!\n");
117 if (mntflags & MNT_FORCE)
120 error = vflush(mp, 0, flags);
124 devfs_mount_del(DEVFS_MNTDATA(mp));
125 kfree(mp->mnt_data, M_DEVFS);
132 * Sets *vpp to the root procfs vnode, referenced and exclusively locked
135 devfs_root(struct mount *mp, struct vnode **vpp)
138 devfs_debug(DEVFS_DEBUG_DEBUG, "(vfsops) devfs_root() called!\n");
139 lockmgr(&devfs_lock, LK_EXCLUSIVE);
140 ret = devfs_allocv(vpp, DEVFS_MNTDATA(mp)->root_node);
141 lockmgr(&devfs_lock, LK_RELEASE);
146 * Get file system statistics.
149 devfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
151 devfs_debug(DEVFS_DEBUG_DEBUG, "(vfsops) devfs_stat() called!\n");
152 sbp->f_bsize = DEV_BSIZE;
153 sbp->f_iosize = DEV_BSIZE;
154 sbp->f_blocks = 2; /* avoid divide by zero in some df's */
160 if (sbp != &mp->mnt_stat) {
161 sbp->f_type = mp->mnt_vfc->vfc_typenum;
162 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
163 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
169 static struct vfsops devfs_vfsops = {
170 .vfs_mount = devfs_mount,
171 .vfs_unmount = devfs_unmount,
172 .vfs_root = devfs_root,
173 .vfs_statfs = devfs_statfs,
174 .vfs_sync = vfs_stdsync
177 VFS_SET(devfs_vfsops, devfs, VFCF_SYNTHETIC);
178 MODULE_VERSION(devfs, 1);