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