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