kernfs_vfsops.c revision 1.39.2.7 1 /* $NetBSD: kernfs_vfsops.c,v 1.39.2.7 2002/10/18 02:45:03 nathanw Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993, 1995
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.10 (Berkeley) 5/14/95
39 */
40
41 /*
42 * Kernel params Filesystem
43 */
44
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.39.2.7 2002/10/18 02:45:03 nathanw Exp $");
47
48 #if defined(_KERNEL_OPT)
49 #include "opt_compat_netbsd.h"
50 #endif
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/conf.h>
55 #include <sys/proc.h>
56 #include <sys/vnode.h>
57 #include <sys/mount.h>
58 #include <sys/namei.h>
59 #include <sys/malloc.h>
60
61 #include <miscfs/specfs/specdev.h>
62 #include <miscfs/kernfs/kernfs.h>
63
64 dev_t rrootdev = NODEV;
65
66 void kernfs_init __P((void));
67 void kernfs_done __P((void));
68 void kernfs_get_rrootdev __P((void));
69 int kernfs_mount __P((struct mount *, const char *, void *,
70 struct nameidata *, struct proc *));
71 int kernfs_start __P((struct mount *, int, struct proc *));
72 int kernfs_unmount __P((struct mount *, int, struct proc *));
73 int kernfs_root __P((struct mount *, struct vnode **));
74 int kernfs_statfs __P((struct mount *, struct statfs *, struct proc *));
75 int kernfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
76 struct proc *));
77 int kernfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
78 int kernfs_vget __P((struct mount *, ino_t, struct vnode **));
79 int kernfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
80 int kernfs_checkexp __P((struct mount *, struct mbuf *, int *,
81 struct ucred **));
82 int kernfs_vptofh __P((struct vnode *, struct fid *));
83 int kernfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
84 struct proc *));
85
86 void
87 kernfs_init()
88 {
89 }
90
91 void
92 kernfs_done()
93 {
94 }
95
96 void
97 kernfs_get_rrootdev()
98 {
99 static int tried = 0;
100
101 if (tried) {
102 /* Already did it once. */
103 return;
104 }
105 tried = 1;
106
107 if (rootdev == NODEV)
108 return;
109 rrootdev = devsw_blk2chr(rootdev);
110 if (rrootdev != NODEV) {
111 #ifdef KERNFS_DIAGNOSTIC
112 printf("kernfs_mount: rootdev = %u.%u; rrootdev = %u.%u\n",
113 major(rootdev), minor(rootdev), major(rrootdev), minor(rrootdev));
114 #endif
115 return;
116 }
117 rrootdev = NODEV;
118 printf("kernfs_get_rrootdev: no raw root device\n");
119 }
120
121 /*
122 * Mount the Kernel params filesystem
123 */
124 int
125 kernfs_mount(mp, path, data, ndp, p)
126 struct mount *mp;
127 const char *path;
128 void *data;
129 struct nameidata *ndp;
130 struct proc *p;
131 {
132 int error = 0;
133 size_t size;
134 struct kernfs_mount *fmp;
135 struct vnode *rvp;
136
137 #ifdef KERNFS_DIAGNOSTIC
138 printf("kernfs_mount(mp = %p)\n", mp);
139 #endif
140
141 if (mp->mnt_flag & MNT_GETARGS)
142 return 0;
143 /*
144 * Update is a no-op
145 */
146 if (mp->mnt_flag & MNT_UPDATE)
147 return (EOPNOTSUPP);
148
149 error = getnewvnode(VT_KERNFS, mp, kernfs_vnodeop_p, &rvp);
150 if (error)
151 return (error);
152
153 MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
154 M_MISCFSMNT, M_WAITOK);
155 rvp->v_type = VDIR;
156 rvp->v_flag |= VROOT;
157 #ifdef KERNFS_DIAGNOSTIC
158 printf("kernfs_mount: root vp = %p\n", rvp);
159 #endif
160 fmp->kf_root = rvp;
161 mp->mnt_flag |= MNT_LOCAL;
162 mp->mnt_data = fmp;
163 vfs_getnewfsid(mp);
164
165 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
166 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
167 memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
168 memcpy(mp->mnt_stat.f_mntfromname, "kernfs", sizeof("kernfs"));
169 #ifdef KERNFS_DIAGNOSTIC
170 printf("kernfs_mount: at %s\n", mp->mnt_stat.f_mntonname);
171 #endif
172
173 kernfs_get_rrootdev();
174 return (0);
175 }
176
177 int
178 kernfs_start(mp, flags, p)
179 struct mount *mp;
180 int flags;
181 struct proc *p;
182 {
183
184 return (0);
185 }
186
187 int
188 kernfs_unmount(mp, mntflags, p)
189 struct mount *mp;
190 int mntflags;
191 struct proc *p;
192 {
193 int error;
194 int flags = 0;
195 struct vnode *rootvp = VFSTOKERNFS(mp)->kf_root;
196
197 #ifdef KERNFS_DIAGNOSTIC
198 printf("kernfs_unmount(mp = %p)\n", mp);
199 #endif
200
201 if (mntflags & MNT_FORCE)
202 flags |= FORCECLOSE;
203
204 /*
205 * Clear out buffer cache. I don't think we
206 * ever get anything cached at this level at the
207 * moment, but who knows...
208 */
209 if (rootvp->v_usecount > 1)
210 return (EBUSY);
211 #ifdef KERNFS_DIAGNOSTIC
212 printf("kernfs_unmount: calling vflush\n");
213 #endif
214 if ((error = vflush(mp, rootvp, flags)) != 0)
215 return (error);
216
217 #ifdef KERNFS_DIAGNOSTIC
218 vprint("kernfs root", rootvp);
219 #endif
220 /*
221 * Clean out the old root vnode for reuse.
222 */
223 vrele(rootvp);
224 vgone(rootvp);
225 /*
226 * Finally, throw away the kernfs_mount structure
227 */
228 free(mp->mnt_data, M_MISCFSMNT);
229 mp->mnt_data = 0;
230 return (0);
231 }
232
233 int
234 kernfs_root(mp, vpp)
235 struct mount *mp;
236 struct vnode **vpp;
237 {
238 struct vnode *vp;
239
240 #ifdef KERNFS_DIAGNOSTIC
241 printf("kernfs_root(mp = %p)\n", mp);
242 #endif
243
244 /*
245 * Return locked reference to root.
246 */
247 vp = VFSTOKERNFS(mp)->kf_root;
248 VREF(vp);
249 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
250 *vpp = vp;
251 return (0);
252 }
253
254 int
255 kernfs_quotactl(mp, cmd, uid, arg, p)
256 struct mount *mp;
257 int cmd;
258 uid_t uid;
259 caddr_t arg;
260 struct proc *p;
261 {
262
263 return (EOPNOTSUPP);
264 }
265
266 int
267 kernfs_statfs(mp, sbp, p)
268 struct mount *mp;
269 struct statfs *sbp;
270 struct proc *p;
271 {
272
273 #ifdef KERNFS_DIAGNOSTIC
274 printf("kernfs_statfs(mp = %p)\n", mp);
275 #endif
276
277 sbp->f_bsize = DEV_BSIZE;
278 sbp->f_iosize = DEV_BSIZE;
279 sbp->f_blocks = 2; /* 1K to keep df happy */
280 sbp->f_bfree = 0;
281 sbp->f_bavail = 0;
282 sbp->f_files = 0;
283 sbp->f_ffree = 0;
284 #ifdef COMPAT_09
285 sbp->f_type = 7;
286 #else
287 sbp->f_type = 0;
288 #endif
289 if (sbp != &mp->mnt_stat) {
290 memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
291 memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
292 memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
293 }
294 strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
295 return (0);
296 }
297
298 /*ARGSUSED*/
299 int
300 kernfs_sync(mp, waitfor, uc, p)
301 struct mount *mp;
302 int waitfor;
303 struct ucred *uc;
304 struct proc *p;
305 {
306
307 return (0);
308 }
309
310 /*
311 * Kernfs flat namespace lookup.
312 * Currently unsupported.
313 */
314 int
315 kernfs_vget(mp, ino, vpp)
316 struct mount *mp;
317 ino_t ino;
318 struct vnode **vpp;
319 {
320
321 return (EOPNOTSUPP);
322 }
323
324 /*ARGSUSED*/
325 int
326 kernfs_fhtovp(mp, fhp, vpp)
327 struct mount *mp;
328 struct fid *fhp;
329 struct vnode **vpp;
330 {
331
332 return (EOPNOTSUPP);
333 }
334
335 /*ARGSUSED*/
336 int
337 kernfs_checkexp(mp, mb, what, anon)
338 struct mount *mp;
339 struct mbuf *mb;
340 int *what;
341 struct ucred **anon;
342 {
343
344 return (EOPNOTSUPP);
345 }
346
347 /*ARGSUSED*/
348 int
349 kernfs_vptofh(vp, fhp)
350 struct vnode *vp;
351 struct fid *fhp;
352 {
353
354 return (EOPNOTSUPP);
355 }
356
357 int
358 kernfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
359 int *name;
360 u_int namelen;
361 void *oldp;
362 size_t *oldlenp;
363 void *newp;
364 size_t newlen;
365 struct proc *p;
366 {
367 return (EOPNOTSUPP);
368 }
369
370 extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
371
372 const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
373 &kernfs_vnodeop_opv_desc,
374 NULL,
375 };
376
377 struct vfsops kernfs_vfsops = {
378 MOUNT_KERNFS,
379 kernfs_mount,
380 kernfs_start,
381 kernfs_unmount,
382 kernfs_root,
383 kernfs_quotactl,
384 kernfs_statfs,
385 kernfs_sync,
386 kernfs_vget,
387 kernfs_fhtovp,
388 kernfs_vptofh,
389 kernfs_init,
390 NULL,
391 kernfs_done,
392 kernfs_sysctl,
393 NULL, /* vfs_mountroot */
394 kernfs_checkexp,
395 kernfs_vnodeopv_descs,
396 };
397