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*68622Smckusick  *	@(#)procfs_vfsops.c	8.6 (Berkeley) 03/29/95
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>
22*68622Smckusick #include <sys/systm.h>
2365524Spendry #include <sys/time.h>
2465524Spendry #include <sys/kernel.h>
2565524Spendry #include <sys/proc.h>
2665524Spendry #include <sys/buf.h>
2765524Spendry #include <sys/syslog.h>
2865524Spendry #include <sys/mount.h>
2965524Spendry #include <sys/signalvar.h>
3065524Spendry #include <sys/vnode.h>
3165524Spendry #include <miscfs/procfs/procfs.h>
3265524Spendry #include <vm/vm.h>			/* for PAGE_SIZE */
3365524Spendry 
3465524Spendry /*
3565524Spendry  * VFS Operations.
3665524Spendry  *
3765524Spendry  * mount system call
3865524Spendry  */
3965524Spendry /* ARGSUSED */
4065524Spendry procfs_mount(mp, path, data, ndp, p)
4165524Spendry 	struct mount *mp;
4265524Spendry 	char *path;
4365524Spendry 	caddr_t data;
4465524Spendry 	struct nameidata *ndp;
4565524Spendry 	struct proc *p;
4665524Spendry {
4765524Spendry 	u_int size;
4865524Spendry 
4965524Spendry 	if (UIO_MX & (UIO_MX-1)) {
5065524Spendry 		log(LOG_ERR, "procfs: invalid directory entry size");
5165524Spendry 		return (EINVAL);
5265524Spendry 	}
5365524Spendry 
5465524Spendry 	if (mp->mnt_flag & MNT_UPDATE)
5565524Spendry 		return (EOPNOTSUPP);
5665524Spendry 
5765524Spendry 	mp->mnt_flag |= MNT_LOCAL;
5865524Spendry 	mp->mnt_data = 0;
59*68622Smckusick 	vfs_getnewfsid(mp);
6065524Spendry 
6165524Spendry 	(void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
6265524Spendry 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
6365524Spendry 
6465542Spendry 	size = sizeof("procfs") - 1;
6565542Spendry 	bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
6665524Spendry 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
6765524Spendry 
6865524Spendry 	return (0);
6965524Spendry }
7065524Spendry 
7165524Spendry /*
7265524Spendry  * unmount system call
7365524Spendry  */
7465524Spendry procfs_unmount(mp, mntflags, p)
7565524Spendry 	struct mount *mp;
7665524Spendry 	int mntflags;
7765524Spendry 	struct proc *p;
7865524Spendry {
7965524Spendry 	int error;
8065524Spendry 	extern int doforce;
8165524Spendry 	int flags = 0;
8265524Spendry 
8365524Spendry 	if (mntflags & MNT_FORCE) {
8465524Spendry 		/* procfs can never be rootfs so don't check for it */
8565524Spendry 		if (!doforce)
8665524Spendry 			return (EINVAL);
8765524Spendry 		flags |= FORCECLOSE;
8865524Spendry 	}
8965524Spendry 
9065524Spendry 	if (error = vflush(mp, 0, flags))
9165524Spendry 		return (error);
9265524Spendry 
9365524Spendry 	return (0);
9465524Spendry }
9565524Spendry 
9665524Spendry procfs_root(mp, vpp)
9765524Spendry 	struct mount *mp;
9865524Spendry 	struct vnode **vpp;
9965524Spendry {
10065524Spendry 
10167389Spendry 	return (procfs_allocvp(mp, vpp, 0, Proot));
10265524Spendry }
10365524Spendry 
10465524Spendry /* ARGSUSED */
10565524Spendry procfs_start(mp, flags, p)
10665524Spendry 	struct mount *mp;
10765524Spendry 	int flags;
10865524Spendry 	struct proc *p;
10965524Spendry {
11065524Spendry 
11165524Spendry 	return (0);
11265524Spendry }
11365524Spendry 
11465524Spendry /*
11565524Spendry  * Get file system statistics.
11665524Spendry  */
11765524Spendry procfs_statfs(mp, sbp, p)
11865524Spendry 	struct mount *mp;
11965524Spendry 	struct statfs *sbp;
12065524Spendry 	struct proc *p;
12165524Spendry {
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) {
131*68622Smckusick 		sbp->f_type = mp->mnt_vfc->vfc_typenum;
13265524Spendry 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
13365524Spendry 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
13465524Spendry 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
13565524Spendry 	}
13665524Spendry 
13765524Spendry 	return (0);
13865524Spendry }
13965524Spendry 
140*68622Smckusick procfs_init(vfsp)
141*68622Smckusick 	struct vfsconf *vfsp;
14265524Spendry {
14365524Spendry 
14465524Spendry 	return (0);
14565524Spendry }
14665524Spendry 
147*68622Smckusick #define procfs_fhtovp ((int (*) __P((struct mount *, struct fid *, \
148*68622Smckusick 	    struct mbuf *, struct vnode **, int *, struct ucred **)))einval)
149*68622Smckusick #define procfs_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
150*68622Smckusick 	    struct proc *)))eopnotsupp)
151*68622Smckusick #define procfs_sync ((int (*) __P((struct mount *, int, struct ucred *, \
152*68622Smckusick 	    struct proc *)))nullop)
153*68622Smckusick #define procfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
154*68622Smckusick 	    size_t, struct proc *)))eopnotsupp)
155*68622Smckusick #define procfs_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
156*68622Smckusick 	    eopnotsupp)
157*68622Smckusick #define procfs_vptofh ((int (*) __P((struct vnode *, struct fid *)))einval)
15865524Spendry 
15965524Spendry struct vfsops procfs_vfsops = {
16065524Spendry 	procfs_mount,
16165524Spendry 	procfs_start,
16265524Spendry 	procfs_unmount,
16365524Spendry 	procfs_root,
16465524Spendry 	procfs_quotactl,
16565524Spendry 	procfs_statfs,
16665524Spendry 	procfs_sync,
16765524Spendry 	procfs_vget,
16865524Spendry 	procfs_fhtovp,
16965524Spendry 	procfs_vptofh,
17065524Spendry 	procfs_init,
171*68622Smckusick 	procfs_sysctl,
17265524Spendry };
173