procfs_vfsops.c revision 1.38.2.3 1 /* $NetBSD: procfs_vfsops.c,v 1.38.2.3 2001/11/14 19:17:12 nathanw Exp $ */
2
3 /*
4 * Copyright (c) 1993 Jan-Simon Pendry
5 * Copyright (c) 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95
40 */
41
42 /*
43 * procfs VFS interface
44 */
45
46 #include <sys/cdefs.h>
47 __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.38.2.3 2001/11/14 19:17:12 nathanw Exp $");
48
49 #if defined(_KERNEL_OPT)
50 #include "opt_compat_netbsd.h"
51 #endif
52
53 #include <sys/param.h>
54 #include <sys/time.h>
55 #include <sys/kernel.h>
56 #include <sys/systm.h>
57 #include <sys/proc.h>
58 #include <sys/buf.h>
59 #include <sys/syslog.h>
60 #include <sys/mount.h>
61 #include <sys/signalvar.h>
62 #include <sys/vnode.h>
63 #include <sys/malloc.h>
64
65 #include <miscfs/procfs/procfs.h>
66
67 #include <uvm/uvm_extern.h> /* for PAGE_SIZE */
68
69 void procfs_init __P((void));
70 void procfs_reinit __P((void));
71 void procfs_done __P((void));
72 int procfs_mount __P((struct mount *, const char *, void *,
73 struct nameidata *, struct proc *));
74 int procfs_start __P((struct mount *, int, struct proc *));
75 int procfs_unmount __P((struct mount *, int, struct proc *));
76 int procfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
77 struct proc *));
78 int procfs_statfs __P((struct mount *, struct statfs *, struct proc *));
79 int procfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
80 int procfs_vget __P((struct mount *, ino_t, struct vnode **));
81 int procfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
82 int procfs_checkexp __P((struct mount *, struct mbuf *, int *,
83 struct ucred **));
84 int procfs_vptofh __P((struct vnode *, struct fid *));
85 int procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
86 struct proc *));
87 /*
88 * VFS Operations.
89 *
90 * mount system call
91 */
92 /* ARGSUSED */
93 int
94 procfs_mount(mp, path, data, ndp, p)
95 struct mount *mp;
96 const char *path;
97 void *data;
98 struct nameidata *ndp;
99 struct proc *p;
100 {
101 size_t size;
102 struct procfsmount *pmnt;
103 struct procfs_args args;
104 int error;
105
106 if (UIO_MX & (UIO_MX-1)) {
107 log(LOG_ERR, "procfs: invalid directory entry size");
108 return (EINVAL);
109 }
110
111 if (mp->mnt_flag & MNT_UPDATE)
112 return (EOPNOTSUPP);
113
114 if (data != NULL) {
115 error = copyin(data, &args, sizeof args);
116 if (error != 0)
117 return error;
118
119 if (args.version != PROCFS_ARGSVERSION)
120 return EINVAL;
121 } else
122 args.flags = 0;
123
124 mp->mnt_flag |= MNT_LOCAL;
125 pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
126 M_UFSMNT, M_WAITOK); /* XXX need new malloc type */
127
128 mp->mnt_data = (qaddr_t)pmnt;
129 vfs_getnewfsid(mp);
130
131 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size);
132 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
133 memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
134 memcpy(mp->mnt_stat.f_mntfromname, "procfs", sizeof("procfs"));
135
136 pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp);
137 pmnt->pmnt_flags = args.flags;
138
139 return (0);
140 }
141
142 /*
143 * unmount system call
144 */
145 int
146 procfs_unmount(mp, mntflags, p)
147 struct mount *mp;
148 int mntflags;
149 struct proc *p;
150 {
151 int error;
152 int flags = 0;
153
154 if (mntflags & MNT_FORCE)
155 flags |= FORCECLOSE;
156
157 if ((error = vflush(mp, 0, flags)) != 0)
158 return (error);
159
160 exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
161
162 free(mp->mnt_data, M_UFSMNT);
163 mp->mnt_data = 0;
164
165 return (0);
166 }
167
168 int
169 procfs_root(mp, vpp)
170 struct mount *mp;
171 struct vnode **vpp;
172 {
173
174 return (procfs_allocvp(mp, vpp, 0, Proot));
175 }
176
177 /* ARGSUSED */
178 int
179 procfs_start(mp, flags, p)
180 struct mount *mp;
181 int flags;
182 struct proc *p;
183 {
184
185 return (0);
186 }
187
188 /*
189 * Get file system statistics.
190 */
191 int
192 procfs_statfs(mp, sbp, p)
193 struct mount *mp;
194 struct statfs *sbp;
195 struct proc *p;
196 {
197
198 sbp->f_bsize = PAGE_SIZE;
199 sbp->f_iosize = PAGE_SIZE;
200 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
201 sbp->f_bfree = 0;
202 sbp->f_bavail = 0;
203 sbp->f_files = maxproc; /* approx */
204 sbp->f_ffree = maxproc - nprocs; /* approx */
205 #ifdef COMPAT_09
206 sbp->f_type = 10;
207 #else
208 sbp->f_type = 0;
209 #endif
210 if (sbp != &mp->mnt_stat) {
211 memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
212 memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
213 memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
214 }
215 strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
216 return (0);
217 }
218
219 /*ARGSUSED*/
220 int
221 procfs_quotactl(mp, cmds, uid, arg, p)
222 struct mount *mp;
223 int cmds;
224 uid_t uid;
225 caddr_t arg;
226 struct proc *p;
227 {
228
229 return (EOPNOTSUPP);
230 }
231
232 /*ARGSUSED*/
233 int
234 procfs_sync(mp, waitfor, uc, p)
235 struct mount *mp;
236 int waitfor;
237 struct ucred *uc;
238 struct proc *p;
239 {
240
241 return (0);
242 }
243
244 /*ARGSUSED*/
245 int
246 procfs_vget(mp, ino, vpp)
247 struct mount *mp;
248 ino_t ino;
249 struct vnode **vpp;
250 {
251
252 return (EOPNOTSUPP);
253 }
254
255 /*ARGSUSED*/
256 int
257 procfs_fhtovp(mp, fhp, vpp)
258 struct mount *mp;
259 struct fid *fhp;
260 struct vnode **vpp;
261 {
262
263 return (EINVAL);
264 }
265
266 /*ARGSUSED*/
267 int
268 procfs_checkexp(mp, mb, what, anon)
269 struct mount *mp;
270 struct mbuf *mb;
271 int *what;
272 struct ucred **anon;
273 {
274
275 return (EINVAL);
276 }
277
278 /*ARGSUSED*/
279 int
280 procfs_vptofh(vp, fhp)
281 struct vnode *vp;
282 struct fid *fhp;
283 {
284
285 return (EINVAL);
286 }
287
288 void
289 procfs_init()
290 {
291 procfs_hashinit();
292 }
293
294 void
295 procfs_reinit()
296 {
297 procfs_hashreinit();
298 }
299
300 void
301 procfs_done()
302 {
303 procfs_hashdone();
304 }
305
306 int
307 procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
308 int *name;
309 u_int namelen;
310 void *oldp;
311 size_t *oldlenp;
312 void *newp;
313 size_t newlen;
314 struct proc *p;
315 {
316 return (EOPNOTSUPP);
317 }
318
319 extern const struct vnodeopv_desc procfs_vnodeop_opv_desc;
320
321 const struct vnodeopv_desc * const procfs_vnodeopv_descs[] = {
322 &procfs_vnodeop_opv_desc,
323 NULL,
324 };
325
326 struct vfsops procfs_vfsops = {
327 MOUNT_PROCFS,
328 procfs_mount,
329 procfs_start,
330 procfs_unmount,
331 procfs_root,
332 procfs_quotactl,
333 procfs_statfs,
334 procfs_sync,
335 procfs_vget,
336 procfs_fhtovp,
337 procfs_vptofh,
338 procfs_init,
339 procfs_reinit,
340 procfs_done,
341 procfs_sysctl,
342 NULL, /* vfs_mountroot */
343 procfs_checkexp,
344 procfs_vnodeopv_descs,
345 };
346