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