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