xref: /netbsd-src/sys/miscfs/procfs/procfs_vfsops.c (revision 8f62c773e89467c252bb590cb1fe34e1a3c8530e)
1 /*	$NetBSD: procfs_vfsops.c,v 1.24 1995/06/18 14:47:39 cgd 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 	size_t 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, mp->mnt_op->vfs_name, MFSNAMELEN);
162 	return (0);
163 }
164 
165 procfs_quotactl(mp, cmds, uid, arg, p)
166 	struct mount *mp;
167 	int cmds;
168 	uid_t uid;
169 	caddr_t arg;
170 	struct proc *p;
171 {
172 
173 	return (EOPNOTSUPP);
174 }
175 
176 procfs_sync(mp, waitfor)
177 	struct mount *mp;
178 	int waitfor;
179 {
180 
181 	return (0);
182 }
183 
184 procfs_vget(mp, ino, vpp)
185 	struct mount *mp;
186 	ino_t ino;
187 	struct vnode **vpp;
188 {
189 
190 	return (EOPNOTSUPP);
191 }
192 
193 procfs_fhtovp(mp, fhp, vpp)
194 	struct mount *mp;
195 	struct fid *fhp;
196 	struct vnode **vpp;
197 {
198 
199 	return (EINVAL);
200 }
201 
202 procfs_vptofh(vp, fhp)
203 	struct vnode *vp;
204 	struct fid *fhp;
205 {
206 
207 	return (EINVAL);
208 }
209 
210 procfs_init()
211 {
212 
213 	return (0);
214 }
215 
216 struct vfsops procfs_vfsops = {
217 	MOUNT_PROCFS,
218 	procfs_mount,
219 	procfs_start,
220 	procfs_unmount,
221 	procfs_root,
222 	procfs_quotactl,
223 	procfs_statfs,
224 	procfs_sync,
225 	procfs_vget,
226 	procfs_fhtovp,
227 	procfs_vptofh,
228 	procfs_init,
229 };
230