PTY: split off from TTY
Requires recreation of /dev/tty[pq]*, /dev/pty[pq]* device nodes. Change-Id: I0e5a28d82faa934497fd3b97d619e506bcb5f439
This commit is contained in:
parent
fad76abe45
commit
760f3d62d7
14 changed files with 1449 additions and 59 deletions
|
@ -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]|9,1[3-8]?|9,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
|
||||
;;
|
||||
|
|
|
@ -418,8 +418,8 @@ do
|
|||
minor_tty=`expr ${group} '*' 16 + ${pty} + 128`
|
||||
minor_pty=`expr ${group} '*' 16 + ${pty} + 192`
|
||||
|
||||
makedev tty${dev} c 4 ${minor_tty} ${uname} tty 666
|
||||
makedev pty${dev} c 4 ${minor_pty} ${uname} tty 666
|
||||
makedev tty${dev} c 9 ${minor_tty} ${uname} tty 666
|
||||
makedev pty${dev} c 9 ${minor_pty} ${uname} tty 666
|
||||
;;
|
||||
ttyc[1-7])
|
||||
# Virtual consoles.
|
||||
|
|
|
@ -4892,6 +4892,7 @@
|
|||
./usr/sbin/pfs minix-sys
|
||||
./usr/sbin/pm minix-sys
|
||||
./usr/sbin/postinstall minix-sys
|
||||
./usr/sbin/pty minix-sys
|
||||
./usr/sbin/pwd_mkdb minix-sys
|
||||
./usr/sbin/rdate minix-sys
|
||||
./usr/sbin/rs minix-sys
|
||||
|
|
|
@ -31,7 +31,7 @@ SUBDIR= bmp085 cat24c256 fb gpio i2c lan8710a \
|
|||
.endif
|
||||
|
||||
# Drivers available on all platforms
|
||||
SUBDIR+= log mmc random tty uds vnd readclock
|
||||
SUBDIR+= log mmc pty random tty uds vnd readclock
|
||||
|
||||
.endif # ${MKIMAGEONLY} != "yes"
|
||||
|
||||
|
|
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>
|
|
@ -23,8 +23,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 */
|
||||
|
@ -618,7 +616,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;
|
||||
|
@ -638,5 +636,3 @@ void pty_init(tty_t *tp)
|
|||
tp->tty_close = pty_slave_close;
|
||||
tp->tty_select_ops = 0;
|
||||
}
|
||||
|
||||
#endif /* NR_PTYS > 0 */
|
1281
drivers/pty/tty.c
Normal file
1281
drivers/pty/tty.c
Normal file
File diff suppressed because it is too large
Load diff
121
drivers/pty/tty.h
Normal file
121
drivers/pty/tty.h
Normal file
|
@ -0,0 +1,121 @@
|
|||
/* 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_on; /* let the device assert a break */
|
||||
devfun_t tty_break_off; /* let the device de-assert 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 TTY 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
|
||||
|
|
|
@ -44,7 +44,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)
|
||||
|
@ -58,11 +57,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);
|
||||
|
@ -132,7 +126,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;
|
||||
|
@ -232,15 +226,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. */
|
||||
|
@ -290,10 +275,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;
|
||||
}
|
||||
|
@ -957,10 +938,6 @@ tty_t *tp; /* TTY to check for events. */
|
|||
{
|
||||
select_retry(tp);
|
||||
}
|
||||
#if NR_PTYS > 0
|
||||
if (ispty(tp))
|
||||
select_retry_pty(tp);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
@ -1582,13 +1559,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 */
|
||||
|
@ -88,7 +86,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 */
|
||||
|
||||
|
@ -155,8 +153,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);
|
||||
|
|
|
@ -707,3 +707,13 @@ service uds
|
|||
;
|
||||
uid 0; # only for checkperms(2) and copyfd(2)
|
||||
};
|
||||
|
||||
service pty
|
||||
{
|
||||
system
|
||||
KILL # 06
|
||||
;
|
||||
ipc
|
||||
SYSTEM vfs rs vm
|
||||
;
|
||||
};
|
||||
|
|
|
@ -196,6 +196,8 @@ start|autoboot)
|
|||
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 a new issue