2 * Copyright (c) 2000-2002 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>
75 #include <sys/signalvar.h>
79 #define FREE_BSDSTATIC static
81 #include <machine/spl.h>
83 #define FREE_BSDSTATIC __private_extern__
84 #define d_devtotty_t struct tty **
89 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 ut
= (struct uthread
*)get_bsdthread_info(current_act());
323 if (pti
->pt_flags
& PF_REMOTE
) {
324 while (isbackground(p
, tp
)) {
325 if ((p
->p_sigignore
& sigmask(SIGTTIN
)) ||
326 (ut
->uu_sigmask
& sigmask(SIGTTIN
)) ||
327 p
->p_pgrp
->pg_jobc
== 0 ||
328 p
->p_flag
& P_PPWAIT
)
330 pgsignal(p
->p_pgrp
, SIGTTIN
, 1);
331 error
= ttysleep(tp
, &lbolt
, TTIPRI
| PCATCH
| PTTYBLOCK
, "ptsbg",
336 if (tp
->t_canq
.c_cc
== 0) {
337 if (flag
& IO_NDELAY
)
338 return (EWOULDBLOCK
);
339 error
= ttysleep(tp
, TSA_PTS_READ(tp
), TTIPRI
| PCATCH
,
345 while (tp
->t_canq
.c_cc
> 1 && uio
->uio_resid
> 0)
346 if (ureadc(getc(&tp
->t_canq
), uio
) < 0) {
350 if (tp
->t_canq
.c_cc
== 1)
351 (void) getc(&tp
->t_canq
);
356 error
= (*linesw
[tp
->t_line
].l_read
)(tp
, uio
, flag
);
357 ptcwakeup(tp
, FWRITE
);
362 * Write to pseudo-tty.
363 * Wakeups of controlling tty will happen
364 * indirectly, when tty driver calls ptsstart.
367 ptswrite(dev
, uio
, flag
)
372 register struct tty
*tp
;
374 tp
= pt_tty
[minor(dev
)];
375 if (tp
->t_oproc
== 0)
377 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, flag
));
381 * Start output on pseudo-tty.
382 * Wake up process selecting or sleeping for input from controlling tty.
388 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
390 if (tp
->t_state
& TS_TTSTOP
)
392 if (pti
->pt_flags
& PF_STOPPED
) {
393 pti
->pt_flags
&= ~PF_STOPPED
;
394 pti
->pt_send
= TIOCPKT_START
;
396 ptcwakeup(tp
, FREAD
);
404 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
407 selwakeup(&pti
->pt_selr
);
408 wakeup(TSA_PTC_READ(tp
));
411 selwakeup(&pti
->pt_selw
);
412 wakeup(TSA_PTC_WRITE(tp
));
417 ptcopen(dev
, flag
, devtype
, p
)
422 register struct tty
*tp
;
423 struct pt_ioctl
*pti
;
425 if (minor(dev
) >= npty
)
427 if(!pt_tty
[minor(dev
)]) {
428 tp
= pt_tty
[minor(dev
)] = ttymalloc();
430 tp
= pt_tty
[minor(dev
)];
433 tp
->t_oproc
= ptsstart
;
435 tp
->t_stop
= ptsstop
;
437 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
438 tp
->t_lflag
&= ~EXTPROC
;
439 pti
= &pt_ioctl
[minor(dev
)];
447 ptcclose(dev
, flags
, fmt
, p
)
453 register struct tty
*tp
;
455 tp
= pt_tty
[minor(dev
)];
456 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 0);
459 * XXX MDMBUF makes no sense for ptys but would inhibit the above
460 * l_modem(). CLOCAL makes sense but isn't supported. Special
461 * l_modem()s that ignore carrier drop make no sense for ptys but
462 * may be in use because other parts of the line discipline make
463 * sense for ptys. Recover by doing everything that a normal
464 * ttymodem() would have done except for sending a SIGHUP.
466 if (tp
->t_state
& TS_ISOPEN
) {
467 tp
->t_state
&= ~(TS_CARR_ON
| TS_CONNECTED
);
468 tp
->t_state
|= TS_ZOMBIE
;
469 ttyflush(tp
, FREAD
| FWRITE
);
472 tp
->t_oproc
= 0; /* mark closed */
477 ptcread(dev
, uio
, flag
)
482 register struct tty
*tp
= pt_tty
[minor(dev
)];
483 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
488 * We want to block until the slave
489 * is open, and there's something to read;
490 * but if we lost the slave or we're NBIO,
491 * then return the appropriate error instead.
494 if (tp
->t_state
&TS_ISOPEN
) {
495 if (pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) {
496 error
= ureadc((int)pti
->pt_send
, uio
);
499 if (pti
->pt_send
& TIOCPKT_IOCTL
) {
500 cc
= min(uio
->uio_resid
,
501 sizeof(tp
->t_termios
));
502 uiomove((caddr_t
)&tp
->t_termios
, cc
,
508 if (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
) {
509 error
= ureadc((int)pti
->pt_ucntl
, uio
);
515 if (tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0)
518 if ((tp
->t_state
& TS_CONNECTED
) == 0)
519 return (0); /* EOF */
520 if (flag
& IO_NDELAY
)
521 return (EWOULDBLOCK
);
522 error
= tsleep(TSA_PTC_READ(tp
), TTIPRI
| PCATCH
, "ptcin", 0);
526 if (pti
->pt_flags
& (PF_PKT
|PF_UCNTL
))
527 error
= ureadc(0, uio
);
528 while (uio
->uio_resid
> 0 && error
== 0) {
529 cc
= q_to_b(&tp
->t_outq
, buf
, min(uio
->uio_resid
, BUFSIZ
));
532 error
= uiomove(buf
, cc
, uio
);
540 register struct tty
*tp
;
543 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
546 /* note: FLUSHREAD and FLUSHWRITE already ok */
548 flush
= TIOCPKT_STOP
;
549 pti
->pt_flags
|= PF_STOPPED
;
551 pti
->pt_flags
&= ~PF_STOPPED
;
552 pti
->pt_send
|= flush
;
553 /* change of perspective */
563 ptcselect(dev
, rw
, wql
, p
)
569 register struct tty
*tp
= pt_tty
[minor(dev
)];
570 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
573 if ((tp
->t_state
& TS_CONNECTED
) == 0)
579 * Need to block timeouts (ttrstart).
582 if ((tp
->t_state
&TS_ISOPEN
) &&
583 tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0) {
590 case 0: /* exceptional */
591 if ((tp
->t_state
&TS_ISOPEN
) &&
592 ((pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) ||
593 (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
)))
595 selrecord(p
, &pti
->pt_selr
, wql
);
600 if (tp
->t_state
&TS_ISOPEN
) {
601 if (pti
->pt_flags
& PF_REMOTE
) {
602 if (tp
->t_canq
.c_cc
== 0)
605 if (tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
< TTYHOG
-2)
607 if (tp
->t_canq
.c_cc
== 0 && (tp
->t_iflag
&ICANON
))
611 selrecord(p
, &pti
->pt_selw
, wql
);
619 ptcwrite(dev
, uio
, flag
)
621 register struct uio
*uio
;
624 register struct tty
*tp
= pt_tty
[minor(dev
)];
625 register u_char
*cp
= NULL
;
627 u_char locbuf
[BUFSIZ
];
629 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
633 if ((tp
->t_state
&TS_ISOPEN
) == 0)
635 if (pti
->pt_flags
& PF_REMOTE
) {
638 while ((uio
->uio_resid
> 0 || cc
> 0) &&
639 tp
->t_canq
.c_cc
< TTYHOG
- 1) {
641 cc
= min(uio
->uio_resid
, BUFSIZ
);
642 cc
= min(cc
, TTYHOG
- 1 - tp
->t_canq
.c_cc
);
644 error
= uiomove((caddr_t
)cp
, cc
, uio
);
647 /* check again for safety */
648 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
649 /* adjust as usual */
650 uio
->uio_resid
+= cc
;
655 cc
= b_to_q((char *)cp
, cc
, &tp
->t_canq
);
657 * XXX we don't guarantee that the canq size
658 * is >= TTYHOG, so the above b_to_q() may
659 * leave some bytes uncopied. However, space
660 * is guaranteed for the null terminator if
661 * we don't fail here since (TTYHOG - 1) is
662 * not a multiple of CBSIZE.
668 /* adjust for data copied in but not written */
669 uio
->uio_resid
+= cc
;
670 (void) putc(0, &tp
->t_canq
);
672 wakeup(TSA_PTS_READ(tp
));
675 while (uio
->uio_resid
> 0 || cc
> 0) {
677 cc
= min(uio
->uio_resid
, BUFSIZ
);
679 error
= uiomove((caddr_t
)cp
, cc
, uio
);
682 /* check again for safety */
683 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
684 /* adjust for data copied in but not written */
685 uio
->uio_resid
+= cc
;
690 if ((tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
) >= TTYHOG
- 2 &&
691 (tp
->t_canq
.c_cc
> 0 || !(tp
->t_iflag
&ICANON
))) {
692 wakeup(TSA_HUP_OR_INPUT(tp
));
695 (*linesw
[tp
->t_line
].l_rint
)(*cp
++, tp
);
704 * Come here to wait for slave to open, for space
705 * in outq, or space in rawq, or an empty canq.
707 if ((tp
->t_state
& TS_CONNECTED
) == 0) {
708 /* adjust for data copied in but not written */
709 uio
->uio_resid
+= cc
;
712 if (flag
& IO_NDELAY
) {
713 /* adjust for data copied in but not written */
714 uio
->uio_resid
+= cc
;
716 return (EWOULDBLOCK
);
719 error
= tsleep(TSA_PTC_WRITE(tp
), TTOPRI
| PCATCH
, "ptcout", 0);
721 /* adjust for data copied in but not written */
722 uio
->uio_resid
+= cc
;
729 /* XXX we eventually want to go to this model,
730 * but premier can't change the cdevsw */
735 if (minor(dev
) >= npty
)
738 return &pt_tty
[minor(dev
)];
745 ptyioctl(dev
, cmd
, data
, flag
)
751 ptyioctl(dev
, cmd
, data
, flag
, p
)
759 register struct tty
*tp
= pt_tty
[minor(dev
)];
760 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
761 register u_char
*cc
= tp
->t_cc
;
765 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
766 * ttywflush(tp) will hang if there are characters in the outq.
768 if (cmd
== TIOCEXT
) {
770 * When the EXTPROC bit is being toggled, we need
771 * to send an TIOCPKT_IOCTL if the packet driver
775 if (pti
->pt_flags
& PF_PKT
) {
776 pti
->pt_send
|= TIOCPKT_IOCTL
;
777 ptcwakeup(tp
, FREAD
);
779 tp
->t_lflag
|= EXTPROC
;
781 if ((tp
->t_lflag
& EXTPROC
) &&
782 (pti
->pt_flags
& PF_PKT
)) {
783 pti
->pt_send
|= TIOCPKT_IOCTL
;
784 ptcwakeup(tp
, FREAD
);
786 tp
->t_lflag
&= ~EXTPROC
;
791 if (cdevsw
[major(dev
)]->d_open
== ptcopen
)
793 if (cdevsw
[major(dev
)].d_open
== ptcopen
)
799 * We aviod calling ttioctl on the controller since,
800 * in that case, tp must be the controlling terminal.
802 *(int *)data
= tp
->t_pgrp
? tp
->t_pgrp
->pg_id
: 0;
807 if (pti
->pt_flags
& PF_UCNTL
)
809 pti
->pt_flags
|= PF_PKT
;
811 pti
->pt_flags
&= ~PF_PKT
;
816 if (pti
->pt_flags
& PF_PKT
)
818 pti
->pt_flags
|= PF_UCNTL
;
820 pti
->pt_flags
&= ~PF_UCNTL
;
825 pti
->pt_flags
|= PF_REMOTE
;
827 pti
->pt_flags
&= ~PF_REMOTE
;
828 ttyflush(tp
, FREAD
|FWRITE
);
839 ndflush(&tp
->t_outq
, tp
->t_outq
.c_cc
);
843 if (*(unsigned int *)data
>= NSIG
||
844 *(unsigned int *)data
== 0)
846 if ((tp
->t_lflag
&NOFLSH
) == 0)
847 ttyflush(tp
, FREAD
|FWRITE
);
848 pgsignal(tp
->t_pgrp
, *(unsigned int *)data
, 1);
849 if ((*(unsigned int *)data
== SIGINFO
) &&
850 ((tp
->t_lflag
&NOKERNINFO
) == 0))
854 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
856 error
= ttioctl(tp
, cmd
, data
, flag
, p
);
858 if (pti
->pt_flags
& PF_UCNTL
&&
859 (cmd
& ~0xff) == UIOCCMD(0)) {
861 pti
->pt_ucntl
= (u_char
)cmd
;
862 ptcwakeup(tp
, FREAD
);
869 * If external processing and packet mode send ioctl packet.
871 if ((tp
->t_lflag
&EXTPROC
) && (pti
->pt_flags
& PF_PKT
)) {
880 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
887 pti
->pt_send
|= TIOCPKT_IOCTL
;
888 ptcwakeup(tp
, FREAD
);
893 stop
= (tp
->t_iflag
& IXON
) && CCEQ(cc
[VSTOP
], CTRL('s'))
894 && CCEQ(cc
[VSTART
], CTRL('q'));
895 if (pti
->pt_flags
& PF_NOSTOP
) {
897 pti
->pt_send
&= ~TIOCPKT_NOSTOP
;
898 pti
->pt_send
|= TIOCPKT_DOSTOP
;
899 pti
->pt_flags
&= ~PF_NOSTOP
;
900 ptcwakeup(tp
, FREAD
);
904 pti
->pt_send
&= ~TIOCPKT_DOSTOP
;
905 pti
->pt_send
|= TIOCPKT_NOSTOP
;
906 pti
->pt_flags
|= PF_NOSTOP
;
907 ptcwakeup(tp
, FREAD
);
914 static ptc_devsw_installed
= 0;
917 ptc_drvinit(void *unused
)
924 if( ! ptc_devsw_installed
) {
925 dev
= makedev(CDEV_MAJOR_S
, 0);
926 cdevsw_add(&dev
, &pts_cdevsw
, NULL
);
927 dev
= makedev(CDEV_MAJOR_C
, 0);
928 cdevsw_add(&dev
, &ptc_cdevsw
, NULL
);
929 ptc_devsw_installed
= 1;
931 for ( i
= 0 ; i
<NPTY
; i
++ ) {
935 devfs_add_devswf(&pts_cdevsw
,i
,
937 "tty%c%n",jnames
[j
],k
);
939 devfs_add_devswf(&ptc_cdevsw
,i
,
941 "pty%c%n",jnames
[j
],k
);
947 SYSINIT(ptcdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR_C
,ptc_drvinit
,NULL
)