Make linesw[] an array of pointers to linedesc instead of an array of

linedisc.
This commit is contained in:
Poul-Henning Kamp 2004-06-07 20:45:45 +00:00
parent 3786c125c7
commit 5df76176f7
4 changed files with 103 additions and 107 deletions

View File

@ -1430,7 +1430,7 @@ static void cx_receive (cx_chan_t *c, char *data, int len)
&& (!(tp->t_iflag & PARMRK)\
|| (tp->t_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))\
&& !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))\
&& linesw[tp->t_line].l_rint == ttyinput)
&& linesw[tp->t_line]->l_rint == ttyinput)
/*
* Error callback function.

View File

@ -1015,7 +1015,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag)
if (t != tp->t_line) {
s = spltty();
ttyld_close(tp, flag);
error = (*linesw[t].l_open)(device, tp);
error = (*linesw[t]->l_open)(device, tp);
if (error) {
(void)ttyld_open(tp, device);
splx(s);
@ -2772,9 +2772,9 @@ ttyldoptim(struct tty *tp)
&& (!(t->c_iflag & PARMRK)
|| (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
&& !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
&& linesw[tp->t_line].l_rint == ttyinput)
&& linesw[tp->t_line]->l_rint == ttyinput)
tp->t_state |= TS_CAN_BYPASS_L_RINT;
else
tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
return (linesw[tp->t_line].l_hotchar);
return (linesw[tp->t_line]->l_hotchar);
}

View File

@ -1,4 +1,5 @@
/*-
* Copyright (c) 2004 Poul-Henning Kamp. All rights reserved.
* Copyright (c) 1982, 1986, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
@ -59,36 +60,51 @@ static l_start_t l_nostart;
* Reconsider the removal of nullmodem anyway. It was too much like
* ttymodem, but a completely null version might be useful.
*/
#define NODISC(n) \
{ l_noopen, l_noclose, l_noread, l_nowrite, \
l_nullioctl, l_norint, l_nostart, ttymodem }
struct linesw linesw[MAXLDISC] =
{
/* 0- termios */
{ ttyopen, ttylclose, ttread, ttwrite,
l_nullioctl, ttyinput, ttstart, ttymodem },
NODISC(1), /* 1- defunct */
/* 2- NTTYDISC */
static struct linesw nodisc = {
.l_open = l_noopen,
.l_close = l_noclose,
.l_read = l_noread,
.l_write = l_nowrite,
.l_ioctl = l_nullioctl,
.l_rint = l_norint,
.l_start = l_nostart,
.l_modem = ttymodem
};
static struct linesw termios_disc = {
.l_open = ttyopen,
.l_close = ttylclose,
.l_read = ttread,
.l_write = ttwrite,
.l_ioctl = l_nullioctl,
.l_rint = ttyinput,
.l_start = ttstart,
.l_modem = ttymodem
};
#ifdef COMPAT_43
{ ttyopen, ttylclose, ttread, ttwrite,
l_nullioctl, ttyinput, ttstart, ttymodem },
# define ntty_disc termios_disc
#else
NODISC(2),
# define ntty_disc nodisc
#endif
NODISC(3), /* loadable */
NODISC(4), /* SLIPDISC */
NODISC(5), /* PPPDISC */
NODISC(6), /* NETGRAPHDISC */
NODISC(7), /* loadable */
NODISC(8), /* loadable */
struct linesw *linesw[MAXLDISC] = {
&termios_disc, /* 0 - termios */
&nodisc, /* 1 - defunct */
&ntty_disc, /* 2 - NTTYDISC */
&nodisc, /* 3 - loadable */
&nodisc, /* 4 - SLIPDISC */
&nodisc, /* 5 - PPPDISC */
&nodisc, /* 6 - NETGRAPHDISC */
&nodisc, /* 7 - loadable */
&nodisc, /* 8 - loadable */
};
int nlinesw = sizeof (linesw) / sizeof (linesw[0]);
static struct linesw nodisc = NODISC(0);
#define LOADABLE_LDISC 7
/*
* ldisc_register: Register a line discipline.
*
@ -97,10 +113,9 @@ static struct linesw nodisc = NODISC(0);
*
* Returns: Index used or -1 on failure.
*/
int
ldisc_register(discipline, linesw_p)
int discipline;
struct linesw *linesw_p;
ldisc_register(int discipline, struct linesw *linesw_p)
{
int slot = -1;
@ -110,13 +125,12 @@ ldisc_register(discipline, linesw_p)
if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) {
slot = i;
}
}
else if (discipline >= 0 && discipline < MAXLDISC) {
} else if (discipline >= 0 && discipline < MAXLDISC) {
slot = discipline;
}
if (slot != -1 && linesw_p)
linesw[slot] = *linesw_p;
linesw[slot] = linesw_p;
return slot;
}
@ -127,81 +141,63 @@ ldisc_register(discipline, linesw_p)
*
* discipline: Index for discipline to unload.
*/
void
ldisc_deregister(discipline)
int discipline;
{
if (discipline < MAXLDISC) {
linesw[discipline] = nodisc;
}
}
static int
l_noopen(dev, tp)
dev_t dev;
struct tty *tp;
ldisc_deregister(int discipline)
{
return (ENODEV);
}
static int
l_noclose(tp, flag)
struct tty *tp;
int flag;
{
return (ENODEV);
}
int
l_noread(tp, uio, flag)
struct tty *tp;
struct uio *uio;
int flag;
{
return (ENODEV);
}
int
l_nowrite(tp, uio, flag)
struct tty *tp;
struct uio *uio;
int flag;
{
return (ENODEV);
}
static int
l_norint(c, tp)
int c;
struct tty *tp;
{
return (ENODEV);
}
static int
l_nostart(tp)
struct tty *tp;
{
return (ENODEV);
if (discipline < MAXLDISC)
linesw[discipline] = &nodisc;
}
/*
* Do nothing specific version of line
* discipline specific ioctl command.
* "no" and "null" versions of line discipline functions
*/
static int
l_noopen(dev_t dev, struct tty *tp)
{
return (ENODEV);
}
static int
l_noclose(struct tty *tp, int flag)
{
return (ENODEV);
}
int
l_nullioctl(tp, cmd, data, flags, td)
struct tty *tp;
u_long cmd;
char *data;
int flags;
struct thread *td;
l_noread(struct tty *tp, struct uio *uio, int flag)
{
return (ENODEV);
}
int
l_nowrite(struct tty *tp, struct uio *uio, int flag)
{
return (ENODEV);
}
static int
l_norint(int c, struct tty *tp)
{
return (ENODEV);
}
static int
l_nostart(struct tty *tp)
{
return (ENODEV);
}
int
l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags, struct thread *td)
{
return (ENOIOCTL);

View File

@ -69,7 +69,7 @@ struct linesw {
u_char l_hotchar;
};
extern struct linesw linesw[];
extern struct linesw *linesw[];
extern int nlinesw;
int ldisc_register(int , struct linesw *);
@ -84,28 +84,28 @@ static __inline int
ttyld_open(struct tty *tp, dev_t dev)
{
return ((*linesw[tp->t_line].l_open)(dev, tp));
return ((*linesw[tp->t_line]->l_open)(dev, tp));
}
static __inline int
ttyld_close(struct tty *tp, int flag)
{
return ((*linesw[tp->t_line].l_close)(tp, flag));
return ((*linesw[tp->t_line]->l_close)(tp, flag));
}
static __inline int
ttyld_read(struct tty *tp, struct uio *uio, int flag)
{
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
return ((*linesw[tp->t_line]->l_read)(tp, uio, flag));
}
static __inline int
ttyld_write(struct tty *tp, struct uio *uio, int flag)
{
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
return ((*linesw[tp->t_line]->l_write)(tp, uio, flag));
}
static __inline int
@ -113,28 +113,28 @@ ttyld_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
struct thread *td)
{
return ((*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td));
return ((*linesw[tp->t_line]->l_ioctl)(tp, cmd, data, flag, td));
}
static __inline int
ttyld_rint(struct tty *tp, int c)
{
return ((*linesw[tp->t_line].l_rint)(c, tp));
return ((*linesw[tp->t_line]->l_rint)(c, tp));
}
static __inline int
ttyld_start(struct tty *tp)
{
return ((*linesw[tp->t_line].l_start)(tp));
return ((*linesw[tp->t_line]->l_start)(tp));
}
static __inline int
ttyld_modem(struct tty *tp, int flag)
{
return ((*linesw[tp->t_line].l_modem)(tp, flag));
return ((*linesw[tp->t_line]->l_modem)(tp, flag));
}
#endif /* _KERNEL */