diff options
author | dufault <dufault@FreeBSD.org> | 1995-03-21 11:24:05 +0000 |
---|---|---|
committer | dufault <dufault@FreeBSD.org> | 1995-03-21 11:24:05 +0000 |
commit | 0d7a7de4477ab79130ffa5843d2637f588db0415 (patch) | |
tree | 35c2fac1677fc3b5c6b768c17bba08d61ecf43be | |
parent | 0015f4c42bcc7da928de9f828fdbd46603010eca (diff) | |
download | FreeBSD-src-0d7a7de4477ab79130ffa5843d2637f588db0415.zip FreeBSD-src-0d7a7de4477ab79130ffa5843d2637f588db0415.tar.gz |
Set it so you can add and remove line disciplines without replicating
code for looking for open slots in table (and you could hide the table
if you wanted to).
-rw-r--r-- | sys/kern/tty_conf.c | 63 | ||||
-rw-r--r-- | sys/sys/conf.h | 6 | ||||
-rw-r--r-- | sys/sys/linedisc.h | 6 |
3 files changed, 72 insertions, 3 deletions
diff --git a/sys/kern/tty_conf.c b/sys/kern/tty_conf.c index 6b9bf4f..e565c61 100644 --- a/sys/kern/tty_conf.c +++ b/sys/kern/tty_conf.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)tty_conf.c 8.4 (Berkeley) 1/21/94 - * $Id: tty_conf.c,v 1.3 1994/08/02 07:42:50 davidg Exp $ + * $Id: tty_conf.c,v 1.4 1994/10/05 21:22:24 wollman Exp $ */ #include <sys/param.h> @@ -89,6 +89,67 @@ struct linesw linesw[MAXLDISC] = int nlinesw = sizeof (linesw) / sizeof (linesw[0]); +static struct linesw nodisc = +{ + ttynodisc, + ttyerrclose, + ttyerrio, + ttyerrio, + nullioctl, + ttyerrinput, + ttyerrstart, + nullmodem +}; + +#define LOADABLE_LDISC 6 +/* + * ldisc_register: Register a line discipline. + * + * discipline: Index for discipline to load, or LDISC_LOAD for us to choose. + * linesw_p: Pointer to linesw_p. + * + * Returns: Index used or -1 on failure. + */ +int +ldisc_register(discipline, linesw_p) + int discipline; + struct linesw *linesw_p; +{ + int slot = -1; + + if (discipline == LDISC_LOAD) { + int i; + for (i = LOADABLE_LDISC; i < MAXLDISC; i++) + if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) { + slot = i; + } + } + else if (discipline >= 0 && discipline < MAXLDISC) { + slot = discipline; + } + + if (slot != -1 && linesw_p) + linesw[slot] = *linesw_p; + + return slot; +} + +/* + * ldisc_deregister: Deregister a line discipline obtained with + * ldisc_register. Can only deregister "loadable" ones now. + * + * discipline: Index for discipline to unload. + */ +void +ldisc_deregister(discipline) + int discipline; +{ + if (discipline >= LOADABLE_LDISC && discipline < MAXLDISC) { + linesw[discipline] = nodisc; + } +} + + /* * Do nothing specific version of line * discipline specific ioctl command. diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 04242b1..664f034 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)conf.h 8.3 (Berkeley) 1/21/94 - * $Id: conf.h,v 1.9 1995/02/25 20:09:36 pst Exp $ + * $Id: conf.h,v 1.10 1995/03/16 18:16:13 bde Exp $ */ #ifndef _SYS_CONF_H_ @@ -121,6 +121,10 @@ struct linesw { #ifdef KERNEL extern struct linesw linesw[]; extern int nlinesw; + +int ldisc_register __P((int , struct linesw *)); +void ldisc_deregister __P((int)); +#define LDISC_LOAD -1 /* Loadable line discipline */ #endif struct swdevt { diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h index 04242b1..664f034 100644 --- a/sys/sys/linedisc.h +++ b/sys/sys/linedisc.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)conf.h 8.3 (Berkeley) 1/21/94 - * $Id: conf.h,v 1.9 1995/02/25 20:09:36 pst Exp $ + * $Id: conf.h,v 1.10 1995/03/16 18:16:13 bde Exp $ */ #ifndef _SYS_CONF_H_ @@ -121,6 +121,10 @@ struct linesw { #ifdef KERNEL extern struct linesw linesw[]; extern int nlinesw; + +int ldisc_register __P((int , struct linesw *)); +void ldisc_deregister __P((int)); +#define LDISC_LOAD -1 /* Loadable line discipline */ #endif struct swdevt { |