FreeBSD kernel kern code
tty_ttydisc.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/fcntl.h>
#include <sys/filio.h>
#include <sys/kernel.h>
#include <sys/signal.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/ttycom.h>
#include <sys/ttydefaults.h>
#include <sys/uio.h>
#include <sys/vnode.h>
Include dependency graph for tty_ttydisc.c:

Go to the source code of this file.

Data Structures

struct  ttydisc_recalc_length
 

Macros

#define CMP_CC(v, c)
 
#define CMP_FLAG(field, opt)   (tp->t_termios.c_ ## field ## flag & (opt))
 
#define CTAB   '\t'
 
#define CNL   '\n'
 
#define CCR   '\r'
 
#define CTL_VALID(c)   ((c) == 0x7f || (unsigned char)(c) < 0x20)
 
#define CTL_ECHO(c, q)
 
#define CTL_PRINT(c, q)
 
#define CTL_WHITE(c)   ((c) == ' ' || (c) == CTAB)
 
#define CTL_ALNUM(c)
 
#define TTY_STACKBUF   256
 
#define BREAK_ADD(c)
 
#define PRINT_NORMAL()   ttyoutq_write_nofrag(&tp->t_outq, &c, 1)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 SYSCTL_ULONG (_kern, OID_AUTO, tty_nin, CTLFLAG_RD, &tty_nin, 0, "Total amount of bytes received")
 
 SYSCTL_ULONG (_kern, OID_AUTO, tty_nout, CTLFLAG_RD, &tty_nout, 0, "Total amount of bytes transmitted")
 
void ttydisc_open (struct tty *tp)
 
void ttydisc_close (struct tty *tp)
 
static int ttydisc_read_canonical (struct tty *tp, struct uio *uio, int ioflag)
 
static int ttydisc_read_raw_no_timer (struct tty *tp, struct uio *uio, int ioflag)
 
static int ttydisc_read_raw_read_timer (struct tty *tp, struct uio *uio, int ioflag, int oresid)
 
static int ttydisc_read_raw_interbyte_timer (struct tty *tp, struct uio *uio, int ioflag)
 
int ttydisc_read (struct tty *tp, struct uio *uio, int ioflag)
 
static __inline unsigned int ttydisc_findchar (const char *obstart, unsigned int oblen)
 
static int ttydisc_write_oproc (struct tty *tp, char c)
 
int ttydisc_write (struct tty *tp, struct uio *uio, int ioflag)
 
void ttydisc_optimize (struct tty *tp)
 
void ttydisc_modem (struct tty *tp, int open)
 
static int ttydisc_echo_force (struct tty *tp, char c, int quote)
 
static int ttydisc_echo (struct tty *tp, char c, int quote)
 
static void ttydisc_reprint_char (void *d, char c, int quote)
 
static void ttydisc_reprint (struct tty *tp)
 
static void ttydisc_recalc_charlength (void *d, char c, int quote)
 
static unsigned int ttydisc_recalc_linelength (struct tty *tp)
 
static int ttydisc_rubchar (struct tty *tp)
 
static void ttydisc_rubword (struct tty *tp)
 
int ttydisc_rint (struct tty *tp, char c, int flags)
 
size_t ttydisc_rint_simple (struct tty *tp, const void *buf, size_t len)
 
size_t ttydisc_rint_bypass (struct tty *tp, const void *buf, size_t len)
 
void ttydisc_rint_done (struct tty *tp)
 
size_t ttydisc_rint_poll (struct tty *tp)
 
static void ttydisc_wakeup_watermark (struct tty *tp)
 
size_t ttydisc_getc (struct tty *tp, void *buf, size_t len)
 
int ttydisc_getc_uio (struct tty *tp, struct uio *uio)
 
size_t ttydisc_getc_poll (struct tty *tp)
 
int tty_putstrn (struct tty *tp, const char *p, size_t n)
 
int tty_putchar (struct tty *tp, char c)
 

Variables

static unsigned long tty_nin = 0
 
static unsigned long tty_nout = 0
 

Macro Definition Documentation

◆ BREAK_ADD

#define BREAK_ADD (   c)
Value:
do { \
if (tp->t_termios.c_cc[c] != _POSIX_VDISABLE) \
breakc[n++] = tp->t_termios.c_cc[c]; \
} while (0)

◆ CCR

#define CCR   '\r'

Definition at line 68 of file tty_ttydisc.c.

◆ CMP_CC

#define CMP_CC (   v,
 
)
Value:
(tp->t_termios.c_cc[v] != _POSIX_VDISABLE && \
tp->t_termios.c_cc[v] == (c))

Definition at line 61 of file tty_ttydisc.c.

◆ CMP_FLAG

#define CMP_FLAG (   field,
  opt 
)    (tp->t_termios.c_ ## field ## flag & (opt))

Definition at line 63 of file tty_ttydisc.c.

◆ CNL

#define CNL   '\n'

Definition at line 67 of file tty_ttydisc.c.

◆ CTAB

#define CTAB   '\t'

Definition at line 66 of file tty_ttydisc.c.

◆ CTL_ALNUM

#define CTL_ALNUM (   c)
Value:
(((c) >= '0' && (c) <= '9') || \
((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))

Definition at line 81 of file tty_ttydisc.c.

◆ CTL_ECHO

#define CTL_ECHO (   c,
 
)
Value:
(!(q) && ((c) == CERASE2 || (c) == CTAB || \
(c) == CNL || (c) == CCR))
#define CNL
Definition: tty_ttydisc.c:67
#define CTAB
Definition: tty_ttydisc.c:66
#define CCR
Definition: tty_ttydisc.c:68

Definition at line 73 of file tty_ttydisc.c.

◆ CTL_PRINT

#define CTL_PRINT (   c,
 
)
Value:
((c) == 0x7f || ((unsigned char)(c) < 0x20 && \
((q) || ((c) != CTAB && (c) != CNL))))

Definition at line 76 of file tty_ttydisc.c.

◆ CTL_VALID

#define CTL_VALID (   c)    ((c) == 0x7f || (unsigned char)(c) < 0x20)

Definition at line 71 of file tty_ttydisc.c.

◆ CTL_WHITE

#define CTL_WHITE (   c)    ((c) == ' ' || (c) == CTAB)

Definition at line 79 of file tty_ttydisc.c.

◆ PRINT_NORMAL

#define PRINT_NORMAL ( )    ttyoutq_write_nofrag(&tp->t_outq, &c, 1)

◆ TTY_STACKBUF

#define TTY_STACKBUF   256

Definition at line 84 of file tty_ttydisc.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ SYSCTL_ULONG() [1/2]

SYSCTL_ULONG ( _kern  ,
OID_AUTO  ,
tty_nin  ,
CTLFLAG_RD  ,
tty_nin,
,
"Total amount of bytes received"   
)

◆ SYSCTL_ULONG() [2/2]

SYSCTL_ULONG ( _kern  ,
OID_AUTO  ,
tty_nout  ,
CTLFLAG_RD  ,
tty_nout,
,
"Total amount of bytes transmitted"   
)

◆ tty_putchar()

int tty_putchar ( struct tty *  tp,
char  c 
)

Definition at line 1304 of file tty_ttydisc.c.

References ttydisc_recalc_length::tp, and tty_putstrn().

Referenced by constty_timeout(), and putchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_putstrn()

int tty_putstrn ( struct tty *  tp,
const char *  p,
size_t  n 
)

Definition at line 1284 of file tty_ttydisc.c.

References ttydisc_recalc_length::tp, ttydisc_echo_force(), and ttyinq_reprintpos_set().

Referenced by sbuf_tty_drain(), and tty_putchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_close()

void ttydisc_close ( struct tty *  tp)

Definition at line 93 of file tty_ttydisc.c.

References tty_flush().

Referenced by ttydev_leave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_echo()

static int ttydisc_echo ( struct tty *  tp,
char  c,
int  quote 
)
static

Definition at line 681 of file tty_ttydisc.c.

References CMP_FLAG, CNL, and ttydisc_echo_force().

Referenced by ttydisc_reprint(), ttydisc_reprint_char(), ttydisc_rint(), and ttydisc_rubchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_echo_force()

static int ttydisc_echo_force ( struct tty *  tp,
char  c,
int  quote 
)
static

Definition at line 642 of file tty_ttydisc.c.

References CMP_CC, CMP_FLAG, CTL_ECHO, CTL_PRINT, ttydisc_write_oproc(), and ttyoutq_write_nofrag().

Referenced by tty_putstrn(), and ttydisc_echo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_findchar()

static __inline unsigned int ttydisc_findchar ( const char *  obstart,
unsigned int  oblen 
)
static

Definition at line 355 of file tty_ttydisc.c.

References CTL_VALID.

Referenced by ttydisc_write().

Here is the caller graph for this function:

◆ ttydisc_getc()

size_t ttydisc_getc ( struct tty *  tp,
void *  buf,
size_t  len 
)

Definition at line 1195 of file tty_ttydisc.c.

References buf, ttydisc_recalc_length::tp, tty_nout, ttydisc_wakeup_watermark(), and ttyoutq_read().

Referenced by termtty_outwakeup(), and ttydisc_getc_uio().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_getc_poll()

size_t ttydisc_getc_poll ( struct tty *  tp)

Definition at line 1263 of file tty_ttydisc.c.

References ttydisc_recalc_length::tp.

Referenced by pts_kqops_read_event(), ptsdev_ioctl(), ptsdev_poll(), and ptsdev_read().

Here is the caller graph for this function:

◆ ttydisc_getc_uio()

int ttydisc_getc_uio ( struct tty *  tp,
struct uio *  uio 
)

Definition at line 1218 of file tty_ttydisc.c.

References buf, ttydisc_recalc_length::tp, tty_nout, TTY_STACKBUF, ttydisc_getc(), ttydisc_wakeup_watermark(), ttyoutq_read_uio(), and uiomove().

Referenced by ptsdev_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_modem()

void ttydisc_modem ( struct tty *  tp,
int  open 
)

Definition at line 607 of file tty_ttydisc.c.

References CMP_FLAG, tty_flush(), and tty_signal_sessleader().

Referenced by tty_rel_gone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_open()

void ttydisc_open ( struct tty *  tp)

Definition at line 87 of file tty_ttydisc.c.

References ttydisc_optimize().

Referenced by ttydev_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_optimize()

void ttydisc_optimize ( struct tty *  tp)

Definition at line 587 of file tty_ttydisc.c.

References CMP_FLAG.

Referenced by tty_generic_ioctl(), ttydisc_open(), ttyhook_register(), and ttyhook_unregister().

Here is the caller graph for this function:

◆ ttydisc_read()

int ttydisc_read ( struct tty *  tp,
struct uio *  uio,
int  ioflag 
)

Definition at line 326 of file tty_ttydisc.c.

References CMP_FLAG, tty_hiwat_in_unblock(), ttydisc_read_canonical(), ttydisc_read_raw_interbyte_timer(), ttydisc_read_raw_no_timer(), and ttydisc_read_raw_read_timer().

Referenced by ttydev_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_read_canonical()

static int ttydisc_read_canonical ( struct tty *  tp,
struct uio *  uio,
int  ioflag 
)
static

Definition at line 111 of file tty_ttydisc.c.

References BREAK_ADD, CMP_CC, CNL, tty_wait(), tty_wait_background(), ttyinq_findchar(), and ttyinq_read_uio().

Referenced by ttydisc_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_read_raw_interbyte_timer()

static int ttydisc_read_raw_interbyte_timer ( struct tty *  tp,
struct uio *  uio,
int  ioflag 
)
static

Definition at line 277 of file tty_ttydisc.c.

References tty_wait(), tty_wait_background(), ttydisc_read_raw_read_timer(), and ttyinq_read_uio().

Referenced by ttydisc_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_read_raw_no_timer()

static int ttydisc_read_raw_no_timer ( struct tty *  tp,
struct uio *  uio,
int  ioflag 
)
static

Definition at line 184 of file tty_ttydisc.c.

References tty_wait(), tty_wait_background(), and ttyinq_read_uio().

Referenced by ttydisc_read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_read_raw_read_timer()

static int ttydisc_read_raw_read_timer ( struct tty *  tp,
struct uio *  uio,
int  ioflag,
int  oresid 
)
static

Definition at line 223 of file tty_ttydisc.c.

References getmicrotime(), hz, timevaladd(), timevalsub(), tty_timedwait(), tty_wait_background(), ttyinq_read_uio(), and tvtohz().

Referenced by ttydisc_read(), and ttydisc_read_raw_interbyte_timer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_recalc_charlength()

static void ttydisc_recalc_charlength ( void *  d,
char  c,
int  quote 
)
static

Definition at line 724 of file tty_ttydisc.c.

References CMP_FLAG, CTAB, CTL_PRINT, and data.

Referenced by ttydisc_recalc_linelength().

Here is the caller graph for this function:

◆ ttydisc_recalc_linelength()

static unsigned int ttydisc_recalc_linelength ( struct tty *  tp)
static

Definition at line 740 of file tty_ttydisc.c.

References data, ttydisc_recalc_length::tp, ttydisc_recalc_charlength(), and ttyinq_line_iterate_from_reprintpos().

Referenced by ttydisc_rubchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_reprint()

static void ttydisc_reprint ( struct tty *  tp)
static

Definition at line 704 of file tty_ttydisc.c.

References CNL, ttydisc_echo(), ttydisc_reprint_char(), ttyinq_line_iterate_from_linestart(), and ttyinq_reprintpos_reset().

Referenced by ttydisc_rint(), and ttydisc_rubchar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_reprint_char()

static void ttydisc_reprint_char ( void *  d,
char  c,
int  quote 
)
static

Definition at line 696 of file tty_ttydisc.c.

References ttydisc_echo().

Referenced by ttydisc_reprint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_rint()

int ttydisc_rint ( struct tty *  tp,
char  c,
int  flags 
)

◆ ttydisc_rint_bypass()

size_t ttydisc_rint_bypass ( struct tty *  tp,
const void *  buf,
size_t  len 
)

Definition at line 1114 of file tty_ttydisc.c.

References buf, ttydisc_recalc_length::tp, tty_hiwat_in_block(), tty_nin, ttyinq_canonicalize(), and ttyinq_write().

Referenced by ttydisc_rint_simple().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_rint_done()

void ttydisc_rint_done ( struct tty *  tp)

Definition at line 1136 of file tty_ttydisc.c.

References ttydisc_recalc_length::tp, and tty_wakeup().

Referenced by ptsdev_write(), terminal_input_char(), terminal_input_raw(), terminal_input_special(), termteken_respond(), and tty_generic_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_rint_poll()

size_t ttydisc_rint_poll ( struct tty *  tp)

Definition at line 1151 of file tty_ttydisc.c.

References ttydisc_recalc_length::tp.

Referenced by pts_kqops_write_event(), and ptsdev_poll().

Here is the caller graph for this function:

◆ ttydisc_rint_simple()

size_t ttydisc_rint_simple ( struct tty *  tp,
const void *  buf,
size_t  len 
)

Definition at line 1098 of file tty_ttydisc.c.

References buf, ttydisc_recalc_length::tp, ttydisc_rint(), and ttydisc_rint_bypass().

Referenced by ptsdev_write(), terminal_input_char(), terminal_input_special(), and termteken_respond().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_rubchar()

static int ttydisc_rubchar ( struct tty *  tp)
static

Definition at line 750 of file tty_ttydisc.c.

References CMP_FLAG, CTAB, CTL_PRINT, ttydisc_recalc_length::tp, ttydisc_echo(), ttydisc_recalc_linelength(), ttydisc_reprint(), ttyinq_peekchar(), ttyinq_unputchar(), and ttyoutq_write_nofrag().

Referenced by ttydisc_rint(), and ttydisc_rubword().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_rubword()

static void ttydisc_rubword ( struct tty *  tp)
static

Definition at line 823 of file tty_ttydisc.c.

References CMP_FLAG, CTL_ALNUM, CTL_WHITE, ttydisc_recalc_length::tp, ttydisc_rubchar(), and ttyinq_peekchar().

Referenced by ttydisc_rint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_wakeup_watermark()

static void ttydisc_wakeup_watermark ( struct tty *  tp)
static

Definition at line 1174 of file tty_ttydisc.c.

References ttydisc_recalc_length::tp, and tty_wakeup().

Referenced by ttydisc_getc(), and ttydisc_getc_uio().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_write()

int ttydisc_write ( struct tty *  tp,
struct uio *  uio,
int  ioflag 
)

Definition at line 455 of file tty_ttydisc.c.

References CMP_FLAG, TTY_STACKBUF, tty_wait(), ttydisc_findchar(), ttydisc_write_oproc(), ttyinq_reprintpos_set(), ttyoutq_write(), and uiomove().

Referenced by ttydev_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ttydisc_write_oproc()

static int ttydisc_write_oproc ( struct tty *  tp,
char  c 
)
static

Definition at line 369 of file tty_ttydisc.c.

References CCR, CMP_FLAG, CNL, CTAB, CTL_VALID, PRINT_NORMAL, ttyinq_reprintpos_set(), and ttyoutq_write_nofrag().

Referenced by ttydisc_echo_force(), and ttydisc_write().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ tty_nin

unsigned long tty_nin = 0
static

Definition at line 53 of file tty_ttydisc.c.

Referenced by ttydisc_rint(), and ttydisc_rint_bypass().

◆ tty_nout

unsigned long tty_nout = 0
static

Definition at line 56 of file tty_ttydisc.c.

Referenced by ttydisc_getc(), and ttydisc_getc_uio().