procfs_vfsops.c revision 1.1.1.1 1 /*
2 * Copyright (c) 1993 Jan-Simon Pendry
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Jan-Simon Pendry.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)procfs_vfsops.c 8.4 (Berkeley) 1/21/94
38 *
39 * From:
40 * $Id: procfs_vfsops.c,v 1.1.1.1 1998/03/01 02:10:02 fvdl Exp $
41 */
42
43 /*
44 * procfs VFS interface
45 */
46
47 #include <sys/param.h>
48 #include <sys/time.h>
49 #include <sys/kernel.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 /*
60 * VFS Operations.
61 *
62 * mount system call
63 */
64 /* ARGSUSED */
65 procfs_mount(mp, path, data, ndp, p)
66 struct mount *mp;
67 char *path;
68 caddr_t data;
69 struct nameidata *ndp;
70 struct proc *p;
71 {
72 u_int size;
73
74 if (UIO_MX & (UIO_MX-1)) {
75 log(LOG_ERR, "procfs: invalid directory entry size");
76 return (EINVAL);
77 }
78
79 if (mp->mnt_flag & MNT_UPDATE)
80 return (EOPNOTSUPP);
81
82 mp->mnt_flag |= MNT_LOCAL;
83 mp->mnt_data = 0;
84 getnewfsid(mp, MOUNT_PROCFS);
85
86 (void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
87 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
88
89 size = sizeof("procfs") - 1;
90 bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
91 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
92
93 return (0);
94 }
95
96 /*
97 * unmount system call
98 */
99 procfs_unmount(mp, mntflags, p)
100 struct mount *mp;
101 int mntflags;
102 struct proc *p;
103 {
104 int error;
105 extern int doforce;
106 int flags = 0;
107
108 if (mntflags & MNT_FORCE) {
109 /* procfs can never be rootfs so don't check for it */
110 if (!doforce)
111 return (EINVAL);
112 flags |= FORCECLOSE;
113 }
114
115 if (error = vflush(mp, 0, flags))
116 return (error);
117
118 return (0);
119 }
120
121 procfs_root(mp, vpp)
122 struct mount *mp;
123 struct vnode **vpp;
124 {
125 struct pfsnode *pfs;
126 struct vnode *vp;
127 int error;
128
129 error = procfs_allocvp(mp, &vp, (pid_t) 0, Proot);
130 if (error)
131 return (error);
132
133 vp->v_type = VDIR;
134 vp->v_flag = VROOT;
135 pfs = VTOPFS(vp);
136
137 *vpp = vp;
138 return (0);
139 }
140
141 /*
142 */
143 /* ARGSUSED */
144 procfs_start(mp, flags, p)
145 struct mount *mp;
146 int flags;
147 struct proc *p;
148 {
149
150 return (0);
151 }
152
153 /*
154 * Get file system statistics.
155 */
156 procfs_statfs(mp, sbp, p)
157 struct mount *mp;
158 struct statfs *sbp;
159 struct proc *p;
160 {
161 sbp->f_type = MOUNT_PROCFS;
162 sbp->f_bsize = PAGE_SIZE;
163 sbp->f_iosize = PAGE_SIZE;
164 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
165 sbp->f_bfree = 0;
166 sbp->f_bavail = 0;
167 sbp->f_files = maxproc; /* approx */
168 sbp->f_ffree = maxproc - nprocs; /* approx */
169
170 if (sbp != &mp->mnt_stat) {
171 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
172 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
173 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
174 }
175
176 return (0);
177 }
178
179
180 procfs_quotactl(mp, cmds, uid, arg, p)
181 struct mount *mp;
182 int cmds;
183 uid_t uid;
184 caddr_t arg;
185 struct proc *p;
186 {
187
188 return (EOPNOTSUPP);
189 }
190
191 procfs_sync(mp, waitfor)
192 struct mount *mp;
193 int waitfor;
194 {
195
196 return (0);
197 }
198
199 procfs_vget(mp, ino, vpp)
200 struct mount *mp;
201 ino_t ino;
202 struct vnode **vpp;
203 {
204
205 return (EOPNOTSUPP);
206 }
207
208 procfs_fhtovp(mp, fhp, vpp)
209 struct mount *mp;
210 struct fid *fhp;
211 struct vnode **vpp;
212 {
213
214 return (EINVAL);
215 }
216
217 procfs_vptofh(vp, fhp)
218 struct vnode *vp;
219 struct fid *fhp;
220 {
221
222 return EINVAL;
223 }
224
225 procfs_init()
226 {
227
228 return (0);
229 }
230
231 struct vfsops procfs_vfsops = {
232 procfs_mount,
233 procfs_start,
234 procfs_unmount,
235 procfs_root,
236 procfs_quotactl,
237 procfs_statfs,
238 procfs_sync,
239 procfs_vget,
240 procfs_fhtovp,
241 procfs_vptofh,
242 procfs_init,
243 };
244