kernfs_vfsops.c revision 1.19 1 /* $NetBSD: kernfs_vfsops.c,v 1.19 1994/09/15 03:42:39 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. 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. 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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kernfs_vfsops.c 8.5 (Berkeley) 6/15/94
39 */
40
41 /*
42 * Kernel params Filesystem
43 */
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/conf.h>
48 #include <sys/types.h>
49 #include <sys/proc.h>
50 #include <sys/vnode.h>
51 #include <sys/mount.h>
52 #include <sys/namei.h>
53 #include <sys/malloc.h>
54
55 #include <miscfs/specfs/specdev.h>
56 #include <miscfs/kernfs/kernfs.h>
57
58 dev_t rrootdev = NODEV;
59
60 kernfs_init()
61 {
62
63 }
64
65 void
66 kernfs_get_rrootdev()
67 {
68 static int tried = 0;
69 int cmaj;
70
71 if (tried) {
72 /* Already did it once. */
73 return;
74 }
75 tried = 1;
76
77 if (rootdev == NODEV)
78 return;
79 for (cmaj = 0; cmaj < nchrdev; cmaj++) {
80 rrootdev = makedev(cmaj, minor(rootdev));
81 if (chrtoblk(rrootdev) == rootdev)
82 return;
83 }
84 rrootdev = NODEV;
85 printf("kernfs_get_rrootdev: no raw root device\n");
86 }
87
88 /*
89 * Mount the Kernel params filesystem
90 */
91 kernfs_mount(mp, path, data, ndp, p)
92 struct mount *mp;
93 char *path;
94 caddr_t data;
95 struct nameidata *ndp;
96 struct proc *p;
97 {
98 int error = 0;
99 u_int size;
100 struct kernfs_mount *fmp;
101 struct vnode *rvp;
102
103 #ifdef KERNFS_DIAGNOSTIC
104 printf("kernfs_mount(mp = %x)\n", mp);
105 #endif
106
107 /*
108 * Update is a no-op
109 */
110 if (mp->mnt_flag & MNT_UPDATE)
111 return (EOPNOTSUPP);
112
113 if (error = getnewvnode(VT_KERNFS, mp, kernfs_vnodeop_p, &rvp))
114 return (error);
115
116 MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
117 M_MISCFSMNT, M_WAITOK);
118 rvp->v_type = VDIR;
119 rvp->v_flag |= VROOT;
120 #ifdef KERNFS_DIAGNOSTIC
121 printf("kernfs_mount: root vp = %x\n", rvp);
122 #endif
123 fmp->kf_root = rvp;
124 mp->mnt_flag |= MNT_LOCAL;
125 mp->mnt_data = (qaddr_t)fmp;
126 getnewfsid(mp, makefstype(MOUNT_KERNFS));
127
128 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
129 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
130 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
131 bcopy("kernfs", mp->mnt_stat.f_mntfromname, sizeof("kernfs"));
132 (void)kernfs_statfs(mp, &mp->mnt_stat, p);
133 #ifdef KERNFS_DIAGNOSTIC
134 printf("kernfs_mount: at %s\n", mp->mnt_stat.f_mntonname);
135 #endif
136
137 kernfs_get_rrootdev();
138 return (0);
139 }
140
141 kernfs_start(mp, flags, p)
142 struct mount *mp;
143 int flags;
144 struct proc *p;
145 {
146
147 return (0);
148 }
149
150 kernfs_unmount(mp, mntflags, p)
151 struct mount *mp;
152 int mntflags;
153 struct proc *p;
154 {
155 int error;
156 int flags = 0;
157 extern int doforce;
158 struct vnode *rootvp = VFSTOKERNFS(mp)->kf_root;
159
160 #ifdef KERNFS_DIAGNOSTIC
161 printf("kernfs_unmount(mp = %x)\n", mp);
162 #endif
163
164 if (mntflags & MNT_FORCE) {
165 /* kernfs can never be rootfs so don't check for it */
166 if (!doforce)
167 return (EINVAL);
168 flags |= FORCECLOSE;
169 }
170
171 /*
172 * Clear out buffer cache. I don't think we
173 * ever get anything cached at this level at the
174 * moment, but who knows...
175 */
176 if (rootvp->v_usecount > 1)
177 return (EBUSY);
178 #ifdef KERNFS_DIAGNOSTIC
179 printf("kernfs_unmount: calling vflush\n");
180 #endif
181 if (error = vflush(mp, rootvp, flags))
182 return (error);
183
184 #ifdef KERNFS_DIAGNOSTIC
185 vprint("kernfs root", rootvp);
186 #endif
187 /*
188 * Clean out the old root vnode for reuse.
189 */
190 vrele(rootvp);
191 vgone(rootvp);
192 /*
193 * Finally, throw away the kernfs_mount structure
194 */
195 free(mp->mnt_data, M_MISCFSMNT);
196 mp->mnt_data = 0;
197 return (0);
198 }
199
200 kernfs_root(mp, vpp)
201 struct mount *mp;
202 struct vnode **vpp;
203 {
204 struct vnode *vp;
205
206 #ifdef KERNFS_DIAGNOSTIC
207 printf("kernfs_root(mp = %x)\n", mp);
208 #endif
209
210 /*
211 * Return locked reference to root.
212 */
213 vp = VFSTOKERNFS(mp)->kf_root;
214 VREF(vp);
215 VOP_LOCK(vp);
216 *vpp = vp;
217 return (0);
218 }
219
220 kernfs_quotactl(mp, cmd, uid, arg, p)
221 struct mount *mp;
222 int cmd;
223 uid_t uid;
224 caddr_t arg;
225 struct proc *p;
226 {
227
228 return (EOPNOTSUPP);
229 }
230
231 kernfs_statfs(mp, sbp, p)
232 struct mount *mp;
233 struct statfs *sbp;
234 struct proc *p;
235 {
236
237 #ifdef KERNFS_DIAGNOSTIC
238 printf("kernfs_statfs(mp = %x)\n", mp);
239 #endif
240
241 #ifdef COMPAT_09
242 sbp->f_type = 7;
243 #else
244 sbp->f_type = 0;
245 #endif
246 sbp->f_bsize = DEV_BSIZE;
247 sbp->f_iosize = DEV_BSIZE;
248 sbp->f_blocks = 2; /* 1K to keep df happy */
249 sbp->f_bfree = 0;
250 sbp->f_bavail = 0;
251 sbp->f_files = 0;
252 sbp->f_ffree = 0;
253 if (sbp != &mp->mnt_stat) {
254 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
255 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
256 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
257 }
258 strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN);
259 sbp->f_fstypename[MFSNAMELEN] = '\0';
260 return (0);
261 }
262
263 kernfs_sync(mp, waitfor)
264 struct mount *mp;
265 int waitfor;
266 {
267
268 return (0);
269 }
270
271 /*
272 * Kernfs flat namespace lookup.
273 * Currently unsupported.
274 */
275 kernfs_vget(mp, ino, vpp)
276 struct mount *mp;
277 ino_t ino;
278 struct vnode **vpp;
279 {
280
281 return (EOPNOTSUPP);
282 }
283
284
285 kernfs_fhtovp(mp, fhp, setgen, vpp)
286 struct mount *mp;
287 struct fid *fhp;
288 int setgen;
289 struct vnode **vpp;
290 {
291
292 return (EOPNOTSUPP);
293 }
294
295 kernfs_vptofh(vp, fhp)
296 struct vnode *vp;
297 struct fid *fhp;
298 {
299
300 return (EOPNOTSUPP);
301 }
302
303 struct vfsops kernfs_vfsops = {
304 MOUNT_KERNFS,
305 kernfs_mount,
306 kernfs_start,
307 kernfs_unmount,
308 kernfs_root,
309 kernfs_quotactl,
310 kernfs_statfs,
311 kernfs_sync,
312 kernfs_vget,
313 kernfs_fhtovp,
314 kernfs_vptofh,
315 kernfs_init,
316 };
317