PTY: split off from TTY
Requires recreation of /dev/tty[pq]*, /dev/pty[pq]* device nodes. Duplicates a large part of tty.c, but that can be solved later. Change-Id: I8e00eda76d9ca5315d00d18cc6b5a28b6c66256c
This commit is contained in:
parent
26c3bf3373
commit
c206f56b30
|
|
@ -126,18 +126,6 @@ do
|
|||
;;
|
||||
4,125) des="video output" dev=video
|
||||
;;
|
||||
4,12[89]|4,1[3-8]?|4,19[01])
|
||||
p=`expr \\( $minor - 128 \\) / 16 | tr '0123' 'pqrs'`
|
||||
n=`expr $minor % 16`
|
||||
test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
|
||||
des="pseudo tty `expr $minor - 128`" dev=tty$p$n
|
||||
;;
|
||||
4,???)
|
||||
p=`expr \\( $minor - 192 \\) / 16 | tr '0123' 'pqrs'`
|
||||
n=`expr $minor % 16`
|
||||
test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
|
||||
des="controller of tty$p$n" dev=pty$p$n
|
||||
;;
|
||||
5,0) des="anonymous tty" dev=tty
|
||||
;;
|
||||
6,0) des="line printer, parallel port" dev=lp
|
||||
|
|
@ -171,6 +159,18 @@ do
|
|||
fi
|
||||
esac
|
||||
;;
|
||||
9,12[89]|4,1[3-8]?|4,19[01])
|
||||
p=`expr \\( $minor - 128 \\) / 16 | tr '0123' 'pqrs'`
|
||||
n=`expr $minor % 16`
|
||||
test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
|
||||
des="pseudo tty `expr $minor - 128`" dev=tty$p$n
|
||||
;;
|
||||
9,???)
|
||||
p=`expr \\( $minor - 192 \\) / 16 | tr '0123' 'pqrs'`
|
||||
n=`expr $minor % 16`
|
||||
test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
|
||||
des="controller of tty$p$n" dev=pty$p$n
|
||||
;;
|
||||
11,0)
|
||||
des="block filter" dev=filter
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -233,8 +233,8 @@ do
|
|||
[a-f]) n=1`/bin/echo $n | tr 'abcdef' '012345'`
|
||||
esac
|
||||
|
||||
$e mknod tty$dev c 4 `expr $g '*' 16 + $n + 128`
|
||||
$e mknod pty$dev c 4 `expr $g '*' 16 + $n + 192`
|
||||
$e mknod tty$dev c 9 `expr $g '*' 16 + $n + 128`
|
||||
$e mknod pty$dev c 9 `expr $g '*' 16 + $n + 192`
|
||||
$e chgrp tty tty$dev pty$dev
|
||||
$e chmod 666 tty$dev pty$dev
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ SUBDIR= tty
|
|||
.if ${MACHINE_ARCH} == "i386"
|
||||
SUBDIR= ahci amddev atl2 at_wini audio dec21140A dp8390 dpeth \
|
||||
e1000 fbd filter floppy fxp hello lance log mmc orinoco pci pckbd \
|
||||
printer random readclock rtl8139 rtl8169 ti1225 tty uds vbox acpi \
|
||||
printer pty random readclock rtl8139 rtl8169 ti1225 tty uds vbox acpi \
|
||||
virtio_blk virtio_net vnd
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_ARCH} == "earm"
|
||||
SUBDIR= bmp085 cat24c256 fb gpio i2c mmc lan8710a log readclock \
|
||||
SUBDIR= bmp085 cat24c256 fb gpio i2c mmc lan8710a log pty readclock \
|
||||
sht21 tda19988 tps65217 tps65950 tsl2550 tty random uds vnd
|
||||
.endif
|
||||
|
||||
|
|
|
|||
13
drivers/pty/Makefile
Normal file
13
drivers/pty/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Makefile for pseudo terminal driver (PTY)
|
||||
|
||||
PROG= pty
|
||||
SRCS= tty.c pty.c
|
||||
|
||||
DPADD+= ${LIBCHARDRIVER} ${LIBSYS} ${LIBTIMERS}
|
||||
LDADD+= -lchardriver -lsys -ltimers
|
||||
|
||||
MAN=
|
||||
|
||||
BINDIR?= /usr/sbin
|
||||
|
||||
.include <minix.service.mk>
|
||||
|
|
@ -21,8 +21,6 @@
|
|||
#include <signal.h>
|
||||
#include "tty.h"
|
||||
|
||||
#if NR_PTYS > 0
|
||||
|
||||
/* PTY bookkeeping structure, one per pty/tty pair. */
|
||||
typedef struct pty {
|
||||
tty_t *tty; /* associated TTY structure */
|
||||
|
|
@ -350,7 +348,7 @@ static int pty_slave_write(tty_t *tp, int try)
|
|||
|
||||
/* PTY closed down? */
|
||||
if (pp->state & PTY_CLOSED) {
|
||||
if (try) return 1;
|
||||
if (try) return 1;
|
||||
if (tp->tty_outleft > 0) {
|
||||
chardriver_reply_task(tp->tty_outcaller, tp->tty_outid, EIO);
|
||||
tp->tty_outleft = tp->tty_outcum = 0;
|
||||
|
|
@ -441,7 +439,7 @@ static void pty_start(pty_t *pp)
|
|||
|
||||
/* While there are things to do. */
|
||||
for (;;) {
|
||||
int s;
|
||||
int s;
|
||||
count = bufend(pp->obuf) - pp->otail;
|
||||
if (count > pp->ocount) count = pp->ocount;
|
||||
if (count > pp->rdleft) count = pp->rdleft;
|
||||
|
|
@ -451,7 +449,7 @@ static void pty_start(pty_t *pp)
|
|||
if((s = sys_safecopyto(pp->rdcaller, pp->rdgrant, pp->rdcum,
|
||||
(vir_bytes) pp->otail, count)) != OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Bookkeeping. */
|
||||
pp->ocount -= count;
|
||||
|
|
@ -500,13 +498,13 @@ static int pty_slave_read(tty_t *tp, int try)
|
|||
}
|
||||
|
||||
if (try) {
|
||||
if (pp->wrleft > 0)
|
||||
return 1;
|
||||
return 0;
|
||||
if (pp->wrleft > 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (pp->wrleft > 0) {
|
||||
int s;
|
||||
int s;
|
||||
|
||||
/* Transfer one character to 'c'. */
|
||||
if ((s = sys_safecopyfrom(pp->wrcaller, pp->wrgrant, pp->wrcum,
|
||||
|
|
@ -616,7 +614,7 @@ void pty_init(tty_t *tp)
|
|||
int line;
|
||||
|
||||
/* Associate PTY and TTY structures. */
|
||||
line = tp - &tty_table[NR_CONS + NR_RS_LINES];
|
||||
line = tp - tty_table;
|
||||
pp = tp->tty_priv = &pty_table[line];
|
||||
pp->tty = tp;
|
||||
pp->select_ops = 0;
|
||||
|
|
@ -636,5 +634,3 @@ void pty_init(tty_t *tp)
|
|||
tp->tty_close = pty_slave_close;
|
||||
tp->tty_select_ops = 0;
|
||||
}
|
||||
|
||||
#endif /* NR_PTYS > 0 */
|
||||
1254
drivers/pty/tty.c
Normal file
1254
drivers/pty/tty.c
Normal file
File diff suppressed because it is too large
Load Diff
120
drivers/pty/tty.h
Normal file
120
drivers/pty/tty.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/* tty.h - Terminals */
|
||||
|
||||
#include <minix/chardriver.h>
|
||||
#include <minix/timers.h>
|
||||
|
||||
/* First minor numbers for the various classes of TTY devices. */
|
||||
#define TTYPX_MINOR 128
|
||||
#define PTYPX_MINOR 192
|
||||
|
||||
#define TTY_IN_BYTES 256 /* tty input queue size */
|
||||
#define TAB_SIZE 8 /* distance between tab stops */
|
||||
#define TAB_MASK 7 /* mask to compute a tab stop position */
|
||||
|
||||
#define ESC '\33' /* escape */
|
||||
|
||||
struct tty;
|
||||
typedef int(*devfun_t) (struct tty *tp, int try_only);
|
||||
typedef void(*devfunarg_t) (struct tty *tp, int c);
|
||||
|
||||
typedef struct tty {
|
||||
int tty_events; /* set when TTY should inspect this line */
|
||||
int tty_index; /* index into TTY table */
|
||||
devminor_t tty_minor; /* device minor number */
|
||||
|
||||
/* Input queue. Typed characters are stored here until read by a program. */
|
||||
u16_t *tty_inhead; /* pointer to place where next char goes */
|
||||
u16_t *tty_intail; /* pointer to next char to be given to prog */
|
||||
int tty_incount; /* # chars in the input queue */
|
||||
int tty_eotct; /* number of "line breaks" in input queue */
|
||||
devfun_t tty_devread; /* routine to read from low level buffers */
|
||||
devfun_t tty_icancel; /* cancel any device input */
|
||||
int tty_min; /* minimum requested #chars in input queue */
|
||||
minix_timer_t tty_tmr; /* the timer for this tty */
|
||||
|
||||
/* Output section. */
|
||||
devfun_t tty_devwrite; /* routine to start actual device output */
|
||||
devfunarg_t tty_echo; /* routine to echo characters input */
|
||||
devfun_t tty_ocancel; /* cancel any ongoing device output */
|
||||
devfun_t tty_break; /* let the device send a break */
|
||||
|
||||
/* Terminal parameters and status. */
|
||||
int tty_position; /* current position on the screen for echoing */
|
||||
char tty_reprint; /* 1 when echoed input messed up, else 0 */
|
||||
char tty_escaped; /* 1 when LNEXT (^V) just seen, else 0 */
|
||||
char tty_inhibited; /* 1 when STOP (^S) just seen (stops output) */
|
||||
endpoint_t tty_pgrp; /* endpoint of controlling process */
|
||||
char tty_openct; /* count of number of opens of this tty */
|
||||
|
||||
/* Information about incomplete I/O requests is stored here. */
|
||||
endpoint_t tty_incaller; /* process that made the call, or NONE */
|
||||
cdev_id_t tty_inid; /* ID of suspended read request */
|
||||
cp_grant_id_t tty_ingrant; /* grant where data is to go */
|
||||
size_t tty_inleft; /* how many chars are still needed */
|
||||
size_t tty_incum; /* # chars input so far */
|
||||
endpoint_t tty_outcaller; /* process that made the call, or NONE */
|
||||
cdev_id_t tty_outid; /* ID of suspended write request */
|
||||
cp_grant_id_t tty_outgrant; /* grant where data comes from */
|
||||
size_t tty_outleft; /* # chars yet to be output */
|
||||
size_t tty_outcum; /* # chars output so far */
|
||||
endpoint_t tty_iocaller; /* process that made the call, or NONE */
|
||||
cdev_id_t tty_ioid; /* ID of suspended ioctl request */
|
||||
unsigned int tty_ioreq; /* ioctl request code */
|
||||
cp_grant_id_t tty_iogrant; /* virtual address of ioctl buffer or grant */
|
||||
|
||||
/* select() data */
|
||||
unsigned int tty_select_ops; /* which operations are interesting */
|
||||
endpoint_t tty_select_proc; /* which process wants notification */
|
||||
devminor_t tty_select_minor; /* minor used to start select query */
|
||||
|
||||
/* Miscellaneous. */
|
||||
devfun_t tty_ioctl; /* set line speed, etc. at the device level */
|
||||
devfun_t tty_open; /* tell the device that the tty is opened */
|
||||
devfun_t tty_close; /* tell the device that the tty is closed */
|
||||
void *tty_priv; /* pointer to per device private data */
|
||||
struct termios tty_termios; /* terminal attributes */
|
||||
struct winsize tty_winsize; /* window size (#lines and #columns) */
|
||||
|
||||
u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
|
||||
|
||||
} tty_t;
|
||||
|
||||
/* Memory allocated in tty.c, so extern here. */
|
||||
extern tty_t tty_table[NR_PTYS];
|
||||
extern u32_t system_hz; /* system clock frequency */
|
||||
|
||||
/* Values for the fields. */
|
||||
#define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
|
||||
#define ESCAPED 1 /* previous character was LNEXT (^V) */
|
||||
#define RUNNING 0 /* no STOP (^S) has been typed to stop output */
|
||||
#define STOPPED 1 /* STOP (^S) has been typed to stop output */
|
||||
|
||||
/* Fields and flags on characters in the input queue. */
|
||||
#define IN_CHAR 0x00FF /* low 8 bits are the character itself */
|
||||
#define IN_LEN 0x0F00 /* length of char if it has been echoed */
|
||||
#define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */
|
||||
#define IN_EOT 0x1000 /* char is a line break (^D, LF) */
|
||||
#define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */
|
||||
#define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */
|
||||
|
||||
/* Number of elements and limit of a buffer. */
|
||||
#define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
|
||||
#define bufend(buf) ((buf) + buflen(buf))
|
||||
|
||||
/* Function prototypes for PTY driver. */
|
||||
/* tty.c */
|
||||
void handle_events(struct tty *tp);
|
||||
void sigchar(struct tty *tp, int sig, int mayflush);
|
||||
void tty_task(void);
|
||||
tty_t *line2tty(devminor_t minor);
|
||||
int in_process(struct tty *tp, char *buf, int count);
|
||||
void out_process(struct tty *tp, char *bstart, char *bpos, char *bend,
|
||||
int *icount, int *ocount);
|
||||
void tty_wakeup(clock_t now);
|
||||
int select_try(struct tty *tp, int ops);
|
||||
int select_retry(struct tty *tp);
|
||||
|
||||
/* pty.c */
|
||||
void do_pty(message *m_ptr, int ipc_status);
|
||||
void pty_init(struct tty *tp);
|
||||
void select_retry_pty(struct tty *tp);
|
||||
|
|
@ -4,7 +4,7 @@ PROG= tty
|
|||
|
||||
.include "arch/${MACHINE_ARCH}/Makefile.inc"
|
||||
|
||||
SRCS += tty.c pty.c
|
||||
SRCS += tty.c
|
||||
|
||||
DPADD+= ${LIBCHARDRIVER} ${LIBSYS} ${LIBTIMERS}
|
||||
LDADD+= -lchardriver -lsys -ltimers
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ unsigned long rs_irq_set = 0;
|
|||
|
||||
/* Macros for magic tty types. */
|
||||
#define isconsole(tp) ((tp) < tty_addr(NR_CONS))
|
||||
#define ispty(tp) ((tp) != NULL && (tp)->tty_minor >= TTYPX_MINOR)
|
||||
|
||||
/* Macros for magic tty structure pointers. */
|
||||
#define FIRST_TTY tty_addr(0)
|
||||
|
|
@ -56,11 +55,6 @@ unsigned long rs_irq_set = 0;
|
|||
#define rs_init(tp) ((void) 0)
|
||||
#endif
|
||||
|
||||
#if NR_PTYS == 0
|
||||
#define pty_init(tp) ((void) 0)
|
||||
#define do_pty(tp, mp) ((void) 0)
|
||||
#endif
|
||||
|
||||
struct kmessages kmess;
|
||||
|
||||
static void tty_timed_out(minix_timer_t *tp);
|
||||
|
|
@ -113,7 +107,7 @@ static struct termios termios_defaults = {
|
|||
static struct winsize winsize_defaults; /* = all zeroes */
|
||||
|
||||
/* Global variables for the TTY task (declared extern in tty.h). */
|
||||
tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
|
||||
tty_t tty_table[NR_CONS+NR_RS_LINES];
|
||||
int ccurrent; /* currently active console */
|
||||
struct machine machine; /* kernel environment variables */
|
||||
u32_t system_hz;
|
||||
|
|
@ -213,15 +207,6 @@ int main(void)
|
|||
if (line == VIDEO_MINOR) {
|
||||
do_video(&tty_mess, ipc_status);
|
||||
continue;
|
||||
} else if (line - PTYPX_MINOR < NR_PTYS &&
|
||||
tty_mess.m_type != CDEV_IOCTL) {
|
||||
/* Terminals and pseudo terminals belong together. We can only
|
||||
* make a distinction between the two based on position in the
|
||||
* tty_table and not on minor number (i.e., use ispty macro).
|
||||
* Hence this special case.
|
||||
*/
|
||||
do_pty(&tty_mess, ipc_status);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Execute the requested device driver function. */
|
||||
|
|
@ -271,10 +256,6 @@ line2tty(devminor_t line)
|
|||
tp = tty_addr(line - CONS_MINOR);
|
||||
} else if ((line - RS232_MINOR) < NR_RS_LINES) {
|
||||
tp = tty_addr(line - RS232_MINOR + NR_CONS);
|
||||
} else if ((line - TTYPX_MINOR) < NR_PTYS) {
|
||||
tp = tty_addr(line - TTYPX_MINOR + NR_CONS + NR_RS_LINES);
|
||||
} else if ((line - PTYPX_MINOR) < NR_PTYS) {
|
||||
tp = tty_addr(line - PTYPX_MINOR + NR_CONS + NR_RS_LINES);
|
||||
} else {
|
||||
tp = NULL;
|
||||
}
|
||||
|
|
@ -938,10 +919,6 @@ tty_t *tp; /* TTY to check for events. */
|
|||
{
|
||||
select_retry(tp);
|
||||
}
|
||||
#if NR_PTYS > 0
|
||||
if (ispty(tp))
|
||||
select_retry_pty(tp);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
|
@ -1558,13 +1535,9 @@ static void tty_init()
|
|||
kb_init(tp);
|
||||
|
||||
tp->tty_minor = CONS_MINOR + s;
|
||||
} else
|
||||
if (tp < tty_addr(NR_CONS+NR_RS_LINES)) {
|
||||
} else {
|
||||
rs_init(tp);
|
||||
tp->tty_minor = RS232_MINOR + s-NR_CONS;
|
||||
} else {
|
||||
pty_init(tp);
|
||||
tp->tty_minor = s - (NR_CONS+NR_RS_LINES) + TTYPX_MINOR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
#define LOG_MINOR 15
|
||||
#define RS232_MINOR 16
|
||||
#define VIDEO_MINOR 125
|
||||
#define TTYPX_MINOR 128
|
||||
#define PTYPX_MINOR 192
|
||||
|
||||
#define CONS_ARG 30 /* console= boot param length (incl. nul) */
|
||||
#define LINEWRAP 1 /* console.c - wrap lines at column 80 */
|
||||
|
|
@ -87,7 +85,7 @@ typedef struct tty {
|
|||
} tty_t;
|
||||
|
||||
/* Memory allocated in tty.c, so extern here. */
|
||||
extern tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
|
||||
extern tty_t tty_table[NR_CONS+NR_RS_LINES];
|
||||
extern int ccurrent; /* currently visible console */
|
||||
extern u32_t system_hz; /* system clock frequency */
|
||||
|
||||
|
|
@ -154,8 +152,3 @@ void kb_init_once(void);
|
|||
int kbd_loadmap(endpoint_t endpt, cp_grant_id_t grant);
|
||||
void do_fkey_ctl(message *m);
|
||||
void do_input(message *m);
|
||||
|
||||
/* pty.c */
|
||||
void do_pty(message *m_ptr, int ipc_status);
|
||||
void pty_init(struct tty *tp);
|
||||
void select_retry_pty(struct tty *tp);
|
||||
|
|
|
|||
|
|
@ -708,3 +708,13 @@ service uds
|
|||
;
|
||||
uid 0; # only for checkperms(2) and copyfd(2)
|
||||
};
|
||||
|
||||
service pty
|
||||
{
|
||||
system
|
||||
KILL # 06
|
||||
;
|
||||
ipc
|
||||
SYSTEM vfs rs vm
|
||||
;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -193,6 +193,8 @@ start)
|
|||
up inet -script /etc/rs.inet -dev /dev/ip
|
||||
fi
|
||||
|
||||
up pty -dev /dev/ptyp0
|
||||
|
||||
up uds -dev /dev/uds
|
||||
|
||||
up -n ipc
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#define PRINTER_MAJOR 6 /* 6 = /dev/lp (printer driver) */
|
||||
#define INET_MAJOR 7 /* 7 = /dev/ip (inet) */
|
||||
/* 8 = /dev/c1 */
|
||||
/* 9 = not used */
|
||||
#define PTY_MAJOR 9 /* 9 = /dev/ptyp0 (pty driver) */
|
||||
/* 10 = /dev/c2 */
|
||||
#define FILTER_MAJOR 11 /* 11 = /dev/filter (filter driver) */
|
||||
/* 12 = /dev/c3 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user