Annotation of kernel/bsd/miscfs/portal/portal_vfsops.c, revision 1.1

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:  *     @(#)portal_vfsops.c     8.11 (Berkeley) 5/14/95
        !            62:  *
        !            63:  *     @(#)portal_vfsops.c     8.6 (Berkeley) 1/21/94
        !            64:  */
        !            65: 
        !            66: /*
        !            67:  * Portal Filesystem
        !            68:  */
        !            69: 
        !            70: #include <sys/param.h>
        !            71: #include <sys/systm.h>
        !            72: #include <sys/time.h>
        !            73: #include <sys/types.h>
        !            74: #include <sys/proc.h>
        !            75: #include <sys/filedesc.h>
        !            76: #include <sys/file.h>
        !            77: #include <sys/vnode.h>
        !            78: #include <sys/mount.h>
        !            79: #include <sys/namei.h>
        !            80: #include <sys/malloc.h>
        !            81: #include <sys/mbuf.h>
        !            82: #include <sys/socket.h>
        !            83: #include <sys/socketvar.h>
        !            84: #include <sys/protosw.h>
        !            85: #include <sys/domain.h>
        !            86: #include <sys/un.h>
        !            87: #include <miscfs/portal/portal.h>
        !            88: 
        !            89: int
        !            90: portal_init(vfsp)
        !            91:        struct vfsconf *vfsp;
        !            92: {
        !            93: 
        !            94:        return (0);
        !            95: }
        !            96: 
        !            97: /*
        !            98:  * Mount the per-process file descriptors (/dev/fd)
        !            99:  */
        !           100: int
        !           101: portal_mount(mp, path, data, ndp, p)
        !           102:        struct mount *mp;
        !           103:        char *path;
        !           104:        caddr_t data;
        !           105:        struct nameidata *ndp;
        !           106:        struct proc *p;
        !           107: {
        !           108:        struct file *fp;
        !           109:        struct portal_args args;
        !           110:        struct portalmount *fmp;
        !           111:        struct socket *so;
        !           112:        struct vnode *rvp;
        !           113:        u_int size;
        !           114:        int error;
        !           115: 
        !           116:        /*
        !           117:         * Update is a no-op
        !           118:         */
        !           119:        if (mp->mnt_flag & MNT_UPDATE)
        !           120:                return (EOPNOTSUPP);
        !           121: 
        !           122:        if (error = copyin(data, (caddr_t) &args, sizeof(struct portal_args)))
        !           123:                return (error);
        !           124: 
        !           125:        if (error = getsock(p, args.pa_socket, &fp))
        !           126:                return (error);
        !           127:        so = (struct socket *) fp->f_data;
        !           128:        if (so->so_proto->pr_domain->dom_family != AF_UNIX)
        !           129:                return (ESOCKTNOSUPPORT);
        !           130: 
        !           131:        error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
        !           132:        if (error)
        !           133:                return (error);
        !           134:        MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
        !           135:                M_TEMP, M_WAITOK);
        !           136: 
        !           137:        fmp = (struct portalmount *) _MALLOC(sizeof(struct portalmount),
        !           138:                                 M_UFSMNT, M_WAITOK);   /* XXX */
        !           139:        rvp->v_type = VDIR;
        !           140:        rvp->v_flag |= VROOT;
        !           141:        VTOPORTAL(rvp)->pt_arg = 0;
        !           142:        VTOPORTAL(rvp)->pt_size = 0;
        !           143:        VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
        !           144:        fmp->pm_root = rvp;
        !           145:        fmp->pm_server = fp; fp->f_count++;
        !           146: 
        !           147:        mp->mnt_flag |= MNT_LOCAL;
        !           148:        mp->mnt_data = (qaddr_t) fmp;
        !           149:        vfs_getnewfsid(mp);
        !           150: 
        !           151:        (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
        !           152:        bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
        !           153:        (void)copyinstr(args.pa_config,
        !           154:            mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
        !           155:        bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
        !           156: 
        !           157: #ifdef notdef
        !           158:        bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
        !           159:        bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
        !           160: #endif
        !           161: 
        !           162:        return (0);
        !           163: }
        !           164: 
        !           165: int
        !           166: portal_start(mp, flags, p)
        !           167:        struct mount *mp;
        !           168:        int flags;
        !           169:        struct proc *p;
        !           170: {
        !           171: 
        !           172:        return (0);
        !           173: }
        !           174: 
        !           175: int
        !           176: portal_unmount(mp, mntflags, p)
        !           177:        struct mount *mp;
        !           178:        int mntflags;
        !           179:        struct proc *p;
        !           180: {
        !           181:        struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
        !           182:        int error, flags = 0;
        !           183: 
        !           184: 
        !           185:        if (mntflags & MNT_FORCE)
        !           186:                flags |= FORCECLOSE;
        !           187: 
        !           188:        /*
        !           189:         * Clear out buffer cache.  I don't think we
        !           190:         * ever get anything cached at this level at the
        !           191:         * moment, but who knows...
        !           192:         */
        !           193: #ifdef notyet
        !           194:        mntflushbuf(mp, 0); 
        !           195:        if (mntinvalbuf(mp, 1))
        !           196:                return (EBUSY);
        !           197: #endif
        !           198:        if (rootvp->v_usecount > 1)
        !           199:                return (EBUSY);
        !           200:        if (error = vflush(mp, rootvp, flags))
        !           201:                return (error);
        !           202: 
        !           203:        /*
        !           204:         * Release reference on underlying root vnode
        !           205:         */
        !           206:        vrele(rootvp);
        !           207:        /*
        !           208:         * And blow it away for future re-use
        !           209:         */
        !           210:        vgone(rootvp);
        !           211:        /*
        !           212:         * Shutdown the socket.  This will cause the select in the
        !           213:         * daemon to wake up, and then the accept will get ECONNABORTED
        !           214:         * which it interprets as a request to go and bury itself.
        !           215:         */
        !           216:        soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
        !           217:        /*
        !           218:         * Discard reference to underlying file.  Must call closef because
        !           219:         * this may be the last reference.
        !           220:         */
        !           221:        closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
        !           222:        /*
        !           223:         * Finally, throw away the portalmount structure
        !           224:         */
        !           225:        _FREE(mp->mnt_data, M_UFSMNT);  /* XXX */
        !           226:        mp->mnt_data = 0;
        !           227:        return (0);
        !           228: }
        !           229: 
        !           230: int
        !           231: portal_root(mp, vpp)
        !           232:        struct mount *mp;
        !           233:        struct vnode **vpp;
        !           234: {
        !           235:        struct proc *p = current_proc();        /* XXX */
        !           236:        struct vnode *vp;
        !           237: 
        !           238:        /*
        !           239:         * Return locked reference to root.
        !           240:         */
        !           241:        vp = VFSTOPORTAL(mp)->pm_root;
        !           242:        VREF(vp);
        !           243:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
        !           244:        *vpp = vp;
        !           245:        return (0);
        !           246: }
        !           247: 
        !           248: int
        !           249: portal_statfs(mp, sbp, p)
        !           250:        struct mount *mp;
        !           251:        struct statfs *sbp;
        !           252:        struct proc *p;
        !           253: {
        !           254: 
        !           255:        sbp->f_flags = 0;
        !           256:        sbp->f_bsize = DEV_BSIZE;
        !           257:        sbp->f_iosize = DEV_BSIZE;
        !           258:        sbp->f_blocks = 2;              /* 1K to keep df happy */
        !           259:        sbp->f_bfree = 0;
        !           260:        sbp->f_bavail = 0;
        !           261:        sbp->f_files = 1;               /* Allow for "." */
        !           262:        sbp->f_ffree = 0;               /* See comments above */
        !           263:        if (sbp != &mp->mnt_stat) {
        !           264:                sbp->f_type = mp->mnt_vfc->vfc_typenum;
        !           265:                bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
        !           266:                bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
        !           267:                bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
        !           268:        }
        !           269:        return (0);
        !           270: }
        !           271: 
        !           272: #define portal_fhtovp ((int (*) __P((struct mount *, struct fid *, \
        !           273:            struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp)
        !           274: #define portal_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
        !           275:            struct proc *)))eopnotsupp)
        !           276: #define portal_sync ((int (*) __P((struct mount *, int, struct ucred *, \
        !           277:            struct proc *)))nullop)
        !           278: #define portal_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
        !           279:            size_t, struct proc *)))eopnotsupp)
        !           280: #define portal_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
        !           281:            eopnotsupp)
        !           282: #define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
        !           283: 
        !           284: struct vfsops portal_vfsops = {
        !           285:        portal_mount,
        !           286:        portal_start,
        !           287:        portal_unmount,
        !           288:        portal_root,
        !           289:        portal_quotactl,
        !           290:        portal_statfs,
        !           291:        portal_sync,
        !           292:        portal_vget,
        !           293:        portal_fhtovp,
        !           294:        portal_vptofh,
        !           295:        portal_init,
        !           296:        portal_sysctl,
        !           297: };

unix.superglobalmegacorp.com

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