1 /* $NetBSD: procfs_vfsops.c,v 1.40 2001/09/15 16:12:59 chs 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_OPT) 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 <sys/malloc.h> 61 62 #include <miscfs/procfs/procfs.h> 63 64 #include <uvm/uvm_extern.h> /* for PAGE_SIZE */ 65 66 void procfs_init __P((void)); 67 void procfs_reinit __P((void)); 68 void procfs_done __P((void)); 69 int procfs_mount __P((struct mount *, const char *, void *, 70 struct nameidata *, struct proc *)); 71 int procfs_start __P((struct mount *, int, struct proc *)); 72 int procfs_unmount __P((struct mount *, int, struct proc *)); 73 int procfs_quotactl __P((struct mount *, int, uid_t, caddr_t, 74 struct proc *)); 75 int procfs_statfs __P((struct mount *, struct statfs *, struct proc *)); 76 int procfs_sync __P((struct mount *, int, struct ucred *, struct proc *)); 77 int procfs_vget __P((struct mount *, ino_t, struct vnode **)); 78 int procfs_fhtovp __P((struct mount *, struct fid *, struct vnode **)); 79 int procfs_checkexp __P((struct mount *, struct mbuf *, int *, 80 struct ucred **)); 81 int procfs_vptofh __P((struct vnode *, struct fid *)); 82 int procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t, 83 struct proc *)); 84 /* 85 * VFS Operations. 86 * 87 * mount system call 88 */ 89 /* ARGSUSED */ 90 int 91 procfs_mount(mp, path, data, ndp, p) 92 struct mount *mp; 93 const char *path; 94 void *data; 95 struct nameidata *ndp; 96 struct proc *p; 97 { 98 size_t size; 99 struct procfsmount *pmnt; 100 struct procfs_args args; 101 int error; 102 103 if (UIO_MX & (UIO_MX-1)) { 104 log(LOG_ERR, "procfs: invalid directory entry size"); 105 return (EINVAL); 106 } 107 108 if (mp->mnt_flag & MNT_UPDATE) 109 return (EOPNOTSUPP); 110 111 if (data != NULL) { 112 error = copyin(data, &args, sizeof args); 113 if (error != 0) 114 return error; 115 116 if (args.version != PROCFS_ARGSVERSION) 117 return EINVAL; 118 } else 119 args.flags = 0; 120 121 mp->mnt_flag |= MNT_LOCAL; 122 pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount), 123 M_UFSMNT, M_WAITOK); /* XXX need new malloc type */ 124 125 mp->mnt_data = (qaddr_t)pmnt; 126 vfs_getnewfsid(mp); 127 128 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN, &size); 129 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size); 130 memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN); 131 memcpy(mp->mnt_stat.f_mntfromname, "procfs", sizeof("procfs")); 132 133 pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp); 134 pmnt->pmnt_flags = args.flags; 135 136 return (0); 137 } 138 139 /* 140 * unmount system call 141 */ 142 int 143 procfs_unmount(mp, mntflags, p) 144 struct mount *mp; 145 int mntflags; 146 struct proc *p; 147 { 148 int error; 149 int flags = 0; 150 151 if (mntflags & MNT_FORCE) 152 flags |= FORCECLOSE; 153 154 if ((error = vflush(mp, 0, flags)) != 0) 155 return (error); 156 157 exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook); 158 159 free(mp->mnt_data, M_UFSMNT); 160 mp->mnt_data = 0; 161 162 return (0); 163 } 164 165 int 166 procfs_root(mp, vpp) 167 struct mount *mp; 168 struct vnode **vpp; 169 { 170 171 return (procfs_allocvp(mp, vpp, 0, Proot)); 172 } 173 174 /* ARGSUSED */ 175 int 176 procfs_start(mp, flags, p) 177 struct mount *mp; 178 int flags; 179 struct proc *p; 180 { 181 182 return (0); 183 } 184 185 /* 186 * Get file system statistics. 187 */ 188 int 189 procfs_statfs(mp, sbp, p) 190 struct mount *mp; 191 struct statfs *sbp; 192 struct proc *p; 193 { 194 195 sbp->f_bsize = PAGE_SIZE; 196 sbp->f_iosize = PAGE_SIZE; 197 sbp->f_blocks = 1; /* avoid divide by zero in some df's */ 198 sbp->f_bfree = 0; 199 sbp->f_bavail = 0; 200 sbp->f_files = maxproc; /* approx */ 201 sbp->f_ffree = maxproc - nprocs; /* approx */ 202 #ifdef COMPAT_09 203 sbp->f_type = 10; 204 #else 205 sbp->f_type = 0; 206 #endif 207 if (sbp != &mp->mnt_stat) { 208 memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid)); 209 memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN); 210 memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN); 211 } 212 strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN); 213 return (0); 214 } 215 216 /*ARGSUSED*/ 217 int 218 procfs_quotactl(mp, cmds, uid, arg, p) 219 struct mount *mp; 220 int cmds; 221 uid_t uid; 222 caddr_t arg; 223 struct proc *p; 224 { 225 226 return (EOPNOTSUPP); 227 } 228 229 /*ARGSUSED*/ 230 int 231 procfs_sync(mp, waitfor, uc, p) 232 struct mount *mp; 233 int waitfor; 234 struct ucred *uc; 235 struct proc *p; 236 { 237 238 return (0); 239 } 240 241 /*ARGSUSED*/ 242 int 243 procfs_vget(mp, ino, vpp) 244 struct mount *mp; 245 ino_t ino; 246 struct vnode **vpp; 247 { 248 249 return (EOPNOTSUPP); 250 } 251 252 /*ARGSUSED*/ 253 int 254 procfs_fhtovp(mp, fhp, vpp) 255 struct mount *mp; 256 struct fid *fhp; 257 struct vnode **vpp; 258 { 259 260 return (EINVAL); 261 } 262 263 /*ARGSUSED*/ 264 int 265 procfs_checkexp(mp, mb, what, anon) 266 struct mount *mp; 267 struct mbuf *mb; 268 int *what; 269 struct ucred **anon; 270 { 271 272 return (EINVAL); 273 } 274 275 /*ARGSUSED*/ 276 int 277 procfs_vptofh(vp, fhp) 278 struct vnode *vp; 279 struct fid *fhp; 280 { 281 282 return (EINVAL); 283 } 284 285 void 286 procfs_init() 287 { 288 procfs_hashinit(); 289 } 290 291 void 292 procfs_reinit() 293 { 294 procfs_hashreinit(); 295 } 296 297 void 298 procfs_done() 299 { 300 procfs_hashdone(); 301 } 302 303 int 304 procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 305 int *name; 306 u_int namelen; 307 void *oldp; 308 size_t *oldlenp; 309 void *newp; 310 size_t newlen; 311 struct proc *p; 312 { 313 return (EOPNOTSUPP); 314 } 315 316 extern const struct vnodeopv_desc procfs_vnodeop_opv_desc; 317 318 const struct vnodeopv_desc * const procfs_vnodeopv_descs[] = { 319 &procfs_vnodeop_opv_desc, 320 NULL, 321 }; 322 323 struct vfsops procfs_vfsops = { 324 MOUNT_PROCFS, 325 procfs_mount, 326 procfs_start, 327 procfs_unmount, 328 procfs_root, 329 procfs_quotactl, 330 procfs_statfs, 331 procfs_sync, 332 procfs_vget, 333 procfs_fhtovp, 334 procfs_vptofh, 335 procfs_init, 336 procfs_reinit, 337 procfs_done, 338 procfs_sysctl, 339 NULL, /* vfs_mountroot */ 340 procfs_checkexp, 341 procfs_vnodeopv_descs, 342 }; 343