|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ ! 26: /* ! 27: * Copyright (c) 1992, 1993, 1995 ! 28: * The Regents of the University of California. All rights reserved. ! 29: * ! 30: * This code is derived from software donated to Berkeley by ! 31: * Jan-Simon Pendry. ! 32: * ! 33: * Redistribution and use in source and binary forms, with or without ! 34: * modification, are permitted provided that the following conditions ! 35: * are met: ! 36: * 1. Redistributions of source code must retain the above copyright ! 37: * notice, this list of conditions and the following disclaimer. ! 38: * 2. Redistributions in binary form must reproduce the above copyright ! 39: * notice, this list of conditions and the following disclaimer in the ! 40: * documentation and/or other materials provided with the distribution. ! 41: * 3. All advertising materials mentioning features or use of this software ! 42: * must display the following acknowledgement: ! 43: * This product includes software developed by the University of ! 44: * California, Berkeley and its contributors. ! 45: * 4. Neither the name of the University nor the names of its contributors ! 46: * may be used to endorse or promote products derived from this software ! 47: * without specific prior written permission. ! 48: * ! 49: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 50: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 51: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 52: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 53: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 54: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 55: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 56: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 57: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 58: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 59: * SUCH DAMAGE. ! 60: * ! 61: * @(#)fdesc_vfsops.c 8.10 (Berkeley) 5/14/95 ! 62: * ! 63: */ ! 64: ! 65: /* ! 66: * /dev/fd Filesystem ! 67: */ ! 68: ! 69: #include <sys/param.h> ! 70: #include <sys/systm.h> ! 71: #include <sys/time.h> ! 72: #include <sys/types.h> ! 73: #include <sys/proc.h> ! 74: #include <sys/resourcevar.h> ! 75: #include <sys/filedesc.h> ! 76: #include <sys/vnode.h> ! 77: #include <sys/mount.h> ! 78: #include <sys/namei.h> ! 79: #include <sys/malloc.h> ! 80: #include <miscfs/fdesc/fdesc.h> ! 81: ! 82: /* ! 83: * Mount the per-process file descriptors (/dev/fd) ! 84: */ ! 85: int ! 86: fdesc_mount(mp, path, data, ndp, p) ! 87: struct mount *mp; ! 88: char *path; ! 89: caddr_t data; ! 90: struct nameidata *ndp; ! 91: struct proc *p; ! 92: { ! 93: int error = 0; ! 94: u_int size; ! 95: struct fdescmount *fmp; ! 96: struct vnode *rvp; ! 97: ! 98: /* ! 99: * Update is a no-op ! 100: */ ! 101: if (mp->mnt_flag & MNT_UPDATE) ! 102: return (EOPNOTSUPP); ! 103: ! 104: error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp); ! 105: if (error) ! 106: return (error); ! 107: ! 108: MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount), ! 109: M_UFSMNT, M_WAITOK); /* XXX */ ! 110: rvp->v_type = VDIR; ! 111: rvp->v_flag |= VROOT; ! 112: fmp->f_root = rvp; ! 113: /* XXX -- don't mark as local to work around fts() problems */ ! 114: /*mp->mnt_flag |= MNT_LOCAL;*/ ! 115: mp->mnt_data = (qaddr_t) fmp; ! 116: vfs_getnewfsid(mp); ! 117: ! 118: (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); ! 119: bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); ! 120: bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); ! 121: bcopy("fdesc", mp->mnt_stat.f_mntfromname, sizeof("fdesc")); ! 122: return (0); ! 123: } ! 124: ! 125: int ! 126: fdesc_start(mp, flags, p) ! 127: struct mount *mp; ! 128: int flags; ! 129: struct proc *p; ! 130: { ! 131: return (0); ! 132: } ! 133: ! 134: int ! 135: fdesc_unmount(mp, mntflags, p) ! 136: struct mount *mp; ! 137: int mntflags; ! 138: struct proc *p; ! 139: { ! 140: int error; ! 141: int flags = 0; ! 142: struct vnode *rootvp = VFSTOFDESC(mp)->f_root; ! 143: ! 144: if (mntflags & MNT_FORCE) ! 145: flags |= FORCECLOSE; ! 146: ! 147: /* ! 148: * Clear out buffer cache. I don't think we ! 149: * ever get anything cached at this level at the ! 150: * moment, but who knows... ! 151: */ ! 152: if (rootvp->v_usecount > 1) ! 153: return (EBUSY); ! 154: if (error = vflush(mp, rootvp, flags)) ! 155: return (error); ! 156: ! 157: /* ! 158: * Release reference on underlying root vnode ! 159: */ ! 160: vrele(rootvp); ! 161: /* ! 162: * And blow it away for future re-use ! 163: */ ! 164: vgone(rootvp); ! 165: /* ! 166: * Finally, throw away the fdescmount structure ! 167: */ ! 168: _FREE(mp->mnt_data, M_UFSMNT); /* XXX */ ! 169: mp->mnt_data = 0; ! 170: ! 171: return (0); ! 172: } ! 173: ! 174: int ! 175: fdesc_root(mp, vpp) ! 176: struct mount *mp; ! 177: struct vnode **vpp; ! 178: { ! 179: struct proc *p = current_proc(); /* XXX */ ! 180: struct vnode *vp; ! 181: ! 182: /* ! 183: * Return locked reference to root. ! 184: */ ! 185: vp = VFSTOFDESC(mp)->f_root; ! 186: VREF(vp); ! 187: vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); ! 188: *vpp = vp; ! 189: return (0); ! 190: } ! 191: ! 192: int ! 193: fdesc_statfs(mp, sbp, p) ! 194: struct mount *mp; ! 195: struct statfs *sbp; ! 196: struct proc *p; ! 197: { ! 198: struct filedesc *fdp; ! 199: int lim; ! 200: int i; ! 201: int last; ! 202: int freefd; ! 203: ! 204: /* ! 205: * Compute number of free file descriptors. ! 206: * [ Strange results will ensue if the open file ! 207: * limit is ever reduced below the current number ! 208: * of open files... ] ! 209: */ ! 210: lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur; ! 211: fdp = p->p_fd; ! 212: last = min(fdp->fd_nfiles, lim); ! 213: freefd = 0; ! 214: for (i = fdp->fd_freefile; i < last; i++) ! 215: if (fdp->fd_ofiles[i] == NULL && ! 216: !(fdp->fd_ofileflags[i] & UF_RESERVED)) ! 217: freefd++; ! 218: ! 219: /* ! 220: * Adjust for the fact that the fdesc array may not ! 221: * have been fully allocated yet. ! 222: */ ! 223: if (fdp->fd_nfiles < lim) ! 224: freefd += (lim - fdp->fd_nfiles); ! 225: ! 226: sbp->f_flags = 0; ! 227: sbp->f_bsize = DEV_BSIZE; ! 228: sbp->f_iosize = DEV_BSIZE; ! 229: sbp->f_blocks = 2; /* 1K to keep df happy */ ! 230: sbp->f_bfree = 0; ! 231: sbp->f_bavail = 0; ! 232: sbp->f_files = lim + 1; /* Allow for "." */ ! 233: sbp->f_ffree = freefd; /* See comments above */ ! 234: if (sbp != &mp->mnt_stat) { ! 235: sbp->f_type = mp->mnt_vfc->vfc_typenum; ! 236: bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); ! 237: bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); ! 238: bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); ! 239: } ! 240: return (0); ! 241: } ! 242: ! 243: int ! 244: fdesc_sync(mp, waitfor) ! 245: struct mount *mp; ! 246: int waitfor; ! 247: { ! 248: ! 249: return (0); ! 250: } ! 251: ! 252: #define fdesc_fhtovp ((int (*) __P((struct mount *, struct fid *, \ ! 253: struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp) ! 254: #define fdesc_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \ ! 255: struct proc *)))eopnotsupp) ! 256: #define fdesc_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \ ! 257: size_t, struct proc *)))eopnotsupp) ! 258: #define fdesc_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \ ! 259: eopnotsupp) ! 260: #define fdesc_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp) ! 261: ! 262: struct vfsops fdesc_vfsops = { ! 263: fdesc_mount, ! 264: fdesc_start, ! 265: fdesc_unmount, ! 266: fdesc_root, ! 267: fdesc_quotactl, ! 268: fdesc_statfs, ! 269: fdesc_sync, ! 270: fdesc_vget, ! 271: fdesc_fhtovp, ! 272: fdesc_vptofh, ! 273: fdesc_init, ! 274: fdesc_sysctl, ! 275: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.