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*69339Smckusick * @(#)procfs_vfsops.c 8.7 (Berkeley) 05/10/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> 2268622Smckusick #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; 5968622Smckusick 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 int flags = 0; 8165524Spendry 82*69339Smckusick if (mntflags & MNT_FORCE) 8365524Spendry flags |= FORCECLOSE; 8465524Spendry 8565524Spendry if (error = vflush(mp, 0, flags)) 8665524Spendry return (error); 8765524Spendry 8865524Spendry return (0); 8965524Spendry } 9065524Spendry 9165524Spendry procfs_root(mp, vpp) 9265524Spendry struct mount *mp; 9365524Spendry struct vnode **vpp; 9465524Spendry { 9565524Spendry 9667389Spendry return (procfs_allocvp(mp, vpp, 0, Proot)); 9765524Spendry } 9865524Spendry 9965524Spendry /* ARGSUSED */ 10065524Spendry procfs_start(mp, flags, p) 10165524Spendry struct mount *mp; 10265524Spendry int flags; 10365524Spendry struct proc *p; 10465524Spendry { 10565524Spendry 10665524Spendry return (0); 10765524Spendry } 10865524Spendry 10965524Spendry /* 11065524Spendry * Get file system statistics. 11165524Spendry */ 11265524Spendry procfs_statfs(mp, sbp, p) 11365524Spendry struct mount *mp; 11465524Spendry struct statfs *sbp; 11565524Spendry struct proc *p; 11665524Spendry { 11765524Spendry sbp->f_bsize = PAGE_SIZE; 11865524Spendry sbp->f_iosize = PAGE_SIZE; 11965524Spendry sbp->f_blocks = 1; /* avoid divide by zero in some df's */ 12065524Spendry sbp->f_bfree = 0; 12165524Spendry sbp->f_bavail = 0; 12265524Spendry sbp->f_files = maxproc; /* approx */ 12365524Spendry sbp->f_ffree = maxproc - nprocs; /* approx */ 12465524Spendry 12565524Spendry if (sbp != &mp->mnt_stat) { 12668622Smckusick sbp->f_type = mp->mnt_vfc->vfc_typenum; 12765524Spendry bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 12865524Spendry bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 12965524Spendry bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 13065524Spendry } 13165524Spendry 13265524Spendry return (0); 13365524Spendry } 13465524Spendry 13568622Smckusick procfs_init(vfsp) 13668622Smckusick struct vfsconf *vfsp; 13765524Spendry { 13865524Spendry 13965524Spendry return (0); 14065524Spendry } 14165524Spendry 14268622Smckusick #define procfs_fhtovp ((int (*) __P((struct mount *, struct fid *, \ 14368622Smckusick struct mbuf *, struct vnode **, int *, struct ucred **)))einval) 14468622Smckusick #define procfs_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \ 14568622Smckusick struct proc *)))eopnotsupp) 14668622Smckusick #define procfs_sync ((int (*) __P((struct mount *, int, struct ucred *, \ 14768622Smckusick struct proc *)))nullop) 14868622Smckusick #define procfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \ 14968622Smckusick size_t, struct proc *)))eopnotsupp) 15068622Smckusick #define procfs_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \ 15168622Smckusick eopnotsupp) 15268622Smckusick #define procfs_vptofh ((int (*) __P((struct vnode *, struct fid *)))einval) 15365524Spendry 15465524Spendry struct vfsops procfs_vfsops = { 15565524Spendry procfs_mount, 15665524Spendry procfs_start, 15765524Spendry procfs_unmount, 15865524Spendry procfs_root, 15965524Spendry procfs_quotactl, 16065524Spendry procfs_statfs, 16165524Spendry procfs_sync, 16265524Spendry procfs_vget, 16365524Spendry procfs_fhtovp, 16465524Spendry procfs_vptofh, 16565524Spendry procfs_init, 16668622Smckusick procfs_sysctl, 16765524Spendry }; 168