1 /* 2 * Copyright (c) 1993 Jan-Simon Pendry 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Jan-Simon Pendry. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * from: @(#)procfs_vfsops.c 8.5 (Berkeley) 6/15/94 38 * $Id: procfs_vfsops.c,v 1.17 1994/06/15 22:59:14 mycroft Exp $ 39 */ 40 41 /* 42 * procfs VFS interface 43 */ 44 45 #include <sys/param.h> 46 #include <sys/time.h> 47 #include <sys/kernel.h> 48 #include <sys/proc.h> 49 #include <sys/buf.h> 50 #include <sys/syslog.h> 51 #include <sys/mount.h> 52 #include <sys/signalvar.h> 53 #include <sys/vnode.h> 54 #include <miscfs/procfs/procfs.h> 55 #include <vm/vm.h> /* for PAGE_SIZE */ 56 57 /* 58 * VFS Operations. 59 * 60 * mount system call 61 */ 62 /* ARGSUSED */ 63 procfs_mount(mp, path, data, ndp, p) 64 struct mount *mp; 65 char *path; 66 caddr_t data; 67 struct nameidata *ndp; 68 struct proc *p; 69 { 70 u_int size; 71 72 if (UIO_MX & (UIO_MX-1)) { 73 log(LOG_ERR, "procfs: invalid directory entry size"); 74 return (EINVAL); 75 } 76 77 if (mp->mnt_flag & MNT_UPDATE) 78 return (EOPNOTSUPP); 79 80 mp->mnt_flag |= MNT_LOCAL; 81 mp->mnt_data = 0; 82 getnewfsid(mp, makefstype(MOUNT_PROCFS)); 83 84 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size); 85 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 86 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); 87 bcopy("procfs", mp->mnt_stat.f_mntfromname, sizeof("procfs")); 88 return (0); 89 } 90 91 /* 92 * unmount system call 93 */ 94 procfs_unmount(mp, mntflags, p) 95 struct mount *mp; 96 int mntflags; 97 struct proc *p; 98 { 99 int error; 100 extern int doforce; 101 int flags = 0; 102 103 if (mntflags & MNT_FORCE) { 104 /* procfs can never be rootfs so don't check for it */ 105 if (!doforce) 106 return (EINVAL); 107 flags |= FORCECLOSE; 108 } 109 110 if (error = vflush(mp, 0, flags)) 111 return (error); 112 113 return (0); 114 } 115 116 procfs_root(mp, vpp) 117 struct mount *mp; 118 struct vnode **vpp; 119 { 120 121 return (procfs_allocvp(mp, vpp, 0, Proot)); 122 } 123 124 /* ARGSUSED */ 125 procfs_start(mp, flags, p) 126 struct mount *mp; 127 int flags; 128 struct proc *p; 129 { 130 131 return (0); 132 } 133 134 /* 135 * Get file system statistics. 136 */ 137 procfs_statfs(mp, sbp, p) 138 struct mount *mp; 139 struct statfs *sbp; 140 struct proc *p; 141 { 142 143 #ifdef COMPAT_09 144 sbp->f_type = 10; 145 #else 146 sbp->f_type = 0; 147 #endif 148 sbp->f_bsize = PAGE_SIZE; 149 sbp->f_iosize = PAGE_SIZE; 150 sbp->f_blocks = 1; /* avoid divide by zero in some df's */ 151 sbp->f_bfree = 0; 152 sbp->f_bavail = 0; 153 sbp->f_files = maxproc; /* approx */ 154 sbp->f_ffree = maxproc - nprocs; /* approx */ 155 if (sbp != &mp->mnt_stat) { 156 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); 157 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 158 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 159 } 160 strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN); 161 sbp->f_fstypename[MFSNAMELEN] = '\0'; 162 return (0); 163 } 164 165 procfs_quotactl(mp, cmds, uid, arg, p) 166 struct mount *mp; 167 int cmds; 168 uid_t uid; 169 caddr_t arg; 170 struct proc *p; 171 { 172 173 return (EOPNOTSUPP); 174 } 175 176 procfs_sync(mp, waitfor) 177 struct mount *mp; 178 int waitfor; 179 { 180 181 return (0); 182 } 183 184 procfs_vget(mp, ino, vpp) 185 struct mount *mp; 186 ino_t ino; 187 struct vnode **vpp; 188 { 189 190 return (EOPNOTSUPP); 191 } 192 193 procfs_fhtovp(mp, fhp, vpp) 194 struct mount *mp; 195 struct fid *fhp; 196 struct vnode **vpp; 197 { 198 199 return (EINVAL); 200 } 201 202 procfs_vptofh(vp, fhp) 203 struct vnode *vp; 204 struct fid *fhp; 205 { 206 207 return (EINVAL); 208 } 209 210 procfs_init() 211 { 212 213 return (0); 214 } 215 216 struct vfsops procfs_vfsops = { 217 MOUNT_PROCFS, 218 procfs_mount, 219 procfs_start, 220 procfs_unmount, 221 procfs_root, 222 procfs_quotactl, 223 procfs_statfs, 224 procfs_sync, 225 procfs_vget, 226 procfs_fhtovp, 227 procfs_vptofh, 228 procfs_init, 229 }; 230