procfs_vfsops.c revision 1.21 1 /* $NetBSD: procfs_vfsops.c,v 1.21 1994/12/15 20:00:21 mycroft 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.5 (Berkeley) 6/15/94
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/proc.h>
50 #include <sys/buf.h>
51 #include <sys/syslog.h>
52 #include <sys/mount.h>
53 #include <sys/signalvar.h>
54 #include <sys/vnode.h>
55 #include <miscfs/procfs/procfs.h>
56 #include <vm/vm.h> /* for PAGE_SIZE */
57
58 /*
59 * VFS Operations.
60 *
61 * mount system call
62 */
63 /* ARGSUSED */
64 procfs_mount(mp, path, data, ndp, p)
65 struct mount *mp;
66 char *path;
67 caddr_t data;
68 struct nameidata *ndp;
69 struct proc *p;
70 {
71 u_int size;
72
73 if (UIO_MX & (UIO_MX-1)) {
74 log(LOG_ERR, "procfs: invalid directory entry size");
75 return (EINVAL);
76 }
77
78 if (mp->mnt_flag & MNT_UPDATE)
79 return (EOPNOTSUPP);
80
81 mp->mnt_flag |= MNT_LOCAL;
82 mp->mnt_data = 0;
83 getnewfsid(mp, makefstype(MOUNT_PROCFS));
84
85 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size);
86 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
87 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
88 bcopy("procfs", mp->mnt_stat.f_mntfromname, sizeof("procfs"));
89 return (0);
90 }
91
92 /*
93 * unmount system call
94 */
95 procfs_unmount(mp, mntflags, p)
96 struct mount *mp;
97 int mntflags;
98 struct proc *p;
99 {
100 int error;
101 extern int doforce;
102 int flags = 0;
103
104 if (mntflags & MNT_FORCE) {
105 /* procfs can never be rootfs so don't check for it */
106 if (!doforce)
107 return (EINVAL);
108 flags |= FORCECLOSE;
109 }
110
111 if (error = vflush(mp, 0, flags))
112 return (error);
113
114 return (0);
115 }
116
117 procfs_root(mp, vpp)
118 struct mount *mp;
119 struct vnode **vpp;
120 {
121
122 return (procfs_allocvp(mp, vpp, 0, Proot));
123 }
124
125 /* ARGSUSED */
126 procfs_start(mp, flags, p)
127 struct mount *mp;
128 int flags;
129 struct proc *p;
130 {
131
132 return (0);
133 }
134
135 /*
136 * Get file system statistics.
137 */
138 procfs_statfs(mp, sbp, p)
139 struct mount *mp;
140 struct statfs *sbp;
141 struct proc *p;
142 {
143
144 #ifdef COMPAT_09
145 sbp->f_type = 10;
146 #else
147 sbp->f_type = 0;
148 #endif
149 sbp->f_bsize = PAGE_SIZE;
150 sbp->f_iosize = PAGE_SIZE;
151 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
152 sbp->f_bfree = 0;
153 sbp->f_bavail = 0;
154 sbp->f_files = maxproc; /* approx */
155 sbp->f_ffree = maxproc - nprocs; /* approx */
156 if (sbp != &mp->mnt_stat) {
157 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
158 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
159 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
160 }
161 strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN);
162 sbp->f_fstypename[MFSNAMELEN] = '\0';
163 return (0);
164 }
165
166 procfs_quotactl(mp, cmds, uid, arg, p)
167 struct mount *mp;
168 int cmds;
169 uid_t uid;
170 caddr_t arg;
171 struct proc *p;
172 {
173
174 return (EOPNOTSUPP);
175 }
176
177 procfs_sync(mp, waitfor)
178 struct mount *mp;
179 int waitfor;
180 {
181
182 return (0);
183 }
184
185 procfs_vget(mp, ino, vpp)
186 struct mount *mp;
187 ino_t ino;
188 struct vnode **vpp;
189 {
190
191 return (EOPNOTSUPP);
192 }
193
194 procfs_fhtovp(mp, fhp, vpp)
195 struct mount *mp;
196 struct fid *fhp;
197 struct vnode **vpp;
198 {
199
200 return (EINVAL);
201 }
202
203 procfs_vptofh(vp, fhp)
204 struct vnode *vp;
205 struct fid *fhp;
206 {
207
208 return (EINVAL);
209 }
210
211 procfs_init()
212 {
213
214 return (0);
215 }
216
217 struct vfsops procfs_vfsops = {
218 MOUNT_PROCFS,
219 procfs_mount,
220 procfs_start,
221 procfs_unmount,
222 procfs_root,
223 procfs_quotactl,
224 procfs_statfs,
225 procfs_sync,
226 procfs_vget,
227 procfs_fhtovp,
228 procfs_vptofh,
229 procfs_init,
230 };
231