#ifndef _SYS_TTY_H_
#define _SYS_TTY_H_
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/selinfo.h>
#include <sys/_termios.h>
#include <sys/ttycom.h>
#include <sys/ttyqueue.h>
struct cdev;
struct file;
struct pgrp;
struct session;
struct ucred;
struct ttydevsw;
struct tty {
struct mtx *t_mtx;
struct mtx t_mtxobj;
TAILQ_ENTRY(tty) t_list;
int t_drainwait;
unsigned int t_flags;
#define TF_NOPREFIX 0x00001
#define TF_INITLOCK 0x00002
#define TF_CALLOUT 0x00004
#define TF_OPENED_IN 0x00008
#define TF_OPENED_OUT 0x00010
#define TF_OPENED_CONS 0x00020
#define TF_OPENED (TF_OPENED_IN|TF_OPENED_OUT|TF_OPENED_CONS)
#define TF_GONE 0x00040
#define TF_OPENCLOSE 0x00080
#define TF_ASYNC 0x00100
#define TF_LITERAL 0x00200
#define TF_HIWAT_IN 0x00400
#define TF_HIWAT_OUT 0x00800
#define TF_HIWAT (TF_HIWAT_IN|TF_HIWAT_OUT)
#define TF_STOPPED 0x01000
#define TF_EXCLUDE 0x02000
#define TF_BYPASS 0x04000
#define TF_ZOMBIE 0x08000
#define TF_HOOK 0x10000
#define TF_BUSY_IN 0x20000
#define TF_BUSY_OUT 0x40000
#define TF_BUSY (TF_BUSY_IN|TF_BUSY_OUT)
unsigned int t_revokecnt;
struct ttyinq t_inq;
size_t t_inlow;
struct ttyoutq t_outq;
size_t t_outlow;
struct cv t_inwait;
struct cv t_outwait;
struct cv t_outserwait;
struct cv t_bgwait;
struct cv t_dcdwait;
struct selinfo t_inpoll;
struct selinfo t_outpoll;
struct sigio *t_sigio;
struct termios t_termios;
struct winsize t_winsize;
unsigned int t_column;
unsigned int t_writepos;
int t_compatflags;
struct termios t_termios_init_in;
struct termios t_termios_lock_in;
struct termios t_termios_init_out;
struct termios t_termios_lock_out;
struct ttydevsw *t_devsw;
struct ttyhook *t_hook;
struct pgrp *t_pgrp;
struct session *t_session;
unsigned int t_sessioncnt;
void *t_devswsoftc;
void *t_hooksoftc;
struct cdev *t_dev;
size_t t_prbufsz;
char t_prbuf[];
};
struct xtty {
size_t xt_size;
size_t xt_insize;
size_t xt_incc;
size_t xt_inlc;
size_t xt_inlow;
size_t xt_outsize;
size_t xt_outcc;
size_t xt_outlow;
unsigned int xt_column;
pid_t xt_pgid;
pid_t xt_sid;
unsigned int xt_flags;
uint32_t xt_dev;
};
#ifdef _KERNEL
#define TTYUNIT_INIT 0x1
#define TTYUNIT_LOCK 0x2
#define TTYUNIT_CALLOUT 0x4
struct tty *tty_alloc(struct ttydevsw *tsw, void *softc);
struct tty *tty_alloc_mutex(struct ttydevsw *tsw, void *softc, struct mtx *mtx);
void tty_rel_pgrp(struct tty *tp, struct pgrp *pgrp);
void tty_rel_sess(struct tty *tp, struct session *sess);
void tty_rel_gone(struct tty *tp);
#define tty_lock(tp) mtx_lock((tp)->t_mtx)
#define tty_unlock(tp) mtx_unlock((tp)->t_mtx)
#define tty_lock_owned(tp) mtx_owned((tp)->t_mtx)
#define tty_assert_locked(tp) mtx_assert((tp)->t_mtx, MA_OWNED)
#define tty_getlock(tp) ((tp)->t_mtx)
#define tty_lock_assert(tp, ma) mtx_assert((tp)->t_mtx, (ma))
int tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
const char *fmt, ...) __printflike(4, 5);
#define TTYMK_CLONING 0x1
#define tty_makedev(tp, cred, fmt, ...) \
(void )tty_makedevf((tp), (cred), 0, (fmt), ## __VA_ARGS__)
#define tty_makealias(tp,fmt,...) \
make_dev_alias((tp)->t_dev, fmt, ## __VA_ARGS__)
void tty_signal_sessleader(struct tty *tp, int signal);
void tty_signal_pgrp(struct tty *tp, int signal);
int tty_wait(struct tty *tp, struct cv *cv);
int tty_wait_background(struct tty *tp, struct thread *td, int sig);
int tty_timedwait(struct tty *tp, struct cv *cv, int timo);
void tty_wakeup(struct tty *tp, int flags);
int tty_checkoutq(struct tty *tp);
int tty_putchar(struct tty *tp, char c);
int tty_putstrn(struct tty *tp, const char *p, size_t n);
int tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
struct thread *td);
int tty_ioctl_compat(struct tty *tp, u_long cmd, caddr_t data,
int fflag, struct thread *td);
void tty_set_winsize(struct tty *tp, const struct winsize *wsz);
void tty_init_console(struct tty *tp, speed_t speed);
void tty_flush(struct tty *tp, int flags);
void tty_hiwat_in_block(struct tty *tp);
void tty_hiwat_in_unblock(struct tty *tp);
dev_t tty_udev(struct tty *tp);
#define tty_opened(tp) ((tp)->t_flags & TF_OPENED)
#define tty_gone(tp) ((tp)->t_flags & TF_GONE)
#define tty_softc(tp) ((tp)->t_devswsoftc)
#define tty_devname(tp) devtoname((tp)->t_dev)
void tty_info(struct tty *tp);
void ttyconsdev_select(const char *name);
int pts_alloc(int fflags, struct thread *td, struct file *fp);
int pts_alloc_external(int fd, struct thread *td, struct file *fp,
struct cdev *dev, const char *name);
#include <sys/ttydisc.h>
#include <sys/ttydevsw.h>
#include <sys/ttyhook.h>
#endif
#endif