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

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;
1.1.1.2 ! root      145:        fmp->pm_server = fp;
        !           146:        if (++fp->f_count <= 0)
        !           147:                panic("portal_mount f_count");
1.1       root      148: 
                    149:        mp->mnt_flag |= MNT_LOCAL;
                    150:        mp->mnt_data = (qaddr_t) fmp;
                    151:        vfs_getnewfsid(mp);
                    152: 
                    153:        (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
                    154:        bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
                    155:        (void)copyinstr(args.pa_config,
                    156:            mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
                    157:        bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
                    158: 
                    159: #ifdef notdef
                    160:        bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
                    161:        bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
                    162: #endif
                    163: 
                    164:        return (0);
                    165: }
                    166: 
                    167: int
                    168: portal_start(mp, flags, p)
                    169:        struct mount *mp;
                    170:        int flags;
                    171:        struct proc *p;
                    172: {
                    173: 
                    174:        return (0);
                    175: }
                    176: 
                    177: int
                    178: portal_unmount(mp, mntflags, p)
                    179:        struct mount *mp;
                    180:        int mntflags;
                    181:        struct proc *p;
                    182: {
                    183:        struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
                    184:        int error, flags = 0;
                    185: 
                    186: 
                    187:        if (mntflags & MNT_FORCE)
                    188:                flags |= FORCECLOSE;
                    189: 
                    190:        /*
                    191:         * Clear out buffer cache.  I don't think we
                    192:         * ever get anything cached at this level at the
                    193:         * moment, but who knows...
                    194:         */
                    195: #ifdef notyet
                    196:        mntflushbuf(mp, 0); 
                    197:        if (mntinvalbuf(mp, 1))
                    198:                return (EBUSY);
                    199: #endif
                    200:        if (rootvp->v_usecount > 1)
                    201:                return (EBUSY);
                    202:        if (error = vflush(mp, rootvp, flags))
                    203:                return (error);
                    204: 
                    205:        /*
                    206:         * Release reference on underlying root vnode
                    207:         */
                    208:        vrele(rootvp);
                    209:        /*
                    210:         * And blow it away for future re-use
                    211:         */
                    212:        vgone(rootvp);
                    213:        /*
                    214:         * Shutdown the socket.  This will cause the select in the
                    215:         * daemon to wake up, and then the accept will get ECONNABORTED
                    216:         * which it interprets as a request to go and bury itself.
                    217:         */
                    218:        soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
                    219:        /*
                    220:         * Discard reference to underlying file.  Must call closef because
                    221:         * this may be the last reference.
                    222:         */
                    223:        closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
                    224:        /*
                    225:         * Finally, throw away the portalmount structure
                    226:         */
                    227:        _FREE(mp->mnt_data, M_UFSMNT);  /* XXX */
                    228:        mp->mnt_data = 0;
                    229:        return (0);
                    230: }
                    231: 
                    232: int
                    233: portal_root(mp, vpp)
                    234:        struct mount *mp;
                    235:        struct vnode **vpp;
                    236: {
                    237:        struct proc *p = current_proc();        /* XXX */
                    238:        struct vnode *vp;
                    239: 
                    240:        /*
                    241:         * Return locked reference to root.
                    242:         */
                    243:        vp = VFSTOPORTAL(mp)->pm_root;
                    244:        VREF(vp);
                    245:        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
                    246:        *vpp = vp;
                    247:        return (0);
                    248: }
                    249: 
                    250: int
                    251: portal_statfs(mp, sbp, p)
                    252:        struct mount *mp;
                    253:        struct statfs *sbp;
                    254:        struct proc *p;
                    255: {
                    256: 
                    257:        sbp->f_flags = 0;
                    258:        sbp->f_bsize = DEV_BSIZE;
                    259:        sbp->f_iosize = DEV_BSIZE;
                    260:        sbp->f_blocks = 2;              /* 1K to keep df happy */
                    261:        sbp->f_bfree = 0;
                    262:        sbp->f_bavail = 0;
                    263:        sbp->f_files = 1;               /* Allow for "." */
                    264:        sbp->f_ffree = 0;               /* See comments above */
                    265:        if (sbp != &mp->mnt_stat) {
                    266:                sbp->f_type = mp->mnt_vfc->vfc_typenum;
                    267:                bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
                    268:                bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
                    269:                bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
                    270:        }
                    271:        return (0);
                    272: }
                    273: 
                    274: #define portal_fhtovp ((int (*) __P((struct mount *, struct fid *, \
                    275:            struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp)
                    276: #define portal_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
                    277:            struct proc *)))eopnotsupp)
                    278: #define portal_sync ((int (*) __P((struct mount *, int, struct ucred *, \
                    279:            struct proc *)))nullop)
                    280: #define portal_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
                    281:            size_t, struct proc *)))eopnotsupp)
                    282: #define portal_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
                    283:            eopnotsupp)
                    284: #define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
                    285: 
                    286: struct vfsops portal_vfsops = {
                    287:        portal_mount,
                    288:        portal_start,
                    289:        portal_unmount,
                    290:        portal_root,
                    291:        portal_quotactl,
                    292:        portal_statfs,
                    293:        portal_sync,
                    294:        portal_vget,
                    295:        portal_fhtovp,
                    296:        portal_vptofh,
                    297:        portal_init,
                    298:        portal_sysctl,
                    299: };

unix.superglobalmegacorp.com

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