1 /* $NetBSD: procfs_vfsops.c,v 1.50 2003/09/27 13:29:02 darcy Exp $ */ 2 3 /* 4 * Copyright (c) 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Jan-Simon Pendry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95 35 */ 36 37 /* 38 * Copyright (c) 1993 Jan-Simon Pendry 39 * 40 * This code is derived from software contributed to Berkeley by 41 * Jan-Simon Pendry. 42 * 43 * Redistribution and use in source and binary forms, with or without 44 * modification, are permitted provided that the following conditions 45 * are met: 46 * 1. Redistributions of source code must retain the above copyright 47 * notice, this list of conditions and the following disclaimer. 48 * 2. Redistributions in binary form must reproduce the above copyright 49 * notice, this list of conditions and the following disclaimer in the 50 * documentation and/or other materials provided with the distribution. 51 * 3. All advertising materials mentioning features or use of this software 52 * must display the following acknowledgement: 53 * This product includes software developed by the University of 54 * California, Berkeley and its contributors. 55 * 4. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95 72 */ 73 74 /* 75 * procfs VFS interface 76 */ 77 78 #include <sys/cdefs.h> 79 __KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.50 2003/09/27 13:29:02 darcy Exp $"); 80 81 #if defined(_KERNEL_OPT) 82 #include "opt_compat_netbsd.h" 83 #endif 84 85 #include <sys/param.h> 86 #include <sys/time.h> 87 #include <sys/kernel.h> 88 #include <sys/systm.h> 89 #include <sys/proc.h> 90 #include <sys/buf.h> 91 #include <sys/syslog.h> 92 #include <sys/mount.h> 93 #include <sys/signalvar.h> 94 #include <sys/vnode.h> 95 #include <sys/malloc.h> 96 97 #include <miscfs/procfs/procfs.h> 98 99 #include <uvm/uvm_extern.h> /* for PAGE_SIZE */ 100 101 void procfs_init __P((void)); 102 void procfs_reinit __P((void)); 103 void procfs_done __P((void)); 104 int procfs_mount __P((struct mount *, const char *, void *, 105 struct nameidata *, struct proc *)); 106 int procfs_start __P((struct mount *, int, struct proc *)); 107 int procfs_unmount __P((struct mount *, int, struct proc *)); 108 int procfs_quotactl __P((struct mount *, int, uid_t, caddr_t, 109 struct proc *)); 110 int procfs_statfs __P((struct mount *, struct statfs *, struct proc *)); 111 int procfs_sync __P((struct mount *, int, struct ucred *, struct proc *)); 112 int procfs_vget __P((struct mount *, ino_t, struct vnode **)); 113 int procfs_fhtovp __P((struct mount *, struct fid *, struct vnode **)); 114 int procfs_checkexp __P((struct mount *, struct mbuf *, int *, 115 struct ucred **)); 116 int procfs_vptofh __P((struct vnode *, struct fid *)); 117 int procfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t, 118 struct proc *)); 119 /* 120 * VFS Operations. 121 * 122 * mount system call 123 */ 124 /* ARGSUSED */ 125 int 126 procfs_mount(mp, path, data, ndp, p) 127 struct mount *mp; 128 const char *path; 129 void *data; 130 struct nameidata *ndp; 131 struct proc *p; 132 { 133 struct procfsmount *pmnt; 134 struct procfs_args args; 135 int error; 136 137 if (UIO_MX & (UIO_MX-1)) { 138 log(LOG_ERR, "procfs: invalid directory entry size"); 139 return (EINVAL); 140 } 141 142 if (mp->mnt_flag & MNT_GETARGS) { 143 pmnt = VFSTOPROC(mp); 144 if (pmnt == NULL) 145 return EIO; 146 args.version = PROCFS_ARGSVERSION; 147 args.flags = pmnt->pmnt_flags; 148 return copyout(&args, data, sizeof(args)); 149 } 150 151 if (mp->mnt_flag & MNT_UPDATE) 152 return (EOPNOTSUPP); 153 154 if (data != NULL) { 155 error = copyin(data, &args, sizeof args); 156 if (error != 0) 157 return error; 158 159 if (args.version != PROCFS_ARGSVERSION) 160 return EINVAL; 161 } else 162 args.flags = 0; 163 164 mp->mnt_flag |= MNT_LOCAL; 165 pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount), 166 M_UFSMNT, M_WAITOK); /* XXX need new malloc type */ 167 168 mp->mnt_data = pmnt; 169 vfs_getnewfsid(mp); 170 171 error = set_statfs_info(path, UIO_USERSPACE, "procfs", UIO_SYSSPACE, 172 mp, p); 173 pmnt->pmnt_exechook = exechook_establish(procfs_revoke_vnodes, mp); 174 pmnt->pmnt_flags = args.flags; 175 176 return error; 177 } 178 179 /* 180 * unmount system call 181 */ 182 int 183 procfs_unmount(mp, mntflags, p) 184 struct mount *mp; 185 int mntflags; 186 struct proc *p; 187 { 188 int error; 189 int flags = 0; 190 191 if (mntflags & MNT_FORCE) 192 flags |= FORCECLOSE; 193 194 if ((error = vflush(mp, 0, flags)) != 0) 195 return (error); 196 197 exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook); 198 199 free(mp->mnt_data, M_UFSMNT); 200 mp->mnt_data = 0; 201 202 return (0); 203 } 204 205 int 206 procfs_root(mp, vpp) 207 struct mount *mp; 208 struct vnode **vpp; 209 { 210 211 return (procfs_allocvp(mp, vpp, 0, PFSroot, -1)); 212 } 213 214 /* ARGSUSED */ 215 int 216 procfs_start(mp, flags, p) 217 struct mount *mp; 218 int flags; 219 struct proc *p; 220 { 221 222 return (0); 223 } 224 225 /* 226 * Get file system statistics. 227 */ 228 int 229 procfs_statfs(mp, sbp, p) 230 struct mount *mp; 231 struct statfs *sbp; 232 struct proc *p; 233 { 234 235 sbp->f_bsize = PAGE_SIZE; 236 sbp->f_iosize = PAGE_SIZE; 237 sbp->f_blocks = 1; /* avoid divide by zero in some df's */ 238 sbp->f_bfree = 0; 239 sbp->f_bavail = 0; 240 sbp->f_files = maxproc; /* approx */ 241 sbp->f_ffree = maxproc - nprocs; /* approx */ 242 #ifdef COMPAT_09 243 sbp->f_type = 10; 244 #else 245 sbp->f_type = 0; 246 #endif 247 copy_statfs_info(sbp, mp); 248 return (0); 249 } 250 251 /*ARGSUSED*/ 252 int 253 procfs_quotactl(mp, cmds, uid, arg, p) 254 struct mount *mp; 255 int cmds; 256 uid_t uid; 257 caddr_t arg; 258 struct proc *p; 259 { 260 261 return (EOPNOTSUPP); 262 } 263 264 /*ARGSUSED*/ 265 int 266 procfs_sync(mp, waitfor, uc, p) 267 struct mount *mp; 268 int waitfor; 269 struct ucred *uc; 270 struct proc *p; 271 { 272 273 return (0); 274 } 275 276 /*ARGSUSED*/ 277 int 278 procfs_vget(mp, ino, vpp) 279 struct mount *mp; 280 ino_t ino; 281 struct vnode **vpp; 282 { 283 return (EOPNOTSUPP); 284 } 285 286 /*ARGSUSED*/ 287 int 288 procfs_fhtovp(mp, fhp, vpp) 289 struct mount *mp; 290 struct fid *fhp; 291 struct vnode **vpp; 292 { 293 294 return (EINVAL); 295 } 296 297 /*ARGSUSED*/ 298 int 299 procfs_checkexp(mp, mb, what, anon) 300 struct mount *mp; 301 struct mbuf *mb; 302 int *what; 303 struct ucred **anon; 304 { 305 306 return (EINVAL); 307 } 308 309 /*ARGSUSED*/ 310 int 311 procfs_vptofh(vp, fhp) 312 struct vnode *vp; 313 struct fid *fhp; 314 { 315 316 return (EINVAL); 317 } 318 319 void 320 procfs_init() 321 { 322 procfs_hashinit(); 323 } 324 325 void 326 procfs_reinit() 327 { 328 procfs_hashreinit(); 329 } 330 331 void 332 procfs_done() 333 { 334 procfs_hashdone(); 335 } 336 337 int 338 procfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 339 int *name; 340 u_int namelen; 341 void *oldp; 342 size_t *oldlenp; 343 void *newp; 344 size_t newlen; 345 struct proc *p; 346 { 347 return (EOPNOTSUPP); 348 } 349 350 extern const struct vnodeopv_desc procfs_vnodeop_opv_desc; 351 352 const struct vnodeopv_desc * const procfs_vnodeopv_descs[] = { 353 &procfs_vnodeop_opv_desc, 354 NULL, 355 }; 356 357 struct vfsops procfs_vfsops = { 358 MOUNT_PROCFS, 359 procfs_mount, 360 procfs_start, 361 procfs_unmount, 362 procfs_root, 363 procfs_quotactl, 364 procfs_statfs, 365 procfs_sync, 366 procfs_vget, 367 procfs_fhtovp, 368 procfs_vptofh, 369 procfs_init, 370 procfs_reinit, 371 procfs_done, 372 procfs_sysctl, 373 NULL, /* vfs_mountroot */ 374 procfs_checkexp, 375 procfs_vnodeopv_descs, 376 }; 377