Deleted Added
sdiff udiff text old ( 65051 ) new ( 65132 )
full compact
1/*
2 * Copyright (c) 1992, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2000
5 * Poul-Henning Kamp. All rights reserved.
6 *
7 * This code is derived from software donated to Berkeley by
8 * Jan-Simon Pendry.
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)kernfs_vfsops.c 8.10 (Berkeley) 5/14/95
32 * From: FreeBSD: src/sys/miscfs/kernfs/kernfs_vfsops.c 1.36
33 *
34 * $FreeBSD: head/sys/fs/devfs/devfs_vfsops.c 65051 2000-08-24 15:36:55Z phk $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/proc.h>
41#include <sys/vnode.h>
42#include <sys/mount.h>
43#include <sys/malloc.h>
44#include <sys/eventhandler.h>
45
46#define DEVFS_INTERN
47#include <fs/devfs/devfs.h>
48
49MALLOC_DEFINE(M_DEVFS, "DEVFS", "DEVFS data");
50
51static int devfs_mount __P((struct mount *mp, char *path, caddr_t data,
52 struct nameidata *ndp, struct proc *p));
53static int devfs_unmount __P((struct mount *mp, int mntflags,
54 struct proc *p));
55static int devfs_root __P((struct mount *mp, struct vnode **vpp));
56static int devfs_statfs __P((struct mount *mp, struct statfs *sbp,
57 struct proc *p));
58
59/*
60 * Mount the filesystem
61 */
62static int
63devfs_mount(mp, path, data, ndp, p)
64 struct mount *mp;
65 char *path;
66 caddr_t data;
67 struct nameidata *ndp;
68 struct proc *p;
69{
70 int error = 0;
71 u_int size;
72 struct devfs_mount *fmp;
73 struct vnode *rvp;
74
75 /*
76 * Update is a no-op
77 */
78 if (mp->mnt_flag & MNT_UPDATE)
79 return (EOPNOTSUPP);
80
81 MALLOC(fmp, struct devfs_mount *, sizeof(struct devfs_mount), M_DEVFS, M_WAITOK);
82
83 bzero(fmp, sizeof(*fmp));
84
85 error = getnewvnode(VT_DEVFS, mp, devfs_vnodeop_p, &rvp);
86 if (error) {
87 FREE(fmp, M_DEVFS);
88 return (error);
89 }
90
91 vhold(rvp);
92 rvp->v_type = VDIR;
93 rvp->v_flag |= VROOT;
94 mp->mnt_flag |= MNT_LOCAL;
95 mp->mnt_data = (qaddr_t) fmp;
96 vfs_getnewfsid(mp);
97
98 fmp->dm_inode = NDEVINO;
99 fmp->dm_root = rvp;
100
101 fmp->dm_rootdir = devfs_vmkdir("(root)", 6, NULL);
102 fmp->dm_rootdir->de_inode = 2;
103 rvp->v_data = fmp->dm_rootdir;
104
105 fmp->dm_basedir = fmp->dm_rootdir;
106
107 if (path != NULL) {
108 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
109 } else {
110 strcpy(mp->mnt_stat.f_mntonname, "/");
111 size = 1;
112 }
113 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
114 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
115 bcopy("devfs", mp->mnt_stat.f_mntfromname, sizeof("devfs"));
116 (void)devfs_statfs(mp, &mp->mnt_stat, p);
117 devfs_populate(fmp);
118
119 return (0);
120}
121
122static int
123devfs_unmount(mp, mntflags, p)
124 struct mount *mp;
125 int mntflags;
126 struct proc *p;
127{
128 int error;
129 int flags = 0;
130 struct vnode *rootvp = VFSTODEVFS(mp)->dm_root;
131 struct devfs_mount *fmp;
132
133 fmp = (struct devfs_mount*) mp->mnt_data;
134 if (mntflags & MNT_FORCE)
135 flags |= FORCECLOSE;
136
137 /*
138 * Clear out buffer cache. I don't think we
139 * ever get anything cached at this level at the
140 * moment, but who knows...
141 */
142 if (rootvp->v_usecount > 2)
143 return (EBUSY);
144 devfs_purge(fmp->dm_rootdir);
145 error = vflush(mp, rootvp, flags);
146 if (error)
147 return (error);
148
149 /*
150 * Release reference on underlying root vnode
151 */
152 vrele(rootvp);
153 /*
154 * And blow it away for future re-use
155 */
156 vgone(rootvp);
157 /*
158 * Finally, throw away the devfs_mount structure
159 */
160 free(mp->mnt_data, M_DEVFS);
161 mp->mnt_data = 0;
162 return 0;
163}
164
165static int
166devfs_root(mp, vpp)
167 struct mount *mp;
168 struct vnode **vpp;
169{
170 struct proc *p = curproc; /* XXX */
171 struct vnode *vp;
172
173 /*
174 * Return locked reference to root.
175 */
176 vp = VFSTODEVFS(mp)->dm_root;
177 VREF(vp);
178 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
179 *vpp = vp;
180 return (0);
181}
182
183static int
184devfs_statfs(mp, sbp, p)
185 struct mount *mp;
186 struct statfs *sbp;
187 struct proc *p;
188{
189
190 sbp->f_flags = 0;
191 sbp->f_bsize = DEV_BSIZE;
192 sbp->f_iosize = DEV_BSIZE;
193 sbp->f_blocks = 2; /* 1K to keep df happy */
194 sbp->f_bfree = 0;
195 sbp->f_bavail = 0;
196 sbp->f_files = 0;
197 sbp->f_ffree = 0;
198 if (sbp != &mp->mnt_stat) {
199 sbp->f_type = mp->mnt_vfc->vfc_typenum;
200 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
201 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
202 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
203 }
204 return (0);
205}
206
207static struct vfsops devfs_vfsops = {
208 devfs_mount,
209 vfs_stdstart,
210 devfs_unmount,
211 devfs_root,
212 vfs_stdquotactl,
213 devfs_statfs,
214 vfs_stdsync,
215 vfs_stdvget,
216 vfs_stdfhtovp,
217 vfs_stdcheckexp,
218 vfs_stdvptofh,
219 vfs_stdinit,
220 vfs_stduninit,
221 vfs_stdextattrctl,
222};
223
224VFS_SET(devfs_vfsops, devfs, VFCF_SYNTHETIC);