pty.c (9626) | pty.c (9639) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93 |
34 * $Id: tty_pty.c,v 1.13 1995/07/21 20:52:40 bde Exp $ | 34 * $Id: tty_pty.c,v 1.14 1995/07/22 01:30:32 bde Exp $ |
35 */ 36 37/* 38 * Pseudo-teletype Driver 39 * (Actually two drivers, requiring two entries in 'cdevsw') 40 */ 41#include "pty.h" /* XXX */ 42 --- 88 unchanged lines hidden (view full) --- 131 ttsetwater(tp); /* would be done in xxparam() */ 132 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0) 133 return (EBUSY); 134 if (tp->t_oproc) /* Ctrlr still around. */ 135 tp->t_state |= TS_CARR_ON; 136 while ((tp->t_state & TS_CARR_ON) == 0) { 137 if (flag&FNONBLOCK) 138 break; | 35 */ 36 37/* 38 * Pseudo-teletype Driver 39 * (Actually two drivers, requiring two entries in 'cdevsw') 40 */ 41#include "pty.h" /* XXX */ 42 --- 88 unchanged lines hidden (view full) --- 131 ttsetwater(tp); /* would be done in xxparam() */ 132 } else if (tp->t_state&TS_XCLUDE && p->p_ucred->cr_uid != 0) 133 return (EBUSY); 134 if (tp->t_oproc) /* Ctrlr still around. */ 135 tp->t_state |= TS_CARR_ON; 136 while ((tp->t_state & TS_CARR_ON) == 0) { 137 if (flag&FNONBLOCK) 138 break; |
139 error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, | 139 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH, |
140 "ptsopn", 0); 141 if (error) 142 return (error); 143 } 144 error = (*linesw[tp->t_line].l_open)(dev, tp); 145 if (error == 0) 146 ptcwakeup(tp, FREAD|FWRITE); 147 return (error); --- 38 unchanged lines hidden (view full) --- 186 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, "ptsbg", 187 0); 188 if (error) 189 return (error); 190 } 191 if (tp->t_canq.c_cc == 0) { 192 if (flag & IO_NDELAY) 193 return (EWOULDBLOCK); | 140 "ptsopn", 0); 141 if (error) 142 return (error); 143 } 144 error = (*linesw[tp->t_line].l_open)(dev, tp); 145 if (error == 0) 146 ptcwakeup(tp, FREAD|FWRITE); 147 return (error); --- 38 unchanged lines hidden (view full) --- 186 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, "ptsbg", 187 0); 188 if (error) 189 return (error); 190 } 191 if (tp->t_canq.c_cc == 0) { 192 if (flag & IO_NDELAY) 193 return (EWOULDBLOCK); |
194 error = ttysleep(tp, &tp->t_canq, TTIPRI | PCATCH, | 194 error = ttysleep(tp, TSA_PTS_READ(tp), TTIPRI | PCATCH, |
195 "ptsin", 0); 196 if (error) 197 return (error); 198 goto again; 199 } 200 while (tp->t_canq.c_cc > 1 && uio->uio_resid > 0) 201 if (ureadc(getc(&tp->t_canq), uio) < 0) { 202 error = EFAULT; --- 52 unchanged lines hidden (view full) --- 255ptcwakeup(tp, flag) 256 struct tty *tp; 257 int flag; 258{ 259 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; 260 261 if (flag & FREAD) { 262 selwakeup(&pti->pt_selr); | 195 "ptsin", 0); 196 if (error) 197 return (error); 198 goto again; 199 } 200 while (tp->t_canq.c_cc > 1 && uio->uio_resid > 0) 201 if (ureadc(getc(&tp->t_canq), uio) < 0) { 202 error = EFAULT; --- 52 unchanged lines hidden (view full) --- 255ptcwakeup(tp, flag) 256 struct tty *tp; 257 int flag; 258{ 259 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; 260 261 if (flag & FREAD) { 262 selwakeup(&pti->pt_selr); |
263 wakeup((caddr_t)&tp->t_outq.c_cf); | 263 wakeup(TSA_PTC_READ(tp)); |
264 } 265 if (flag & FWRITE) { 266 selwakeup(&pti->pt_selw); | 264 } 265 if (flag & FWRITE) { 266 selwakeup(&pti->pt_selw); |
267 wakeup((caddr_t)&tp->t_rawq.c_cl); | 267 wakeup(TSA_PTC_WRITE(tp)); |
268 } 269} 270 271/*ARGSUSED*/ 272#ifdef __STDC__ 273int 274ptcopen(dev_t dev, int flag, int devtype, struct proc *p) 275#else --- 80 unchanged lines hidden (view full) --- 356 } 357 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) 358 break; 359 } 360 if ((tp->t_state&TS_CARR_ON) == 0) 361 return (0); /* EOF */ 362 if (flag & IO_NDELAY) 363 return (EWOULDBLOCK); | 268 } 269} 270 271/*ARGSUSED*/ 272#ifdef __STDC__ 273int 274ptcopen(dev_t dev, int flag, int devtype, struct proc *p) 275#else --- 80 unchanged lines hidden (view full) --- 356 } 357 if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) 358 break; 359 } 360 if ((tp->t_state&TS_CARR_ON) == 0) 361 return (0); /* EOF */ 362 if (flag & IO_NDELAY) 363 return (EWOULDBLOCK); |
364 error = tsleep(&tp->t_outq.c_cf, TTIPRI | PCATCH, "ptcin", 0); | 364 error = tsleep(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0); |
365 if (error) 366 return (error); 367 } 368 if (pti->pt_flags & (PF_PKT|PF_UCNTL)) 369 error = ureadc(0, uio); 370 while (uio->uio_resid > 0 && error == 0) { 371 cc = q_to_b(&tp->t_outq, buf, min(uio->uio_resid, BUFSIZ)); 372 if (cc <= 0) --- 116 unchanged lines hidden (view full) --- 489 return (EIO); 490 } 491 if (cc) 492 (void) b_to_q((char *)cp, cc, &tp->t_canq); 493 cc = 0; 494 } 495 (void) putc(0, &tp->t_canq); 496 ttwakeup(tp); | 365 if (error) 366 return (error); 367 } 368 if (pti->pt_flags & (PF_PKT|PF_UCNTL)) 369 error = ureadc(0, uio); 370 while (uio->uio_resid > 0 && error == 0) { 371 cc = q_to_b(&tp->t_outq, buf, min(uio->uio_resid, BUFSIZ)); 372 if (cc <= 0) --- 116 unchanged lines hidden (view full) --- 489 return (EIO); 490 } 491 if (cc) 492 (void) b_to_q((char *)cp, cc, &tp->t_canq); 493 cc = 0; 494 } 495 (void) putc(0, &tp->t_canq); 496 ttwakeup(tp); |
497 wakeup((caddr_t)&tp->t_canq); | 497 wakeup(TSA_PTS_READ(tp)); |
498 return (0); 499 } 500 while (uio->uio_resid > 0) { 501 if (cc == 0) { 502 cc = min(uio->uio_resid, BUFSIZ); 503 cp = locbuf; 504 error = uiomove((caddr_t)cp, cc, uio); 505 if (error) 506 return (error); 507 /* check again for safety */ 508 if ((tp->t_state&TS_ISOPEN) == 0) 509 return (EIO); 510 } 511 while (cc > 0) { 512 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && 513 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { | 498 return (0); 499 } 500 while (uio->uio_resid > 0) { 501 if (cc == 0) { 502 cc = min(uio->uio_resid, BUFSIZ); 503 cp = locbuf; 504 error = uiomove((caddr_t)cp, cc, uio); 505 if (error) 506 return (error); 507 /* check again for safety */ 508 if ((tp->t_state&TS_ISOPEN) == 0) 509 return (EIO); 510 } 511 while (cc > 0) { 512 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && 513 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { |
514 wakeup((caddr_t)&tp->t_rawq); | 514 wakeup(TSA_CARR_ON(tp)); |
515 goto block; 516 } 517 (*linesw[tp->t_line].l_rint)(*cp++, tp); 518 cnt++; 519 cc--; 520 } 521 cc = 0; 522 } --- 7 unchanged lines hidden (view full) --- 530 return (EIO); 531 if (flag & IO_NDELAY) { 532 /* adjust for data copied in but not written */ 533 uio->uio_resid += cc; 534 if (cnt == 0) 535 return (EWOULDBLOCK); 536 return (0); 537 } | 515 goto block; 516 } 517 (*linesw[tp->t_line].l_rint)(*cp++, tp); 518 cnt++; 519 cc--; 520 } 521 cc = 0; 522 } --- 7 unchanged lines hidden (view full) --- 530 return (EIO); 531 if (flag & IO_NDELAY) { 532 /* adjust for data copied in but not written */ 533 uio->uio_resid += cc; 534 if (cnt == 0) 535 return (EWOULDBLOCK); 536 return (0); 537 } |
538 error = tsleep(&tp->t_rawq.c_cl, TTOPRI | PCATCH, "ptcout", 0); | 538 error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptcout", 0); |
539 if (error) { 540 /* adjust for data copied in but not written */ 541 uio->uio_resid += cc; 542 return (error); 543 } 544 goto again; 545} 546 --- 167 unchanged lines hidden --- | 539 if (error) { 540 /* adjust for data copied in but not written */ 541 uio->uio_resid += cc; 542 return (error); 543 } 544 goto again; 545} 546 --- 167 unchanged lines hidden --- |