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