Annotation of 41BSD/4.0.upgrade/sys/dev/bk.c, revision 1.1.1.1

1.1       root        1: /*     bk.c    4.6     81/03/11        */
                      2: 
                      3: #include "bk.h"
                      4: 
                      5: #if NBK > 0
                      6: #include "../h/param.h"
                      7: #include "../h/systm.h"
                      8: #include "../h/dir.h"
                      9: #include "../h/user.h"
                     10: #include "../h/tty.h"
                     11: #include "../h/proc.h"
                     12: #include "../h/mx.h"
                     13: #include "../h/inode.h"
                     14: #include "../h/file.h"
                     15: #include "../h/conf.h"
                     16: #include "../h/buf.h"
                     17: 
                     18: /*
                     19:  * Line discipline for Berkeley network.
                     20:  *
                     21:  * This supplies single lines to a user level program
                     22:  * with a minimum of fuss.  Lines are newline terminated.
                     23:  *
                     24:  * This discipline requires that tty device drivers call
                     25:  * the line specific l_ioctl routine from their ioctl routines,
                     26:  * assigning the result to cmd so that we can refuse most tty specific
                     27:  * ioctls which are unsafe because we have ambushed the
                     28:  * teletype input queues, overlaying them with other information.
                     29:  */
                     30: 
                     31: /*
                     32:  * Open as networked discipline.  Called when discipline changed
                     33:  * with ioctl, this assigns a buffer to the line for input, and
                     34:  * changing the interpretation of the information in the tty structure.
                     35:  */
                     36: /*ARGSUSED*/
                     37: bkopen(dev, tp)
                     38: dev_t dev;
                     39: register struct tty *tp;
                     40: {
                     41:        register struct buf *bp;
                     42: 
                     43:        if (u.u_error)
                     44:                return;         /* paranoia */
                     45:        if (tp->t_line == NETLDISC) {
                     46:                u.u_error = EBUSY;              /* sometimes the network */
                     47:                return;                         /* ... opens /dev/tty */
                     48:        }
                     49:        bp = geteblk();
                     50:        flushtty(tp, FREAD|FWRITE);
                     51:        tp->t_bufp = bp;
                     52:        tp->t_cp = (char *)bp->b_un.b_addr;
                     53:        tp->t_inbuf = 0;
                     54:        tp->t_rec = 0;
                     55: }
                     56: 
                     57: /*
                     58:  * Break down... called when discipline changed or from device
                     59:  * close routine.
                     60:  */
                     61: bkclose(tp)
                     62: register struct tty *tp;
                     63: {
                     64:        register s;
                     65: 
                     66:        s = spl5();
                     67:        wakeup((caddr_t)&tp->t_rawq);
                     68:        if (tp->t_bufp) {
                     69:                brelse(tp->t_bufp);
                     70:                tp->t_bufp = 0;
                     71:        } else
                     72:                printf("bkclose: no buf\n");
                     73:        tp->t_cp = 0;
                     74:        tp->t_inbuf = 0;
                     75:        tp->t_rec = 0;
                     76:        tp->t_line = 0;         /* paranoid: avoid races */
                     77:        splx(s);
                     78: }
                     79: 
                     80: /*
                     81:  * Read from a network line.
                     82:  * Characters have been buffered in a system buffer and are
                     83:  * now dumped back to the user in one fell swoop, and with a
                     84:  * minimum of fuss.  Note that no input is accepted when a record
                     85:  * is waiting.  Our clearing tp->t_rec here allows further input
                     86:  * to accumulate.
                     87:  */
                     88: bkread(tp)
                     89: register struct tty *tp;
                     90: {
                     91:        register int i;
                     92:        register s;
                     93: 
                     94:        if ((tp->t_state&CARR_ON)==0)
                     95:                return (-1);
                     96:        s = spl5();
                     97:        while (tp->t_rec == 0 && tp->t_line == NETLDISC)
                     98:                sleep((caddr_t)&tp->t_rawq, TTIPRI);
                     99:        splx(s);
                    100:        if (tp->t_line != NETLDISC)
                    101:                return (-1);
                    102:        i = MIN(tp->t_inbuf, (int)u.u_count);
                    103:        if (copyout(tp->t_bufp->b_un.b_addr, u.u_base, (unsigned)i)) {
                    104:                u.u_error = EFAULT;
                    105:                return (-1);
                    106:        }
                    107:        u.u_count -= i;
                    108:        u.u_base += i;
                    109:        u.u_offset += i;
                    110:        tp->t_cp = (char *)tp->t_bufp->b_un.b_addr;
                    111:        tp->t_inbuf = 0;
                    112:        tp->t_rec = 0;
                    113:        return (0);
                    114: }
                    115: 
                    116: /*
                    117:  * Low level character input routine.
                    118:  * Stuff the character in the buffer, and wake up the top
                    119:  * half after setting t_rec if this completes the record
                    120:  * or if the buffer is (ick!) full.
                    121:  *
                    122:  * Thisis where the formatting should get done to allow
                    123:  * 8 character data paths through escapes.
                    124:  *
                    125:  * This rutine should be expanded in-line in the receiver
                    126:  * interrupt routine of the dh-11 to make it run as fast as possible.
                    127:  */
                    128: bkinput(c, tp)
                    129: register c;
                    130: register struct tty *tp;
                    131: {
                    132: 
                    133:        if (tp->t_rec)
                    134:                return;
                    135:        *tp->t_cp++ = c;
                    136:        if (++tp->t_inbuf == BSIZE || c == '\n') {
                    137:                tp->t_rec = 1;
                    138:                wakeup((caddr_t)&tp->t_rawq);
                    139:        }
                    140: }
                    141: 
                    142: /*
                    143:  * This routine is called whenever a ioctl is about to be performed
                    144:  * and gets a chance to reject the ioctl.  We reject all teletype
                    145:  * oriented ioctl's except those which set the discipline, and
                    146:  * those which get parameters (gtty and get special characters).
                    147:  */
                    148: /*ARGSUSED*/
                    149: bkioctl(tp, cmd, addr)
                    150: struct tty *tp;
                    151: caddr_t addr;
                    152: {
                    153: 
                    154:        if ((cmd>>8) != 't')
                    155:                return (cmd);
                    156:        switch (cmd) {
                    157: 
                    158:        case TIOCSETD:
                    159:        case TIOCGETD:
                    160:        case TIOCGETP:
                    161:        case TIOCGETC:
                    162:                return (cmd);
                    163:        }
                    164:        u.u_error = ENOTTY;
                    165:        return (0);
                    166: }
                    167: #endif

unix.superglobalmegacorp.com

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