|
|
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: /* $NetBSD: kernfs_vfsops.c,v 1.23 1995/03/09 12:05:52 mycroft Exp $ */ ! 26: ! 27: /* ! 28: * Copyright (c) 1992, 1993 ! 29: * The Regents of the University of California. All rights reserved. ! 30: * ! 31: * This code is derived from software donated to Berkeley by ! 32: * Jan-Simon Pendry. ! 33: * ! 34: * Redistribution and use in source and binary forms, with or without ! 35: * modification, are permitted provided that the following conditions ! 36: * are met: ! 37: * 1. Redistributions of source code must retain the above copyright ! 38: * notice, this list of conditions and the following disclaimer. ! 39: * 2. Redistributions in binary form must reproduce the above copyright ! 40: * notice, this list of conditions and the following disclaimer in the ! 41: * documentation and/or other materials provided with the distribution. ! 42: * 3. All advertising materials mentioning features or use of this software ! 43: * must display the following acknowledgement: ! 44: * This product includes software developed by the University of ! 45: * California, Berkeley and its contributors. ! 46: * 4. Neither the name of the University nor the names of its contributors ! 47: * may be used to endorse or promote products derived from this software ! 48: * without specific prior written permission. ! 49: * ! 50: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 51: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 52: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 53: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 54: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 55: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 56: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 57: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 58: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 59: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 60: * SUCH DAMAGE. ! 61: * ! 62: * @(#)kernfs_vfsops.c 8.5 (Berkeley) 6/15/94 ! 63: */ ! 64: ! 65: /* ! 66: * Kernel params Filesystem ! 67: */ ! 68: ! 69: #include <sys/param.h> ! 70: #include <sys/systm.h> ! 71: #include <sys/conf.h> ! 72: #include <sys/types.h> ! 73: #include <sys/proc.h> ! 74: #include <sys/vnode.h> ! 75: #include <sys/mount.h> ! 76: #include <sys/namei.h> ! 77: #include <sys/malloc.h> ! 78: ! 79: #include <miscfs/specfs/specdev.h> ! 80: #include <miscfs/kernfs/kernfs.h> ! 81: ! 82: dev_t rrootdev = NODEV; ! 83: ! 84: kernfs_init() ! 85: { ! 86: ! 87: } ! 88: ! 89: void ! 90: kernfs_get_rrootdev() ! 91: { ! 92: static int tried = 0; ! 93: int cmaj; ! 94: ! 95: if (tried) { ! 96: /* Already did it once. */ ! 97: return; ! 98: } ! 99: tried = 1; ! 100: ! 101: if (rootdev == NODEV) ! 102: return; ! 103: for (cmaj = 0; cmaj < nchrdev; cmaj++) { ! 104: rrootdev = makedev(cmaj, minor(rootdev)); ! 105: if (chrtoblk(rrootdev) == rootdev) ! 106: return; ! 107: } ! 108: rrootdev = NODEV; ! 109: printf("kernfs_get_rrootdev: no raw root device\n"); ! 110: } ! 111: ! 112: /* ! 113: * Mount the Kernel params filesystem ! 114: */ ! 115: kernfs_mount(mp, path, data, ndp, p) ! 116: struct mount *mp; ! 117: char *path; ! 118: caddr_t data; ! 119: struct nameidata *ndp; ! 120: struct proc *p; ! 121: { ! 122: int error = 0; ! 123: size_t size; ! 124: struct kernfs_mount *fmp; ! 125: struct vnode *rvp; ! 126: ! 127: #ifdef KERNFS_DIAGNOSTIC ! 128: printf("kernfs_mount(mp = %x)\n", mp); ! 129: #endif ! 130: ! 131: /* ! 132: * Update is a no-op ! 133: */ ! 134: if (mp->mnt_flag & MNT_UPDATE) ! 135: return (EOPNOTSUPP); ! 136: ! 137: if (error = getnewvnode(VT_KERNFS, mp, kernfs_vnodeop_p, &rvp)) ! 138: return (error); ! 139: ! 140: MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount), ! 141: M_MISCFSMNT, M_WAITOK); ! 142: rvp->v_type = VDIR; ! 143: rvp->v_flag |= VROOT; ! 144: #ifdef KERNFS_DIAGNOSTIC ! 145: printf("kernfs_mount: root vp = %x\n", rvp); ! 146: #endif ! 147: fmp->kf_root = rvp; ! 148: mp->mnt_flag |= MNT_LOCAL; ! 149: mp->mnt_data = (qaddr_t)fmp; ! 150: getnewfsid(mp, makefstype(MOUNT_KERNFS)); ! 151: ! 152: (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); ! 153: bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); ! 154: bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); ! 155: bcopy("kernfs", mp->mnt_stat.f_mntfromname, sizeof("kernfs")); ! 156: #ifdef KERNFS_DIAGNOSTIC ! 157: printf("kernfs_mount: at %s\n", mp->mnt_stat.f_mntonname); ! 158: #endif ! 159: ! 160: kernfs_get_rrootdev(); ! 161: return (0); ! 162: } ! 163: ! 164: kernfs_start(mp, flags, p) ! 165: struct mount *mp; ! 166: int flags; ! 167: struct proc *p; ! 168: { ! 169: ! 170: return (0); ! 171: } ! 172: ! 173: kernfs_unmount(mp, mntflags, p) ! 174: struct mount *mp; ! 175: int mntflags; ! 176: struct proc *p; ! 177: { ! 178: int error; ! 179: int flags = 0; ! 180: extern int doforce; ! 181: struct vnode *rootvp = VFSTOKERNFS(mp)->kf_root; ! 182: ! 183: #ifdef KERNFS_DIAGNOSTIC ! 184: printf("kernfs_unmount(mp = %x)\n", mp); ! 185: #endif ! 186: ! 187: if (mntflags & MNT_FORCE) { ! 188: /* kernfs can never be rootfs so don't check for it */ ! 189: if (!doforce) ! 190: return (EINVAL); ! 191: flags |= FORCECLOSE; ! 192: } ! 193: ! 194: /* ! 195: * Clear out buffer cache. I don't think we ! 196: * ever get anything cached at this level at the ! 197: * moment, but who knows... ! 198: */ ! 199: if (rootvp->v_usecount > 1) ! 200: return (EBUSY); ! 201: #ifdef KERNFS_DIAGNOSTIC ! 202: printf("kernfs_unmount: calling vflush\n"); ! 203: #endif ! 204: if (error = vflush(mp, rootvp, flags)) ! 205: return (error); ! 206: ! 207: #ifdef KERNFS_DIAGNOSTIC ! 208: vprint("kernfs root", rootvp); ! 209: #endif ! 210: /* ! 211: * Clean out the old root vnode for reuse. ! 212: */ ! 213: vrele(rootvp); ! 214: vgone(rootvp); ! 215: /* ! 216: * Finally, throw away the kernfs_mount structure ! 217: */ ! 218: free(mp->mnt_data, M_MISCFSMNT); ! 219: mp->mnt_data = 0; ! 220: return (0); ! 221: } ! 222: ! 223: kernfs_root(mp, vpp) ! 224: struct mount *mp; ! 225: struct vnode **vpp; ! 226: { ! 227: struct vnode *vp; ! 228: ! 229: #ifdef KERNFS_DIAGNOSTIC ! 230: printf("kernfs_root(mp = %x)\n", mp); ! 231: #endif ! 232: ! 233: /* ! 234: * Return locked reference to root. ! 235: */ ! 236: vp = VFSTOKERNFS(mp)->kf_root; ! 237: VREF(vp); ! 238: VOP_LOCK(vp); ! 239: *vpp = vp; ! 240: return (0); ! 241: } ! 242: ! 243: kernfs_quotactl(mp, cmd, uid, arg, p) ! 244: struct mount *mp; ! 245: int cmd; ! 246: uid_t uid; ! 247: caddr_t arg; ! 248: struct proc *p; ! 249: { ! 250: ! 251: return (EOPNOTSUPP); ! 252: } ! 253: ! 254: kernfs_statfs(mp, sbp, p) ! 255: struct mount *mp; ! 256: struct statfs *sbp; ! 257: struct proc *p; ! 258: { ! 259: ! 260: #ifdef KERNFS_DIAGNOSTIC ! 261: printf("kernfs_statfs(mp = %x)\n", mp); ! 262: #endif ! 263: ! 264: #ifdef COMPAT_09 ! 265: sbp->f_type = 7; ! 266: #else ! 267: sbp->f_type = 0; ! 268: #endif ! 269: sbp->f_bsize = DEV_BSIZE; ! 270: sbp->f_iosize = DEV_BSIZE; ! 271: sbp->f_blocks = 2; /* 1K to keep df happy */ ! 272: sbp->f_bfree = 0; ! 273: sbp->f_bavail = 0; ! 274: sbp->f_files = 0; ! 275: sbp->f_ffree = 0; ! 276: if (sbp != &mp->mnt_stat) { ! 277: bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid)); ! 278: bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); ! 279: bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); ! 280: } ! 281: strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN); ! 282: sbp->f_fstypename[MFSNAMELEN] = '\0'; ! 283: return (0); ! 284: } ! 285: ! 286: kernfs_sync(mp, waitfor) ! 287: struct mount *mp; ! 288: int waitfor; ! 289: { ! 290: ! 291: return (0); ! 292: } ! 293: ! 294: /* ! 295: * Kernfs flat namespace lookup. ! 296: * Currently unsupported. ! 297: */ ! 298: kernfs_vget(mp, ino, vpp) ! 299: struct mount *mp; ! 300: ino_t ino; ! 301: struct vnode **vpp; ! 302: { ! 303: ! 304: return (EOPNOTSUPP); ! 305: } ! 306: ! 307: ! 308: kernfs_fhtovp(mp, fhp, setgen, vpp) ! 309: struct mount *mp; ! 310: struct fid *fhp; ! 311: int setgen; ! 312: struct vnode **vpp; ! 313: { ! 314: ! 315: return (EOPNOTSUPP); ! 316: } ! 317: ! 318: kernfs_vptofh(vp, fhp) ! 319: struct vnode *vp; ! 320: struct fid *fhp; ! 321: { ! 322: ! 323: return (EOPNOTSUPP); ! 324: } ! 325: ! 326: struct vfsops kernfs_vfsops = { ! 327: MOUNT_KERNFS, ! 328: kernfs_mount, ! 329: kernfs_start, ! 330: kernfs_unmount, ! 331: kernfs_root, ! 332: kernfs_quotactl, ! 333: kernfs_statfs, ! 334: kernfs_sync, ! 335: kernfs_vget, ! 336: kernfs_fhtovp, ! 337: kernfs_vptofh, ! 338: kernfs_init, ! 339: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.