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