2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
59 * Pseudo-teletype Driver
60 * (Actually two drivers, requiring two entries in 'cdevsw')
62 #include "pty.h" /* XXX */
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/ioctl.h>
72 #include <sys/kernel.h>
73 #include <sys/vnode.h>
74 #include <sys/signalvar.h>
78 #define FREE_BSDSTATIC static
80 #include <machine/spl.h>
82 #define FREE_BSDSTATIC __private_extern__
83 #define d_open_t open_close_fcn_t
84 #define d_close_t open_close_fcn_t
85 #define d_devtotty_t struct tty **
86 #define d_ioctl_t ioctl_fcn_t
87 #define d_read_t read_write_fcn_t
88 #define d_write_t read_write_fcn_t
89 #define d_select_t select_fcn_t
90 typedef void d_stop_t
__P((struct tty
*tp
, int rw
));
94 static void ptyattach
__P((int n
));
96 static void ptsstart
__P((struct tty
*tp
));
97 static void ptcwakeup
__P((struct tty
*tp
, int flag
));
99 FREE_BSDSTATIC d_open_t ptsopen
;
100 FREE_BSDSTATIC d_close_t ptsclose
;
101 FREE_BSDSTATIC d_read_t ptsread
;
102 FREE_BSDSTATIC d_write_t ptswrite
;
103 FREE_BSDSTATIC d_ioctl_t ptyioctl
;
104 FREE_BSDSTATIC d_stop_t ptsstop
;
105 FREE_BSDSTATIC d_devtotty_t ptydevtotty
;
106 FREE_BSDSTATIC d_open_t ptcopen
;
107 FREE_BSDSTATIC d_close_t ptcclose
;
108 FREE_BSDSTATIC d_read_t ptcread
;
109 FREE_BSDSTATIC d_write_t ptcwrite
;
110 FREE_BSDSTATIC d_select_t ptcselect
;
113 #define CDEV_MAJOR_S 5
114 #define CDEV_MAJOR_C 6
115 static struct cdevsw pts_cdevsw
=
116 { ptsopen
, ptsclose
, ptsread
, ptswrite
, /*5*/
117 ptyioctl
, ptsstop
, nullreset
, ptydevtotty
,/* ttyp */
118 ttselect
, nommap
, NULL
, "pts", NULL
, -1 };
120 static struct cdevsw ptc_cdevsw
=
121 { ptcopen
, ptcclose
, ptcread
, ptcwrite
, /*6*/
122 ptyioctl
, nullstop
, nullreset
, ptydevtotty
,/* ptyp */
123 ptcselect
, nommap
, NULL
, "ptc", NULL
, -1 };
129 #define NPTY 32 /* crude XXX */
130 #warning You have only one pty defined, redefining to 32.
135 #define MAXUNITS (8 * 32)
136 static void *devfs_token_pts
[MAXUNITS
];
137 static void *devfs_token_ptc
[MAXUNITS
];
138 static const char jnames
[] = "pqrsPQRS";
141 #define NPTY MAXUNITS
142 #warning Can't have more than 256 pty's with DEVFS defined.
143 #endif /* NPTY > MAXUNITS */
147 #define BUFSIZ 100 /* Chunk size iomoved to/from user */
150 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
151 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
154 FREE_BSDSTATIC
struct tty pt_tty
[NPTY
]; /* XXX */
156 /* NeXT All references to have been changed to indirections in the file */
157 FREE_BSDSTATIC
struct tty
*pt_tty
[NPTY
] = { NULL
};
160 static struct pt_ioctl
{
162 struct selinfo pt_selr
, pt_selw
;
165 } pt_ioctl
[NPTY
]; /* XXX */
166 static int npty
= NPTY
; /* for pstat -t */
168 #define PF_PKT 0x08 /* packet mode */
169 #define PF_STOPPED 0x10 /* user told stopped */
170 #define PF_REMOTE 0x20 /* remote and flow controlled input */
171 #define PF_NOSTOP 0x40
172 #define PF_UCNTL 0x80 /* user control mode */
176 * Establish n (or default if n is 1) ptys in the system.
178 * XXX cdevsw & pstat require the array `pty[]' to be an array
186 #define DEFAULT_NPTY 32
188 /* maybe should allow 0 => none? */
191 ntb
= n
* sizeof(struct tty
);
193 mem
= malloc(ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
196 MALLOC(mem
, char *, ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
199 pt_tty
= (struct tty
*)mem
;
200 mem
= (char *)ALIGN(mem
+ ntb
);
201 pt_ioctl
= (struct pt_ioctl
*)mem
;
212 #include <miscfs/devfs/devfs.h>
213 #define START_CHAR 'p'
215 int pty_init(int n_ptys
)
220 /* create the pseudo tty device nodes */
221 for (j
= 0; j
< 10; j
++) {
222 for (i
= 0; i
< HEX_BASE
; i
++) {
223 int m
= j
* HEX_BASE
+ i
;
226 (void)devfs_make_node(makedev(4, m
),
227 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
228 "tty%c%x", j
+ START_CHAR
, i
);
229 (void)devfs_make_node(makedev(5, m
),
230 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
231 "pty%c%x", j
+ START_CHAR
, i
);
241 ptsopen(dev
, flag
, devtype
, p
)
246 register struct tty
*tp
;
250 tp
= &pt_tty
[minor(dev
)];
253 * You will see this sourt of code coming up in diffs later both
254 * the ttymalloc and the tp indirection.
256 if (minor(dev
) >= npty
)
258 if (!pt_tty
[minor(dev
)]) {
259 tp
= pt_tty
[minor(dev
)] = ttymalloc();
261 tp
= pt_tty
[minor(dev
)];
263 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
264 ttychars(tp
); /* Set up default chars */
265 tp
->t_iflag
= TTYDEF_IFLAG
;
266 tp
->t_oflag
= TTYDEF_OFLAG
;
267 tp
->t_lflag
= TTYDEF_LFLAG
;
268 tp
->t_cflag
= TTYDEF_CFLAG
;
269 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
270 ttsetwater(tp
); /* would be done in xxparam() */
271 } else if (tp
->t_state
&TS_XCLUDE
&& p
->p_ucred
->cr_uid
!= 0)
273 if (tp
->t_oproc
) /* Ctrlr still around. */
274 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
275 while ((tp
->t_state
& TS_CARR_ON
) == 0) {
278 error
= ttysleep(tp
, TSA_CARR_ON(tp
), TTIPRI
| PCATCH
,
283 error
= (*linesw
[tp
->t_line
].l_open
)(dev
, tp
);
285 ptcwakeup(tp
, FREAD
|FWRITE
);
290 ptsclose(dev
, flag
, mode
, p
)
295 register struct tty
*tp
;
298 tp
= pt_tty
[minor(dev
)];
299 err
= (*linesw
[tp
->t_line
].l_close
)(tp
, flag
);
300 ptsstop(tp
, FREAD
|FWRITE
);
306 ptsread(dev
, uio
, flag
)
312 struct proc
*p
= curproc
;
314 struct proc
*p
= current_proc();
316 register struct tty
*tp
= pt_tty
[minor(dev
)];
317 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
321 if (pti
->pt_flags
& PF_REMOTE
) {
322 while (isbackground(p
, tp
)) {
323 if ((p
->p_sigignore
& sigmask(SIGTTIN
)) ||
324 (p
->p_sigmask
& sigmask(SIGTTIN
)) ||
325 p
->p_pgrp
->pg_jobc
== 0 ||
326 p
->p_flag
& P_PPWAIT
)
328 pgsignal(p
->p_pgrp
, SIGTTIN
, 1);
329 error
= ttysleep(tp
, &lbolt
, TTIPRI
| PCATCH
| PTTYBLOCK
, "ptsbg",
334 if (tp
->t_canq
.c_cc
== 0) {
335 if (flag
& IO_NDELAY
)
336 return (EWOULDBLOCK
);
337 error
= ttysleep(tp
, TSA_PTS_READ(tp
), TTIPRI
| PCATCH
,
343 while (tp
->t_canq
.c_cc
> 1 && uio
->uio_resid
> 0)
344 if (ureadc(getc(&tp
->t_canq
), uio
) < 0) {
348 if (tp
->t_canq
.c_cc
== 1)
349 (void) getc(&tp
->t_canq
);
354 error
= (*linesw
[tp
->t_line
].l_read
)(tp
, uio
, flag
);
355 ptcwakeup(tp
, FWRITE
);
360 * Write to pseudo-tty.
361 * Wakeups of controlling tty will happen
362 * indirectly, when tty driver calls ptsstart.
365 ptswrite(dev
, uio
, flag
)
370 register struct tty
*tp
;
372 tp
= pt_tty
[minor(dev
)];
373 if (tp
->t_oproc
== 0)
375 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, flag
));
379 * Start output on pseudo-tty.
380 * Wake up process selecting or sleeping for input from controlling tty.
386 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
388 if (tp
->t_state
& TS_TTSTOP
)
390 if (pti
->pt_flags
& PF_STOPPED
) {
391 pti
->pt_flags
&= ~PF_STOPPED
;
392 pti
->pt_send
= TIOCPKT_START
;
394 ptcwakeup(tp
, FREAD
);
402 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
405 selwakeup(&pti
->pt_selr
);
406 wakeup(TSA_PTC_READ(tp
));
409 selwakeup(&pti
->pt_selw
);
410 wakeup(TSA_PTC_WRITE(tp
));
415 ptcopen(dev
, flag
, devtype
, p
)
420 register struct tty
*tp
;
421 struct pt_ioctl
*pti
;
423 if (minor(dev
) >= npty
)
425 if(!pt_tty
[minor(dev
)]) {
426 tp
= pt_tty
[minor(dev
)] = ttymalloc();
428 tp
= pt_tty
[minor(dev
)];
431 tp
->t_oproc
= ptsstart
;
433 tp
->t_stop
= ptsstop
;
435 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
436 tp
->t_lflag
&= ~EXTPROC
;
437 pti
= &pt_ioctl
[minor(dev
)];
445 ptcclose(dev
, flags
, fmt
, p
)
451 register struct tty
*tp
;
453 tp
= pt_tty
[minor(dev
)];
454 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 0);
457 * XXX MDMBUF makes no sense for ptys but would inhibit the above
458 * l_modem(). CLOCAL makes sense but isn't supported. Special
459 * l_modem()s that ignore carrier drop make no sense for ptys but
460 * may be in use because other parts of the line discipline make
461 * sense for ptys. Recover by doing everything that a normal
462 * ttymodem() would have done except for sending a SIGHUP.
464 if (tp
->t_state
& TS_ISOPEN
) {
465 tp
->t_state
&= ~(TS_CARR_ON
| TS_CONNECTED
);
466 tp
->t_state
|= TS_ZOMBIE
;
467 ttyflush(tp
, FREAD
| FWRITE
);
470 tp
->t_oproc
= 0; /* mark closed */
475 ptcread(dev
, uio
, flag
)
480 register struct tty
*tp
= pt_tty
[minor(dev
)];
481 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
486 * We want to block until the slave
487 * is open, and there's something to read;
488 * but if we lost the slave or we're NBIO,
489 * then return the appropriate error instead.
492 if (tp
->t_state
&TS_ISOPEN
) {
493 if (pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) {
494 error
= ureadc((int)pti
->pt_send
, uio
);
497 if (pti
->pt_send
& TIOCPKT_IOCTL
) {
498 cc
= min(uio
->uio_resid
,
499 sizeof(tp
->t_termios
));
500 uiomove((caddr_t
)&tp
->t_termios
, cc
,
506 if (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
) {
507 error
= ureadc((int)pti
->pt_ucntl
, uio
);
513 if (tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0)
516 if ((tp
->t_state
& TS_CONNECTED
) == 0)
517 return (0); /* EOF */
518 if (flag
& IO_NDELAY
)
519 return (EWOULDBLOCK
);
520 error
= tsleep(TSA_PTC_READ(tp
), TTIPRI
| PCATCH
, "ptcin", 0);
524 if (pti
->pt_flags
& (PF_PKT
|PF_UCNTL
))
525 error
= ureadc(0, uio
);
526 while (uio
->uio_resid
> 0 && error
== 0) {
527 cc
= q_to_b(&tp
->t_outq
, buf
, min(uio
->uio_resid
, BUFSIZ
));
530 error
= uiomove(buf
, cc
, uio
);
538 register struct tty
*tp
;
541 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
544 /* note: FLUSHREAD and FLUSHWRITE already ok */
546 flush
= TIOCPKT_STOP
;
547 pti
->pt_flags
|= PF_STOPPED
;
549 pti
->pt_flags
&= ~PF_STOPPED
;
550 pti
->pt_send
|= flush
;
551 /* change of perspective */
561 ptcselect(dev
, rw
, wql
, p
)
567 register struct tty
*tp
= pt_tty
[minor(dev
)];
568 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
571 if ((tp
->t_state
& TS_CONNECTED
) == 0)
577 * Need to block timeouts (ttrstart).
580 if ((tp
->t_state
&TS_ISOPEN
) &&
581 tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0) {
588 case 0: /* exceptional */
589 if ((tp
->t_state
&TS_ISOPEN
) &&
590 ((pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) ||
591 (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
)))
593 selrecord(p
, &pti
->pt_selr
, wql
);
598 if (tp
->t_state
&TS_ISOPEN
) {
599 if (pti
->pt_flags
& PF_REMOTE
) {
600 if (tp
->t_canq
.c_cc
== 0)
603 if (tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
< TTYHOG
-2)
605 if (tp
->t_canq
.c_cc
== 0 && (tp
->t_iflag
&ICANON
))
609 selrecord(p
, &pti
->pt_selw
, wql
);
617 ptcwrite(dev
, uio
, flag
)
619 register struct uio
*uio
;
622 register struct tty
*tp
= pt_tty
[minor(dev
)];
623 register u_char
*cp
= NULL
;
625 u_char locbuf
[BUFSIZ
];
627 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
631 if ((tp
->t_state
&TS_ISOPEN
) == 0)
633 if (pti
->pt_flags
& PF_REMOTE
) {
636 while ((uio
->uio_resid
> 0 || cc
> 0) &&
637 tp
->t_canq
.c_cc
< TTYHOG
- 1) {
639 cc
= min(uio
->uio_resid
, BUFSIZ
);
640 cc
= min(cc
, TTYHOG
- 1 - tp
->t_canq
.c_cc
);
642 error
= uiomove((caddr_t
)cp
, cc
, uio
);
645 /* check again for safety */
646 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
647 /* adjust as usual */
648 uio
->uio_resid
+= cc
;
653 cc
= b_to_q((char *)cp
, cc
, &tp
->t_canq
);
655 * XXX we don't guarantee that the canq size
656 * is >= TTYHOG, so the above b_to_q() may
657 * leave some bytes uncopied. However, space
658 * is guaranteed for the null terminator if
659 * we don't fail here since (TTYHOG - 1) is
660 * not a multiple of CBSIZE.
666 /* adjust for data copied in but not written */
667 uio
->uio_resid
+= cc
;
668 (void) putc(0, &tp
->t_canq
);
670 wakeup(TSA_PTS_READ(tp
));
673 while (uio
->uio_resid
> 0 || cc
> 0) {
675 cc
= min(uio
->uio_resid
, BUFSIZ
);
677 error
= uiomove((caddr_t
)cp
, cc
, uio
);
680 /* check again for safety */
681 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
682 /* adjust for data copied in but not written */
683 uio
->uio_resid
+= cc
;
688 if ((tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
) >= TTYHOG
- 2 &&
689 (tp
->t_canq
.c_cc
> 0 || !(tp
->t_iflag
&ICANON
))) {
690 wakeup(TSA_HUP_OR_INPUT(tp
));
693 (*linesw
[tp
->t_line
].l_rint
)(*cp
++, tp
);
702 * Come here to wait for slave to open, for space
703 * in outq, or space in rawq, or an empty canq.
705 if ((tp
->t_state
& TS_CONNECTED
) == 0) {
706 /* adjust for data copied in but not written */
707 uio
->uio_resid
+= cc
;
710 if (flag
& IO_NDELAY
) {
711 /* adjust for data copied in but not written */
712 uio
->uio_resid
+= cc
;
714 return (EWOULDBLOCK
);
717 error
= tsleep(TSA_PTC_WRITE(tp
), TTOPRI
| PCATCH
, "ptcout", 0);
719 /* adjust for data copied in but not written */
720 uio
->uio_resid
+= cc
;
727 /* XXX we eventually want to go to this model,
728 * but premier can't change the cdevsw */
733 if (minor(dev
) >= npty
)
736 return &pt_tty
[minor(dev
)];
743 ptyioctl(dev
, cmd
, data
, flag
)
749 ptyioctl(dev
, cmd
, data
, flag
, p
)
757 register struct tty
*tp
= pt_tty
[minor(dev
)];
758 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
759 register u_char
*cc
= tp
->t_cc
;
763 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
764 * ttywflush(tp) will hang if there are characters in the outq.
766 if (cmd
== TIOCEXT
) {
768 * When the EXTPROC bit is being toggled, we need
769 * to send an TIOCPKT_IOCTL if the packet driver
773 if (pti
->pt_flags
& PF_PKT
) {
774 pti
->pt_send
|= TIOCPKT_IOCTL
;
775 ptcwakeup(tp
, FREAD
);
777 tp
->t_lflag
|= EXTPROC
;
779 if ((tp
->t_lflag
& EXTPROC
) &&
780 (pti
->pt_flags
& PF_PKT
)) {
781 pti
->pt_send
|= TIOCPKT_IOCTL
;
782 ptcwakeup(tp
, FREAD
);
784 tp
->t_lflag
&= ~EXTPROC
;
789 if (cdevsw
[major(dev
)]->d_open
== ptcopen
)
791 if (cdevsw
[major(dev
)].d_open
== ptcopen
)
797 * We aviod calling ttioctl on the controller since,
798 * in that case, tp must be the controlling terminal.
800 *(int *)data
= tp
->t_pgrp
? tp
->t_pgrp
->pg_id
: 0;
805 if (pti
->pt_flags
& PF_UCNTL
)
807 pti
->pt_flags
|= PF_PKT
;
809 pti
->pt_flags
&= ~PF_PKT
;
814 if (pti
->pt_flags
& PF_PKT
)
816 pti
->pt_flags
|= PF_UCNTL
;
818 pti
->pt_flags
&= ~PF_UCNTL
;
823 pti
->pt_flags
|= PF_REMOTE
;
825 pti
->pt_flags
&= ~PF_REMOTE
;
826 ttyflush(tp
, FREAD
|FWRITE
);
837 ndflush(&tp
->t_outq
, tp
->t_outq
.c_cc
);
841 if (*(unsigned int *)data
>= NSIG
||
842 *(unsigned int *)data
== 0)
844 if ((tp
->t_lflag
&NOFLSH
) == 0)
845 ttyflush(tp
, FREAD
|FWRITE
);
846 pgsignal(tp
->t_pgrp
, *(unsigned int *)data
, 1);
847 if ((*(unsigned int *)data
== SIGINFO
) &&
848 ((tp
->t_lflag
&NOKERNINFO
) == 0))
852 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
854 error
= ttioctl(tp
, cmd
, data
, flag
, p
);
856 if (pti
->pt_flags
& PF_UCNTL
&&
857 (cmd
& ~0xff) == UIOCCMD(0)) {
859 pti
->pt_ucntl
= (u_char
)cmd
;
860 ptcwakeup(tp
, FREAD
);
867 * If external processing and packet mode send ioctl packet.
869 if ((tp
->t_lflag
&EXTPROC
) && (pti
->pt_flags
& PF_PKT
)) {
878 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
885 pti
->pt_send
|= TIOCPKT_IOCTL
;
886 ptcwakeup(tp
, FREAD
);
891 stop
= (tp
->t_iflag
& IXON
) && CCEQ(cc
[VSTOP
], CTRL('s'))
892 && CCEQ(cc
[VSTART
], CTRL('q'));
893 if (pti
->pt_flags
& PF_NOSTOP
) {
895 pti
->pt_send
&= ~TIOCPKT_NOSTOP
;
896 pti
->pt_send
|= TIOCPKT_DOSTOP
;
897 pti
->pt_flags
&= ~PF_NOSTOP
;
898 ptcwakeup(tp
, FREAD
);
902 pti
->pt_send
&= ~TIOCPKT_DOSTOP
;
903 pti
->pt_send
|= TIOCPKT_NOSTOP
;
904 pti
->pt_flags
|= PF_NOSTOP
;
905 ptcwakeup(tp
, FREAD
);
912 static ptc_devsw_installed
= 0;
915 ptc_drvinit(void *unused
)
922 if( ! ptc_devsw_installed
) {
923 dev
= makedev(CDEV_MAJOR_S
, 0);
924 cdevsw_add(&dev
, &pts_cdevsw
, NULL
);
925 dev
= makedev(CDEV_MAJOR_C
, 0);
926 cdevsw_add(&dev
, &ptc_cdevsw
, NULL
);
927 ptc_devsw_installed
= 1;
929 for ( i
= 0 ; i
<NPTY
; i
++ ) {
933 devfs_add_devswf(&pts_cdevsw
,i
,
935 "tty%c%n",jnames
[j
],k
);
937 devfs_add_devswf(&ptc_cdevsw
,i
,
939 "pty%c%n",jnames
[j
],k
);
945 SYSINIT(ptcdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR_C
,ptc_drvinit
,NULL
)