[BACK]Return to tty.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/tty.h, Revision 1.29

1.29    ! christos    1: /*     $NetBSD: tty.h,v 1.28 1995/03/26 20:24:57 jtc Exp $     */
1.25      cgd         2:
                      3: /*-
                      4:  * Copyright (c) 1982, 1986, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  * (c) UNIX System Laboratories, Inc.
                      7:  * All or some portions of this file are derived from material licensed
                      8:  * to the University of California by American Telephone and Telegraph
                      9:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     10:  * the permission of UNIX System Laboratories, Inc.
                     11:  *
                     12:  * Redistribution and use in source and binary forms, with or without
                     13:  * modification, are permitted provided that the following conditions
                     14:  * are met:
                     15:  * 1. Redistributions of source code must retain the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer.
                     17:  * 2. Redistributions in binary form must reproduce the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer in the
                     19:  *    documentation and/or other materials provided with the distribution.
                     20:  * 3. All advertising materials mentioning features or use of this software
                     21:  *    must display the following acknowledgement:
                     22:  *     This product includes software developed by the University of
                     23:  *     California, Berkeley and its contributors.
                     24:  * 4. Neither the name of the University nor the names of its contributors
                     25:  *    may be used to endorse or promote products derived from this software
                     26:  *    without specific prior written permission.
                     27:  *
                     28:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     29:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     30:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     31:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     32:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     33:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     34:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     35:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     36:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     37:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     38:  * SUCH DAMAGE.
                     39:  *
                     40:  *     @(#)tty.h       8.6 (Berkeley) 1/21/94
                     41:  */
                     42:
                     43: #include <sys/termios.h>
                     44: #include <sys/select.h>                /* For struct selinfo. */
                     45:
                     46: #ifndef REAL_CLISTS
                     47: /*
                     48:  * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
                     49:  * exactly the same behaviour as in true clists.
                     50:  * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
                     51:  * (but, saves memory and cpu time)
                     52:  *
                     53:  * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
                     54:  */
                     55: struct clist {
                     56:        int     c_cc;           /* count of characters in queue */
                     57:        int     c_cn;           /* total ring buffer length */
                     58:        u_char  *c_cf;          /* points to first character */
                     59:        u_char  *c_cl;          /* points to next open character */
                     60:        u_char  *c_cs;          /* start of ring buffer */
                     61:        u_char  *c_ce;          /* c_ce + c_len */
                     62:        u_char  *c_cq;          /* N bits/bytes long, see tty_subr.c */
                     63: };
                     64: #else
                     65: /*
                     66:  * Clists are character lists, which is a variable length linked list
                     67:  * of cblocks, with a count of the number of characters in the list.
                     68:  */
                     69: struct clist {
                     70:        int     c_cc;           /* Number of characters in the clist. */
                     71:        u_char  *c_cf;          /* Pointer to the first cblock. */
                     72:        u_char  *c_cl;          /* Pointer to the last cblock. */
                     73: };
                     74: #endif
                     75:
                     76: /*
                     77:  * Per-tty structure.
                     78:  *
                     79:  * Should be split in two, into device and tty drivers.
                     80:  * Glue could be masks of what to echo and circular buffer
                     81:  * (low, high, timeout).
                     82:  */
                     83: struct tty {
                     84:        struct  clist t_rawq;           /* Device raw input queue. */
                     85:        long    t_rawcc;                /* Raw input queue statistics. */
                     86:        struct  clist t_canq;           /* Device canonical queue. */
                     87:        long    t_cancc;                /* Canonical queue statistics. */
                     88:        struct  clist t_outq;           /* Device output queue. */
                     89:        long    t_outcc;                /* Output queue statistics. */
1.26      cgd        90:        u_char  t_line;                 /* Interface to device drivers. */
1.25      cgd        91:        dev_t   t_dev;                  /* Device. */
                     92:        int     t_state;                /* Device and driver (TS*) state. */
                     93:        int     t_flags;                /* Tty flags. */
                     94:        struct  pgrp *t_pgrp;           /* Foreground process group. */
                     95:        struct  session *t_session;     /* Enclosing session. */
                     96:        struct  selinfo t_rsel;         /* Tty read/oob select. */
                     97:        struct  selinfo t_wsel;         /* Tty write select. */
                     98:        struct  termios t_termios;      /* Termios state. */
                     99:        struct  winsize t_winsize;      /* Window size. */
                    100:                                        /* Start output. */
                    101:        void    (*t_oproc) __P((struct tty *));
                    102:                                        /* Set hardware state. */
                    103:        int     (*t_param) __P((struct tty *, struct termios *));
                    104:                                        /* Set hardware flow control. */
                    105:        int     (*t_hwiflow) __P((struct tty *tp, int flag));
                    106:        void    *t_sc;                  /* XXX: net/if_sl.c:sl_softc. */
                    107:        short   t_column;               /* Tty output column. */
                    108:        short   t_rocount, t_rocol;     /* Tty. */
                    109:        short   t_hiwat;                /* High water mark. */
                    110:        short   t_lowat;                /* Low water mark. */
                    111:        short   t_gen;                  /* Generation number. */
                    112: };
                    113:
                    114: #define        t_cc            t_termios.c_cc
                    115: #define        t_cflag         t_termios.c_cflag
                    116: #define        t_iflag         t_termios.c_iflag
                    117: #define        t_ispeed        t_termios.c_ispeed
                    118: #define        t_lflag         t_termios.c_lflag
                    119: #define        t_min           t_termios.c_min
                    120: #define        t_oflag         t_termios.c_oflag
                    121: #define        t_ospeed        t_termios.c_ospeed
                    122: #define        t_time          t_termios.c_time
                    123:
                    124: #define        TTIPRI  25                      /* Sleep priority for tty reads. */
                    125: #define        TTOPRI  26                      /* Sleep priority for tty writes. */
                    126:
                    127: #define        TTMASK  15
                    128: #define        OBUFSIZ 100
                    129: #define        TTYHOG  1024
                    130:
1.28      jtc       131: #ifdef _KERNEL
1.25      cgd       132: #define        TTMAXHIWAT      roundup(2048, CBSIZE)
                    133: #define        TTMINHIWAT      roundup(100, CBSIZE)
                    134: #define        TTMAXLOWAT      256
                    135: #define        TTMINLOWAT      32
                    136: #endif
                    137:
                    138: /* These flags are kept in t_state. */
                    139: #define        TS_ASLEEP       0x00001         /* Process waiting for tty. */
                    140: #define        TS_ASYNC        0x00002         /* Tty in async I/O mode. */
                    141: #define        TS_BUSY         0x00004         /* Draining output. */
                    142: #define        TS_CARR_ON      0x00008         /* Carrier is present. */
                    143: #define        TS_FLUSH        0x00010         /* Outq has been flushed during DMA. */
                    144: #define        TS_ISOPEN       0x00020         /* Open has completed. */
                    145: #define        TS_TBLOCK       0x00040         /* Further input blocked. */
                    146: #define        TS_TIMEOUT      0x00080         /* Wait for output char processing. */
                    147: #define        TS_TTSTOP       0x00100         /* Output paused. */
                    148: #define        TS_WOPEN        0x00200         /* Open in progress. */
                    149: #define        TS_XCLUDE       0x00400         /* Tty requires exclusivity. */
                    150:
                    151: /* State for intra-line fancy editing work. */
                    152: #define        TS_BKSL         0x00800         /* State for lowercase \ work. */
                    153: #define        TS_CNTTB        0x01000         /* Counting tab width, ignore FLUSHO. */
                    154: #define        TS_ERASE        0x02000         /* Within a \.../ for PRTRUB. */
                    155: #define        TS_LNCH         0x04000         /* Next character is literal. */
                    156: #define        TS_TYPEN        0x08000         /* Retyping suspended input (PENDIN). */
                    157: #define        TS_LOCAL        (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
                    158:
                    159: /* Character type information. */
                    160: #define        ORDINARY        0
                    161: #define        CONTROL         1
                    162: #define        BACKSPACE       2
                    163: #define        NEWLINE         3
                    164: #define        TAB             4
                    165: #define        VTAB            5
                    166: #define        RETURN          6
                    167:
                    168: struct speedtab {
                    169:        int sp_speed;                   /* Speed. */
                    170:        int sp_code;                    /* Code. */
                    171: };
                    172:
                    173: /* Modem control commands (driver). */
                    174: #define        DMSET           0
                    175: #define        DMBIS           1
                    176: #define        DMBIC           2
                    177: #define        DMGET           3
                    178:
                    179: /* Flags on a character passed to ttyinput. */
                    180: #define        TTY_CHARMASK    0x000000ff      /* Character mask */
                    181: #define        TTY_QUOTE       0x00000100      /* Character quoted */
                    182: #define        TTY_ERRORMASK   0xff000000      /* Error mask */
                    183: #define        TTY_FE          0x01000000      /* Framing error or BREAK condition */
                    184: #define        TTY_PE          0x02000000      /* Parity error */
                    185:
                    186: /* Is tp controlling terminal for p? */
                    187: #define        isctty(p, tp)                                                   \
                    188:        ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
                    189:
                    190: /* Is p in background of tp? */
                    191: #define        isbackground(p, tp)                                             \
                    192:        (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
                    193:
1.28      jtc       194: #ifdef _KERNEL
1.25      cgd       195: extern struct ttychars ttydefaults;
                    196:
                    197: /* Symbolic sleep message strings. */
                    198: extern  char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
                    199:
                    200: int     b_to_q __P((u_char *cp, int cc, struct clist *q));
                    201: void    catq __P((struct clist *from, struct clist *to));
                    202: void    clist_init __P((void));
                    203: int     getc __P((struct clist *q));
                    204: void    ndflush __P((struct clist *q, int cc));
                    205: int     ndqb __P((struct clist *q, int flag));
                    206: u_char *nextc __P((struct clist *q, u_char *cp, int *c));
                    207: int     putc __P((int c, struct clist *q));
                    208: int     q_to_b __P((struct clist *q, u_char *cp, int cc));
                    209: int     unputc __P((struct clist *q));
                    210:
                    211: int     nullmodem __P((struct tty *tp, int flag));
                    212: int     tputchar __P((int c, struct tty *tp));
1.27      mycroft   213: int     ttioctl __P((struct tty *tp, u_long com, caddr_t data, int flag,
1.25      cgd       214:            struct proc *p));
                    215: int     ttread __P((struct tty *tp, struct uio *uio, int flag));
                    216: void    ttrstrt __P((void *tp));
                    217: int     ttselect __P((dev_t device, int rw, struct proc *p));
                    218: void    ttsetwater __P((struct tty *tp));
                    219: int     ttspeedtab __P((int speed, struct speedtab *table));
                    220: int     ttstart __P((struct tty *tp));
                    221: void    ttwakeup __P((struct tty *tp));
                    222: int     ttwrite __P((struct tty *tp, struct uio *uio, int flag));
                    223: void    ttychars __P((struct tty *tp));
                    224: int     ttycheckoutq __P((struct tty *tp, int wait));
                    225: int     ttyclose __P((struct tty *tp));
                    226: void    ttyflush __P((struct tty *tp, int rw));
                    227: void    ttyinfo __P((struct tty *tp));
                    228: int     ttyinput __P((int c, struct tty *tp));
                    229: int     ttylclose __P((struct tty *tp, int flag));
                    230: int     ttymodem __P((struct tty *tp, int flag));
                    231: int     ttyopen __P((dev_t device, struct tty *tp));
                    232: int     ttyoutput __P((int c, struct tty *tp));
                    233: void    ttypend __P((struct tty *tp));
                    234: void    ttyretype __P((struct tty *tp));
                    235: void    ttyrub __P((int c, struct tty *tp));
                    236: int     ttysleep __P((struct tty *tp,
                    237:            void *chan, int pri, char *wmesg, int timeout));
                    238: int     ttywait __P((struct tty *tp));
                    239: int     ttywflush __P((struct tty *tp));
                    240:
                    241: struct tty *ttymalloc __P((void));
                    242: void    ttyfree __P((struct tty *));
                    243: u_char *firstc           __P((struct clist *clp, int *c));
1.29    ! christos  244:
        !           245: int    cttyopen __P((dev_t, int, int, struct proc *));
        !           246: int    cttyread __P((dev_t, struct uio *, int));
        !           247: int    cttywrite __P((dev_t, struct uio *, int));
        !           248: int    cttyioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
        !           249: int    cttyselect __P((dev_t, int, struct proc *));
        !           250:
        !           251: int    clalloc __P((struct clist *, int, int));
        !           252: void   clfree __P((struct clist *));
        !           253:
        !           254: #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \
        !           255:     defined(COMPAT_FREEBSD)
        !           256: # define COMPAT_OLDTTY
        !           257: int    ttcompat __P((struct tty *, u_long, caddr_t, int, struct proc *));
        !           258: #endif
        !           259:
1.25      cgd       260: #endif

CVSweb <webmaster@jp.NetBSD.org>