procfs_vfsops.c revision 1.7.2.1 1 /*
2 * Copyright (c) 1993 Paul Kranenburg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Paul Kranenburg.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software withough specific prior written permission
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id: procfs_vfsops.c,v 1.7.2.1 1993/11/14 22:35:05 mycroft Exp $
31 */
32
33 /*
34 * PROCFS VFS interface routines
35 */
36
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/buf.h>
42 #include <sys/mount.h>
43 #include <sys/signalvar.h>
44 #include <sys/vnode.h>
45
46 #include <miscfs/procfs/pfsnode.h>
47
48 extern struct vnodeops pfs_vnodeops;
49
50 /*
51 * mfs vfs operations.
52 */
53 int pfs_mount();
54 int pfs_start();
55 int pfs_unmount();
56 int pfs_root();
57 int pfs_quotactl();
58 int pfs_statfs();
59 int pfs_sync();
60 int pfs_fhtovp();
61 int pfs_vptofh();
62 int pfs_init();
63
64 struct vfsops procfs_vfsops = {
65 pfs_mount,
66 pfs_start,
67 pfs_unmount,
68 pfs_root,
69 pfs_quotactl,
70 pfs_statfs,
71 pfs_sync,
72 pfs_fhtovp,
73 pfs_vptofh,
74 pfs_init,
75 };
76
77 /*
78 * VFS Operations.
79 *
80 * mount system call
81 */
82 /* ARGSUSED */
83 pfs_mount(mp, path, data, ndp, p)
84 register struct mount *mp;
85 char *path;
86 caddr_t data;
87 struct nameidata *ndp;
88 struct proc *p;
89 {
90 #if 0
91 struct pfs_args args;
92 #endif
93 struct vnode *pvp;
94 u_int size;
95 int error;
96
97 if (mp->mnt_flag & MNT_UPDATE) {
98 return (0);
99 }
100
101 #if 0
102 if (error = copyin(data, (caddr_t)&args, sizeof (struct pfs_args)))
103 return (error);
104 #endif
105 (void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
106 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
107
108 size = sizeof("proc") - 1;
109 bcopy("proc", mp->mnt_stat.f_mntfromname, size);
110 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
111
112 (void) pfs_statfs(mp, &mp->mnt_stat, p);
113 return (0);
114 }
115
116 /*
117 * unmount system call
118 */
119 pfs_unmount(mp, mntflags, p)
120 struct mount *mp;
121 int mntflags;
122 struct proc *p;
123 {
124 return (0);
125 }
126
127 pfs_root(mp, vpp)
128 struct mount *mp;
129 struct vnode **vpp;
130 {
131 struct vnode *vp;
132 struct pfsnode *pfsp, **pp;
133 int error;
134
135 /* Look in "cache" first */
136 for (pfsp = pfshead; pfsp != NULL; pfsp = pfsp->pfs_next) {
137 if (pfsp->pfs_vnode->v_flag & VROOT) {
138 *vpp = pfsp->pfs_vnode;
139 vref(*vpp);
140 return 0;
141 }
142 }
143
144 /* Not on list, allocate new vnode */
145 error = getnewvnode(VT_PROCFS, mp, &pfs_vnodeops, &vp);
146 if (error)
147 return error;
148
149 vp->v_type = VDIR;
150 vp->v_flag = VROOT;
151 pfsp = VTOPFS(vp);
152 pfsp->pfs_next = NULL;
153 pfsp->pfs_pid = 0;
154 pfsp->pfs_vnode = vp;
155 pfsp->pfs_flags = 0;
156 pfsp->pfs_vflags = 0;
157 pfsp->pfs_uid = 0;
158 pfsp->pfs_gid = 0;
159 pfsp->pfs_mode = 0755; /* /proc = drwxr-xr-x */
160
161 /* Append to pfs node list */
162 for (pp = &pfshead; *pp; pp = &(*pp)->pfs_next);
163 *pp = pfsp;
164
165 *vpp = vp;
166 return 0;
167 }
168
169 /*
170 */
171 /* ARGSUSED */
172 pfs_start(mp, flags, p)
173 struct mount *mp;
174 int flags;
175 struct proc *p;
176 {
177 return 0;
178 }
179
180 /*
181 * Get file system statistics.
182 */
183 pfs_statfs(mp, sbp, p)
184 struct mount *mp;
185 struct statfs *sbp;
186 struct proc *p;
187 {
188 sbp->f_type = MOUNT_PROCFS;
189 sbp->f_fsize = 0;
190 sbp->f_bsize = 0;
191 sbp->f_blocks = 0;
192 sbp->f_bfree = 0;
193 sbp->f_bavail = 0;
194 sbp->f_files = maxproc + 3;
195 sbp->f_ffree = maxproc - nprocs;
196
197 return 0;
198 }
199
200
201 pfs_quotactl(mp, cmds, uid, arg, p)
202 struct mount *mp;
203 int cmds;
204 uid_t uid;
205 caddr_t arg;
206 struct proc *p;
207 {
208 return EOPNOTSUPP;
209 }
210
211 pfs_sync(mp, waitfor)
212 struct mount *mp;
213 int waitfor;
214 {
215 return 0;
216 }
217
218 pfs_fhtovp(mp, fhp, vpp)
219 register struct mount *mp;
220 struct fid *fhp;
221 struct vnode **vpp;
222 {
223 return EINVAL;
224 }
225
226 pfs_vptofh(vp, fhp)
227 struct vnode *vp;
228 struct fid *fhp;
229 {
230 return EINVAL;
231 }
232
233 pfs_init()
234 {
235 return 0;
236 }
237