165524Spendry /* 265524Spendry * Copyright (c) 1993 Jan-Simon Pendry 3*65808Sbostic * Copyright (c) 1993 4*65808Sbostic * 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*65808Sbostic * @(#)procfs_vfsops.c 8.4 (Berkeley) 01/21/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 struct pfsnode *pfs; 10065524Spendry struct vnode *vp; 10165524Spendry int error; 10265524Spendry 10365524Spendry error = procfs_allocvp(mp, &vp, (pid_t) 0, Proot); 10465524Spendry if (error) 10565524Spendry return (error); 10665524Spendry 10765524Spendry vp->v_type = VDIR; 10865524Spendry vp->v_flag = VROOT; 10965524Spendry pfs = VTOPFS(vp); 11065524Spendry 11165524Spendry *vpp = vp; 11265524Spendry return (0); 11365524Spendry } 11465524Spendry 11565524Spendry /* 11665524Spendry */ 11765524Spendry /* ARGSUSED */ 11865524Spendry procfs_start(mp, flags, p) 11965524Spendry struct mount *mp; 12065524Spendry int flags; 12165524Spendry struct proc *p; 12265524Spendry { 12365524Spendry 12465524Spendry return (0); 12565524Spendry } 12665524Spendry 12765524Spendry /* 12865524Spendry * Get file system statistics. 12965524Spendry */ 13065524Spendry procfs_statfs(mp, sbp, p) 13165524Spendry struct mount *mp; 13265524Spendry struct statfs *sbp; 13365524Spendry struct proc *p; 13465524Spendry { 13565524Spendry sbp->f_type = MOUNT_PROCFS; 13665524Spendry sbp->f_bsize = PAGE_SIZE; 13765524Spendry sbp->f_iosize = PAGE_SIZE; 13865524Spendry sbp->f_blocks = 1; /* avoid divide by zero in some df's */ 13965524Spendry sbp->f_bfree = 0; 14065524Spendry sbp->f_bavail = 0; 14165524Spendry sbp->f_files = maxproc; /* approx */ 14265524Spendry sbp->f_ffree = maxproc - nprocs; /* approx */ 14365524Spendry 14465524Spendry if (sbp != &mp->mnt_stat) { 14565524Spendry bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 14665524Spendry bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 14765524Spendry bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 14865524Spendry } 14965524Spendry 15065524Spendry return (0); 15165524Spendry } 15265524Spendry 15365524Spendry 15465524Spendry procfs_quotactl(mp, cmds, uid, arg, p) 15565524Spendry struct mount *mp; 15665524Spendry int cmds; 15765524Spendry uid_t uid; 15865524Spendry caddr_t arg; 15965524Spendry struct proc *p; 16065524Spendry { 16165524Spendry 16265524Spendry return (EOPNOTSUPP); 16365524Spendry } 16465524Spendry 16565524Spendry procfs_sync(mp, waitfor) 16665524Spendry struct mount *mp; 16765524Spendry int waitfor; 16865524Spendry { 16965524Spendry 17065524Spendry return (0); 17165524Spendry } 17265524Spendry 17365524Spendry procfs_vget(mp, ino, vpp) 17465524Spendry struct mount *mp; 17565524Spendry ino_t ino; 17665524Spendry struct vnode **vpp; 17765524Spendry { 17865524Spendry 17965524Spendry return (EOPNOTSUPP); 18065524Spendry } 18165524Spendry 18265524Spendry procfs_fhtovp(mp, fhp, vpp) 18365524Spendry struct mount *mp; 18465524Spendry struct fid *fhp; 18565524Spendry struct vnode **vpp; 18665524Spendry { 18765524Spendry 18865524Spendry return (EINVAL); 18965524Spendry } 19065524Spendry 19165524Spendry procfs_vptofh(vp, fhp) 19265524Spendry struct vnode *vp; 19365524Spendry struct fid *fhp; 19465524Spendry { 19565524Spendry 19665524Spendry return EINVAL; 19765524Spendry } 19865524Spendry 19965524Spendry procfs_init() 20065524Spendry { 20165524Spendry 20265524Spendry return (0); 20365524Spendry } 20465524Spendry 20565524Spendry struct vfsops procfs_vfsops = { 20665524Spendry procfs_mount, 20765524Spendry procfs_start, 20865524Spendry procfs_unmount, 20965524Spendry procfs_root, 21065524Spendry procfs_quotactl, 21165524Spendry procfs_statfs, 21265524Spendry procfs_sync, 21365524Spendry procfs_vget, 21465524Spendry procfs_fhtovp, 21565524Spendry procfs_vptofh, 21665524Spendry procfs_init, 21765524Spendry }; 218