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.21 1995/09/19 12:26:47 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 --- 4 unchanged lines hidden (view full) --- 47#include <sys/tty.h> 48#include <sys/conf.h> 49#include <sys/file.h> 50#include <sys/uio.h> 51#include <sys/kernel.h> 52#include <sys/vnode.h> 53#include <sys/signalvar.h> 54 |
55void ptyattach __P((int n)); 56void ptsstart __P((struct tty *tp)); 57void ptcwakeup __P((struct tty *tp, int flag)); 58 |
59#if NPTY == 1 60#undef NPTY 61#define NPTY 32 /* crude XXX */ 62#endif 63 64#define BUFSIZ 100 /* Chunk size iomoved to/from user */ 65 66/* --- 418 unchanged lines hidden (view full) --- 485 int error = 0; 486 487again: 488 if ((tp->t_state&TS_ISOPEN) == 0) 489 goto block; 490 if (pti->pt_flags & PF_REMOTE) { 491 if (tp->t_canq.c_cc) 492 goto block; |
493 while ((uio->uio_resid > 0 || cc > 0) && 494 tp->t_canq.c_cc < TTYHOG - 1) { |
495 if (cc == 0) { 496 cc = min(uio->uio_resid, BUFSIZ); 497 cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc); 498 cp = locbuf; 499 error = uiomove((caddr_t)cp, cc, uio); 500 if (error) 501 return (error); 502 /* check again for safety */ |
503 if ((tp->t_state & TS_ISOPEN) == 0) { 504 /* adjust as usual */ 505 uio->uio_resid += cc; |
506 return (EIO); |
507 } |
508 } 509 if (cc) |
510 cc -= b_to_q((char *)cp, cc, &tp->t_canq); |
511 } |
512 /* adjust for data copied in but not written */ 513 uio->uio_resid += cc; |
514 (void) putc(0, &tp->t_canq); 515 ttwakeup(tp); 516 wakeup(TSA_PTS_READ(tp)); 517 return (0); 518 } |
519 while (uio->uio_resid > 0 || cc > 0) { |
520 if (cc == 0) { 521 cc = min(uio->uio_resid, BUFSIZ); 522 cp = locbuf; 523 error = uiomove((caddr_t)cp, cc, uio); 524 if (error) 525 return (error); 526 /* check again for safety */ |
527 if ((tp->t_state & TS_ISOPEN) == 0) { 528 /* adjust for data copied in but not written */ 529 uio->uio_resid += cc; |
530 return (EIO); |
531 } |
532 } 533 while (cc > 0) { 534 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && 535 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { 536 wakeup(TSA_HUP_OR_INPUT(tp)); 537 goto block; 538 } 539 (*linesw[tp->t_line].l_rint)(*cp++, tp); 540 cnt++; 541 cc--; 542 } 543 cc = 0; 544 } 545 return (0); 546block: 547 /* 548 * Come here to wait for slave to open, for space 549 * in outq, or space in rawq. 550 */ |
551 if ((tp->t_state & TS_CONNECTED) == 0) { 552 /* adjust for data copied in but not written */ 553 uio->uio_resid += cc; |
554 return (EIO); |
555 } |
556 if (flag & IO_NDELAY) { 557 /* adjust for data copied in but not written */ 558 uio->uio_resid += cc; 559 if (cnt == 0) 560 return (EWOULDBLOCK); 561 return (0); 562 } 563 error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptcout", 0); --- 175 unchanged lines hidden --- |