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.20 1995/09/08 11:08:38 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
55#if NPTY == 1
56#undef NPTY
57#define NPTY 32 /* crude XXX */
58#endif
59
60#define BUFSIZ 100 /* Chunk size iomoved to/from user */
61
62/*
--- 418 unchanged lines hidden (view full) ---
481 int error = 0;
482
483again:
484 if ((tp->t_state&TS_ISOPEN) == 0)
485 goto block;
486 if (pti->pt_flags & PF_REMOTE) {
487 if (tp->t_canq.c_cc)
488 goto block;
489 while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) {
490 if (cc == 0) {
491 cc = min(uio->uio_resid, BUFSIZ);
492 cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc);
493 cp = locbuf;
494 error = uiomove((caddr_t)cp, cc, uio);
495 if (error)
496 return (error);
497 /* check again for safety */
498 if ((tp->t_state&TS_ISOPEN) == 0)
499 return (EIO);
500 }
501 if (cc)
502 (void) b_to_q((char *)cp, cc, &tp->t_canq);
503 cc = 0;
504 }
505 (void) putc(0, &tp->t_canq);
506 ttwakeup(tp);
507 wakeup(TSA_PTS_READ(tp));
508 return (0);
509 }
510 while (uio->uio_resid > 0) {
511 if (cc == 0) {
512 cc = min(uio->uio_resid, BUFSIZ);
513 cp = locbuf;
514 error = uiomove((caddr_t)cp, cc, uio);
515 if (error)
516 return (error);
517 /* check again for safety */
518 if ((tp->t_state&TS_ISOPEN) == 0)
519 return (EIO);
520 }
521 while (cc > 0) {
522 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
523 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
524 wakeup(TSA_HUP_OR_INPUT(tp));
525 goto block;
526 }
527 (*linesw[tp->t_line].l_rint)(*cp++, tp);
528 cnt++;
529 cc--;
530 }
531 cc = 0;
532 }
533 return (0);
534block:
535 /*
536 * Come here to wait for slave to open, for space
537 * in outq, or space in rawq.
538 */
539 if ((tp->t_state & TS_CONNECTED) == 0)
540 return (EIO);
541 if (flag & IO_NDELAY) {
542 /* adjust for data copied in but not written */
543 uio->uio_resid += cc;
544 if (cnt == 0)
545 return (EWOULDBLOCK);
546 return (0);
547 }
548 error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptcout", 0);
--- 175 unchanged lines hidden ---
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.20 1995/09/08 11:08:38 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
55#if NPTY == 1
56#undef NPTY
57#define NPTY 32 /* crude XXX */
58#endif
59
60#define BUFSIZ 100 /* Chunk size iomoved to/from user */
61
62/*
--- 418 unchanged lines hidden (view full) ---
481 int error = 0;
482
483again:
484 if ((tp->t_state&TS_ISOPEN) == 0)
485 goto block;
486 if (pti->pt_flags & PF_REMOTE) {
487 if (tp->t_canq.c_cc)
488 goto block;
489 while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) {
490 if (cc == 0) {
491 cc = min(uio->uio_resid, BUFSIZ);
492 cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc);
493 cp = locbuf;
494 error = uiomove((caddr_t)cp, cc, uio);
495 if (error)
496 return (error);
497 /* check again for safety */
498 if ((tp->t_state&TS_ISOPEN) == 0)
499 return (EIO);
500 }
501 if (cc)
502 (void) b_to_q((char *)cp, cc, &tp->t_canq);
503 cc = 0;
504 }
505 (void) putc(0, &tp->t_canq);
506 ttwakeup(tp);
507 wakeup(TSA_PTS_READ(tp));
508 return (0);
509 }
510 while (uio->uio_resid > 0) {
511 if (cc == 0) {
512 cc = min(uio->uio_resid, BUFSIZ);
513 cp = locbuf;
514 error = uiomove((caddr_t)cp, cc, uio);
515 if (error)
516 return (error);
517 /* check again for safety */
518 if ((tp->t_state&TS_ISOPEN) == 0)
519 return (EIO);
520 }
521 while (cc > 0) {
522 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
523 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) {
524 wakeup(TSA_HUP_OR_INPUT(tp));
525 goto block;
526 }
527 (*linesw[tp->t_line].l_rint)(*cp++, tp);
528 cnt++;
529 cc--;
530 }
531 cc = 0;
532 }
533 return (0);
534block:
535 /*
536 * Come here to wait for slave to open, for space
537 * in outq, or space in rawq.
538 */
539 if ((tp->t_state & TS_CONNECTED) == 0)
540 return (EIO);
541 if (flag & IO_NDELAY) {
542 /* adjust for data copied in but not written */
543 uio->uio_resid += cc;
544 if (cnt == 0)
545 return (EWOULDBLOCK);
546 return (0);
547 }
548 error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptcout", 0);
--- 175 unchanged lines hidden ---