Annotation of XNU/bsd/miscfs/nullfs/null_vfsops.c, revision 1.1.1.1

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: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
                     23: /*
                     24:  * Copyright (c) 1992, 1993
                     25:  *     The Regents of the University of California.  All rights reserved.
                     26:  *
                     27:  * This code is derived from software donated to Berkeley by
                     28:  * Jan-Simon Pendry.
                     29:  *
                     30:  * Redistribution and use in source and binary forms, with or without
                     31:  * modification, are permitted provided that the following conditions
                     32:  * are met:
                     33:  * 1. Redistributions of source code must retain the above copyright
                     34:  *    notice, this list of conditions and the following disclaimer.
                     35:  * 2. Redistributions in binary form must reproduce the above copyright
                     36:  *    notice, this list of conditions and the following disclaimer in the
                     37:  *    documentation and/or other materials provided with the distribution.
                     38:  * 3. All advertising materials mentioning features or use of this software
                     39:  *    must display the following acknowledgement:
                     40:  *     This product includes software developed by the University of
                     41:  *     California, Berkeley and its contributors.
                     42:  * 4. Neither the name of the University nor the names of its contributors
                     43:  *    may be used to endorse or promote products derived from this software
                     44:  *    without specific prior written permission.
                     45:  *
                     46:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     47:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     48:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     49:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     50:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     51:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     52:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     53:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     54:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     55:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     56:  * SUCH DAMAGE.
                     57:  *
                     58:  *     @(#)null_vfsops.c       8.7 (Berkeley) 5/14/95
                     59:  *
                     60:  * @(#)lofs_vfsops.c   1.2 (Berkeley) 6/18/92
                     61:  */
                     62: 
                     63: /*
                     64:  * Null Layer
                     65:  * (See null_vnops.c for a description of what this does.)
                     66:  */
                     67: 
                     68: #include <sys/param.h>
                     69: #include <sys/systm.h>
                     70: #include <sys/proc.h>
                     71: #include <sys/time.h>
                     72: #include <sys/types.h>
                     73: #include <sys/vnode.h>
                     74: #include <sys/mount.h>
                     75: #include <sys/namei.h>
                     76: #include <sys/malloc.h>
                     77: #include <miscfs/nullfs/null.h>
                     78: 
                     79: /*
                     80:  * Mount null layer
                     81:  */
                     82: int
                     83: nullfs_mount(mp, path, data, ndp, p)
                     84:        struct mount *mp;
                     85:        char *path;
                     86:        caddr_t data;
                     87:        struct nameidata *ndp;
                     88:        struct proc *p;
                     89: {
                     90:        int error = 0;
                     91:        struct null_args args;
                     92:        struct vnode *lowerrootvp, *vp;
                     93:        struct vnode *nullm_rootvp;
                     94:        struct null_mount *xmp;
                     95:        u_int size;
                     96: 
                     97: #ifdef NULLFS_DIAGNOSTIC
                     98:        printf("nullfs_mount(mp = %x)\n", mp);
                     99: #endif
                    100: 
                    101:        /*
                    102:         * Update is a no-op
                    103:         */
                    104:        if (mp->mnt_flag & MNT_UPDATE) {
                    105:                return (EOPNOTSUPP);
                    106:                /* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, p);*/
                    107:        }
                    108: 
                    109:        /*
                    110:         * Get argument
                    111:         */
                    112:        if (error = copyin(data, (caddr_t)&args, sizeof(struct null_args)))
                    113:                return (error);
                    114: 
                    115:        /*
                    116:         * Find lower node
                    117:         */
                    118:        NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
                    119:                UIO_USERSPACE, args.target, p);
                    120:        if (error = namei(ndp))
                    121:                return (error);
                    122: 
                    123:        /*
                    124:         * Sanity check on lower vnode
                    125:         */
                    126:        lowerrootvp = ndp->ni_vp;
                    127: 
                    128:        vrele(ndp->ni_dvp);
                    129:        ndp->ni_dvp = NULL;
                    130: 
                    131:        xmp = (struct null_mount *) _MALLOC(sizeof(struct null_mount),
                    132:                                M_UFSMNT, M_WAITOK);    /* XXX */
                    133: 
                    134:        /*
                    135:         * Save reference to underlying FS
                    136:         */
                    137:        xmp->nullm_vfs = lowerrootvp->v_mount;
                    138: 
                    139:        /*
                    140:         * Save reference.  Each mount also holds
                    141:         * a reference on the root vnode.
                    142:         */
                    143:        error = null_node_create(mp, lowerrootvp, &vp);
                    144:        /*
                    145:         * Unlock the node (either the lower or the alias)
                    146:         */
                    147:        VOP_UNLOCK(vp, 0, p);
                    148:        /*
                    149:         * Make sure the node alias worked
                    150:         */
                    151:        if (error) {
                    152:                vrele(lowerrootvp);
                    153:                FREE(xmp, M_UFSMNT);    /* XXX */
                    154:                return (error);
                    155:        }
                    156: 
                    157:        /*
                    158:         * Keep a held reference to the root vnode.
                    159:         * It is vrele'd in nullfs_unmount.
                    160:         */
                    161:        nullm_rootvp = vp;
                    162:        nullm_rootvp->v_flag |= VROOT;
                    163:        xmp->nullm_rootvp = nullm_rootvp;
                    164:        if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
                    165:                mp->mnt_flag |= MNT_LOCAL;
                    166:        mp->mnt_data = (qaddr_t) xmp;
                    167:        vfs_getnewfsid(mp);
                    168: 
                    169:        (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
                    170:        bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
                    171:        (void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 
                    172:            &size);
                    173:        bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
                    174: #ifdef NULLFS_DIAGNOSTIC
                    175:        printf("nullfs_mount: lower %s, alias at %s\n",
                    176:                mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
                    177: #endif
                    178:        return (0);
                    179: }
                    180: 
                    181: /*
                    182:  * VFS start.  Nothing needed here - the start routine
                    183:  * on the underlying filesystem will have been called
                    184:  * when that filesystem was mounted.
                    185:  */
                    186: int
                    187: nullfs_start(mp, flags, p)
                    188:        struct mount *mp;
                    189:        int flags;
                    190:        struct proc *p;
                    191: {
                    192:        return (0);
                    193:        /* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, p); */
                    194: }
                    195: 
                    196: /*
                    197:  * Free reference to null layer
                    198:  */
                    199: int
                    200: nullfs_unmount(mp, mntflags, p)
                    201:        struct mount *mp;
                    202:        int mntflags;
                    203:        struct proc *p;
                    204: {
                    205:        struct vnode *nullm_rootvp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
                    206:        int error;
                    207:        int flags = 0;
                    208: 
                    209: #ifdef NULLFS_DIAGNOSTIC
                    210:        printf("nullfs_unmount(mp = %x)\n", mp);
                    211: #endif
                    212: 
                    213:        if (mntflags & MNT_FORCE)
                    214:                flags |= FORCECLOSE;
                    215: 
                    216:        /*
                    217:         * Clear out buffer cache.  I don't think we
                    218:         * ever get anything cached at this level at the
                    219:         * moment, but who knows...
                    220:         */
                    221: #if 0
                    222:        mntflushbuf(mp, 0); 
                    223:        if (mntinvalbuf(mp, 1))
                    224:                return (EBUSY);
                    225: #endif
                    226:        if (nullm_rootvp->v_usecount > 1)
                    227:                return (EBUSY);
                    228:        if (error = vflush(mp, nullm_rootvp, flags))
                    229:                return (error);
                    230: 
                    231: #ifdef NULLFS_DIAGNOSTIC
                    232:        vprint("alias root of lower", nullm_rootvp);
                    233: #endif  
                    234:        /*
                    235:         * Release reference on underlying root vnode
                    236:         */
                    237:        vrele(nullm_rootvp);
                    238:        /*
                    239:         * And blow it away for future re-use
                    240:         */
                    241:        vgone(nullm_rootvp);
                    242:        /*
                    243:         * Finally, throw away the null_mount structure
                    244:         */
                    245:        FREE(mp->mnt_data, M_UFSMNT);   /* XXX */
                    246:        mp->mnt_data = 0;
                    247:        return 0;
                    248: }
                    249: 
                    250: int
                    251: nullfs_root(mp, vpp)
                    252:        struct mount *mp;
                    253:        struct vnode **vpp;
                    254: {
                    255:        struct proc *p = curproc;       /* XXX */
                    256:        struct vnode *vp;
                    257: 
                    258: #ifdef NULLFS_DIAGNOSTIC
                    259:        printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp,
                    260:                        MOUNTTONULLMOUNT(mp)->nullm_rootvp,
                    261:                        NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp)
                    262:                        );
                    263: #endif
                    264: 
                    265:        /*
                    266:         * Return locked reference to root.
                    267:         */
                    268:        vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
                    269:        VREF(vp);
                    270:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
                    271:        *vpp = vp;
                    272:        return 0;
                    273: }
                    274: 
                    275: int
                    276: nullfs_quotactl(mp, cmd, uid, arg, p)
                    277:        struct mount *mp;
                    278:        int cmd;
                    279:        uid_t uid;
                    280:        caddr_t arg;
                    281:        struct proc *p;
                    282: {
                    283:        return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg, p);
                    284: }
                    285: 
                    286: int
                    287: nullfs_statfs(mp, sbp, p)
                    288:        struct mount *mp;
                    289:        struct statfs *sbp;
                    290:        struct proc *p;
                    291: {
                    292:        int error;
                    293:        struct statfs mstat;
                    294: 
                    295: #ifdef NULLFS_DIAGNOSTIC
                    296:        printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp,
                    297:                        MOUNTTONULLMOUNT(mp)->nullm_rootvp,
                    298:                        NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp)
                    299:                        );
                    300: #endif
                    301: 
                    302:        bzero(&mstat, sizeof(mstat));
                    303: 
                    304:        error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat, p);
                    305:        if (error)
                    306:                return (error);
                    307: 
                    308:        /* now copy across the "interesting" information and fake the rest */
                    309:        sbp->f_type = mstat.f_type;
                    310:        sbp->f_flags = mstat.f_flags;
                    311:        sbp->f_bsize = mstat.f_bsize;
                    312:        sbp->f_iosize = mstat.f_iosize;
                    313:        sbp->f_blocks = mstat.f_blocks;
                    314:        sbp->f_bfree = mstat.f_bfree;
                    315:        sbp->f_bavail = mstat.f_bavail;
                    316:        sbp->f_files = mstat.f_files;
                    317:        sbp->f_ffree = mstat.f_ffree;
                    318:        if (sbp != &mp->mnt_stat) {
                    319:                bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
                    320:                bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
                    321:                bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
                    322:        }
                    323:        return (0);
                    324: }
                    325: 
                    326: int
                    327: nullfs_sync(mp, waitfor, cred, p)
                    328:        struct mount *mp;
                    329:        int waitfor;
                    330:        struct ucred *cred;
                    331:        struct proc *p;
                    332: {
                    333:        /*
                    334:         * XXX - Assumes no data cached at null layer.
                    335:         */
                    336:        return (0);
                    337: }
                    338: 
                    339: int
                    340: nullfs_vget(mp, ino, vpp)
                    341:        struct mount *mp;
                    342:        ino_t ino;
                    343:        struct vnode **vpp;
                    344: {
                    345:        
                    346:        return VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, vpp);
                    347: }
                    348: 
                    349: int
                    350: nullfs_fhtovp(mp, fidp, nam, vpp, exflagsp, credanonp)
                    351:        struct mount *mp;
                    352:        struct fid *fidp;
                    353:        struct mbuf *nam;
                    354:        struct vnode **vpp;
                    355:        int *exflagsp;
                    356:        struct ucred**credanonp;
                    357: {
                    358: 
                    359:        return VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, nam, vpp, exflagsp,credanonp);
                    360: }
                    361: 
                    362: int
                    363: nullfs_vptofh(vp, fhp)
                    364:        struct vnode *vp;
                    365:        struct fid *fhp;
                    366: {
                    367:        return VFS_VPTOFH(NULLVPTOLOWERVP(vp), fhp);
                    368: }
                    369: 
                    370: int nullfs_init __P((struct vfsconf *));
                    371: 
                    372: #define nullfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
                    373:            size_t, struct proc *)))eopnotsupp)
                    374: 
                    375: struct vfsops null_vfsops = {
                    376:        nullfs_mount,
                    377:        nullfs_start,
                    378:        nullfs_unmount,
                    379:        nullfs_root,
                    380:        nullfs_quotactl,
                    381:        nullfs_statfs,
                    382:        nullfs_sync,
                    383:        nullfs_vget,
                    384:        nullfs_fhtovp,
                    385:        nullfs_vptofh,
                    386:        nullfs_init,
                    387:        nullfs_sysctl,
                    388: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.