165524Spendry /*
265524Spendry  * Copyright (c) 1993 Jan-Simon Pendry
365808Sbostic  * Copyright (c) 1993
465808Sbostic  *	The Regents of the University of California.  All rights reserved.
565524Spendry  *
665524Spendry  * This code is derived from software contributed to Berkeley by
765524Spendry  * Jan-Simon Pendry.
865524Spendry  *
965524Spendry  * %sccs.include.redist.c%
1065524Spendry  *
11*67389Spendry  *	@(#)procfs_vfsops.c	8.5 (Berkeley) 06/15/94
1265524Spendry  *
1365524Spendry  * From:
1465524Spendry  *	$Id: procfs_vfsops.c,v 3.1 1993/12/15 09:40:17 jsp Exp $
1565524Spendry  */
1665524Spendry 
1765524Spendry /*
1865524Spendry  * procfs VFS interface
1965524Spendry  */
2065524Spendry 
2165524Spendry #include <sys/param.h>
2265524Spendry #include <sys/time.h>
2365524Spendry #include <sys/kernel.h>
2465524Spendry #include <sys/proc.h>
2565524Spendry #include <sys/buf.h>
2665524Spendry #include <sys/syslog.h>
2765524Spendry #include <sys/mount.h>
2865524Spendry #include <sys/signalvar.h>
2965524Spendry #include <sys/vnode.h>
3065524Spendry #include <miscfs/procfs/procfs.h>
3165524Spendry #include <vm/vm.h>			/* for PAGE_SIZE */
3265524Spendry 
3365524Spendry /*
3465524Spendry  * VFS Operations.
3565524Spendry  *
3665524Spendry  * mount system call
3765524Spendry  */
3865524Spendry /* ARGSUSED */
3965524Spendry procfs_mount(mp, path, data, ndp, p)
4065524Spendry 	struct mount *mp;
4165524Spendry 	char *path;
4265524Spendry 	caddr_t data;
4365524Spendry 	struct nameidata *ndp;
4465524Spendry 	struct proc *p;
4565524Spendry {
4665524Spendry 	u_int size;
4765524Spendry 
4865524Spendry 	if (UIO_MX & (UIO_MX-1)) {
4965524Spendry 		log(LOG_ERR, "procfs: invalid directory entry size");
5065524Spendry 		return (EINVAL);
5165524Spendry 	}
5265524Spendry 
5365524Spendry 	if (mp->mnt_flag & MNT_UPDATE)
5465524Spendry 		return (EOPNOTSUPP);
5565524Spendry 
5665524Spendry 	mp->mnt_flag |= MNT_LOCAL;
5765524Spendry 	mp->mnt_data = 0;
5865524Spendry 	getnewfsid(mp, MOUNT_PROCFS);
5965524Spendry 
6065524Spendry 	(void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
6165524Spendry 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
6265524Spendry 
6365542Spendry 	size = sizeof("procfs") - 1;
6465542Spendry 	bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
6565524Spendry 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
6665524Spendry 
6765524Spendry 	return (0);
6865524Spendry }
6965524Spendry 
7065524Spendry /*
7165524Spendry  * unmount system call
7265524Spendry  */
7365524Spendry procfs_unmount(mp, mntflags, p)
7465524Spendry 	struct mount *mp;
7565524Spendry 	int mntflags;
7665524Spendry 	struct proc *p;
7765524Spendry {
7865524Spendry 	int error;
7965524Spendry 	extern int doforce;
8065524Spendry 	int flags = 0;
8165524Spendry 
8265524Spendry 	if (mntflags & MNT_FORCE) {
8365524Spendry 		/* procfs can never be rootfs so don't check for it */
8465524Spendry 		if (!doforce)
8565524Spendry 			return (EINVAL);
8665524Spendry 		flags |= FORCECLOSE;
8765524Spendry 	}
8865524Spendry 
8965524Spendry 	if (error = vflush(mp, 0, flags))
9065524Spendry 		return (error);
9165524Spendry 
9265524Spendry 	return (0);
9365524Spendry }
9465524Spendry 
9565524Spendry procfs_root(mp, vpp)
9665524Spendry 	struct mount *mp;
9765524Spendry 	struct vnode **vpp;
9865524Spendry {
9965524Spendry 
100*67389Spendry 	return (procfs_allocvp(mp, vpp, 0, Proot));
10165524Spendry }
10265524Spendry 
10365524Spendry /* ARGSUSED */
10465524Spendry procfs_start(mp, flags, p)
10565524Spendry 	struct mount *mp;
10665524Spendry 	int flags;
10765524Spendry 	struct proc *p;
10865524Spendry {
10965524Spendry 
11065524Spendry 	return (0);
11165524Spendry }
11265524Spendry 
11365524Spendry /*
11465524Spendry  * Get file system statistics.
11565524Spendry  */
11665524Spendry procfs_statfs(mp, sbp, p)
11765524Spendry 	struct mount *mp;
11865524Spendry 	struct statfs *sbp;
11965524Spendry 	struct proc *p;
12065524Spendry {
12165524Spendry 	sbp->f_type = MOUNT_PROCFS;
12265524Spendry 	sbp->f_bsize = PAGE_SIZE;
12365524Spendry 	sbp->f_iosize = PAGE_SIZE;
12465524Spendry 	sbp->f_blocks = 1;	/* avoid divide by zero in some df's */
12565524Spendry 	sbp->f_bfree = 0;
12665524Spendry 	sbp->f_bavail = 0;
12765524Spendry 	sbp->f_files = maxproc;			/* approx */
12865524Spendry 	sbp->f_ffree = maxproc - nprocs;	/* approx */
12965524Spendry 
13065524Spendry 	if (sbp != &mp->mnt_stat) {
13165524Spendry 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
13265524Spendry 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
13365524Spendry 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
13465524Spendry 	}
13565524Spendry 
13665524Spendry 	return (0);
13765524Spendry }
13865524Spendry 
13965524Spendry 
14065524Spendry procfs_quotactl(mp, cmds, uid, arg, p)
14165524Spendry 	struct mount *mp;
14265524Spendry 	int cmds;
14365524Spendry 	uid_t uid;
14465524Spendry 	caddr_t arg;
14565524Spendry 	struct proc *p;
14665524Spendry {
14765524Spendry 
14865524Spendry 	return (EOPNOTSUPP);
14965524Spendry }
15065524Spendry 
15165524Spendry procfs_sync(mp, waitfor)
15265524Spendry 	struct mount *mp;
15365524Spendry 	int waitfor;
15465524Spendry {
15565524Spendry 
15665524Spendry 	return (0);
15765524Spendry }
15865524Spendry 
15965524Spendry procfs_vget(mp, ino, vpp)
16065524Spendry 	struct mount *mp;
16165524Spendry 	ino_t ino;
16265524Spendry 	struct vnode **vpp;
16365524Spendry {
16465524Spendry 
16565524Spendry 	return (EOPNOTSUPP);
16665524Spendry }
16765524Spendry 
16865524Spendry procfs_fhtovp(mp, fhp, vpp)
16965524Spendry 	struct mount *mp;
17065524Spendry 	struct fid *fhp;
17165524Spendry 	struct vnode **vpp;
17265524Spendry {
17365524Spendry 
17465524Spendry 	return (EINVAL);
17565524Spendry }
17665524Spendry 
17765524Spendry procfs_vptofh(vp, fhp)
17865524Spendry 	struct vnode *vp;
17965524Spendry 	struct fid *fhp;
18065524Spendry {
18165524Spendry 
18265524Spendry 	return EINVAL;
18365524Spendry }
18465524Spendry 
18565524Spendry procfs_init()
18665524Spendry {
18765524Spendry 
18865524Spendry 	return (0);
18965524Spendry }
19065524Spendry 
19165524Spendry struct vfsops procfs_vfsops = {
19265524Spendry 	procfs_mount,
19365524Spendry 	procfs_start,
19465524Spendry 	procfs_unmount,
19565524Spendry 	procfs_root,
19665524Spendry 	procfs_quotactl,
19765524Spendry 	procfs_statfs,
19865524Spendry 	procfs_sync,
19965524Spendry 	procfs_vget,
20065524Spendry 	procfs_fhtovp,
20165524Spendry 	procfs_vptofh,
20265524Spendry 	procfs_init,
20365524Spendry };
204