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.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
--- 84 unchanged lines hidden (view full) ---
127 tp->t_oflag = TTYDEF_OFLAG;
128 tp->t_lflag = TTYDEF_LFLAG;
129 tp->t_cflag = TTYDEF_CFLAG;
130 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
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, TSA_CARR_ON(tp), TTIPRI | PCATCH,
140 "ptsopn", 0);
141 if (error)
142 return (error);
143 }
--- 119 unchanged lines hidden (view full) ---
263 wakeup(TSA_PTC_READ(tp));
264 }
265 if (flag & FWRITE) {
266 selwakeup(&pti->pt_selw);
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
276int
277ptcopen(dev, flag, devtype, p)
278 dev_t dev;
279 int flag, devtype;
280 struct proc *p;
281#endif
282{
283 register struct tty *tp;
284 struct pt_ioctl *pti;
285
286 if (minor(dev) >= npty)
287 return (ENXIO);
288 tp = &pt_tty[minor(dev)];
289 if (tp->t_oproc)
--- 14 unchanged lines hidden (view full) ---
304int
305ptcclose(dev)
306 dev_t dev;
307{
308 register struct tty *tp;
309
310 tp = &pt_tty[minor(dev)];
311 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
312 tp->t_state &= ~TS_CARR_ON;
313 tp->t_oproc = 0; /* mark closed */
314 tp->t_session = 0;
315 return (0);
316}
317
318int
319ptcread(dev, uio, flag)
320 dev_t dev;
--- 31 unchanged lines hidden (view full) ---
352 if (error)
353 return (error);
354 pti->pt_ucntl = 0;
355 return (0);
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(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0);
365 if (error)
366 return (error);
367 }
368 if (pti->pt_flags & (PF_PKT|PF_UCNTL))
--- 37 unchanged lines hidden (view full) ---
406 dev_t dev;
407 int rw;
408 struct proc *p;
409{
410 register struct tty *tp = &pt_tty[minor(dev)];
411 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
412 int s;
413
414 if ((tp->t_state&TS_CARR_ON) == 0)
415 return (1);
416 switch (rw) {
417
418 case FREAD:
419 /*
420 * Need to block timeouts (ttrstart).
421 */
422 s = spltty();
--- 83 unchanged lines hidden (view full) ---
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(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 }
523 return (0);
524block:
525 /*
526 * Come here to wait for slave to open, for space
527 * in outq, or space in rawq.
528 */
529 if ((tp->t_state&TS_CARR_ON) == 0)
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 }
--- 176 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.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
--- 84 unchanged lines hidden (view full) ---
127 tp->t_oflag = TTYDEF_OFLAG;
128 tp->t_lflag = TTYDEF_LFLAG;
129 tp->t_cflag = TTYDEF_CFLAG;
130 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
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, TSA_CARR_ON(tp), TTIPRI | PCATCH,
140 "ptsopn", 0);
141 if (error)
142 return (error);
143 }
--- 119 unchanged lines hidden (view full) ---
263 wakeup(TSA_PTC_READ(tp));
264 }
265 if (flag & FWRITE) {
266 selwakeup(&pti->pt_selw);
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
276int
277ptcopen(dev, flag, devtype, p)
278 dev_t dev;
279 int flag, devtype;
280 struct proc *p;
281#endif
282{
283 register struct tty *tp;
284 struct pt_ioctl *pti;
285
286 if (minor(dev) >= npty)
287 return (ENXIO);
288 tp = &pt_tty[minor(dev)];
289 if (tp->t_oproc)
--- 14 unchanged lines hidden (view full) ---
304int
305ptcclose(dev)
306 dev_t dev;
307{
308 register struct tty *tp;
309
310 tp = &pt_tty[minor(dev)];
311 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
312 tp->t_state &= ~TS_CARR_ON;
313 tp->t_oproc = 0; /* mark closed */
314 tp->t_session = 0;
315 return (0);
316}
317
318int
319ptcread(dev, uio, flag)
320 dev_t dev;
--- 31 unchanged lines hidden (view full) ---
352 if (error)
353 return (error);
354 pti->pt_ucntl = 0;
355 return (0);
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(TSA_PTC_READ(tp), TTIPRI | PCATCH, "ptcin", 0);
365 if (error)
366 return (error);
367 }
368 if (pti->pt_flags & (PF_PKT|PF_UCNTL))
--- 37 unchanged lines hidden (view full) ---
406 dev_t dev;
407 int rw;
408 struct proc *p;
409{
410 register struct tty *tp = &pt_tty[minor(dev)];
411 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
412 int s;
413
414 if ((tp->t_state&TS_CARR_ON) == 0)
415 return (1);
416 switch (rw) {
417
418 case FREAD:
419 /*
420 * Need to block timeouts (ttrstart).
421 */
422 s = spltty();
--- 83 unchanged lines hidden (view full) ---
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(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 }
523 return (0);
524block:
525 /*
526 * Come here to wait for slave to open, for space
527 * in outq, or space in rawq.
528 */
529 if ((tp->t_state&TS_CARR_ON) == 0)
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 }
--- 176 unchanged lines hidden ---