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