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