Annotation of src/sys/miscfs/kernfs/kernfs_vfsops.c, Revision 1.22
1.22 ! cgd 1: /* $NetBSD: kernfs_vfsops.c,v 1.21 1995/01/18 09:34:26 mycroft Exp $ */
1.18 cgd 2:
1.1 cgd 3: /*
1.15 mycroft 4: * Copyright (c) 1992, 1993
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.18 cgd 38: * @(#)kernfs_vfsops.c 8.5 (Berkeley) 6/15/94
1.1 cgd 39: */
40:
41: /*
42: * Kernel params Filesystem
43: */
44:
1.9 mycroft 45: #include <sys/param.h>
46: #include <sys/systm.h>
1.15 mycroft 47: #include <sys/conf.h>
1.9 mycroft 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>
1.15 mycroft 54:
55: #include <miscfs/specfs/specdev.h>
1.9 mycroft 56: #include <miscfs/kernfs/kernfs.h>
1.1 cgd 57:
1.15 mycroft 58: dev_t rrootdev = NODEV;
59:
1.1 cgd 60: kernfs_init()
61: {
1.15 mycroft 62:
1.10 cgd 63: }
64:
1.11 cgd 65: void
1.15 mycroft 66: kernfs_get_rrootdev()
1.10 cgd 67: {
1.16 mycroft 68: static int tried = 0;
69: int cmaj;
1.10 cgd 70:
1.16 mycroft 71: if (tried) {
1.15 mycroft 72: /* Already did it once. */
73: return;
74: }
1.16 mycroft 75: tried = 1;
76:
77: if (rootdev == NODEV)
78: return;
1.10 cgd 79: for (cmaj = 0; cmaj < nchrdev; cmaj++) {
1.16 mycroft 80: rrootdev = makedev(cmaj, minor(rootdev));
81: if (chrtoblk(rrootdev) == rootdev)
1.15 mycroft 82: return;
1.10 cgd 83: }
1.16 mycroft 84: rrootdev = NODEV;
1.15 mycroft 85: printf("kernfs_get_rrootdev: no raw root device\n");
1.1 cgd 86: }
87:
88: /*
1.15 mycroft 89: * Mount the Kernel params filesystem
1.1 cgd 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;
1.22 ! cgd 99: u_long size;
1.1 cgd 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:
1.15 mycroft 113: if (error = getnewvnode(VT_KERNFS, mp, kernfs_vnodeop_p, &rvp))
1.1 cgd 114: return (error);
115:
1.15 mycroft 116: MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
117: M_MISCFSMNT, M_WAITOK);
1.1 cgd 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;
1.15 mycroft 125: mp->mnt_data = (qaddr_t)fmp;
1.14 cgd 126: getnewfsid(mp, makefstype(MOUNT_KERNFS));
1.1 cgd 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: #ifdef KERNFS_DIAGNOSTIC
133: printf("kernfs_mount: at %s\n", mp->mnt_stat.f_mntonname);
134: #endif
1.10 cgd 135:
1.15 mycroft 136: kernfs_get_rrootdev();
1.1 cgd 137: return (0);
138: }
139:
140: kernfs_start(mp, flags, p)
141: struct mount *mp;
142: int flags;
143: struct proc *p;
144: {
1.15 mycroft 145:
1.1 cgd 146: return (0);
147: }
148:
149: kernfs_unmount(mp, mntflags, p)
150: struct mount *mp;
151: int mntflags;
152: struct proc *p;
153: {
154: int error;
155: int flags = 0;
156: extern int doforce;
157: struct vnode *rootvp = VFSTOKERNFS(mp)->kf_root;
158:
159: #ifdef KERNFS_DIAGNOSTIC
160: printf("kernfs_unmount(mp = %x)\n", mp);
161: #endif
162:
163: if (mntflags & MNT_FORCE) {
164: /* kernfs can never be rootfs so don't check for it */
165: if (!doforce)
166: return (EINVAL);
167: flags |= FORCECLOSE;
168: }
169:
170: /*
171: * Clear out buffer cache. I don't think we
172: * ever get anything cached at this level at the
173: * moment, but who knows...
174: */
175: if (rootvp->v_usecount > 1)
176: return (EBUSY);
177: #ifdef KERNFS_DIAGNOSTIC
178: printf("kernfs_unmount: calling vflush\n");
179: #endif
180: if (error = vflush(mp, rootvp, flags))
181: return (error);
182:
183: #ifdef KERNFS_DIAGNOSTIC
184: vprint("kernfs root", rootvp);
1.15 mycroft 185: #endif
1.1 cgd 186: /*
1.15 mycroft 187: * Clean out the old root vnode for reuse.
1.1 cgd 188: */
189: vrele(rootvp);
190: vgone(rootvp);
191: /*
192: * Finally, throw away the kernfs_mount structure
193: */
1.6 cgd 194: free(mp->mnt_data, M_MISCFSMNT);
1.1 cgd 195: mp->mnt_data = 0;
1.15 mycroft 196: return (0);
1.1 cgd 197: }
198:
199: kernfs_root(mp, vpp)
200: struct mount *mp;
201: struct vnode **vpp;
202: {
203: struct vnode *vp;
204:
205: #ifdef KERNFS_DIAGNOSTIC
206: printf("kernfs_root(mp = %x)\n", mp);
207: #endif
208:
209: /*
210: * Return locked reference to root.
211: */
212: vp = VFSTOKERNFS(mp)->kf_root;
213: VREF(vp);
214: VOP_LOCK(vp);
215: *vpp = vp;
216: return (0);
217: }
218:
219: kernfs_quotactl(mp, cmd, uid, arg, p)
220: struct mount *mp;
221: int cmd;
222: uid_t uid;
223: caddr_t arg;
224: struct proc *p;
225: {
1.15 mycroft 226:
1.1 cgd 227: return (EOPNOTSUPP);
228: }
229:
230: kernfs_statfs(mp, sbp, p)
231: struct mount *mp;
232: struct statfs *sbp;
233: struct proc *p;
234: {
235:
236: #ifdef KERNFS_DIAGNOSTIC
237: printf("kernfs_statfs(mp = %x)\n", mp);
238: #endif
239:
1.12 cgd 240: #ifdef COMPAT_09
241: sbp->f_type = 7;
242: #else
243: sbp->f_type = 0;
244: #endif
1.1 cgd 245: sbp->f_bsize = DEV_BSIZE;
1.13 cgd 246: sbp->f_iosize = DEV_BSIZE;
1.1 cgd 247: sbp->f_blocks = 2; /* 1K to keep df happy */
248: sbp->f_bfree = 0;
249: sbp->f_bavail = 0;
1.15 mycroft 250: sbp->f_files = 0;
251: sbp->f_ffree = 0;
1.1 cgd 252: if (sbp != &mp->mnt_stat) {
253: bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
254: bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
255: bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
256: }
1.21 mycroft 257: strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
1.12 cgd 258: sbp->f_fstypename[MFSNAMELEN] = '\0';
1.1 cgd 259: return (0);
260: }
261:
262: kernfs_sync(mp, waitfor)
263: struct mount *mp;
264: int waitfor;
265: {
1.15 mycroft 266:
1.1 cgd 267: return (0);
268: }
269:
1.15 mycroft 270: /*
271: * Kernfs flat namespace lookup.
272: * Currently unsupported.
273: */
274: kernfs_vget(mp, ino, vpp)
275: struct mount *mp;
276: ino_t ino;
277: struct vnode **vpp;
278: {
279:
280: return (EOPNOTSUPP);
281: }
282:
283:
284: kernfs_fhtovp(mp, fhp, setgen, vpp)
1.1 cgd 285: struct mount *mp;
286: struct fid *fhp;
1.15 mycroft 287: int setgen;
1.1 cgd 288: struct vnode **vpp;
289: {
1.15 mycroft 290:
1.1 cgd 291: return (EOPNOTSUPP);
292: }
293:
294: kernfs_vptofh(vp, fhp)
295: struct vnode *vp;
296: struct fid *fhp;
297: {
1.15 mycroft 298:
1.1 cgd 299: return (EOPNOTSUPP);
300: }
301:
302: struct vfsops kernfs_vfsops = {
1.12 cgd 303: MOUNT_KERNFS,
1.1 cgd 304: kernfs_mount,
305: kernfs_start,
306: kernfs_unmount,
307: kernfs_root,
308: kernfs_quotactl,
309: kernfs_statfs,
310: kernfs_sync,
1.15 mycroft 311: kernfs_vget,
1.1 cgd 312: kernfs_fhtovp,
313: kernfs_vptofh,
314: kernfs_init,
315: };
CVSweb <webmaster@jp.NetBSD.org>