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-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
    5  * All rights reserved.
    6  *
    7  * Portions of this software were developed under sponsorship from Snow
    8  * B.V., the Netherlands.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  * $FreeBSD: releng/12.0/sys/sys/tty.h 326256 2017-11-27 15:01:59Z pfg $
   32  */
   33 
   34 #ifndef _SYS_TTY_H_
   35 #define _SYS_TTY_H_
   36 
   37 #include <sys/param.h>
   38 #include <sys/queue.h>
   39 #include <sys/lock.h>
   40 #include <sys/mutex.h>
   41 #include <sys/condvar.h>
   42 #include <sys/selinfo.h>
   43 #include <sys/_termios.h>
   44 #include <sys/ttycom.h>
   45 #include <sys/ttyqueue.h>
   46 
   47 struct cdev;
   48 struct file;
   49 struct pgrp;
   50 struct session;
   51 struct ucred;
   52 
   53 struct ttydevsw;
   54 
   55 /*
   56  * Per-TTY structure, containing buffers, etc.
   57  *
   58  * List of locks
   59  * (t)  locked by t_mtx
   60  * (l)  locked by tty_list_sx
   61  * (c)  const until freeing
   62  */
   63 struct tty {
   64         struct mtx      *t_mtx;         /* TTY lock. */
   65         struct mtx      t_mtxobj;       /* Per-TTY lock (when not borrowing). */
   66         TAILQ_ENTRY(tty) t_list;        /* (l) TTY list entry. */
   67         int             t_drainwait;    /* (t) TIOCDRAIN timeout seconds. */
   68         unsigned int    t_flags;        /* (t) Terminal option flags. */
   69 /* Keep flags in sync with db_show_tty and pstat(8). */
   70 #define TF_NOPREFIX     0x00001 /* Don't prepend "tty" to device name. */
   71 #define TF_INITLOCK     0x00002 /* Create init/lock state devices. */
   72 #define TF_CALLOUT      0x00004 /* Create "cua" devices. */
   73 #define TF_OPENED_IN    0x00008 /* "tty" node is in use. */
   74 #define TF_OPENED_OUT   0x00010 /* "cua" node is in use. */
   75 #define TF_OPENED_CONS  0x00020 /* Device in use as console. */
   76 #define TF_OPENED       (TF_OPENED_IN|TF_OPENED_OUT|TF_OPENED_CONS)
   77 #define TF_GONE         0x00040 /* Device node is gone. */
   78 #define TF_OPENCLOSE    0x00080 /* Device is in open()/close(). */
   79 #define TF_ASYNC        0x00100 /* Asynchronous I/O enabled. */
   80 #define TF_LITERAL      0x00200 /* Accept the next character literally. */
   81 #define TF_HIWAT_IN     0x00400 /* We've reached the input watermark. */
   82 #define TF_HIWAT_OUT    0x00800 /* We've reached the output watermark. */
   83 #define TF_HIWAT        (TF_HIWAT_IN|TF_HIWAT_OUT)
   84 #define TF_STOPPED      0x01000 /* Output flow control - stopped. */
   85 #define TF_EXCLUDE      0x02000 /* Exclusive access. */
   86 #define TF_BYPASS       0x04000 /* Optimized input path. */
   87 #define TF_ZOMBIE       0x08000 /* Modem disconnect received. */
   88 #define TF_HOOK         0x10000 /* TTY has hook attached. */
   89 #define TF_BUSY_IN      0x20000 /* Process busy in read() -- not supported. */
   90 #define TF_BUSY_OUT     0x40000 /* Process busy in write(). */
   91 #define TF_BUSY         (TF_BUSY_IN|TF_BUSY_OUT)
   92         unsigned int    t_revokecnt;    /* (t) revoke() count. */
   93 
   94         /* Buffering mechanisms. */
   95         struct ttyinq   t_inq;          /* (t) Input queue. */
   96         size_t          t_inlow;        /* (t) Input low watermark. */
   97         struct ttyoutq  t_outq;         /* (t) Output queue. */
   98         size_t          t_outlow;       /* (t) Output low watermark. */
   99 
  100         /* Sleeping mechanisms. */
  101         struct cv       t_inwait;       /* (t) Input wait queue. */
  102         struct cv       t_outwait;      /* (t) Output wait queue. */
  103         struct cv       t_outserwait;   /* (t) Serial output wait queue. */
  104         struct cv       t_bgwait;       /* (t) Background wait queue. */
  105         struct cv       t_dcdwait;      /* (t) Carrier Detect wait queue. */
  106 
  107         /* Polling mechanisms. */
  108         struct selinfo  t_inpoll;       /* (t) Input poll queue. */
  109         struct selinfo  t_outpoll;      /* (t) Output poll queue. */
  110         struct sigio    *t_sigio;       /* (t) Asynchronous I/O. */
  111 
  112         struct termios  t_termios;      /* (t) I/O processing flags. */
  113         struct winsize  t_winsize;      /* (t) Window size. */
  114         unsigned int    t_column;       /* (t) Current cursor position. */
  115         unsigned int    t_writepos;     /* (t) Where input was interrupted. */
  116         int             t_compatflags;  /* (t) COMPAT_43TTY flags. */
  117 
  118         /* Init/lock-state devices. */
  119         struct termios  t_termios_init_in;      /* tty%s.init. */
  120         struct termios  t_termios_lock_in;      /* tty%s.lock. */
  121         struct termios  t_termios_init_out;     /* cua%s.init. */
  122         struct termios  t_termios_lock_out;     /* cua%s.lock. */
  123 
  124         struct ttydevsw *t_devsw;       /* (c) Driver hooks. */
  125         struct ttyhook  *t_hook;        /* (t) Capture/inject hook. */
  126 
  127         /* Process signal delivery. */
  128         struct pgrp     *t_pgrp;        /* (t) Foreground process group. */
  129         struct session  *t_session;     /* (t) Associated session. */
  130         unsigned int    t_sessioncnt;   /* (t) Backpointing sessions. */
  131 
  132         void            *t_devswsoftc;  /* (c) Soft config, for drivers. */
  133         void            *t_hooksoftc;   /* (t) Soft config, for hooks. */
  134         struct cdev     *t_dev;         /* (c) Primary character device. */
  135 };
  136 
  137 /*
  138  * Userland version of struct tty, for sysctl kern.ttys
  139  */
  140 struct xtty {
  141         size_t  xt_size;        /* Structure size. */
  142         size_t  xt_insize;      /* Input queue size. */
  143         size_t  xt_incc;        /* Canonicalized characters. */
  144         size_t  xt_inlc;        /* Input line charaters. */
  145         size_t  xt_inlow;       /* Input low watermark. */
  146         size_t  xt_outsize;     /* Output queue size. */
  147         size_t  xt_outcc;       /* Output queue usage. */
  148         size_t  xt_outlow;      /* Output low watermark. */
  149         unsigned int xt_column; /* Current column position. */
  150         pid_t   xt_pgid;        /* Foreground process group. */
  151         pid_t   xt_sid;         /* Session. */
  152         unsigned int xt_flags;  /* Terminal option flags. */
  153         uint32_t xt_dev;        /* Userland device. XXXKIB truncated */
  154 };
  155 
  156 #ifdef _KERNEL
  157 
  158 /* Used to distinguish between normal, callout, lock and init devices. */
  159 #define TTYUNIT_INIT            0x1
  160 #define TTYUNIT_LOCK            0x2
  161 #define TTYUNIT_CALLOUT         0x4
  162 
  163 /* Allocation and deallocation. */
  164 struct tty *tty_alloc(struct ttydevsw *tsw, void *softc);
  165 struct tty *tty_alloc_mutex(struct ttydevsw *tsw, void *softc, struct mtx *mtx);
  166 void    tty_rel_pgrp(struct tty *tp, struct pgrp *pgrp);
  167 void    tty_rel_sess(struct tty *tp, struct session *sess);
  168 void    tty_rel_gone(struct tty *tp);
  169 
  170 #define tty_lock(tp)            mtx_lock((tp)->t_mtx)
  171 #define tty_unlock(tp)          mtx_unlock((tp)->t_mtx)
  172 #define tty_lock_owned(tp)      mtx_owned((tp)->t_mtx)
  173 #define tty_lock_assert(tp,ma)  mtx_assert((tp)->t_mtx, (ma))
  174 #define tty_getlock(tp)         ((tp)->t_mtx)
  175 
  176 /* Device node creation. */
  177 int     tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
  178     const char *fmt, ...) __printflike(4, 5);
  179 #define TTYMK_CLONING           0x1
  180 #define tty_makedev(tp, cred, fmt, ...) \
  181         (void )tty_makedevf((tp), (cred), 0, (fmt), ## __VA_ARGS__)
  182 #define tty_makealias(tp,fmt,...) \
  183         make_dev_alias((tp)->t_dev, fmt, ## __VA_ARGS__)
  184 
  185 /* Signalling processes. */
  186 void    tty_signal_sessleader(struct tty *tp, int signal);
  187 void    tty_signal_pgrp(struct tty *tp, int signal);
  188 /* Waking up readers/writers. */
  189 int     tty_wait(struct tty *tp, struct cv *cv);
  190 int     tty_wait_background(struct tty *tp, struct thread *td, int sig);
  191 int     tty_timedwait(struct tty *tp, struct cv *cv, int timo);
  192 void    tty_wakeup(struct tty *tp, int flags);
  193 
  194 /* System messages. */
  195 int     tty_checkoutq(struct tty *tp);
  196 int     tty_putchar(struct tty *tp, char c);
  197 
  198 int     tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
  199     struct thread *td);
  200 int     tty_ioctl_compat(struct tty *tp, u_long cmd, caddr_t data,
  201     int fflag, struct thread *td);
  202 void    tty_set_winsize(struct tty *tp, const struct winsize *wsz);
  203 void    tty_init_console(struct tty *tp, speed_t speed);
  204 void    tty_flush(struct tty *tp, int flags);
  205 void    tty_hiwat_in_block(struct tty *tp);
  206 void    tty_hiwat_in_unblock(struct tty *tp);
  207 dev_t   tty_udev(struct tty *tp);
  208 #define tty_opened(tp)          ((tp)->t_flags & TF_OPENED)
  209 #define tty_gone(tp)            ((tp)->t_flags & TF_GONE)
  210 #define tty_softc(tp)           ((tp)->t_devswsoftc)
  211 #define tty_devname(tp)         devtoname((tp)->t_dev)
  212 
  213 /* Status line printing. */
  214 void    tty_info(struct tty *tp);
  215 
  216 /* /dev/console selection. */
  217 void    ttyconsdev_select(const char *name);
  218 
  219 /* Pseudo-terminal hooks. */
  220 int     pts_alloc(int fflags, struct thread *td, struct file *fp);
  221 int     pts_alloc_external(int fd, struct thread *td, struct file *fp,
  222     struct cdev *dev, const char *name);
  223 
  224 /* Drivers and line disciplines also need to call these. */
  225 #include <sys/ttydisc.h>
  226 #include <sys/ttydevsw.h>
  227 #include <sys/ttyhook.h>
  228 #endif /* _KERNEL */
  229 
  230 #endif /* !_SYS_TTY_H_ */

Cache object: 73d10f1e02d2a4630a265f1f0e519871


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