Annotation of kernel/bsd/sys/tty.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
                     26: /*-
                     27:  * Copyright (c) 1982, 1986, 1993
                     28:  *     The Regents of the University of California.  All rights reserved.
                     29:  * (c) UNIX System Laboratories, Inc.
                     30:  * All or some portions of this file are derived from material licensed
                     31:  * to the University of California by American Telephone and Telegraph
                     32:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     33:  * the permission of UNIX System Laboratories, Inc.
                     34:  *
                     35:  * Redistribution and use in source and binary forms, with or without
                     36:  * modification, are permitted provided that the following conditions
                     37:  * are met:
                     38:  * 1. Redistributions of source code must retain the above copyright
                     39:  *    notice, this list of conditions and the following disclaimer.
                     40:  * 2. Redistributions in binary form must reproduce the above copyright
                     41:  *    notice, this list of conditions and the following disclaimer in the
                     42:  *    documentation and/or other materials provided with the distribution.
                     43:  * 3. All advertising materials mentioning features or use of this software
                     44:  *    must display the following acknowledgement:
                     45:  *     This product includes software developed by the University of
                     46:  *     California, Berkeley and its contributors.
                     47:  * 4. Neither the name of the University nor the names of its contributors
                     48:  *    may be used to endorse or promote products derived from this software
                     49:  *    without specific prior written permission.
                     50:  *
                     51:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     52:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     53:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     54:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     55:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     56:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     57:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     58:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     59:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     60:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     61:  * SUCH DAMAGE.
                     62:  *
                     63:  *     @(#)tty.h       8.7 (Berkeley) 1/9/95
                     64:  */
                     65: 
                     66: #ifndef _SYS_TTY_H_
                     67: #define        _SYS_TTY_H_
                     68: 
                     69: #include <sys/termios.h>
                     70: #include <sys/select.h>                /* For struct selinfo. */
                     71: 
                     72: #ifndef __APPLE__
                     73: /*
                     74:  * Clists are character lists, which is a variable length linked list
                     75:  * of cblocks, with a count of the number of characters in the list.
                     76:  */
                     77: struct clist {
                     78:        int     c_cc;           /* Number of characters in the clist. */
                     79:        int     c_cbcount;      /* Number of cblocks. */
                     80:        int     c_cbmax;        /* Max # cblocks allowed for this clist. */
                     81:        int     c_cbreserved;   /* # cblocks reserved for this clist. */
                     82:        char    *c_cf;          /* Pointer to the first cblock. */
                     83:        char    *c_cl;          /* Pointer to the last cblock. */
                     84: };
                     85: #else /* __APPLE__ */
                     86: /*
                     87:  * NetBSD Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
                     88:  * exactly the same behaviour as in true clists.
                     89:  * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
                     90:  * (but, saves memory and cpu time)
                     91:  * 
                     92:  * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
                     93:  */
                     94: struct clist {
                     95:        int     c_cc;           /* count of characters in queue */
                     96:        int     c_cn;           /* total ring buffer length */
                     97:        u_char  *c_cf;          /* points to first character */
                     98:        u_char  *c_cl;          /* points to next open character */
                     99:        u_char  *c_cs;          /* start of ring buffer */
                    100:        u_char  *c_ce;          /* c_ce + c_len */
                    101:        u_char  *c_cq;          /* N bits/bytes long, see tty_subr.c */
                    102: };
                    103: 
                    104: #ifndef TTYCLSIZE
                    105: #define TTYCLSIZE 1024
                    106: #endif
                    107: 
                    108: #endif /* __APPLE__ */
                    109: 
                    110: /*
                    111:  * Per-tty structure.
                    112:  *
                    113:  * Should be split in two, into device and tty drivers.
                    114:  * Glue could be masks of what to echo and circular buffer
                    115:  * (low, high, timeout).
                    116:  */
                    117: struct tty {
                    118:        struct  clist t_rawq;           /* Device raw input queue. */
                    119:        long    t_rawcc;                /* Raw input queue statistics. */
                    120:        struct  clist t_canq;           /* Device canonical queue. */
                    121:        long    t_cancc;                /* Canonical queue statistics. */
                    122:        struct  clist t_outq;           /* Device output queue. */
                    123:        long    t_outcc;                /* Output queue statistics. */
                    124:        int     t_line;                 /* Interface to device drivers. */
                    125:        dev_t   t_dev;                  /* Device. */
                    126:        int     t_state;                /* Device and driver (TS*) state. */
                    127:        int     t_flags;                /* Tty flags. */
                    128:        int     t_timeout;              /* Timeout for ttywait() */
                    129:        struct  pgrp *t_pgrp;           /* Foreground process group. */
                    130:        struct  session *t_session;     /* Enclosing session. */
                    131:        struct  selinfo t_rsel;         /* Tty read/oob select. */
                    132:        struct  selinfo t_wsel;         /* Tty write select. */
                    133:        struct  termios t_termios;      /* Termios state. */
                    134:        struct  winsize t_winsize;      /* Window size. */
                    135:                                        /* Start output. */
                    136:        void    (*t_oproc) __P((struct tty *));
                    137:                                        /* Stop output. */
                    138:        void    (*t_stop) __P((struct tty *, int));
                    139:                                        /* Set hardware state. */
                    140:        int     (*t_param) __P((struct tty *, struct termios *));
                    141:        void    *t_sc;                  /* XXX: net/if_sl.c:sl_softc. */
                    142:        int     t_column;               /* Tty output column. */
                    143:        int     t_rocount, t_rocol;     /* Tty. */
                    144:        int     t_hiwat;                /* High water mark. */
                    145:        int     t_lowat;                /* Low water mark. */
                    146:        int     t_gen;                  /* Generation number. */
                    147: };
                    148: 
                    149: #define        t_cc            t_termios.c_cc
                    150: #define        t_cflag         t_termios.c_cflag
                    151: #define        t_iflag         t_termios.c_iflag
                    152: #define        t_ispeed        t_termios.c_ispeed
                    153: #define        t_lflag         t_termios.c_lflag
                    154: #define        t_min           t_termios.c_min
                    155: #define        t_oflag         t_termios.c_oflag
                    156: #define        t_ospeed        t_termios.c_ospeed
                    157: #define        t_time          t_termios.c_time
                    158: 
                    159: #define        TTIPRI  25                      /* Sleep priority for tty reads. */
                    160: #define        TTOPRI  26                      /* Sleep priority for tty writes. */
                    161: 
                    162: /*
                    163:  * User data unfortunately has to be copied through buffers on the way to
                    164:  * and from clists.  The buffers are on the stack so their sizes must be
                    165:  * fairly small.
                    166:  */
                    167: #define        IBUFSIZ 384                     /* Should be >= max value of MIN. */
                    168: #define        OBUFSIZ 100
                    169: 
                    170: #ifndef TTYHOG
                    171: #define        TTYHOG  1024
                    172: #endif
                    173: 
                    174: #ifdef _KERNEL
                    175: #define        TTMAXHIWAT      roundup(2048, CBSIZE)
                    176: #define        TTMINHIWAT      roundup(100, CBSIZE)
                    177: #define        TTMAXLOWAT      256
                    178: #define        TTMINLOWAT      32
                    179: #endif /* _KERNEL */
                    180: 
                    181: /* These flags are kept in t_state. */
                    182: #define        TS_SO_OLOWAT    0x00001         /* Wake up when output <= low water. */
                    183: #define        TS_ASYNC        0x00002         /* Tty in async I/O mode. */
                    184: #define        TS_BUSY         0x00004         /* Draining output. */
                    185: #define        TS_CARR_ON      0x00008         /* Carrier is present. */
                    186: #define        TS_FLUSH        0x00010         /* Outq has been flushed during DMA. */
                    187: #define        TS_ISOPEN       0x00020         /* Open has completed. */
                    188: #define        TS_TBLOCK       0x00040         /* Further input blocked. */
                    189: #define        TS_TIMEOUT      0x00080         /* Wait for output char processing. */
                    190: #define        TS_TTSTOP       0x00100         /* Output paused. */
                    191: #ifdef notyet
                    192: #define        TS_WOPEN        0x00200         /* Open in progress. */
                    193: #endif
                    194: #define        TS_XCLUDE       0x00400         /* Tty requires exclusivity. */
                    195: 
                    196: /* State for intra-line fancy editing work. */
                    197: #define        TS_BKSL         0x00800         /* State for lowercase \ work. */
                    198: #define        TS_CNTTB        0x01000         /* Counting tab width, ignore FLUSHO. */
                    199: #define        TS_ERASE        0x02000         /* Within a \.../ for PRTRUB. */
                    200: #define        TS_LNCH         0x04000         /* Next character is literal. */
                    201: #define        TS_TYPEN        0x08000         /* Retyping suspended input (PENDIN). */
                    202: #define        TS_LOCAL        (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
                    203: 
                    204: /* Extras. */
                    205: #define        TS_CAN_BYPASS_L_RINT 0x010000   /* Device in "raw" mode. */
                    206: #define        TS_CONNECTED    0x020000        /* Connection open. */
                    207: #define        TS_SNOOP        0x040000        /* Device is being snooped on. */
                    208: #define        TS_SO_OCOMPLETE 0x080000        /* Wake up when output completes. */
                    209: #define        TS_ZOMBIE       0x100000        /* Connection lost. */
                    210: 
                    211: /* Hardware flow-control-invoked bits. */
                    212: #define        TS_CAR_OFLOW    0x200000        /* For MDMBUF (XXX handle in driver). */
                    213: #ifdef notyet
                    214: #define        TS_CTS_OFLOW    0x400000        /* For CCTS_OFLOW. */
                    215: #define        TS_DSR_OFLOW    0x800000        /* For CDSR_OFLOW. */
                    216: #endif
                    217: 
                    218: /* Character type information. */
                    219: #define        ORDINARY        0
                    220: #define        CONTROL         1
                    221: #define        BACKSPACE       2
                    222: #define        NEWLINE         3
                    223: #define        TAB             4
                    224: #define        VTAB            5
                    225: #define        RETURN          6
                    226: 
                    227: struct speedtab {
                    228:        int sp_speed;                   /* Speed. */
                    229:        int sp_code;                    /* Code. */
                    230: };
                    231: 
                    232: /* Modem control commands (driver). */
                    233: #define        DMSET           0
                    234: #define        DMBIS           1
                    235: #define        DMBIC           2
                    236: #define        DMGET           3
                    237: 
                    238: /* Flags on a character passed to ttyinput. */
                    239: #define        TTY_CHARMASK    0x000000ff      /* Character mask */
                    240: #define        TTY_QUOTE       0x00000100      /* Character quoted */
                    241: #define        TTY_ERRORMASK   0xff000000      /* Error mask */
                    242: #define        TTY_FE          0x01000000      /* Framing error */
                    243: #define        TTY_PE          0x02000000      /* Parity error */
                    244: #define        TTY_OE          0x04000000      /* Overrun error */
                    245: #define        TTY_BI          0x08000000      /* Break condition */
                    246: 
                    247: /* Is tp controlling terminal for p? */
                    248: #define        isctty(p, tp)                                                   \
                    249:        ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
                    250: 
                    251: /* Is p in background of tp? */
                    252: #define        isbackground(p, tp)                                             \
                    253:        (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
                    254: 
                    255: /* Unique sleep addresses. */
                    256: #define        TSA_CARR_ON(tp)         ((void *)&(tp)->t_rawq)
                    257: #define        TSA_HUP_OR_INPUT(tp)    ((void *)&(tp)->t_rawq.c_cf)
                    258: #define        TSA_OCOMPLETE(tp)       ((void *)&(tp)->t_outq.c_cl)
                    259: #define        TSA_OLOWAT(tp)          ((void *)&(tp)->t_outq)
                    260: #define        TSA_PTC_READ(tp)        ((void *)&(tp)->t_outq.c_cf)
                    261: #define        TSA_PTC_WRITE(tp)       ((void *)&(tp)->t_rawq.c_cl)
                    262: #define        TSA_PTS_READ(tp)        ((void *)&(tp)->t_canq)
                    263: 
                    264: #ifdef _KERNEL
                    265: #ifndef __APPLE__
                    266: extern struct tty *constty;    /* Temporary virtual console. */
                    267: 
                    268: int     b_to_q __P((char *cp, int cc, struct clist *q));
                    269: void    catq __P((struct clist *from, struct clist *to));
                    270: void    clist_alloc_cblocks __P((struct clist *q, int ccmax, int ccres));
                    271: void    clist_free_cblocks __P((struct clist *q));
                    272: /* void         clist_init __P((void)); */ /* defined in systm.h for main() */
                    273: int     getc __P((struct clist *q));
                    274: void    ndflush __P((struct clist *q, int cc));
                    275: int     ndqb __P((struct clist *q, int flag));
                    276: char   *nextc __P((struct clist *q, char *cp, int *c));
                    277: int     putc __P((int c, struct clist *q));
                    278: int     q_to_b __P((struct clist *q, char *cp, int cc));
                    279: int     unputc __P((struct clist *q));
                    280: 
                    281: int    ttcompat __P((struct tty *tp, int com, caddr_t data, int flag));
                    282: int     ttsetcompat __P((struct tty *tp, int *com, caddr_t data, struct termios *term));
                    283: #else /* __APPLE__ */
                    284: int     b_to_q __P((u_char *cp, int cc, struct clist *q));
                    285: void    catq __P((struct clist *from, struct clist *to));
                    286: void    clist_init __P((void));
                    287: int     getc __P((struct clist *q));
                    288: void    ndflush __P((struct clist *q, int cc));
                    289: int     ndqb __P((struct clist *q, int flag));
                    290: u_char *firstc           __P((struct clist *clp, int *c));
                    291: u_char *nextc __P((struct clist *q, u_char *cp, int *c));
                    292: int     putc __P((int c, struct clist *q));
                    293: int     q_to_b __P((struct clist *q, u_char *cp, int cc));
                    294: int     unputc __P((struct clist *q));
                    295: int     clalloc __P((struct clist *clp, int size, int quot));
                    296: void    clfree __P((struct clist *clp));
                    297: 
                    298: #ifdef KERNEL_PRIVATE
                    299: __private_extern__ int
                    300: ttcompat __P((struct tty *tp, u_long com, caddr_t data, int flag,
                    301:            struct proc *p));
                    302: __private_extern__ int
                    303: ttsetcompat __P((struct tty *tp, u_long *com, caddr_t data, struct termios *term));
                    304: #endif /* KERNEL_PRIVATE */
                    305: #endif /* __APPLE__ */
                    306: 
                    307: void    termioschars __P((struct termios *t));
                    308: int     tputchar __P((int c, struct tty *tp));
                    309: #ifndef __APPLE__
                    310: int     ttioctl __P((struct tty *tp, int com, void *data, int flag));
                    311: #else
                    312: int     ttioctl __P((struct tty *tp, u_long com, caddr_t data, int flag,
                    313:            struct proc *p));
                    314: #endif
                    315: int     ttread __P((struct tty *tp, struct uio *uio, int flag));
                    316: void    ttrstrt __P((void *tp));
                    317: int     ttyselect __P((struct tty *tp, int rw, struct proc *p));
                    318: int     ttselect __P((dev_t dev, int rw, struct proc *p));
                    319: void    ttsetwater __P((struct tty *tp));
                    320: int     ttspeedtab __P((int speed, struct speedtab *table));
                    321: int     ttstart __P((struct tty *tp));
                    322: void    ttwakeup __P((struct tty *tp));
                    323: int     ttwrite __P((struct tty *tp, struct uio *uio, int flag));
                    324: void    ttwwakeup __P((struct tty *tp));
                    325: void    ttyblock __P((struct tty *tp));
                    326: void    ttychars __P((struct tty *tp));
                    327: int     ttycheckoutq __P((struct tty *tp, int wait));
                    328: int     ttyclose __P((struct tty *tp));
                    329: void    ttyflush __P((struct tty *tp, int rw));
                    330: void    ttyinfo __P((struct tty *tp));
                    331: int     ttyinput __P((int c, struct tty *tp));
                    332: int     ttylclose __P((struct tty *tp, int flag));
                    333: int     ttymodem __P((struct tty *tp, int flag));
                    334: int     ttyopen __P((dev_t device, struct tty *tp));
                    335: int     ttysleep __P((struct tty *tp,
                    336:            void *chan, int pri, char *wmesg, int timeout));
                    337: int     ttywait __P((struct tty *tp));
                    338: struct tty *ttymalloc __P((void));
                    339: void     ttyfree __P((struct tty *));
                    340: 
                    341: #endif /* _KERNEL */
                    342: 
                    343: #endif /* !_SYS_TTY_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.