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