- tp = &pt_tty[minor(dev)];
- if ((tp->t_state&(TS_CARR_ON|TS_ISOPEN)) == 0)
- return;
- pti = &pt_ioctl[minor(dev)];
- if (pti->pt_flags & PF_PKT) {
- if (pti->pt_send) {
- (void) passc(pti->pt_send);
- pti->pt_send = 0;
- return;
+ /*
+ * We want to block until the slave
+ * is open, and there's something to read;
+ * but if we lost the slave or we're NBIO,
+ * then return the appropriate error instead.
+ */
+ for (;;) {
+ if (tp->t_state&TS_ISOPEN) {
+ if (pti->pt_flags&PF_PKT && pti->pt_send) {
+ error = ureadc((int)pti->pt_send, uio);
+ if (error)
+ return (error);
+ if (pti->pt_send & TIOCPKT_IOCTL) {
+ cc = min(uio->uio_resid,
+ sizeof(tp->t_termios));
+ uiomove(&tp->t_termios, cc, uio);
+ }
+ pti->pt_send = 0;
+ return (0);
+ }
+ if (pti->pt_flags&PF_UCNTL && pti->pt_ucntl) {
+ error = ureadc((int)pti->pt_ucntl, uio);
+ if (error)
+ return (error);
+ pti->pt_ucntl = 0;
+ return (0);
+ }
+ if (pti->pt_flags&PF_TIOC && pti->pt_ioc.c_cc) {
+ if (uio->uio_resid < pti->pt_ioc.c_cc + 1)
+ return (E2BIG);
+ error = ureadc(TIOCPKT_TIOC, uio);
+ while (error == 0 && pti->pt_ioc.c_cc > 0) {
+ cc = q_to_b(&pti->pt_ioc, buf,
+ MIN(pti->pt_ioc.c_cc, BUFSIZ));
+ if (cc <= 0) /* impossible? */
+ break;
+ error = uiomove(buf, cc, UIO_READ, uio);
+ }
+ return (error);
+ }
+ if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0)
+ break;