procfs_vfsops.c revision 1.9 1 /*
2 * Copyright (c) 1993 The Regents of the University of California.
3 * Copyright (c) 1993 Jan-Simon Pendry
4 * 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 * From:
38 * Id: procfs_vfsops.c,v 4.1 1993/12/17 10:47:45 jsp Rel
39 *
40 * $Id: procfs_vfsops.c,v 1.9 1994/01/05 07:51:31 cgd 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 int error;
74
75 if (UIO_MX & (UIO_MX-1)) {
76 log(LOG_ERR, "procfs: invalid directory entry size");
77 return (EINVAL);
78 }
79
80 if (mp->mnt_flag & MNT_UPDATE)
81 return (EOPNOTSUPP);
82
83 mp->mnt_flag |= MNT_LOCAL;
84 mp->mnt_data = 0;
85 getnewfsid(mp, MOUNT_PROCFS);
86
87 (void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
88 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
89
90 size = sizeof("proc") - 1;
91 bcopy("proc", mp->mnt_stat.f_mntfromname, size);
92 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
93
94 return (0);
95 }
96
97 /*
98 * unmount system call
99 */
100 procfs_unmount(mp, mntflags, p)
101 struct mount *mp;
102 int mntflags;
103 struct proc *p;
104 {
105 int error;
106 extern int doforce;
107 int flags = 0;
108
109 if (mntflags & MNT_FORCE) {
110 /* procfs can never be rootfs so don't check for it */
111 if (!doforce)
112 return (EINVAL);
113 flags |= FORCECLOSE;
114 }
115
116 /*
117 * Clear out buffer cache. I don't think we
118 * ever get anything cached at this level at the
119 * moment, but who knows...
120 */
121 mntflushbuf(mp, 0);
122
123 if (mntinvalbuf(mp, 1))
124 return (EBUSY);
125
126 if (error = vflush(mp, 0, flags))
127 return (error);
128
129 return (0);
130 }
131
132 procfs_root(mp, vpp)
133 struct mount *mp;
134 struct vnode **vpp;
135 {
136 struct pfsnode *pfs;
137 struct vnode *vp;
138 int error;
139
140 error = procfs_allocvp(mp, &vp, (pid_t) 0, Proot);
141 if (error)
142 return (error);
143
144 vp->v_type = VDIR;
145 vp->v_flag = VROOT;
146 pfs = VTOPFS(vp);
147
148 *vpp = vp;
149 return (0);
150 }
151
152 /*
153 */
154 /* ARGSUSED */
155 procfs_start(mp, flags, p)
156 struct mount *mp;
157 int flags;
158 struct proc *p;
159 {
160
161 return (0);
162 }
163
164 /*
165 * Get file system statistics.
166 */
167 procfs_statfs(mp, sbp, p)
168 struct mount *mp;
169 struct statfs *sbp;
170 struct proc *p;
171 {
172 sbp->f_type = MOUNT_PROCFS;
173 sbp->f_fsize = page_size >> 2;
174 sbp->f_bsize = page_size;
175 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
176 sbp->f_bfree = 0;
177 sbp->f_bavail = 0;
178 sbp->f_files = maxproc; /* approx */
179 sbp->f_ffree = maxproc - nprocs; /* approx */
180
181 if (sbp != &mp->mnt_stat) {
182 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
183 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
184 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
185 }
186
187 return (0);
188 }
189
190
191 procfs_quotactl(mp, cmds, uid, arg, p)
192 struct mount *mp;
193 int cmds;
194 uid_t uid;
195 caddr_t arg;
196 struct proc *p;
197 {
198
199 return (EOPNOTSUPP);
200 }
201
202 procfs_sync(mp, waitfor)
203 struct mount *mp;
204 int waitfor;
205 {
206
207 return (0);
208 }
209
210 procfs_fhtovp(mp, fhp, vpp)
211 struct mount *mp;
212 struct fid *fhp;
213 struct vnode **vpp;
214 {
215
216 return (EINVAL);
217 }
218
219 procfs_vptofh(vp, fhp)
220 struct vnode *vp;
221 struct fid *fhp;
222 {
223
224 return EINVAL;
225 }
226
227 procfs_init()
228 {
229
230 return (0);
231 }
232
233 struct vfsops procfs_vfsops = {
234 procfs_mount,
235 procfs_start,
236 procfs_unmount,
237 procfs_root,
238 procfs_quotactl,
239 procfs_statfs,
240 procfs_sync,
241 procfs_fhtovp,
242 procfs_vptofh,
243 procfs_init,
244 };
245