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/ttyqueue.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  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
    3  * All rights reserved.
    4  *
    5  * Portions of this software were developed under sponsorship from Snow
    6  * B.V., the Netherlands.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  * $FreeBSD: releng/8.0/sys/sys/ttyqueue.h 188096 2009-02-03 19:58:28Z ed $
   30  */
   31 
   32 #ifndef _SYS_TTYQUEUE_H_
   33 #define _SYS_TTYQUEUE_H_
   34 
   35 #ifndef _SYS_TTY_H_
   36 #error "can only be included through <sys/tty.h>"
   37 #endif /* !_SYS_TTY_H_ */
   38 
   39 struct tty;
   40 struct ttyinq_block;
   41 struct ttyoutq_block;
   42 struct uio;
   43 
   44 /* Data input queue. */
   45 struct ttyinq {
   46         struct ttyinq_block     *ti_firstblock;
   47         struct ttyinq_block     *ti_startblock;
   48         struct ttyinq_block     *ti_reprintblock;
   49         struct ttyinq_block     *ti_lastblock;
   50         unsigned int            ti_begin;
   51         unsigned int            ti_linestart;
   52         unsigned int            ti_reprint;
   53         unsigned int            ti_end;
   54         unsigned int            ti_nblocks;
   55         unsigned int            ti_quota;
   56 };
   57 #define TTYINQ_DATASIZE 128
   58 
   59 /* Data output queue. */
   60 struct ttyoutq {
   61         struct ttyoutq_block    *to_firstblock;
   62         struct ttyoutq_block    *to_lastblock;
   63         unsigned int            to_begin;
   64         unsigned int            to_end;
   65         unsigned int            to_nblocks;
   66         unsigned int            to_quota;
   67 };
   68 #define TTYOUTQ_DATASIZE (256 - sizeof(struct ttyoutq_block *))
   69 
   70 #ifdef _KERNEL
   71 /* Input queue handling routines. */
   72 void    ttyinq_setsize(struct ttyinq *ti, struct tty *tp, size_t len);
   73 void    ttyinq_free(struct ttyinq *ti);
   74 int     ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio,
   75     size_t readlen, size_t flushlen);
   76 size_t  ttyinq_write(struct ttyinq *ti, const void *buf, size_t len,
   77     int quote);
   78 int     ttyinq_write_nofrag(struct ttyinq *ti, const void *buf, size_t len,
   79     int quote);
   80 void    ttyinq_canonicalize(struct ttyinq *ti);
   81 size_t  ttyinq_findchar(struct ttyinq *ti, const char *breakc, size_t maxlen,
   82     char *lastc);
   83 void    ttyinq_flush(struct ttyinq *ti);
   84 int     ttyinq_peekchar(struct ttyinq *ti, char *c, int *quote);
   85 void    ttyinq_unputchar(struct ttyinq *ti);
   86 void    ttyinq_reprintpos_set(struct ttyinq *ti);
   87 void    ttyinq_reprintpos_reset(struct ttyinq *ti);
   88 
   89 static __inline size_t
   90 ttyinq_getsize(struct ttyinq *ti)
   91 {
   92         return (ti->ti_nblocks * TTYINQ_DATASIZE);
   93 }
   94 
   95 static __inline size_t
   96 ttyinq_bytesleft(struct ttyinq *ti)
   97 {
   98         size_t len;
   99 
  100         /* Make sure the usage never exceeds the length. */
  101         len = ti->ti_nblocks * TTYINQ_DATASIZE;
  102         MPASS(len >= ti->ti_end);
  103 
  104         return (len - ti->ti_end);
  105 }
  106 
  107 static __inline size_t
  108 ttyinq_bytescanonicalized(struct ttyinq *ti)
  109 {
  110         MPASS(ti->ti_begin <= ti->ti_linestart);
  111 
  112         return (ti->ti_linestart - ti->ti_begin);
  113 }
  114 
  115 static __inline size_t
  116 ttyinq_bytesline(struct ttyinq *ti)
  117 {
  118         MPASS(ti->ti_linestart <= ti->ti_end);
  119 
  120         return (ti->ti_end - ti->ti_linestart);
  121 }
  122 
  123 /* Input buffer iteration. */
  124 typedef void ttyinq_line_iterator_t(void *data, char c, int flags);
  125 void    ttyinq_line_iterate_from_linestart(struct ttyinq *ti,
  126     ttyinq_line_iterator_t *iterator, void *data);
  127 void    ttyinq_line_iterate_from_reprintpos(struct ttyinq *ti,
  128     ttyinq_line_iterator_t *iterator, void *data);
  129 
  130 /* Output queue handling routines. */
  131 void    ttyoutq_flush(struct ttyoutq *to);
  132 void    ttyoutq_setsize(struct ttyoutq *to, struct tty *tp, size_t len);
  133 void    ttyoutq_free(struct ttyoutq *to);
  134 size_t  ttyoutq_read(struct ttyoutq *to, void *buf, size_t len);
  135 int     ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio);
  136 size_t  ttyoutq_write(struct ttyoutq *to, const void *buf, size_t len);
  137 int     ttyoutq_write_nofrag(struct ttyoutq *to, const void *buf, size_t len);
  138 
  139 static __inline size_t
  140 ttyoutq_getsize(struct ttyoutq *to)
  141 {
  142         return (to->to_nblocks * TTYOUTQ_DATASIZE);
  143 }
  144 
  145 static __inline size_t
  146 ttyoutq_bytesleft(struct ttyoutq *to)
  147 {
  148         size_t len;
  149 
  150         /* Make sure the usage never exceeds the length. */
  151         len = to->to_nblocks * TTYOUTQ_DATASIZE;
  152         MPASS(len >= to->to_end);
  153 
  154         return (len - to->to_end);
  155 }
  156 
  157 static __inline size_t
  158 ttyoutq_bytesused(struct ttyoutq *to)
  159 {
  160         return (to->to_end - to->to_begin);
  161 }
  162 #endif /* _KERNEL */
  163 
  164 #endif /* !_SYS_TTYQUEUE_H_ */

Cache object: a5331aa04241da1eee0bbdcd9eadab62


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