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