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
--- 16 unchanged lines hidden (view full) ---
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 131114 2004-06-25 21:54:49Z phk $");
34
35/*
36 * Pseudo-teletype Driver
37 * (Actually two drivers, requiring two entries in 'cdevsw')
38 */
39#include "opt_compat.h"
40#include "opt_tty.h"
41#include <sys/param.h>
--- 70 unchanged lines hidden (view full) ---
112 u_char pt_ucntl;
113 struct tty *pt_tty;
114 struct cdev *devs, *devc;
115 struct prison *pt_prison;
116};
117
118#define PF_PKT 0x08 /* packet mode */
119#define PF_STOPPED 0x10 /* user told stopped */
120#define PF_NOSTOP 0x40
121#define PF_UCNTL 0x80 /* user control mode */
122
123#define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cf)
124#define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_cl)
125#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
126
127static char *names = "pqrsPQRS";
--- 89 unchanged lines hidden (view full) ---
217 struct thread *td = curthread;
218 struct proc *p = td->td_proc;
219 struct tty *tp = dev->si_tty;
220 struct ptsc *pt = dev->si_drv1;
221 struct pgrp *pg;
222 int error = 0;
223
224again:
225 if (tp->t_oproc)
226 error = ttyld_read(tp, uio, flag);
227 ptcwakeup(tp, FWRITE);
228 return (error);
229}
230
231/*
232 * Write to pseudo-tty.
233 * Wakeups of controlling tty will happen
234 * indirectly, when tty driver calls ptsstart.
--- 195 unchanged lines hidden (view full) ---
430 if ((tp->t_state & TS_ISOPEN) &&
431 ((tp->t_outq.c_cc && (tp->t_state & TS_TTSTOP) == 0) ||
432 ((pt->pt_flags & PF_PKT) && pt->pt_send) ||
433 ((pt->pt_flags & PF_UCNTL) && pt->pt_ucntl)))
434 revents |= events & (POLLIN | POLLRDNORM);
435
436 if (events & (POLLOUT | POLLWRNORM))
437 if (tp->t_state & TS_ISOPEN &&
438 (((tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG - 2) ||
439 (tp->t_canq.c_cc == 0 && (tp->t_lflag & ICANON)))))
440 revents |= events & (POLLOUT | POLLWRNORM);
441
442 if (events & POLLHUP)
443 if ((tp->t_state & TS_CARR_ON) == 0)
444 revents |= POLLHUP;
445
446 if (revents == 0) {
--- 17 unchanged lines hidden (view full) ---
464 u_char locbuf[BUFSIZ];
465 int cnt = 0;
466 struct ptsc *pt = dev->si_drv1;
467 int error = 0;
468
469again:
470 if ((tp->t_state&TS_ISOPEN) == 0)
471 goto block;
472 while (uio->uio_resid > 0 || cc > 0) {
473 if (cc == 0) {
474 cc = min(uio->uio_resid, BUFSIZ);
475 cp = locbuf;
476 error = uiomove(cp, cc, uio);
477 if (error)
478 return (error);
479 /* check again for safety */
--- 74 unchanged lines hidden (view full) ---
554 case TIOCUCNTL:
555 if (*(int *)data) {
556 if (pt->pt_flags & PF_PKT)
557 return (EINVAL);
558 pt->pt_flags |= PF_UCNTL;
559 } else
560 pt->pt_flags &= ~PF_UCNTL;
561 return (0);
562 }
563
564 /*
565 * The rest of the ioctls shouldn't be called until
566 * the slave is open.
567 */
568 if ((tp->t_state & TS_ISOPEN) == 0)
569 return (EAGAIN);
--- 159 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
--- 16 unchanged lines hidden (view full) ---
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 131114 2004-06-25 21:54:49Z phk $");
34
35/*
36 * Pseudo-teletype Driver
37 * (Actually two drivers, requiring two entries in 'cdevsw')
38 */
39#include "opt_compat.h"
40#include "opt_tty.h"
41#include <sys/param.h>
--- 70 unchanged lines hidden (view full) ---
112 u_char pt_ucntl;
113 struct tty *pt_tty;
114 struct cdev *devs, *devc;
115 struct prison *pt_prison;
116};
117
118#define PF_PKT 0x08 /* packet mode */
119#define PF_STOPPED 0x10 /* user told stopped */
120#define PF_NOSTOP 0x40
121#define PF_UCNTL 0x80 /* user control mode */
122
123#define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cf)
124#define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_cl)
125#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
126
127static char *names = "pqrsPQRS";
--- 89 unchanged lines hidden (view full) ---
217 struct thread *td = curthread;
218 struct proc *p = td->td_proc;
219 struct tty *tp = dev->si_tty;
220 struct ptsc *pt = dev->si_drv1;
221 struct pgrp *pg;
222 int error = 0;
223
224again:
225 if (tp->t_oproc)
226 error = ttyld_read(tp, uio, flag);
227 ptcwakeup(tp, FWRITE);
228 return (error);
229}
230
231/*
232 * Write to pseudo-tty.
233 * Wakeups of controlling tty will happen
234 * indirectly, when tty driver calls ptsstart.
--- 195 unchanged lines hidden (view full) ---
430 if ((tp->t_state & TS_ISOPEN) &&
431 ((tp->t_outq.c_cc && (tp->t_state & TS_TTSTOP) == 0) ||
432 ((pt->pt_flags & PF_PKT) && pt->pt_send) ||
433 ((pt->pt_flags & PF_UCNTL) && pt->pt_ucntl)))
434 revents |= events & (POLLIN | POLLRDNORM);
435
436 if (events & (POLLOUT | POLLWRNORM))
437 if (tp->t_state & TS_ISOPEN &&
438 (((tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG - 2) ||
439 (tp->t_canq.c_cc == 0 && (tp->t_lflag & ICANON)))))
440 revents |= events & (POLLOUT | POLLWRNORM);
441
442 if (events & POLLHUP)
443 if ((tp->t_state & TS_CARR_ON) == 0)
444 revents |= POLLHUP;
445
446 if (revents == 0) {
--- 17 unchanged lines hidden (view full) ---
464 u_char locbuf[BUFSIZ];
465 int cnt = 0;
466 struct ptsc *pt = dev->si_drv1;
467 int error = 0;
468
469again:
470 if ((tp->t_state&TS_ISOPEN) == 0)
471 goto block;
472 while (uio->uio_resid > 0 || cc > 0) {
473 if (cc == 0) {
474 cc = min(uio->uio_resid, BUFSIZ);
475 cp = locbuf;
476 error = uiomove(cp, cc, uio);
477 if (error)
478 return (error);
479 /* check again for safety */
--- 74 unchanged lines hidden (view full) ---
554 case TIOCUCNTL:
555 if (*(int *)data) {
556 if (pt->pt_flags & PF_PKT)
557 return (EINVAL);
558 pt->pt_flags |= PF_UCNTL;
559 } else
560 pt->pt_flags &= ~PF_UCNTL;
561 return (0);
562 }
563
564 /*
565 * The rest of the ioctls shouldn't be called until
566 * the slave is open.
567 */
568 if ((tp->t_state & TS_ISOPEN) == 0)
569 return (EAGAIN);
--- 159 unchanged lines hidden ---