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.87 2011/04/24 16:26:52 rmind Exp $   */
    2 
    3 /*-
    4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   26  * POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 /*-
   30  * Copyright (c) 1982, 1986, 1993
   31  *      The Regents of the University of California.  All rights reserved.
   32  * (c) UNIX System Laboratories, Inc.
   33  * All or some portions of this file are derived from material licensed
   34  * to the University of California by American Telephone and Telegraph
   35  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
   36  * the permission of UNIX System Laboratories, Inc.
   37  *
   38  * Redistribution and use in source and binary forms, with or without
   39  * modification, are permitted provided that the following conditions
   40  * are met:
   41  * 1. Redistributions of source code must retain the above copyright
   42  *    notice, this list of conditions and the following disclaimer.
   43  * 2. Redistributions in binary form must reproduce the above copyright
   44  *    notice, this list of conditions and the following disclaimer in the
   45  *    documentation and/or other materials provided with the distribution.
   46  * 3. Neither the name of the University nor the names of its contributors
   47  *    may be used to endorse or promote products derived from this software
   48  *    without specific prior written permission.
   49  *
   50  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   60  * SUCH DAMAGE.
   61  *
   62  *      @(#)tty.h       8.7 (Berkeley) 1/9/95
   63  */
   64 
   65 #ifndef _SYS_TTY_H_
   66 #define _SYS_TTY_H_
   67 
   68 #include <sys/termios.h>
   69 #include <sys/select.h>
   70 #include <sys/selinfo.h>        /* For struct selinfo. */
   71 #include <sys/mutex.h>
   72 #include <sys/condvar.h>
   73 #include <sys/queue.h>
   74 #include <sys/callout.h>
   75 
   76 /*
   77  * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
   78  * exactly the same behaviour as in true clists.
   79  * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
   80  * (but, saves memory and CPU time)
   81  *
   82  * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
   83  */
   84 struct clist {
   85         u_char  *c_cf;          /* points to first character */
   86         u_char  *c_cl;          /* points to next open character */
   87         u_char  *c_cs;          /* start of ring buffer */
   88         u_char  *c_ce;          /* c_ce + c_len */
   89         u_char  *c_cq;          /* N bits/bytes long, see tty_subr.c */
   90         int     c_cc;           /* count of characters in queue */
   91         int     c_cn;           /* total ring buffer length */
   92 };
   93 
   94 /* tty signal types */
   95 enum ttysigtype {
   96         TTYSIG_PG1,
   97         TTYSIG_PG2,
   98         TTYSIG_LEADER,
   99         TTYSIG_COUNT
  100 };
  101 
  102 /*
  103  * Per-tty structure.
  104  *
  105  * Should be split in two, into device and tty drivers.
  106  * Glue could be masks of what to echo and circular buffer
  107  * (low, high, timeout).
  108  */
  109 struct tty {
  110         TAILQ_ENTRY(tty) tty_link;      /* Link in global tty list. */
  111         struct  clist t_rawq;           /* Device raw input queue. */
  112         long    t_rawcc;                /* Raw input queue statistics. */
  113         kcondvar_t t_rawcv;             /* notifier */
  114         kcondvar_t t_rawcvf;            /* notifier */
  115         struct  clist t_canq;           /* Device canonical queue. */
  116         long    t_cancc;                /* Canonical queue statistics. */
  117         kcondvar_t t_cancv;             /* notifier */
  118         kcondvar_t t_cancvf;            /* notifier */
  119         struct  clist t_outq;           /* Device output queue. */
  120         long    t_outcc;                /* Output queue statistics. */
  121         kcondvar_t t_outcv;             /* notifier */
  122         kcondvar_t t_outcvf;            /* notifier */
  123         callout_t t_rstrt_ch;           /* for delayed output start */
  124         struct  linesw *t_linesw;       /* Interface to device drivers. */
  125         dev_t   t_dev;                  /* Device. */
  126         int     t_state;                /* Device and driver (TS*) state. */
  127         int     t_wopen;                /* Processes waiting for open. */
  128         int     t_flags;                /* Tty flags. */
  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)(struct tty *);
  137                                         /* Set hardware state. */
  138         int     (*t_param)(struct tty *, struct termios *);
  139                                         /* Set hardware flow control. */
  140         int     (*t_hwiflow)(struct tty *, int);
  141         void    *t_sc;                  /* XXX: net/if_sl.c:sl_softc. */
  142         short   t_column;               /* Tty output column. */
  143         short   t_rocount, t_rocol;     /* Tty. */
  144         short   t_hiwat;                /* High water mark. */
  145         short   t_lowat;                /* Low water mark. */
  146         short   t_gen;                  /* Generation number. */
  147         sigset_t t_sigs[TTYSIG_COUNT];  /* Pending signals */
  148         int     t_sigcount;             /* # pending signals */
  149         TAILQ_ENTRY(tty) t_sigqueue;    /* entry on pending signal list */
  150 };
  151 
  152 #define t_cc            t_termios.c_cc
  153 #define t_cflag         t_termios.c_cflag
  154 #define t_iflag         t_termios.c_iflag
  155 #define t_ispeed        t_termios.c_ispeed
  156 #define t_lflag         t_termios.c_lflag
  157 #define t_oflag         t_termios.c_oflag
  158 #define t_ospeed        t_termios.c_ospeed
  159 
  160 #define TTIPRI  25                      /* Sleep priority for tty reads. */
  161 #define TTOPRI  26                      /* Sleep priority for tty writes. */
  162 
  163 #define TTMASK  15
  164 #define OBUFSIZ 100
  165 #define TTYHOG  1024
  166 
  167 #ifdef _KERNEL
  168 #define TTMAXHIWAT      roundup(2048, CBSIZE)
  169 #define TTMINHIWAT      roundup(100, CBSIZE)
  170 #define TTMAXLOWAT      256
  171 #define TTMINLOWAT      32
  172 #endif /* _KERNEL */
  173 
  174 /* These flags are kept in t_state. */
  175 #define TS_SIGINFO      0x00001         /* Ignore mask on dispatch SIGINFO */
  176 #define TS_ASYNC        0x00002         /* Tty in async I/O mode. */
  177 #define TS_BUSY         0x00004         /* Draining output. */
  178 #define TS_CARR_ON      0x00008         /* Carrier is present. */
  179 #define TS_DIALOUT      0x00010         /* Tty used for dialout. */
  180 #define TS_FLUSH        0x00020         /* Outq has been flushed during DMA. */
  181 #define TS_ISOPEN       0x00040         /* Open has completed. */
  182 #define TS_TBLOCK       0x00080         /* Further input blocked. */
  183 #define TS_TIMEOUT      0x00100         /* Wait for output char processing. */
  184 #define TS_TTSTOP       0x00200         /* Output paused. */
  185 #define TS_XCLUDE       0x00400         /* Tty requires exclusivity. */
  186 
  187 /* State for intra-line fancy editing work. */
  188 #define TS_BKSL         0x00800         /* State for lowercase \ work. */
  189 #define TS_CNTTB        0x01000         /* Counting tab width, ignore FLUSHO. */
  190 #define TS_ERASE        0x02000         /* Within a \.../ for PRTRUB. */
  191 #define TS_LNCH         0x04000         /* Next character is literal. */
  192 #define TS_TYPEN        0x08000         /* Retyping suspended input (PENDIN). */
  193 #define TS_LOCAL        (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
  194 
  195 /* Character type information. */
  196 #define ORDINARY        0
  197 #define CONTROL         1
  198 #define BACKSPACE       2
  199 #define NEWLINE         3
  200 #define TAB             4
  201 #define VTAB            5
  202 #define RETURN          6
  203 
  204 struct speedtab {
  205         int sp_speed;                   /* Speed. */
  206         int sp_code;                    /* Code. */
  207 };
  208 
  209 /* Modem control commands (driver). */
  210 #define DMSET           0
  211 #define DMBIS           1
  212 #define DMBIC           2
  213 #define DMGET           3
  214 
  215 /* Flags on a character passed to ttyinput. */
  216 #define TTY_CHARMASK    0x000000ff      /* Character mask */
  217 #define TTY_QUOTE       0x00000100      /* Character quoted */
  218 #define TTY_ERRORMASK   0xff000000      /* Error mask */
  219 #define TTY_FE          0x01000000      /* Framing error or BREAK condition */
  220 #define TTY_PE          0x02000000      /* Parity error */
  221 
  222 /* Is tp controlling terminal for p? */
  223 #define isctty(p, tp)                                                   \
  224         ((p)->p_session == (tp)->t_session && (p)->p_lflag & PL_CONTROLT)
  225 
  226 /* Is p in background of tp? */
  227 #define isbackground(p, tp)                                             \
  228         (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
  229 
  230 /*
  231  * ttylist_head is defined here so that user-land has access to it.
  232  */
  233 TAILQ_HEAD(ttylist_head, tty);          /* the ttylist is a TAILQ */
  234 
  235 #ifdef _KERNEL
  236 
  237 extern kmutex_t tty_lock;
  238 
  239 extern  int tty_count;                  /* number of ttys in global ttylist */
  240 extern  struct ttychars ttydefaults;
  241 
  242 /* Symbolic sleep message strings. */
  243 extern   const char ttclos[];
  244 
  245 int      b_to_q(const u_char *, int, struct clist *);
  246 void     catq(struct clist *, struct clist *);
  247 void     clist_init(void);
  248 int      getc(struct clist *);
  249 void     ndflush(struct clist *, int);
  250 int      ndqb(struct clist *, int);
  251 u_char  *nextc(struct clist *, u_char *, int *);
  252 int      putc(int, struct clist *);
  253 int      q_to_b(struct clist *, u_char *, int);
  254 int      unputc(struct clist *);
  255 
  256 int      nullmodem(struct tty *, int);
  257 int      tputchar(int, int, struct tty *);
  258 int      ttioctl(struct tty *, u_long, void *, int, struct lwp *);
  259 int      ttread(struct tty *, struct uio *, int);
  260 void     ttrstrt(void *);
  261 int      ttpoll(struct tty *, int, struct lwp *);
  262 void     ttsetwater(struct tty *);
  263 int      ttspeedtab(int, const struct speedtab *);
  264 int      ttstart(struct tty *);
  265 void     ttwakeup(struct tty *);
  266 int      ttwrite(struct tty *, struct uio *, int);
  267 void     ttychars(struct tty *);
  268 int      ttycheckoutq(struct tty *, int);
  269 int      ttyclose(struct tty *);
  270 void     ttyflush(struct tty *, int);
  271 void     ttygetinfo(struct tty *, int, char *, size_t);
  272 void     ttyputinfo(struct tty *, char *);
  273 int      ttyinput(int, struct tty *);
  274 int      ttyinput_wlock(int, struct tty *); /* XXX see wsdisplay.c */
  275 int      ttylclose(struct tty *, int);
  276 int      ttylopen(dev_t, struct tty *);
  277 int      ttykqfilter(dev_t, struct knote *);
  278 int      ttymodem(struct tty *, int);
  279 int      ttyopen(struct tty *, int, int);
  280 int      ttyoutput(int, struct tty *);
  281 void     ttypend(struct tty *);
  282 void     ttyretype(struct tty *);
  283 void     ttyrub(int, struct tty *);
  284 int      ttysleep(struct tty *, kcondvar_t *, bool, int);
  285 int      ttywait(struct tty *);
  286 int      ttywflush(struct tty *);
  287 void     ttysig(struct tty *, enum ttysigtype, int);
  288 void     tty_attach(struct tty *);
  289 void     tty_detach(struct tty *);
  290 void     tty_init(void);
  291 struct tty
  292         *tty_alloc(void);
  293 void     tty_free(struct tty *);
  294 u_char  *firstc(struct clist *, int *);
  295 bool     ttypull(struct tty *);
  296 
  297 int     clalloc(struct clist *, int, int);
  298 void    clfree(struct clist *);
  299 
  300 extern int (*ttcompatvec)(struct tty *, u_long, void *, int, struct lwp *);
  301 
  302 #endif /* _KERNEL */
  303 
  304 #endif /* !_SYS_TTY_H_ */

Cache object: 47086b3ee1f2ebc1d3d228ed3b2bf5d8


[ 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.