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

unix.superglobalmegacorp.com

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