diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 2004-06-07 20:45:45 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 2004-06-07 20:45:45 +0000 |
commit | 5df76176f77e5acef4604d5c6440c8ededfc7355 (patch) | |
tree | 7b7bb3162ae4f20656b003b9c64c0b109c8d11d0 | |
parent | 3786c125c729a399cff1ba90ca5a540af21a203f (diff) |
Notes
-rw-r--r-- | sys/dev/cx/if_cx.c | 2 | ||||
-rw-r--r-- | sys/kern/tty.c | 6 | ||||
-rw-r--r-- | sys/kern/tty_conf.c | 118 | ||||
-rw-r--r-- | sys/sys/linedisc.h | 18 |
4 files changed, 70 insertions, 74 deletions
diff --git a/sys/dev/cx/if_cx.c b/sys/dev/cx/if_cx.c index 040d0c543a364..4341e5ae5653d 100644 --- a/sys/dev/cx/if_cx.c +++ b/sys/dev/cx/if_cx.c @@ -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. diff --git a/sys/kern/tty.c b/sys/kern/tty.c index da7b696360d66..d59599e69dd18 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -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); } diff --git a/sys/kern/tty_conf.c b/sys/kern/tty_conf.c index dc20ad9364cc4..7a52c5029117d 100644 --- a/sys/kern/tty_conf.c +++ b/sys/kern/tty_conf.c @@ -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; +ldisc_deregister(int discipline) { - if (discipline < MAXLDISC) { - linesw[discipline] = nodisc; - } + + if (discipline < MAXLDISC) + linesw[discipline] = &nodisc; } +/* + * "no" and "null" versions of line discipline functions + */ + static int -l_noopen(dev, tp) - dev_t dev; - struct tty *tp; +l_noopen(dev_t dev, struct tty *tp) { return (ENODEV); } static int -l_noclose(tp, flag) - struct tty *tp; - int flag; +l_noclose(struct tty *tp, int flag) { return (ENODEV); } int -l_noread(tp, uio, flag) - struct tty *tp; - struct uio *uio; - int flag; +l_noread(struct tty *tp, struct uio *uio, int flag) { return (ENODEV); } int -l_nowrite(tp, uio, flag) - struct tty *tp; - struct uio *uio; - int flag; +l_nowrite(struct tty *tp, struct uio *uio, int flag) { return (ENODEV); } static int -l_norint(c, tp) - int c; - struct tty *tp; +l_norint(int c, struct tty *tp) { return (ENODEV); } static int -l_nostart(tp) - struct tty *tp; +l_nostart(struct tty *tp) { return (ENODEV); } -/* - * Do nothing specific version of line - * discipline specific ioctl command. - */ int -l_nullioctl(tp, cmd, data, flags, td) - struct tty *tp; - u_long cmd; - char *data; - int flags; - struct thread *td; +l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags, struct thread *td) { return (ENOIOCTL); diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h index 4076ee5bd7b36..c24194d48cc6a 100644 --- a/sys/sys/linedisc.h +++ b/sys/sys/linedisc.h @@ -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 */ |