Annotation of researchv8dc/sys/dev/connld.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * connector l.d.:  install on a stream-mounted file.
        !             3:  * Opens on the file send new, unique pipe to the
        !             4:  * server and return the other end of the pipe.
        !             5:  */
        !             6: 
        !             7: #include "../h/param.h"
        !             8: #include "../h/systm.h"
        !             9: #include "../h/stream.h"
        !            10: #include "../h/ioctl.h"
        !            11: #include "../h/map.h"
        !            12: #include "../h/buf.h"
        !            13: #include "../h/ubavar.h"
        !            14: #include "../h/conf.h"
        !            15: #include "../h/file.h"
        !            16: #include "../h/inode.h"
        !            17: #include "../h/ttyld.h"
        !            18: #include "connld.h"
        !            19: 
        !            20: #if    NCONNLD
        !            21: 
        !            22: #define        STIPRI  28
        !            23: int    connopen(), connput(), nulldev(), conngput();
        !            24: 
        !            25: static struct qinit connrinit = { connput, 0, connopen, nulldev, 0, 0 };
        !            26: static struct qinit connwinit = { connput, 0, connopen, nulldev, 0, 0 };
        !            27: struct streamtab connldinfo = { &connrinit, &connwinit };
        !            28: 
        !            29: static struct qinit connrgrab = { conngput, 0, nulldev, nulldev, 0, 0 };
        !            30: static struct qinit connwgrab = { connput, 0, nulldev, nulldev, 0, 0 };
        !            31: struct streamtab connginfo = { &connrgrab, &connwgrab };
        !            32: 
        !            33: connopen(q, dev)
        !            34: register struct queue *q;
        !            35: {
        !            36:        struct inode *ip1, *ip2;
        !            37:        register struct file *fp, *nfp;
        !            38:        register s;
        !            39:        register struct block *bp;
        !            40:        register struct queue *nq;
        !            41:        register ioc;
        !            42: 
        !            43:        if ((int)q->ptr == 0) {         /* the open on push does nothing */
        !            44:                q->ptr = (caddr_t)1;
        !            45:                return(1);
        !            46:        }
        !            47:        /* make pipe, send one end to other side */
        !            48:        if ((fp = allocfile()) == NULL)
        !            49:                return(0);
        !            50:        if (makepipe(&ip1, &ip2)==0) {
        !            51:                fp->f_count = 0;
        !            52:                return(0);
        !            53:        }
        !            54:        fp->f_inode = ip2;
        !            55:        fp->f_flag = FREAD|FWRITE;
        !            56:        fp->f_count--;
        !            57:        nq = RD(ip1->i_sptr->wrq);
        !            58:        if (sndfile(WR(q), fp)==0 || qattach(&connginfo, nq, (dev_t)0)==0) {
        !            59:                stclose(ip1);
        !            60:                iput(ip1);
        !            61:                return(0);
        !            62:        }
        !            63:        nq = backq(nq);
        !            64:        /* wait for reply */
        !            65:        s = spl5();
        !            66:        while ((bp = getq(nq))==NULL) {
        !            67:                if (tsleep((caddr_t)nq, STIPRI, 0) != TS_OK) {
        !            68:                        stclose(ip1);
        !            69:                        iput(ip1);
        !            70:                        return(0);
        !            71:                }
        !            72:        }
        !            73:        splx(s);
        !            74: 
        !            75:        switch(bp->type) {
        !            76: 
        !            77:        case M_HANGUP:
        !            78:                freeb(bp);
        !            79:                stclose(ip1, 1);
        !            80:                iput(ip1);
        !            81:                return(0);
        !            82: 
        !            83:        case M_PASS:    /* accept, and provide a newer file */
        !            84:                stclose(ip1, 1);
        !            85:                iput(ip1);
        !            86:                nfp = ((struct kpassfd *)bp->rptr)->f.fp;
        !            87:                ip1 = nfp->f_inode;
        !            88:                ip1->i_count++;
        !            89:                closef(nfp);
        !            90:                return((long)ip1);
        !            91: 
        !            92:        case M_IOCTL:
        !            93:                ioc = ((union stmsg *)bp->rptr)->ioc0.com;
        !            94:                if (ioc==FIOACCEPT || ioc==FIOREJECT) {
        !            95:                        bp->type = M_IOCACK;
        !            96:                        qreply(nq, bp);
        !            97:                        if (ioc==FIOREJECT) {
        !            98:                                stclose(ip1, 1);
        !            99:                                iput(ip1);
        !           100:                                return(0);
        !           101:                        }
        !           102:                        while (bp = getq(nq))
        !           103:                                (*nq->next->qinfo->putp)(nq->next, bp);
        !           104:                        qdetach(nq, 1);
        !           105:                        return((long)ip1);
        !           106:                }
        !           107:        default:                /* flow through */
        !           108:                (*nq->next->qinfo->putp)(nq->next, bp);
        !           109:                while (bp = getq(nq))
        !           110:                        (*nq->next->qinfo->putp)(nq->next, bp);
        !           111:                qdetach(nq, 1);
        !           112:                return((long)ip1);
        !           113:        }
        !           114: }
        !           115: 
        !           116: connput(q, bp)
        !           117: register struct queue *q;
        !           118: register struct block *bp;
        !           119: {
        !           120:        switch (bp->type) {
        !           121: 
        !           122:        case M_HANGUP:
        !           123:        case M_IOCTL:
        !           124:        case M_IOCACK:
        !           125:        case M_IOCNAK:
        !           126:        case M_PASS:
        !           127:                (*q->next->qinfo->putp)(q->next, bp);
        !           128:                return;
        !           129:        }
        !           130:        freeb(bp);
        !           131: }
        !           132: 
        !           133: conngput(q, bp)
        !           134: register struct queue *q;
        !           135: register struct block *bp;
        !           136: {
        !           137:        putq(q, bp);
        !           138:        wakeup((caddr_t)q);
        !           139: }
        !           140: #endif

unix.superglobalmegacorp.com

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