procfs_vfsops.c revision 1.34.2.1 1 /* $NetBSD: procfs_vfsops.c,v 1.34.2.1 2001/03/30 21:49:49 he 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 #if defined(_KERNEL) && !defined(_LKM)
47 #include "opt_compat_netbsd.h"
48 #endif
49
50 #include <sys/param.h>
51 #include <sys/time.h>
52 #include <sys/kernel.h>
53 #include <sys/systm.h>
54 #include <sys/proc.h>
55 #include <sys/buf.h>
56 #include <sys/syslog.h>
57 #include <sys/mount.h>
58 #include <sys/signalvar.h>
59 #include <sys/vnode.h>
60 #include <sys/malloc.h>
61 #include <miscfs/procfs/procfs.h>
62 #include <vm/vm.h> /* for PAGE_SIZE */
63
64 void procfs_init __P((void));
65 void procfs_done __P((void));
66 int procfs_mount __P((struct mount *, const char *, void *,
67 struct nameidata *, struct proc *));
68 int procfs_start __P((struct mount *, int, struct proc *));
69 int procfs_unmount __P((struct mount *, int, struct proc *));
70 int procfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
71 struct proc *));
72 int procfs_statfs __P((struct mount *, struct statfs *, struct proc *));
73 int procfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
74 int procfs_vget __P((struct mount *, ino_t, struct vnode **));
75 int procfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
76 int procfs_checkexp __P((struct mount *, struct mbuf *, int *,
77 struct ucred **));
78 int procfs_vptofh __P((struct vnode *, struct fid *));
79 int procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
80 struct proc *));
81 /*
82 * VFS Operations.
83 *
84 * mount system call
85 */
86 /* ARGSUSED */
87 int
88 procfs_mount(mp, path, data, ndp, p)
89 struct mount *mp;
90 const char *path;
91 void *data;
92 struct nameidata *ndp;
93 struct proc *p;
94 {
95 size_t size;
96 struct procfsmount *pmnt;
97 struct procfs_args args;
98 int error;
99
100 if (UIO_MX & (UIO_MX-1)) {
101 log(LOG_ERR, "procfs: invalid directory entry size");
102 return (EINVAL);
103 }
104
105 if (mp->mnt_flag & MNT_UPDATE)
106 return (EOPNOTSUPP);
107
108 if (data != NULL) {
109 error = copyin(data, &args, sizeof args);
110 if (error != 0)
111 return error;
112
113 if (args.version != PROCFS_ARGSVERSION)
114 return EINVAL;
115 } else
116 args.flags = 0;
117
118 mp->mnt_flag |= MNT_LOCAL;
119 pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
120 M_UFSMNT, M_WAITOK); /* XXX need new malloc type */
121
122 mp->mnt_data = (qaddr_t)pmnt;
123 vfs_getnewfsid(mp);
124
125 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size);
126 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
127 memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
128 memcpy(mp->mnt_stat.f_mntfromname, "procfs", sizeof("procfs"));
129
130 pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp);
131 pmnt->pmnt_mp = mp;
132 pmnt->pmnt_flags = args.flags;
133
134 return (0);
135 }
136
137 /*
138 * unmount system call
139 */
140 int
141 procfs_unmount(mp, mntflags, p)
142 struct mount *mp;
143 int mntflags;
144 struct proc *p;
145 {
146 int error;
147 int flags = 0;
148
149 if (mntflags & MNT_FORCE)
150 flags |= FORCECLOSE;
151
152 if ((error = vflush(mp, 0, flags)) != 0)
153 return (error);
154
155 exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
156
157 free(mp->mnt_data, M_UFSMNT);
158 mp->mnt_data = 0;
159
160 return (0);
161 }
162
163 int
164 procfs_root(mp, vpp)
165 struct mount *mp;
166 struct vnode **vpp;
167 {
168
169 return (procfs_allocvp(mp, vpp, 0, Proot));
170 }
171
172 /* ARGSUSED */
173 int
174 procfs_start(mp, flags, p)
175 struct mount *mp;
176 int flags;
177 struct proc *p;
178 {
179
180 return (0);
181 }
182
183 /*
184 * Get file system statistics.
185 */
186 int
187 procfs_statfs(mp, sbp, p)
188 struct mount *mp;
189 struct statfs *sbp;
190 struct proc *p;
191 {
192
193 sbp->f_bsize = PAGE_SIZE;
194 sbp->f_iosize = PAGE_SIZE;
195 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
196 sbp->f_bfree = 0;
197 sbp->f_bavail = 0;
198 sbp->f_files = maxproc; /* approx */
199 sbp->f_ffree = maxproc - nprocs; /* approx */
200 #ifdef COMPAT_09
201 sbp->f_type = 10;
202 #else
203 sbp->f_type = 0;
204 #endif
205 if (sbp != &mp->mnt_stat) {
206 memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
207 memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
208 memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
209 }
210 strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
211 return (0);
212 }
213
214 /*ARGSUSED*/
215 int
216 procfs_quotactl(mp, cmds, uid, arg, p)
217 struct mount *mp;
218 int cmds;
219 uid_t uid;
220 caddr_t arg;
221 struct proc *p;
222 {
223
224 return (EOPNOTSUPP);
225 }
226
227 /*ARGSUSED*/
228 int
229 procfs_sync(mp, waitfor, uc, p)
230 struct mount *mp;
231 int waitfor;
232 struct ucred *uc;
233 struct proc *p;
234 {
235
236 return (0);
237 }
238
239 /*ARGSUSED*/
240 int
241 procfs_vget(mp, ino, vpp)
242 struct mount *mp;
243 ino_t ino;
244 struct vnode **vpp;
245 {
246
247 return (EOPNOTSUPP);
248 }
249
250 /*ARGSUSED*/
251 int
252 procfs_fhtovp(mp, fhp, vpp)
253 struct mount *mp;
254 struct fid *fhp;
255 struct vnode **vpp;
256 {
257
258 return (EINVAL);
259 }
260
261 /*ARGSUSED*/
262 int
263 procfs_checkexp(mp, mb, what, anon)
264 struct mount *mp;
265 struct mbuf *mb;
266 int *what;
267 struct ucred **anon;
268 {
269
270 return (EINVAL);
271 }
272
273 /*ARGSUSED*/
274 int
275 procfs_vptofh(vp, fhp)
276 struct vnode *vp;
277 struct fid *fhp;
278 {
279
280 return (EINVAL);
281 }
282
283 void
284 procfs_init()
285 {
286 procfs_hashinit();
287 }
288
289 void
290 procfs_done()
291 {
292 procfs_hashdone();
293 }
294
295 int
296 procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
297 int *name;
298 u_int namelen;
299 void *oldp;
300 size_t *oldlenp;
301 void *newp;
302 size_t newlen;
303 struct proc *p;
304 {
305 return (EOPNOTSUPP);
306 }
307
308 extern struct vnodeopv_desc procfs_vnodeop_opv_desc;
309
310 struct vnodeopv_desc *procfs_vnodeopv_descs[] = {
311 &procfs_vnodeop_opv_desc,
312 NULL,
313 };
314
315 struct vfsops procfs_vfsops = {
316 MOUNT_PROCFS,
317 procfs_mount,
318 procfs_start,
319 procfs_unmount,
320 procfs_root,
321 procfs_quotactl,
322 procfs_statfs,
323 procfs_sync,
324 procfs_vget,
325 procfs_fhtovp,
326 procfs_vptofh,
327 procfs_init,
328 procfs_done,
329 procfs_sysctl,
330 NULL, /* vfs_mountroot */
331 procfs_checkexp,
332 procfs_vnodeopv_descs,
333 };
334