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.4 (Berkeley) 2/20/95
34 * $Id: tty_pty.c,v 1.60 1999/05/30 16:52:57 phk Exp $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42#include "opt_compat.h"
43#include "opt_devfs.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
48#include <sys/ioctl_compat.h>
49#endif
50#include <sys/proc.h>
51#include <sys/tty.h>
52#include <sys/conf.h>
53#include <sys/fcntl.h>
54#include <sys/poll.h>
55#include <sys/kernel.h>
56#include <sys/vnode.h>
57#include <sys/signalvar.h>
58
59#ifdef DEVFS
60#include <sys/devfsext.h>
61#endif /*DEVFS*/
62
63#ifdef notyet
64static void ptyattach __P((int n));
65#endif
66static void ptsstart __P((struct tty *tp));
67static void ptcwakeup __P((struct tty *tp, int flag));
68
69static d_open_t ptsopen;
70static d_close_t ptsclose;
71static d_read_t ptsread;
72static d_write_t ptswrite;
73static d_ioctl_t ptyioctl;
74static d_stop_t ptsstop;
75static d_devtotty_t ptydevtotty;
--- 44 unchanged lines hidden (view full) ---
120 /* maj */ CDEV_MAJOR_C,
121 /* dump */ nodump,
122 /* psize */ nopsize,
123 /* flags */ D_TTY,
124 /* maxio */ 0,
125 /* bmaj */ -1
126};
127
128#if NPTY == 1
129#undef NPTY
130#define NPTY 32 /* crude XXX */
131#warning You have only one pty defined, redefining to 32.
132#endif
133
134#ifdef DEVFS
135#define MAXUNITS (8 * 32)
136static void *devfs_token_pts[MAXUNITS];
137static void *devfs_token_ptc[MAXUNITS];
138static const char jnames[] = "pqrsPQRS";
139#if NPTY > MAXUNITS
140#undef NPTY
141#define NPTY MAXUNITS
142#warning Can't have more than 256 pty's with DEVFS defined.
143#endif
144#endif
145
146#define BUFSIZ 100 /* Chunk size iomoved to/from user */
147
148/*
149 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
150 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
151 */
152static struct tty pt_tty[NPTY]; /* XXX */
153static struct pt_ioctl {
154 int pt_flags;
155 struct selinfo pt_selr, pt_selw;
156 u_char pt_send;
157 u_char pt_ucntl;
158} pt_ioctl[NPTY]; /* XXX */
159static int npty = NPTY; /* for pstat -t */
160
161#define PF_PKT 0x08 /* packet mode */
162#define PF_STOPPED 0x10 /* user told stopped */
163#define PF_REMOTE 0x20 /* remote and flow controlled input */
164#define PF_NOSTOP 0x40
165#define PF_UCNTL 0x80 /* user control mode */
166
167#ifdef notyet
168/*
169 * Establish n (or default if n is 1) ptys in the system.
170 *
171 * XXX cdevsw & pstat require the array `pty[]' to be an array
172 */
173static void
174ptyattach(n)
175 int n;
176{
177 char *mem;
178 register u_long ntb;
179#define DEFAULT_NPTY 32
180
181 /* maybe should allow 0 => none? */
182 if (n <= 1)
183 n = DEFAULT_NPTY;
184 ntb = n * sizeof(struct tty);
185 mem = malloc(ntb + ALIGNBYTES + n * sizeof(struct pt_ioctl),
186 M_DEVBUF, M_WAITOK);
187 pt_tty = (struct tty *)mem;
188 mem = (char *)ALIGN(mem + ntb);
189 pt_ioctl = (struct pt_ioctl *)mem;
190 npty = n;
191}
192#endif
193
194/*ARGSUSED*/
195static int
196ptsopen(dev, flag, devtype, p)
197 dev_t dev;
198 int flag, devtype;
199 struct proc *p;
200{
201 register struct tty *tp;
202 int error;
203
204 if (minor(dev) >= npty)
205 return (ENXIO);
206 tp = &pt_tty[minor(dev)];
207 if ((tp->t_state & TS_ISOPEN) == 0) {
208 ttychars(tp); /* Set up default chars */
209 tp->t_iflag = TTYDEF_IFLAG;
210 tp->t_oflag = TTYDEF_OFLAG;
211 tp->t_lflag = TTYDEF_LFLAG;
212 tp->t_cflag = TTYDEF_CFLAG;
213 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
214 } else if (tp->t_state & TS_XCLUDE && suser(p))
--- 18 unchanged lines hidden (view full) ---
233ptsclose(dev, flag, mode, p)
234 dev_t dev;
235 int flag, mode;
236 struct proc *p;
237{
238 register struct tty *tp;
239 int err;
240
241 tp = &pt_tty[minor(dev)];
242 err = (*linesw[tp->t_line].l_close)(tp, flag);
243 ptsstop(tp, FREAD|FWRITE);
244 (void) ttyclose(tp);
245 return (err);
246}
247
248static int
249ptsread(dev, uio, flag)
250 dev_t dev;
251 struct uio *uio;
252 int flag;
253{
254 struct proc *p = curproc;
255 register struct tty *tp = &pt_tty[minor(dev)];
256 register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
257 int error = 0;
258
259again:
260 if (pti->pt_flags & PF_REMOTE) {
261 while (isbackground(p, tp)) {
262 if ((p->p_sigignore & sigmask(SIGTTIN)) ||
263 (p->p_sigmask & sigmask(SIGTTIN)) ||
264 p->p_pgrp->pg_jobc == 0 ||
--- 38 unchanged lines hidden (view full) ---
303static int
304ptswrite(dev, uio, flag)
305 dev_t dev;
306 struct uio *uio;
307 int flag;
308{
309 register struct tty *tp;
310
311 tp = &pt_tty[minor(dev)];
312 if (tp->t_oproc == 0)
313 return (EIO);
314 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
315}
316
317/*
318 * Start output on pseudo-tty.
319 * Wake up process selecting or sleeping for input from controlling tty.
320 */
321static void
322ptsstart(tp)
323 struct tty *tp;
324{
325 register struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
326
327 if (tp->t_state & TS_TTSTOP)
328 return;
329 if (pti->pt_flags & PF_STOPPED) {
330 pti->pt_flags &= ~PF_STOPPED;
331 pti->pt_send = TIOCPKT_START;
332 }
333 ptcwakeup(tp, FREAD);
334}
335
336static void
337ptcwakeup(tp, flag)
338 struct tty *tp;
339 int flag;
340{
341 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
342
343 if (flag & FREAD) {
344 selwakeup(&pti->pt_selr);
345 wakeup(TSA_PTC_READ(tp));
346 }
347 if (flag & FWRITE) {
348 selwakeup(&pti->pt_selw);
349 wakeup(TSA_PTC_WRITE(tp));
--- 4 unchanged lines hidden (view full) ---
354ptcopen(dev, flag, devtype, p)
355 dev_t dev;
356 int flag, devtype;
357 struct proc *p;
358{
359 register struct tty *tp;
360 struct pt_ioctl *pti;
361
362 if (minor(dev) >= npty)
363 return (ENXIO);
364 tp = &pt_tty[minor(dev)];
365 if (tp->t_oproc)
366 return (EIO);
367 tp->t_oproc = ptsstart;
368#ifdef sun4c
369 tp->t_stop = ptsstop;
370#endif
371 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
372 tp->t_lflag &= ~EXTPROC;
373 pti = &pt_ioctl[minor(dev)];
374 pti->pt_flags = 0;
375 pti->pt_send = 0;
376 pti->pt_ucntl = 0;
377 return (0);
378}
379
380static int
381ptcclose(dev, flags, fmt, p)
382 dev_t dev;
383 int flags;
384 int fmt;
385 struct proc *p;
386{
387 register struct tty *tp;
388
389 tp = &pt_tty[minor(dev)];
390 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
391
392 /*
393 * XXX MDMBUF makes no sense for ptys but would inhibit the above
394 * l_modem(). CLOCAL makes sense but isn't supported. Special
395 * l_modem()s that ignore carrier drop make no sense for ptys but
396 * may be in use because other parts of the line discipline make
397 * sense for ptys. Recover by doing everything that a normal
--- 10 unchanged lines hidden (view full) ---
408}
409
410static int
411ptcread(dev, uio, flag)
412 dev_t dev;
413 struct uio *uio;
414 int flag;
415{
416 register struct tty *tp = &pt_tty[minor(dev)];
417 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
418 char buf[BUFSIZ];
419 int error = 0, cc;
420
421 /*
422 * We want to block until the slave
423 * is open, and there's something to read;
424 * but if we lost the slave or we're NBIO,
425 * then return the appropriate error instead.
--- 43 unchanged lines hidden (view full) ---
469 return (error);
470}
471
472static void
473ptsstop(tp, flush)
474 register struct tty *tp;
475 int flush;
476{
477 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
478 int flag;
479
480 /* note: FLUSHREAD and FLUSHWRITE already ok */
481 if (flush == 0) {
482 flush = TIOCPKT_STOP;
483 pti->pt_flags |= PF_STOPPED;
484 } else
485 pti->pt_flags &= ~PF_STOPPED;
--- 8 unchanged lines hidden (view full) ---
494}
495
496static int
497ptcpoll(dev, events, p)
498 dev_t dev;
499 int events;
500 struct proc *p;
501{
502 register struct tty *tp = &pt_tty[minor(dev)];
503 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
504 int revents = 0;
505 int s;
506
507 if ((tp->t_state & TS_CONNECTED) == 0)
508 return (seltrue(dev, events, p) | POLLHUP);
509
510 /*
511 * Need to block timeouts (ttrstart).
--- 32 unchanged lines hidden (view full) ---
544}
545
546static int
547ptcwrite(dev, uio, flag)
548 dev_t dev;
549 register struct uio *uio;
550 int flag;
551{
552 register struct tty *tp = &pt_tty[minor(dev)];
553 register u_char *cp = 0;
554 register int cc = 0;
555 u_char locbuf[BUFSIZ];
556 int cnt = 0;
557 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
558 int error = 0;
559
560again:
561 if ((tp->t_state&TS_ISOPEN) == 0)
562 goto block;
563 if (pti->pt_flags & PF_REMOTE) {
564 if (tp->t_canq.c_cc)
565 goto block;
--- 86 unchanged lines hidden (view full) ---
652 }
653 goto again;
654}
655
656static struct tty *
657ptydevtotty(dev)
658 dev_t dev;
659{
660 if (minor(dev) >= npty)
661 return (NULL);
662
663 return &pt_tty[minor(dev)];
664}
665
666/*ARGSUSED*/
667static int
668ptyioctl(dev, cmd, data, flag, p)
669 dev_t dev;
670 u_long cmd;
671 caddr_t data;
672 int flag;
673 struct proc *p;
674{
675 register struct tty *tp = &pt_tty[minor(dev)];
676 register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
677 register u_char *cc = tp->t_cc;
678 int stop, error;
679
680 if (devsw(dev)->d_open == ptcopen) {
681 switch (cmd) {
682
683 case TIOCGPGRP:
684 /*
--- 143 unchanged lines hidden (view full) ---
828 pti->pt_send |= TIOCPKT_NOSTOP;
829 pti->pt_flags |= PF_NOSTOP;
830 ptcwakeup(tp, FREAD);
831 }
832 }
833 return (error);
834}
835
836static int ptc_devsw_installed;
837
838static void ptc_drvinit __P((void *unused));
839static void
840ptc_drvinit(unused)
841 void *unused;
842{
843#ifdef DEVFS
844 int i,j,k;
845#endif
846
847 if( ! ptc_devsw_installed ) {
848 cdevsw_add(&pts_cdevsw);
849 cdevsw_add(&ptc_cdevsw);
850 ptc_devsw_installed = 1;
851#ifdef DEVFS
852 for ( i = 0 ; i<NPTY ; i++ ) {
853 j = i / 32;
854 k = i % 32;
855 devfs_token_pts[i] =
856 devfs_add_devswf(&pts_cdevsw,i,
857 DV_CHR,0,0,0666,
858 "tty%c%r",jnames[j],k);
859 devfs_token_ptc[i] =
860 devfs_add_devswf(&ptc_cdevsw,i,
861 DV_CHR,0,0,0666,
862 "pty%c%r",jnames[j],k);
863 }
864#endif
865 }
866}
867
868SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL)
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.4 (Berkeley) 2/20/95
34 * $Id: tty_pty.c,v 1.60 1999/05/30 16:52:57 phk Exp $
35 */
36
37/*
38 * Pseudo-teletype Driver
39 * (Actually two drivers, requiring two entries in 'cdevsw')
40 */
41#include "pty.h" /* XXX */
42#include "opt_compat.h"
43#include "opt_devfs.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
48#include <sys/ioctl_compat.h>
49#endif
50#include <sys/proc.h>
51#include <sys/tty.h>
52#include <sys/conf.h>
53#include <sys/fcntl.h>
54#include <sys/poll.h>
55#include <sys/kernel.h>
56#include <sys/vnode.h>
57#include <sys/signalvar.h>
58
59#ifdef DEVFS
60#include <sys/devfsext.h>
61#endif /*DEVFS*/
62
63#ifdef notyet
64static void ptyattach __P((int n));
65#endif
66static void ptsstart __P((struct tty *tp));
67static void ptcwakeup __P((struct tty *tp, int flag));
68
69static d_open_t ptsopen;
70static d_close_t ptsclose;
71static d_read_t ptsread;
72static d_write_t ptswrite;
73static d_ioctl_t ptyioctl;
74static d_stop_t ptsstop;
75static d_devtotty_t ptydevtotty;
--- 44 unchanged lines hidden (view full) ---
120 /* maj */ CDEV_MAJOR_C,
121 /* dump */ nodump,
122 /* psize */ nopsize,
123 /* flags */ D_TTY,
124 /* maxio */ 0,
125 /* bmaj */ -1
126};
127
128#if NPTY == 1
129#undef NPTY
130#define NPTY 32 /* crude XXX */
131#warning You have only one pty defined, redefining to 32.
132#endif
133
134#ifdef DEVFS
135#define MAXUNITS (8 * 32)
136static void *devfs_token_pts[MAXUNITS];
137static void *devfs_token_ptc[MAXUNITS];
138static const char jnames[] = "pqrsPQRS";
139#if NPTY > MAXUNITS
140#undef NPTY
141#define NPTY MAXUNITS
142#warning Can't have more than 256 pty's with DEVFS defined.
143#endif
144#endif
145
146#define BUFSIZ 100 /* Chunk size iomoved to/from user */
147
148/*
149 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
150 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
151 */
152static struct tty pt_tty[NPTY]; /* XXX */
153static struct pt_ioctl {
154 int pt_flags;
155 struct selinfo pt_selr, pt_selw;
156 u_char pt_send;
157 u_char pt_ucntl;
158} pt_ioctl[NPTY]; /* XXX */
159static int npty = NPTY; /* for pstat -t */
160
161#define PF_PKT 0x08 /* packet mode */
162#define PF_STOPPED 0x10 /* user told stopped */
163#define PF_REMOTE 0x20 /* remote and flow controlled input */
164#define PF_NOSTOP 0x40
165#define PF_UCNTL 0x80 /* user control mode */
166
167#ifdef notyet
168/*
169 * Establish n (or default if n is 1) ptys in the system.
170 *
171 * XXX cdevsw & pstat require the array `pty[]' to be an array
172 */
173static void
174ptyattach(n)
175 int n;
176{
177 char *mem;
178 register u_long ntb;
179#define DEFAULT_NPTY 32
180
181 /* maybe should allow 0 => none? */
182 if (n <= 1)
183 n = DEFAULT_NPTY;
184 ntb = n * sizeof(struct tty);
185 mem = malloc(ntb + ALIGNBYTES + n * sizeof(struct pt_ioctl),
186 M_DEVBUF, M_WAITOK);
187 pt_tty = (struct tty *)mem;
188 mem = (char *)ALIGN(mem + ntb);
189 pt_ioctl = (struct pt_ioctl *)mem;
190 npty = n;
191}
192#endif
193
194/*ARGSUSED*/
195static int
196ptsopen(dev, flag, devtype, p)
197 dev_t dev;
198 int flag, devtype;
199 struct proc *p;
200{
201 register struct tty *tp;
202 int error;
203
204 if (minor(dev) >= npty)
205 return (ENXIO);
206 tp = &pt_tty[minor(dev)];
207 if ((tp->t_state & TS_ISOPEN) == 0) {
208 ttychars(tp); /* Set up default chars */
209 tp->t_iflag = TTYDEF_IFLAG;
210 tp->t_oflag = TTYDEF_OFLAG;
211 tp->t_lflag = TTYDEF_LFLAG;
212 tp->t_cflag = TTYDEF_CFLAG;
213 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
214 } else if (tp->t_state & TS_XCLUDE && suser(p))
--- 18 unchanged lines hidden (view full) ---
233ptsclose(dev, flag, mode, p)
234 dev_t dev;
235 int flag, mode;
236 struct proc *p;
237{
238 register struct tty *tp;
239 int err;
240
241 tp = &pt_tty[minor(dev)];
242 err = (*linesw[tp->t_line].l_close)(tp, flag);
243 ptsstop(tp, FREAD|FWRITE);
244 (void) ttyclose(tp);
245 return (err);
246}
247
248static int
249ptsread(dev, uio, flag)
250 dev_t dev;
251 struct uio *uio;
252 int flag;
253{
254 struct proc *p = curproc;
255 register struct tty *tp = &pt_tty[minor(dev)];
256 register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
257 int error = 0;
258
259again:
260 if (pti->pt_flags & PF_REMOTE) {
261 while (isbackground(p, tp)) {
262 if ((p->p_sigignore & sigmask(SIGTTIN)) ||
263 (p->p_sigmask & sigmask(SIGTTIN)) ||
264 p->p_pgrp->pg_jobc == 0 ||
--- 38 unchanged lines hidden (view full) ---
303static int
304ptswrite(dev, uio, flag)
305 dev_t dev;
306 struct uio *uio;
307 int flag;
308{
309 register struct tty *tp;
310
311 tp = &pt_tty[minor(dev)];
312 if (tp->t_oproc == 0)
313 return (EIO);
314 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
315}
316
317/*
318 * Start output on pseudo-tty.
319 * Wake up process selecting or sleeping for input from controlling tty.
320 */
321static void
322ptsstart(tp)
323 struct tty *tp;
324{
325 register struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
326
327 if (tp->t_state & TS_TTSTOP)
328 return;
329 if (pti->pt_flags & PF_STOPPED) {
330 pti->pt_flags &= ~PF_STOPPED;
331 pti->pt_send = TIOCPKT_START;
332 }
333 ptcwakeup(tp, FREAD);
334}
335
336static void
337ptcwakeup(tp, flag)
338 struct tty *tp;
339 int flag;
340{
341 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
342
343 if (flag & FREAD) {
344 selwakeup(&pti->pt_selr);
345 wakeup(TSA_PTC_READ(tp));
346 }
347 if (flag & FWRITE) {
348 selwakeup(&pti->pt_selw);
349 wakeup(TSA_PTC_WRITE(tp));
--- 4 unchanged lines hidden (view full) ---
354ptcopen(dev, flag, devtype, p)
355 dev_t dev;
356 int flag, devtype;
357 struct proc *p;
358{
359 register struct tty *tp;
360 struct pt_ioctl *pti;
361
362 if (minor(dev) >= npty)
363 return (ENXIO);
364 tp = &pt_tty[minor(dev)];
365 if (tp->t_oproc)
366 return (EIO);
367 tp->t_oproc = ptsstart;
368#ifdef sun4c
369 tp->t_stop = ptsstop;
370#endif
371 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
372 tp->t_lflag &= ~EXTPROC;
373 pti = &pt_ioctl[minor(dev)];
374 pti->pt_flags = 0;
375 pti->pt_send = 0;
376 pti->pt_ucntl = 0;
377 return (0);
378}
379
380static int
381ptcclose(dev, flags, fmt, p)
382 dev_t dev;
383 int flags;
384 int fmt;
385 struct proc *p;
386{
387 register struct tty *tp;
388
389 tp = &pt_tty[minor(dev)];
390 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
391
392 /*
393 * XXX MDMBUF makes no sense for ptys but would inhibit the above
394 * l_modem(). CLOCAL makes sense but isn't supported. Special
395 * l_modem()s that ignore carrier drop make no sense for ptys but
396 * may be in use because other parts of the line discipline make
397 * sense for ptys. Recover by doing everything that a normal
--- 10 unchanged lines hidden (view full) ---
408}
409
410static int
411ptcread(dev, uio, flag)
412 dev_t dev;
413 struct uio *uio;
414 int flag;
415{
416 register struct tty *tp = &pt_tty[minor(dev)];
417 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
418 char buf[BUFSIZ];
419 int error = 0, cc;
420
421 /*
422 * We want to block until the slave
423 * is open, and there's something to read;
424 * but if we lost the slave or we're NBIO,
425 * then return the appropriate error instead.
--- 43 unchanged lines hidden (view full) ---
469 return (error);
470}
471
472static void
473ptsstop(tp, flush)
474 register struct tty *tp;
475 int flush;
476{
477 struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)];
478 int flag;
479
480 /* note: FLUSHREAD and FLUSHWRITE already ok */
481 if (flush == 0) {
482 flush = TIOCPKT_STOP;
483 pti->pt_flags |= PF_STOPPED;
484 } else
485 pti->pt_flags &= ~PF_STOPPED;
--- 8 unchanged lines hidden (view full) ---
494}
495
496static int
497ptcpoll(dev, events, p)
498 dev_t dev;
499 int events;
500 struct proc *p;
501{
502 register struct tty *tp = &pt_tty[minor(dev)];
503 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
504 int revents = 0;
505 int s;
506
507 if ((tp->t_state & TS_CONNECTED) == 0)
508 return (seltrue(dev, events, p) | POLLHUP);
509
510 /*
511 * Need to block timeouts (ttrstart).
--- 32 unchanged lines hidden (view full) ---
544}
545
546static int
547ptcwrite(dev, uio, flag)
548 dev_t dev;
549 register struct uio *uio;
550 int flag;
551{
552 register struct tty *tp = &pt_tty[minor(dev)];
553 register u_char *cp = 0;
554 register int cc = 0;
555 u_char locbuf[BUFSIZ];
556 int cnt = 0;
557 struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
558 int error = 0;
559
560again:
561 if ((tp->t_state&TS_ISOPEN) == 0)
562 goto block;
563 if (pti->pt_flags & PF_REMOTE) {
564 if (tp->t_canq.c_cc)
565 goto block;
--- 86 unchanged lines hidden (view full) ---
652 }
653 goto again;
654}
655
656static struct tty *
657ptydevtotty(dev)
658 dev_t dev;
659{
660 if (minor(dev) >= npty)
661 return (NULL);
662
663 return &pt_tty[minor(dev)];
664}
665
666/*ARGSUSED*/
667static int
668ptyioctl(dev, cmd, data, flag, p)
669 dev_t dev;
670 u_long cmd;
671 caddr_t data;
672 int flag;
673 struct proc *p;
674{
675 register struct tty *tp = &pt_tty[minor(dev)];
676 register struct pt_ioctl *pti = &pt_ioctl[minor(dev)];
677 register u_char *cc = tp->t_cc;
678 int stop, error;
679
680 if (devsw(dev)->d_open == ptcopen) {
681 switch (cmd) {
682
683 case TIOCGPGRP:
684 /*
--- 143 unchanged lines hidden (view full) ---
828 pti->pt_send |= TIOCPKT_NOSTOP;
829 pti->pt_flags |= PF_NOSTOP;
830 ptcwakeup(tp, FREAD);
831 }
832 }
833 return (error);
834}
835
836static int ptc_devsw_installed;
837
838static void ptc_drvinit __P((void *unused));
839static void
840ptc_drvinit(unused)
841 void *unused;
842{
843#ifdef DEVFS
844 int i,j,k;
845#endif
846
847 if( ! ptc_devsw_installed ) {
848 cdevsw_add(&pts_cdevsw);
849 cdevsw_add(&ptc_cdevsw);
850 ptc_devsw_installed = 1;
851#ifdef DEVFS
852 for ( i = 0 ; i<NPTY ; i++ ) {
853 j = i / 32;
854 k = i % 32;
855 devfs_token_pts[i] =
856 devfs_add_devswf(&pts_cdevsw,i,
857 DV_CHR,0,0,0666,
858 "tty%c%r",jnames[j],k);
859 devfs_token_ptc[i] =
860 devfs_add_devswf(&ptc_cdevsw,i,
861 DV_CHR,0,0,0666,
862 "pty%c%r",jnames[j],k);
863 }
864#endif
865 }
866}
867
868SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL)