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>
75 #include <sys/signalvar.h>
79 #define FREE_BSDSTATIC static
81 #include <machine/spl.h>
83 #define FREE_BSDSTATIC __private_extern__
84 #define d_open_t open_close_fcn_t
85 #define d_close_t open_close_fcn_t
86 #define d_devtotty_t struct tty **
87 #define d_ioctl_t ioctl_fcn_t
88 #define d_read_t read_write_fcn_t
89 #define d_write_t read_write_fcn_t
90 #define d_select_t select_fcn_t
91 typedef void d_stop_t
__P((struct tty
*tp
, int rw
));
95 static void ptyattach
__P((int n
));
97 static void ptsstart
__P((struct tty
*tp
));
98 static void ptcwakeup
__P((struct tty
*tp
, int flag
));
100 FREE_BSDSTATIC d_open_t ptsopen
;
101 FREE_BSDSTATIC d_close_t ptsclose
;
102 FREE_BSDSTATIC d_read_t ptsread
;
103 FREE_BSDSTATIC d_write_t ptswrite
;
104 FREE_BSDSTATIC d_ioctl_t ptyioctl
;
105 FREE_BSDSTATIC d_stop_t ptsstop
;
106 FREE_BSDSTATIC d_devtotty_t ptydevtotty
;
107 FREE_BSDSTATIC d_open_t ptcopen
;
108 FREE_BSDSTATIC d_close_t ptcclose
;
109 FREE_BSDSTATIC d_read_t ptcread
;
110 FREE_BSDSTATIC d_write_t ptcwrite
;
111 FREE_BSDSTATIC d_select_t ptcselect
;
114 #define CDEV_MAJOR_S 5
115 #define CDEV_MAJOR_C 6
116 static struct cdevsw pts_cdevsw
=
117 { ptsopen
, ptsclose
, ptsread
, ptswrite
, /*5*/
118 ptyioctl
, ptsstop
, nullreset
, ptydevtotty
,/* ttyp */
119 ttselect
, nommap
, NULL
, "pts", NULL
, -1 };
121 static struct cdevsw ptc_cdevsw
=
122 { ptcopen
, ptcclose
, ptcread
, ptcwrite
, /*6*/
123 ptyioctl
, nullstop
, nullreset
, ptydevtotty
,/* ptyp */
124 ptcselect
, nommap
, NULL
, "ptc", NULL
, -1 };
130 #define NPTY 32 /* crude XXX */
131 #warning You have only one pty defined, redefining to 32.
136 #define MAXUNITS (8 * 32)
137 static void *devfs_token_pts
[MAXUNITS
];
138 static void *devfs_token_ptc
[MAXUNITS
];
139 static const char jnames
[] = "pqrsPQRS";
142 #define NPTY MAXUNITS
143 #warning Can't have more than 256 pty's with DEVFS defined.
144 #endif /* NPTY > MAXUNITS */
148 #define BUFSIZ 100 /* Chunk size iomoved to/from user */
151 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
152 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
155 FREE_BSDSTATIC
struct tty pt_tty
[NPTY
]; /* XXX */
157 /* NeXT All references to have been changed to indirections in the file */
158 FREE_BSDSTATIC
struct tty
*pt_tty
[NPTY
] = { NULL
};
161 static struct pt_ioctl
{
163 struct selinfo pt_selr
, pt_selw
;
166 } pt_ioctl
[NPTY
]; /* XXX */
167 static int npty
= NPTY
; /* for pstat -t */
169 #define PF_PKT 0x08 /* packet mode */
170 #define PF_STOPPED 0x10 /* user told stopped */
171 #define PF_REMOTE 0x20 /* remote and flow controlled input */
172 #define PF_NOSTOP 0x40
173 #define PF_UCNTL 0x80 /* user control mode */
177 * Establish n (or default if n is 1) ptys in the system.
179 * XXX cdevsw & pstat require the array `pty[]' to be an array
187 #define DEFAULT_NPTY 32
189 /* maybe should allow 0 => none? */
192 ntb
= n
* sizeof(struct tty
);
194 mem
= malloc(ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
197 MALLOC(mem
, char *, ntb
+ ALIGNBYTES
+ n
* sizeof(struct pt_ioctl
),
200 pt_tty
= (struct tty
*)mem
;
201 mem
= (char *)ALIGN(mem
+ ntb
);
202 pt_ioctl
= (struct pt_ioctl
*)mem
;
213 #include <miscfs/devfs/devfs.h>
214 #define START_CHAR 'p'
216 int pty_init(int n_ptys
)
221 /* create the pseudo tty device nodes */
222 for (j
= 0; j
< 10; j
++) {
223 for (i
= 0; i
< HEX_BASE
; i
++) {
224 int m
= j
* HEX_BASE
+ i
;
227 (void)devfs_make_node(makedev(4, m
),
228 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
229 "tty%c%x", j
+ START_CHAR
, i
);
230 (void)devfs_make_node(makedev(5, m
),
231 DEVFS_CHAR
, UID_ROOT
, GID_WHEEL
, 0666,
232 "pty%c%x", j
+ START_CHAR
, i
);
242 ptsopen(dev
, flag
, devtype
, p
)
247 register struct tty
*tp
;
251 tp
= &pt_tty
[minor(dev
)];
254 * You will see this sourt of code coming up in diffs later both
255 * the ttymalloc and the tp indirection.
257 if (minor(dev
) >= npty
)
259 if (!pt_tty
[minor(dev
)]) {
260 tp
= pt_tty
[minor(dev
)] = ttymalloc();
262 tp
= pt_tty
[minor(dev
)];
264 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
265 ttychars(tp
); /* Set up default chars */
266 tp
->t_iflag
= TTYDEF_IFLAG
;
267 tp
->t_oflag
= TTYDEF_OFLAG
;
268 tp
->t_lflag
= TTYDEF_LFLAG
;
269 tp
->t_cflag
= TTYDEF_CFLAG
;
270 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
271 ttsetwater(tp
); /* would be done in xxparam() */
272 } else if (tp
->t_state
&TS_XCLUDE
&& p
->p_ucred
->cr_uid
!= 0)
274 if (tp
->t_oproc
) /* Ctrlr still around. */
275 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
276 while ((tp
->t_state
& TS_CARR_ON
) == 0) {
279 error
= ttysleep(tp
, TSA_CARR_ON(tp
), TTIPRI
| PCATCH
,
284 error
= (*linesw
[tp
->t_line
].l_open
)(dev
, tp
);
286 ptcwakeup(tp
, FREAD
|FWRITE
);
291 ptsclose(dev
, flag
, mode
, p
)
296 register struct tty
*tp
;
299 tp
= pt_tty
[minor(dev
)];
300 err
= (*linesw
[tp
->t_line
].l_close
)(tp
, flag
);
301 ptsstop(tp
, FREAD
|FWRITE
);
307 ptsread(dev
, uio
, flag
)
313 struct proc
*p
= curproc
;
315 struct proc
*p
= current_proc();
317 register struct tty
*tp
= pt_tty
[minor(dev
)];
318 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
322 ut
= (struct uthread
*)get_bsdthread_info(current_act());
324 if (pti
->pt_flags
& PF_REMOTE
) {
325 while (isbackground(p
, tp
)) {
326 if ((p
->p_sigignore
& sigmask(SIGTTIN
)) ||
327 (ut
->uu_sigmask
& sigmask(SIGTTIN
)) ||
328 p
->p_pgrp
->pg_jobc
== 0 ||
329 p
->p_flag
& P_PPWAIT
)
331 pgsignal(p
->p_pgrp
, SIGTTIN
, 1);
332 error
= ttysleep(tp
, &lbolt
, TTIPRI
| PCATCH
| PTTYBLOCK
, "ptsbg",
337 if (tp
->t_canq
.c_cc
== 0) {
338 if (flag
& IO_NDELAY
)
339 return (EWOULDBLOCK
);
340 error
= ttysleep(tp
, TSA_PTS_READ(tp
), TTIPRI
| PCATCH
,
346 while (tp
->t_canq
.c_cc
> 1 && uio
->uio_resid
> 0)
347 if (ureadc(getc(&tp
->t_canq
), uio
) < 0) {
351 if (tp
->t_canq
.c_cc
== 1)
352 (void) getc(&tp
->t_canq
);
357 error
= (*linesw
[tp
->t_line
].l_read
)(tp
, uio
, flag
);
358 ptcwakeup(tp
, FWRITE
);
363 * Write to pseudo-tty.
364 * Wakeups of controlling tty will happen
365 * indirectly, when tty driver calls ptsstart.
368 ptswrite(dev
, uio
, flag
)
373 register struct tty
*tp
;
375 tp
= pt_tty
[minor(dev
)];
376 if (tp
->t_oproc
== 0)
378 return ((*linesw
[tp
->t_line
].l_write
)(tp
, uio
, flag
));
382 * Start output on pseudo-tty.
383 * Wake up process selecting or sleeping for input from controlling tty.
389 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
391 if (tp
->t_state
& TS_TTSTOP
)
393 if (pti
->pt_flags
& PF_STOPPED
) {
394 pti
->pt_flags
&= ~PF_STOPPED
;
395 pti
->pt_send
= TIOCPKT_START
;
397 ptcwakeup(tp
, FREAD
);
405 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
408 selwakeup(&pti
->pt_selr
);
409 wakeup(TSA_PTC_READ(tp
));
412 selwakeup(&pti
->pt_selw
);
413 wakeup(TSA_PTC_WRITE(tp
));
418 ptcopen(dev
, flag
, devtype
, p
)
423 register struct tty
*tp
;
424 struct pt_ioctl
*pti
;
426 if (minor(dev
) >= npty
)
428 if(!pt_tty
[minor(dev
)]) {
429 tp
= pt_tty
[minor(dev
)] = ttymalloc();
431 tp
= pt_tty
[minor(dev
)];
434 tp
->t_oproc
= ptsstart
;
436 tp
->t_stop
= ptsstop
;
438 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
439 tp
->t_lflag
&= ~EXTPROC
;
440 pti
= &pt_ioctl
[minor(dev
)];
448 ptcclose(dev
, flags
, fmt
, p
)
454 register struct tty
*tp
;
456 tp
= pt_tty
[minor(dev
)];
457 (void)(*linesw
[tp
->t_line
].l_modem
)(tp
, 0);
460 * XXX MDMBUF makes no sense for ptys but would inhibit the above
461 * l_modem(). CLOCAL makes sense but isn't supported. Special
462 * l_modem()s that ignore carrier drop make no sense for ptys but
463 * may be in use because other parts of the line discipline make
464 * sense for ptys. Recover by doing everything that a normal
465 * ttymodem() would have done except for sending a SIGHUP.
467 if (tp
->t_state
& TS_ISOPEN
) {
468 tp
->t_state
&= ~(TS_CARR_ON
| TS_CONNECTED
);
469 tp
->t_state
|= TS_ZOMBIE
;
470 ttyflush(tp
, FREAD
| FWRITE
);
473 tp
->t_oproc
= 0; /* mark closed */
478 ptcread(dev
, uio
, flag
)
483 register struct tty
*tp
= pt_tty
[minor(dev
)];
484 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
489 * We want to block until the slave
490 * is open, and there's something to read;
491 * but if we lost the slave or we're NBIO,
492 * then return the appropriate error instead.
495 if (tp
->t_state
&TS_ISOPEN
) {
496 if (pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) {
497 error
= ureadc((int)pti
->pt_send
, uio
);
500 if (pti
->pt_send
& TIOCPKT_IOCTL
) {
501 cc
= min(uio
->uio_resid
,
502 sizeof(tp
->t_termios
));
503 uiomove((caddr_t
)&tp
->t_termios
, cc
,
509 if (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
) {
510 error
= ureadc((int)pti
->pt_ucntl
, uio
);
516 if (tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0)
519 if ((tp
->t_state
& TS_CONNECTED
) == 0)
520 return (0); /* EOF */
521 if (flag
& IO_NDELAY
)
522 return (EWOULDBLOCK
);
523 error
= tsleep(TSA_PTC_READ(tp
), TTIPRI
| PCATCH
, "ptcin", 0);
527 if (pti
->pt_flags
& (PF_PKT
|PF_UCNTL
))
528 error
= ureadc(0, uio
);
529 while (uio
->uio_resid
> 0 && error
== 0) {
530 cc
= q_to_b(&tp
->t_outq
, buf
, min(uio
->uio_resid
, BUFSIZ
));
533 error
= uiomove(buf
, cc
, uio
);
541 register struct tty
*tp
;
544 struct pt_ioctl
*pti
= &pt_ioctl
[minor(tp
->t_dev
)];
547 /* note: FLUSHREAD and FLUSHWRITE already ok */
549 flush
= TIOCPKT_STOP
;
550 pti
->pt_flags
|= PF_STOPPED
;
552 pti
->pt_flags
&= ~PF_STOPPED
;
553 pti
->pt_send
|= flush
;
554 /* change of perspective */
564 ptcselect(dev
, rw
, wql
, p
)
570 register struct tty
*tp
= pt_tty
[minor(dev
)];
571 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
574 if ((tp
->t_state
& TS_CONNECTED
) == 0)
580 * Need to block timeouts (ttrstart).
583 if ((tp
->t_state
&TS_ISOPEN
) &&
584 tp
->t_outq
.c_cc
&& (tp
->t_state
&TS_TTSTOP
) == 0) {
591 case 0: /* exceptional */
592 if ((tp
->t_state
&TS_ISOPEN
) &&
593 ((pti
->pt_flags
&PF_PKT
&& pti
->pt_send
) ||
594 (pti
->pt_flags
&PF_UCNTL
&& pti
->pt_ucntl
)))
596 selrecord(p
, &pti
->pt_selr
, wql
);
601 if (tp
->t_state
&TS_ISOPEN
) {
602 if (pti
->pt_flags
& PF_REMOTE
) {
603 if (tp
->t_canq
.c_cc
== 0)
606 if (tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
< TTYHOG
-2)
608 if (tp
->t_canq
.c_cc
== 0 && (tp
->t_iflag
&ICANON
))
612 selrecord(p
, &pti
->pt_selw
, wql
);
620 ptcwrite(dev
, uio
, flag
)
622 register struct uio
*uio
;
625 register struct tty
*tp
= pt_tty
[minor(dev
)];
626 register u_char
*cp
= NULL
;
628 u_char locbuf
[BUFSIZ
];
630 struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
634 if ((tp
->t_state
&TS_ISOPEN
) == 0)
636 if (pti
->pt_flags
& PF_REMOTE
) {
639 while ((uio
->uio_resid
> 0 || cc
> 0) &&
640 tp
->t_canq
.c_cc
< TTYHOG
- 1) {
642 cc
= min(uio
->uio_resid
, BUFSIZ
);
643 cc
= min(cc
, TTYHOG
- 1 - tp
->t_canq
.c_cc
);
645 error
= uiomove((caddr_t
)cp
, cc
, uio
);
648 /* check again for safety */
649 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
650 /* adjust as usual */
651 uio
->uio_resid
+= cc
;
656 cc
= b_to_q((char *)cp
, cc
, &tp
->t_canq
);
658 * XXX we don't guarantee that the canq size
659 * is >= TTYHOG, so the above b_to_q() may
660 * leave some bytes uncopied. However, space
661 * is guaranteed for the null terminator if
662 * we don't fail here since (TTYHOG - 1) is
663 * not a multiple of CBSIZE.
669 /* adjust for data copied in but not written */
670 uio
->uio_resid
+= cc
;
671 (void) putc(0, &tp
->t_canq
);
673 wakeup(TSA_PTS_READ(tp
));
676 while (uio
->uio_resid
> 0 || cc
> 0) {
678 cc
= min(uio
->uio_resid
, BUFSIZ
);
680 error
= uiomove((caddr_t
)cp
, cc
, uio
);
683 /* check again for safety */
684 if ((tp
->t_state
& TS_ISOPEN
) == 0) {
685 /* adjust for data copied in but not written */
686 uio
->uio_resid
+= cc
;
691 if ((tp
->t_rawq
.c_cc
+ tp
->t_canq
.c_cc
) >= TTYHOG
- 2 &&
692 (tp
->t_canq
.c_cc
> 0 || !(tp
->t_iflag
&ICANON
))) {
693 wakeup(TSA_HUP_OR_INPUT(tp
));
696 (*linesw
[tp
->t_line
].l_rint
)(*cp
++, tp
);
705 * Come here to wait for slave to open, for space
706 * in outq, or space in rawq, or an empty canq.
708 if ((tp
->t_state
& TS_CONNECTED
) == 0) {
709 /* adjust for data copied in but not written */
710 uio
->uio_resid
+= cc
;
713 if (flag
& IO_NDELAY
) {
714 /* adjust for data copied in but not written */
715 uio
->uio_resid
+= cc
;
717 return (EWOULDBLOCK
);
720 error
= tsleep(TSA_PTC_WRITE(tp
), TTOPRI
| PCATCH
, "ptcout", 0);
722 /* adjust for data copied in but not written */
723 uio
->uio_resid
+= cc
;
730 /* XXX we eventually want to go to this model,
731 * but premier can't change the cdevsw */
736 if (minor(dev
) >= npty
)
739 return &pt_tty
[minor(dev
)];
746 ptyioctl(dev
, cmd
, data
, flag
)
752 ptyioctl(dev
, cmd
, data
, flag
, p
)
760 register struct tty
*tp
= pt_tty
[minor(dev
)];
761 register struct pt_ioctl
*pti
= &pt_ioctl
[minor(dev
)];
762 register u_char
*cc
= tp
->t_cc
;
766 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
767 * ttywflush(tp) will hang if there are characters in the outq.
769 if (cmd
== TIOCEXT
) {
771 * When the EXTPROC bit is being toggled, we need
772 * to send an TIOCPKT_IOCTL if the packet driver
776 if (pti
->pt_flags
& PF_PKT
) {
777 pti
->pt_send
|= TIOCPKT_IOCTL
;
778 ptcwakeup(tp
, FREAD
);
780 tp
->t_lflag
|= EXTPROC
;
782 if ((tp
->t_lflag
& EXTPROC
) &&
783 (pti
->pt_flags
& PF_PKT
)) {
784 pti
->pt_send
|= TIOCPKT_IOCTL
;
785 ptcwakeup(tp
, FREAD
);
787 tp
->t_lflag
&= ~EXTPROC
;
792 if (cdevsw
[major(dev
)]->d_open
== ptcopen
)
794 if (cdevsw
[major(dev
)].d_open
== ptcopen
)
800 * We aviod calling ttioctl on the controller since,
801 * in that case, tp must be the controlling terminal.
803 *(int *)data
= tp
->t_pgrp
? tp
->t_pgrp
->pg_id
: 0;
808 if (pti
->pt_flags
& PF_UCNTL
)
810 pti
->pt_flags
|= PF_PKT
;
812 pti
->pt_flags
&= ~PF_PKT
;
817 if (pti
->pt_flags
& PF_PKT
)
819 pti
->pt_flags
|= PF_UCNTL
;
821 pti
->pt_flags
&= ~PF_UCNTL
;
826 pti
->pt_flags
|= PF_REMOTE
;
828 pti
->pt_flags
&= ~PF_REMOTE
;
829 ttyflush(tp
, FREAD
|FWRITE
);
840 ndflush(&tp
->t_outq
, tp
->t_outq
.c_cc
);
844 if (*(unsigned int *)data
>= NSIG
||
845 *(unsigned int *)data
== 0)
847 if ((tp
->t_lflag
&NOFLSH
) == 0)
848 ttyflush(tp
, FREAD
|FWRITE
);
849 pgsignal(tp
->t_pgrp
, *(unsigned int *)data
, 1);
850 if ((*(unsigned int *)data
== SIGINFO
) &&
851 ((tp
->t_lflag
&NOKERNINFO
) == 0))
855 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, p
);
857 error
= ttioctl(tp
, cmd
, data
, flag
, p
);
859 if (pti
->pt_flags
& PF_UCNTL
&&
860 (cmd
& ~0xff) == UIOCCMD(0)) {
862 pti
->pt_ucntl
= (u_char
)cmd
;
863 ptcwakeup(tp
, FREAD
);
870 * If external processing and packet mode send ioctl packet.
872 if ((tp
->t_lflag
&EXTPROC
) && (pti
->pt_flags
& PF_PKT
)) {
881 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
888 pti
->pt_send
|= TIOCPKT_IOCTL
;
889 ptcwakeup(tp
, FREAD
);
894 stop
= (tp
->t_iflag
& IXON
) && CCEQ(cc
[VSTOP
], CTRL('s'))
895 && CCEQ(cc
[VSTART
], CTRL('q'));
896 if (pti
->pt_flags
& PF_NOSTOP
) {
898 pti
->pt_send
&= ~TIOCPKT_NOSTOP
;
899 pti
->pt_send
|= TIOCPKT_DOSTOP
;
900 pti
->pt_flags
&= ~PF_NOSTOP
;
901 ptcwakeup(tp
, FREAD
);
905 pti
->pt_send
&= ~TIOCPKT_DOSTOP
;
906 pti
->pt_send
|= TIOCPKT_NOSTOP
;
907 pti
->pt_flags
|= PF_NOSTOP
;
908 ptcwakeup(tp
, FREAD
);
915 static ptc_devsw_installed
= 0;
918 ptc_drvinit(void *unused
)
925 if( ! ptc_devsw_installed
) {
926 dev
= makedev(CDEV_MAJOR_S
, 0);
927 cdevsw_add(&dev
, &pts_cdevsw
, NULL
);
928 dev
= makedev(CDEV_MAJOR_C
, 0);
929 cdevsw_add(&dev
, &ptc_cdevsw
, NULL
);
930 ptc_devsw_installed
= 1;
932 for ( i
= 0 ; i
<NPTY
; i
++ ) {
936 devfs_add_devswf(&pts_cdevsw
,i
,
938 "tty%c%n",jnames
[j
],k
);
940 devfs_add_devswf(&ptc_cdevsw
,i
,
942 "pty%c%n",jnames
[j
],k
);
948 SYSINIT(ptcdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR_C
,ptc_drvinit
,NULL
)