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