The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/tty.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: tty.h,v 1.71 2006/06/03 18:18:26 christos Exp $        */
    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. Neither the name of the University nor the names of its contributors
   21  *    may be used to endorse or promote products derived from this software
   22  *    without specific prior written permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   34  * SUCH DAMAGE.
   35  *
   36  *      @(#)tty.h       8.7 (Berkeley) 1/9/95
   37  */
   38 
   39 #ifndef _SYS_TTY_H_
   40 #define _SYS_TTY_H_
   41 
   42 #include <sys/termios.h>
   43 #include <sys/select.h>
   44 #include <sys/selinfo.h>        /* For struct selinfo. */
   45 #include <sys/lock.h>
   46 #include <sys/queue.h>
   47 #include <sys/callout.h>
   48 
   49 /*
   50  * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
   51  * exactly the same behaviour as in true clists.
   52  * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
   53  * (but, saves memory and CPU time)
   54  *
   55  * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
   56  */
   57 struct clist {
   58         int     c_cc;           /* count of characters in queue */
   59         int     c_cn;           /* total ring buffer length */
   60         u_char  *c_cf;          /* points to first character */
   61         u_char  *c_cl;          /* points to next open character */
   62         u_char  *c_cs;          /* start of ring buffer */
   63         u_char  *c_ce;          /* c_ce + c_len */
   64         u_char  *c_cq;          /* N bits/bytes long, see tty_subr.c */
   65 };
   66 
   67 /*
   68  * Per-tty structure.
   69  *
   70  * Should be split in two, into device and tty drivers.
   71  * Glue could be masks of what to echo and circular buffer
   72  * (low, high, timeout).
   73  */
   74 struct tty {
   75         TAILQ_ENTRY(tty) tty_link;      /* Link in global tty list. */
   76         struct  simplelock t_slock;     /* mutex for all access to this tty */
   77         struct  clist t_rawq;           /* Device raw input queue. */
   78         long    t_rawcc;                /* Raw input queue statistics. */
   79         struct  clist t_canq;           /* Device canonical queue. */
   80         long    t_cancc;                /* Canonical queue statistics. */
   81         struct  clist t_outq;           /* Device output queue. */
   82         struct  callout t_rstrt_ch;     /* for delayed output start */
   83         long    t_outcc;                /* Output queue statistics. */
   84         struct  linesw *t_linesw;       /* Interface to device drivers. */
   85         dev_t   t_dev;                  /* Device. */
   86         int     t_state;                /* Device and driver (TS*) state. */
   87         int     t_wopen;                /* Processes waiting for open. */
   88         int     t_flags;                /* Tty flags. */
   89         struct  pgrp *t_pgrp;           /* Foreground process group. */
   90         struct  session *t_session;     /* Enclosing session. */
   91         struct  selinfo t_rsel;         /* Tty read/oob select. */
   92         struct  selinfo t_wsel;         /* Tty write select. */
   93         struct  termios t_termios;      /* Termios state. */
   94         struct  winsize t_winsize;      /* Window size. */
   95                                         /* Start output. */
   96         void    (*t_oproc)(struct tty *);
   97                                         /* Set hardware state. */
   98         int     (*t_param)(struct tty *, struct termios *);
   99                                         /* Set hardware flow control. */
  100         int     (*t_hwiflow)(struct tty *, int);
  101         void    *t_sc;                  /* XXX: net/if_sl.c:sl_softc. */
  102         short   t_column;               /* Tty output column. */
  103         short   t_rocount, t_rocol;     /* Tty. */
  104         short   t_hiwat;                /* High water mark. */
  105         short   t_lowat;                /* Low water mark. */
  106         short   t_gen;                  /* Generation number. */
  107 };
  108 
  109 #define __TTY_ENABLE_SLOCK
  110 #ifdef __TTY_ENABLE_SLOCK
  111 #define TTY_LOCK(tp) simple_lock(&(tp)->t_slock)
  112 #define TTY_UNLOCK(tp) simple_unlock(&(tp)->t_slock)
  113 #else /* __TTY_ENABLE_SLOCK */
  114 #define TTY_LOCK(tp)    /**/
  115 #define TTY_UNLOCK(tp)  /**/
  116 #endif /* __TTY_ENABLE_SLOCK */
  117 
  118 #define t_cc            t_termios.c_cc
  119 #define t_cflag         t_termios.c_cflag
  120 #define t_iflag         t_termios.c_iflag
  121 #define t_ispeed        t_termios.c_ispeed
  122 #define t_lflag         t_termios.c_lflag
  123 #define t_oflag         t_termios.c_oflag
  124 #define t_ospeed        t_termios.c_ospeed
  125 
  126 #define TTIPRI  25                      /* Sleep priority for tty reads. */
  127 #define TTOPRI  26                      /* Sleep priority for tty writes. */
  128 
  129 #define TTMASK  15
  130 #define OBUFSIZ 100
  131 #define TTYHOG  1024
  132 
  133 #ifdef _KERNEL
  134 #define TTMAXHIWAT      roundup(2048, CBSIZE)
  135 #define TTMINHIWAT      roundup(100, CBSIZE)
  136 #define TTMAXLOWAT      256
  137 #define TTMINLOWAT      32
  138 #endif /* _KERNEL */
  139 
  140 /* These flags are kept in t_state. */
  141 #define TS_ASLEEP       0x00001         /* Process waiting for tty. */
  142 #define TS_ASYNC        0x00002         /* Tty in async I/O mode. */
  143 #define TS_BUSY         0x00004         /* Draining output. */
  144 #define TS_CARR_ON      0x00008         /* Carrier is present. */
  145 #define TS_DIALOUT      0x00010         /* Tty used for dialout. */
  146 #define TS_FLUSH        0x00020         /* Outq has been flushed during DMA. */
  147 #define TS_ISOPEN       0x00040         /* Open has completed. */
  148 #define TS_TBLOCK       0x00080         /* Further input blocked. */
  149 #define TS_TIMEOUT      0x00100         /* Wait for output char processing. */
  150 #define TS_TTSTOP       0x00200         /* Output paused. */
  151 #define TS_XCLUDE       0x00400         /* Tty requires exclusivity. */
  152 
  153 /* State for intra-line fancy editing work. */
  154 #define TS_BKSL         0x00800         /* State for lowercase \ work. */
  155 #define TS_CNTTB        0x01000         /* Counting tab width, ignore FLUSHO. */
  156 #define TS_ERASE        0x02000         /* Within a \.../ for PRTRUB. */
  157 #define TS_LNCH         0x04000         /* Next character is literal. */
  158 #define TS_TYPEN        0x08000         /* Retyping suspended input (PENDIN). */
  159 #define TS_LOCAL        (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
  160 
  161 /* Character type information. */
  162 #define ORDINARY        0
  163 #define CONTROL         1
  164 #define BACKSPACE       2
  165 #define NEWLINE         3
  166 #define TAB             4
  167 #define VTAB            5
  168 #define RETURN          6
  169 
  170 struct speedtab {
  171         int sp_speed;                   /* Speed. */
  172         int sp_code;                    /* Code. */
  173 };
  174 
  175 /* Modem control commands (driver). */
  176 #define DMSET           0
  177 #define DMBIS           1
  178 #define DMBIC           2
  179 #define DMGET           3
  180 
  181 /* Flags on a character passed to ttyinput. */
  182 #define TTY_CHARMASK    0x000000ff      /* Character mask */
  183 #define TTY_QUOTE       0x00000100      /* Character quoted */
  184 #define TTY_ERRORMASK   0xff000000      /* Error mask */
  185 #define TTY_FE          0x01000000      /* Framing error or BREAK condition */
  186 #define TTY_PE          0x02000000      /* Parity error */
  187 
  188 /* Is tp controlling terminal for p? */
  189 #define isctty(p, tp)                                                   \
  190         ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
  191 
  192 /* Is p in background of tp? */
  193 #define isbackground(p, tp)                                             \
  194         (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
  195 
  196 /*
  197  * ttylist_head is defined here so that user-land has access to it.
  198  */
  199 TAILQ_HEAD(ttylist_head, tty);          /* the ttylist is a TAILQ */
  200 
  201 #ifdef _KERNEL
  202 #include <sys/mallocvar.h>
  203 
  204 MALLOC_DECLARE(M_TTYS);
  205 
  206 extern  int tty_count;                  /* number of ttys in global ttylist */
  207 extern  struct ttychars ttydefaults;
  208 
  209 /* Symbolic sleep message strings. */
  210 extern   const char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
  211 
  212 int      b_to_q(const u_char *, int, struct clist *);
  213 void     catq(struct clist *, struct clist *);
  214 void     clist_init(void);
  215 int      getc(struct clist *);
  216 void     ndflush(struct clist *, int);
  217 int      ndqb(struct clist *, int);
  218 u_char  *nextc(struct clist *, u_char *, int *);
  219 int      putc(int, struct clist *);
  220 int      q_to_b(struct clist *, u_char *, int);
  221 int      unputc(struct clist *);
  222 
  223 int      nullmodem(struct tty *, int);
  224 int      tputchar(int, int, struct tty *);
  225 int      ttioctl(struct tty *, u_long, caddr_t, int, struct lwp *);
  226 int      ttread(struct tty *, struct uio *, int);
  227 void     ttrstrt(void *);
  228 int      ttpoll(struct tty *, int, struct lwp *);
  229 void     ttsetwater(struct tty *);
  230 int      ttspeedtab(int, const struct speedtab *);
  231 int      ttstart(struct tty *);
  232 void     ttwakeup(struct tty *);
  233 int      ttwrite(struct tty *, struct uio *, int);
  234 void     ttychars(struct tty *);
  235 int      ttycheckoutq(struct tty *, int);
  236 int      ttyclose(struct tty *);
  237 void     ttyflush(struct tty *, int);
  238 void     ttyinfo(struct tty *, int);
  239 int      ttyinput(int, struct tty *);
  240 int      ttylclose(struct tty *, int);
  241 int      ttylopen(dev_t, struct tty *);
  242 int      ttykqfilter(dev_t, struct knote *);
  243 int      ttymodem(struct tty *, int);
  244 int      ttyopen(struct tty *, int, int);
  245 int      ttyoutput(int, struct tty *);
  246 void     ttypend(struct tty *);
  247 void     ttyretype(struct tty *);
  248 void     ttyrub(int, struct tty *);
  249 int      ttysleep(struct tty *, void *, int, const char *, int);
  250 int      ttywait(struct tty *);
  251 int      ttywflush(struct tty *);
  252 
  253 void     tty_attach(struct tty *);
  254 void     tty_detach(struct tty *);
  255 struct tty
  256         *ttymalloc(void);
  257 void     ttyfree(struct tty *);
  258 u_char  *firstc(struct clist *, int *);
  259 
  260 int     clalloc(struct clist *, int, int);
  261 void    clfree(struct clist *);
  262 
  263 #if defined(_KERNEL_OPT)
  264 #include "opt_compat_freebsd.h"
  265 #include "opt_compat_sunos.h"
  266 #include "opt_compat_svr4.h"
  267 #include "opt_compat_43.h"
  268 #include "opt_compat_osf1.h"
  269 #endif
  270 
  271 #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \
  272     defined(COMPAT_FREEBSD) || defined(COMPAT_OSF1) || defined(LKM)
  273 # define COMPAT_OLDTTY
  274 int     ttcompat(struct tty *, u_long, caddr_t, int, struct lwp *);
  275 #endif
  276 
  277 #endif /* _KERNEL */
  278 
  279 #endif /* !_SYS_TTY_H_ */

Cache object: e1f0aef4b780d885a483fb7f81bd592e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.