--- Net2/kern/tty_pty.c 2018/04/24 18:03:57 1.1 +++ Net2/kern/tty_pty.c 2018/04/24 18:04:37 1.1.1.2 @@ -32,6 +32,7 @@ * * @(#)tty_pty.c 7.21 (Berkeley) 5/30/91 */ +static char rcsid[] = "$Header: /var/lib/cvsd/net2/Net2/kern/tty_pty.c,v 1.1.1.2 2018/04/24 18:04:37 root Exp $"; /* * Pseudo-teletype Driver @@ -110,7 +111,7 @@ ptsopen(dev, flag, devtype, p) tp->t_state |= TS_WOPEN; if (flag&FNONBLOCK) break; - if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, + if (error = ttysleep(tp, (caddr_t)&tp->t_raw, TTIPRI | PCATCH, ttopen, 0)) return (error); } @@ -154,22 +155,22 @@ again: TTIPRI | PCATCH, ttybg, 0)) return (error); } - if (tp->t_canq.c_cc == 0) { + if (RB_LEN(&tp->t_can) == 0) { if (flag & IO_NDELAY) return (EWOULDBLOCK); - if (error = ttysleep(tp, (caddr_t)&tp->t_canq, + if (error = ttysleep(tp, (caddr_t)&tp->t_can, TTIPRI | PCATCH, ttyin, 0)) return (error); goto again; } - while (tp->t_canq.c_cc > 1 && uio->uio_resid > 0) - if (ureadc(getc(&tp->t_canq), uio) < 0) { + while (RB_LEN(&tp->t_can) > 1 && uio->uio_resid > 0) + if (ureadc(getc(&tp->t_can), uio) < 0) { error = EFAULT; break; } - if (tp->t_canq.c_cc == 1) - (void) getc(&tp->t_canq); - if (tp->t_canq.c_cc) + if (RB_LEN(&tp->t_can) == 1) + (void) getc(&tp->t_can); + if (RB_LEN(&tp->t_can)) return (error); } else if (tp->t_oproc) @@ -224,7 +225,7 @@ ptcwakeup(tp, flag) pti->pt_selr = 0; pti->pt_flags &= ~PF_RCOLL; } - wakeup((caddr_t)&tp->t_outq.c_cf); + wakeup((caddr_t)&tp->t_out.rb_hd); } if (flag & FWRITE) { if (pti->pt_selw) { @@ -232,7 +233,7 @@ ptcwakeup(tp, flag) pti->pt_selw = 0; pti->pt_flags &= ~PF_WCOLL; } - wakeup((caddr_t)&tp->t_rawq.c_cf); + wakeup((caddr_t)&tp->t_raw.rb_hd); } } @@ -312,29 +313,38 @@ ptcread(dev, uio, flag) pti->pt_ucntl = 0; return (0); } - if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) + if (RB_LEN(&tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) break; } if ((tp->t_state&TS_CARR_ON) == 0) return (0); /* EOF */ if (flag & IO_NDELAY) return (EWOULDBLOCK); - if (error = tsleep((caddr_t)&tp->t_outq.c_cf, TTIPRI | PCATCH, + if (error = tsleep((caddr_t)&tp->t_out.rb_hd, TTIPRI | PCATCH, ttyin, 0)) return (error); } if (pti->pt_flags & (PF_PKT|PF_UCNTL)) error = ureadc(0, uio); while (uio->uio_resid > 0 && error == 0) { +#ifdef was cc = q_to_b(&tp->t_outq, buf, MIN(uio->uio_resid, BUFSIZ)); +#else + cc = min(MIN(uio->uio_resid, BUFSIZ), RB_CONTIGGET(&tp->t_out)); + if (cc) { + bcopy(tp->t_out.rb_hd, buf, cc); + tp->t_out.rb_hd = + RB_ROLLOVER(&tp->t_out, tp->t_out.rb_hd+cc); + } +#endif if (cc <= 0) break; error = uiomove(buf, cc, uio); } - if (tp->t_outq.c_cc <= tp->t_lowat) { + if (RB_LEN(&tp->t_out) <= tp->t_lowat) { if (tp->t_state&TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_outq); + wakeup((caddr_t)&tp->t_out); } if (tp->t_wsel) { selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); @@ -388,7 +398,7 @@ ptcselect(dev, rw, p) */ s = spltty(); if ((tp->t_state&TS_ISOPEN) && - tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) { + RB_LEN(&tp->t_out) && (tp->t_state&TS_TTSTOP) == 0) { splx(s); return (1); } @@ -410,12 +420,12 @@ ptcselect(dev, rw, p) case FWRITE: if (tp->t_state&TS_ISOPEN) { if (pti->pt_flags & PF_REMOTE) { - if (tp->t_canq.c_cc == 0) + if (RB_LEN(&tp->t_can) == 0) return (1); } else { - if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2) + if (RB_LEN(&tp->t_raw) + RB_LEN(&tp->t_can) < TTYHOG-2) return (1); - if (tp->t_canq.c_cc == 0 && (tp->t_iflag&ICANON)) + if (RB_LEN(&tp->t_can) == 0 && (tp->t_iflag&ICANON)) return (1); } } @@ -445,12 +455,12 @@ again: if ((tp->t_state&TS_ISOPEN) == 0) goto block; if (pti->pt_flags & PF_REMOTE) { - if (tp->t_canq.c_cc) + if (RB_LEN(&tp->t_can)) goto block; - while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) { + while (uio->uio_resid > 0 && RB_LEN(&tp->t_can) < TTYHOG - 1) { if (cc == 0) { cc = min(uio->uio_resid, BUFSIZ); - cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc); + cc = min(cc, TTYHOG - 1 - RB_CONTIGPUT(&tp->t_can)); cp = locbuf; error = uiomove((caddr_t)cp, cc, uio); if (error) @@ -459,13 +469,21 @@ again: if ((tp->t_state&TS_ISOPEN) == 0) return (EIO); } +#ifdef was if (cc) (void) b_to_q((char *)cp, cc, &tp->t_canq); +#else + if (cc) { + bcopy(cp, tp->t_can.rb_tl, cc); + tp->t_can.rb_tl = + RB_ROLLOVER(&tp->t_can, tp->t_can.rb_tl+cc); + } +#endif cc = 0; } - (void) putc(0, &tp->t_canq); + (void) putc(0, &tp->t_can); ttwakeup(tp); - wakeup((caddr_t)&tp->t_canq); + wakeup((caddr_t)&tp->t_can); return (0); } while (uio->uio_resid > 0) { @@ -480,9 +498,9 @@ again: return (EIO); } while (cc > 0) { - if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && - (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { - wakeup((caddr_t)&tp->t_rawq); + if ((RB_LEN(&tp->t_raw) + RB_LEN(&tp->t_can)) >= TTYHOG - 2 && + (RB_LEN(&tp->t_can) > 0 || !(tp->t_iflag&ICANON))) { + wakeup((caddr_t)&tp->t_raw); goto block; } (*linesw[tp->t_line].l_rint)(*cp++, tp); @@ -506,7 +524,7 @@ block: return (EWOULDBLOCK); return (0); } - if (error = tsleep((caddr_t)&tp->t_rawq.c_cf, TTOPRI | PCATCH, + if (error = tsleep((caddr_t)&tp->t_raw.rb_hd, TTOPRI | PCATCH, ttyout, 0)) { /* adjust for data copied in but not written */ uio->uio_resid += cc; @@ -595,7 +613,7 @@ ptyioctl(dev, cmd, data, flag) case TIOCSETA: case TIOCSETAW: case TIOCSETAF: - while (getc(&tp->t_outq) >= 0) + while (getc(&tp->t_out) >= 0) ; break;