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  * %sccs.include.redist.c%
10  *
11  *	@(#)procfs_vfsops.c	8.4 (Berkeley) 01/21/94
12  *
13  * From:
14  *	$Id: procfs_vfsops.c,v 3.1 1993/12/15 09:40:17 jsp Exp $
15  */
16 
17 /*
18  * procfs VFS interface
19  */
20 
21 #include <sys/param.h>
22 #include <sys/time.h>
23 #include <sys/kernel.h>
24 #include <sys/proc.h>
25 #include <sys/buf.h>
26 #include <sys/syslog.h>
27 #include <sys/mount.h>
28 #include <sys/signalvar.h>
29 #include <sys/vnode.h>
30 #include <miscfs/procfs/procfs.h>
31 #include <vm/vm.h>			/* for PAGE_SIZE */
32 
33 /*
34  * VFS Operations.
35  *
36  * mount system call
37  */
38 /* ARGSUSED */
39 procfs_mount(mp, path, data, ndp, p)
40 	struct mount *mp;
41 	char *path;
42 	caddr_t data;
43 	struct nameidata *ndp;
44 	struct proc *p;
45 {
46 	u_int size;
47 
48 	if (UIO_MX & (UIO_MX-1)) {
49 		log(LOG_ERR, "procfs: invalid directory entry size");
50 		return (EINVAL);
51 	}
52 
53 	if (mp->mnt_flag & MNT_UPDATE)
54 		return (EOPNOTSUPP);
55 
56 	mp->mnt_flag |= MNT_LOCAL;
57 	mp->mnt_data = 0;
58 	getnewfsid(mp, MOUNT_PROCFS);
59 
60 	(void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
61 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
62 
63 	size = sizeof("procfs") - 1;
64 	bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
65 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
66 
67 	return (0);
68 }
69 
70 /*
71  * unmount system call
72  */
73 procfs_unmount(mp, mntflags, p)
74 	struct mount *mp;
75 	int mntflags;
76 	struct proc *p;
77 {
78 	int error;
79 	extern int doforce;
80 	int flags = 0;
81 
82 	if (mntflags & MNT_FORCE) {
83 		/* procfs can never be rootfs so don't check for it */
84 		if (!doforce)
85 			return (EINVAL);
86 		flags |= FORCECLOSE;
87 	}
88 
89 	if (error = vflush(mp, 0, flags))
90 		return (error);
91 
92 	return (0);
93 }
94 
95 procfs_root(mp, vpp)
96 	struct mount *mp;
97 	struct vnode **vpp;
98 {
99 	struct pfsnode *pfs;
100 	struct vnode *vp;
101 	int error;
102 
103 	error = procfs_allocvp(mp, &vp, (pid_t) 0, Proot);
104 	if (error)
105 		return (error);
106 
107 	vp->v_type = VDIR;
108 	vp->v_flag = VROOT;
109 	pfs = VTOPFS(vp);
110 
111 	*vpp = vp;
112 	return (0);
113 }
114 
115 /*
116  */
117 /* ARGSUSED */
118 procfs_start(mp, flags, p)
119 	struct mount *mp;
120 	int flags;
121 	struct proc *p;
122 {
123 
124 	return (0);
125 }
126 
127 /*
128  * Get file system statistics.
129  */
130 procfs_statfs(mp, sbp, p)
131 	struct mount *mp;
132 	struct statfs *sbp;
133 	struct proc *p;
134 {
135 	sbp->f_type = MOUNT_PROCFS;
136 	sbp->f_bsize = PAGE_SIZE;
137 	sbp->f_iosize = PAGE_SIZE;
138 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
139 	sbp->f_bfree = 0;
140 	sbp->f_bavail = 0;
141 	sbp->f_files = maxproc;			/* approx */
142 	sbp->f_ffree = maxproc - nprocs;	/* approx */
143 
144 	if (sbp != &mp->mnt_stat) {
145 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
146 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
147 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
148 	}
149 
150 	return (0);
151 }
152 
153 
154 procfs_quotactl(mp, cmds, uid, arg, p)
155 	struct mount *mp;
156 	int cmds;
157 	uid_t uid;
158 	caddr_t arg;
159 	struct proc *p;
160 {
161 
162 	return (EOPNOTSUPP);
163 }
164 
165 procfs_sync(mp, waitfor)
166 	struct mount *mp;
167 	int waitfor;
168 {
169 
170 	return (0);
171 }
172 
173 procfs_vget(mp, ino, vpp)
174 	struct mount *mp;
175 	ino_t ino;
176 	struct vnode **vpp;
177 {
178 
179 	return (EOPNOTSUPP);
180 }
181 
182 procfs_fhtovp(mp, fhp, vpp)
183 	struct mount *mp;
184 	struct fid *fhp;
185 	struct vnode **vpp;
186 {
187 
188 	return (EINVAL);
189 }
190 
191 procfs_vptofh(vp, fhp)
192 	struct vnode *vp;
193 	struct fid *fhp;
194 {
195 
196 	return EINVAL;
197 }
198 
199 procfs_init()
200 {
201 
202 	return (0);
203 }
204 
205 struct vfsops procfs_vfsops = {
206 	procfs_mount,
207 	procfs_start,
208 	procfs_unmount,
209 	procfs_root,
210 	procfs_quotactl,
211 	procfs_statfs,
212 	procfs_sync,
213 	procfs_vget,
214 	procfs_fhtovp,
215 	procfs_vptofh,
216 	procfs_init,
217 };
218