Correct misbehaviour of patching sys/sys/tty.h.

For some reason, sys/sys/tty.h was only half patched. This went by
unnoticed, because the copyright notice on the top already displayed my
name, so I thought the file went in properly.

Reported by:	kmacy
This commit is contained in:
Ed Schouten 2008-08-20 08:44:52 +00:00
parent 18cf135421
commit 00ba6aade4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=181907

View File

@ -26,391 +26,172 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)tty.h 8.6 (Berkeley) 1/21/94
* $FreeBSD$ * $FreeBSD$
*/ */
#ifndef _SYS_TTY_H_ #ifndef _SYS_TTY_H_
#define _SYS_TTY_H_ #define _SYS_TTY_H_
#include <sys/clist.h> #include <sys/param.h>
#include <sys/termios.h>
#include <sys/queue.h> #include <sys/queue.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/selinfo.h> #include <sys/selinfo.h>
#include <sys/_lock.h> #include <sys/termios.h>
#include <sys/_mutex.h> #include <sys/ttycom.h>
#include <sys/ttyqueue.h>
struct tty;
struct pps_state;
struct cdev; struct cdev;
struct cdevsw; struct file;
struct thread; struct pgrp;
struct session;
typedef int t_open_t(struct tty *, struct cdev *); struct ucred;
typedef void t_close_t(struct tty *);
typedef void t_oproc_t(struct tty *);
typedef void t_purge_t(struct tty *);
typedef void t_stop_t(struct tty *, int);
typedef int t_param_t(struct tty *, struct termios *);
typedef int t_modem_t(struct tty *, int, int);
typedef void t_break_t(struct tty *, int);
typedef int t_ioctl_t(struct tty *, u_long cmd, void * data,
int fflag, struct thread *td);
/* XXX: same as d_ioctl_t in sys/conf.h to avoid #include polution */
typedef int __d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td);
struct ttydevsw;
/* /*
* Per-tty structure. * Per-TTY structure, containing buffers, etc.
* *
* Should be split in two, into device and tty drivers. * List of locks
* Glue could be masks of what to echo and circular buffer * (t) locked by t_mtx
* (low, high, timeout). * (l) locked by tty_list_sx
* (c) const until freeing
*/ */
struct tty { struct tty {
struct clist t_rawq; /* Device raw input queue. */ struct mtx *t_mtx; /* TTY lock. */
long t_rawcc; /* Raw input queue statistics. */ struct mtx t_mtxobj; /* Per-TTY lock (when not borrowing). */
struct clist t_canq; /* Device canonical queue. */ TAILQ_ENTRY(tty) t_list; /* (l) TTY list entry. */
long t_cancc; /* Canonical queue statistics. */ unsigned int t_flags; /* (t) Terminal option flags. */
struct clist t_outq; /* Device output queue. */ #define TF_NOPREFIX 0x0001 /* Don't prepend "tty" to device name. */
long t_outcc; /* Output queue statistics. */ #define TF_INITLOCK 0x0002 /* Create init/lock state devices. */
int t_line; /* Interface to device drivers. */ #define TF_CALLOUT 0x0004 /* Create "cua" devices. */
struct cdev *t_dev; /* Device. */ #define TF_OPENED_IN 0x0008 /* "tty" node is in use. */
struct cdev *t_mdev; /* Device. */ #define TF_OPENED_OUT 0x0010 /* "cua" node is in use. */
u_int t_devunit; /* Cdev unit number */ #define TF_OPENED (TF_OPENED_IN|TF_OPENED_OUT)
int t_state; /* Device and driver (TS*) state. */ #define TF_GONE 0x0020 /* Device node is gone. */
int t_flags; /* Tty flags. */ #define TF_OPENCLOSE 0x0040 /* Device is in open()/close(). */
int t_timeout; /* Timeout for ttywait() */ #define TF_ASYNC 0x0080 /* Asynchronous I/O enabled. */
struct pgrp *t_pgrp; /* Foreground process group. */ #define TF_LITERAL 0x0100 /* Accept the next character literally. */
struct session *t_session; /* Enclosing session. */ #define TF_HIWAT_IN 0x0200 /* We've reached the input watermark. */
struct sigio *t_sigio; /* Information for async I/O. */ #define TF_HIWAT_OUT 0x0400 /* We've reached the output watermark. */
struct selinfo t_rsel; /* Tty read/oob select. */ #define TF_HIWAT (TF_HIWAT_IN|TF_HIWAT_OUT)
struct selinfo t_wsel; /* Tty write select. */ #define TF_STOPPED 0x0800 /* Output flow control - stopped. */
struct termios t_termios; /* Termios state. */ #define TF_EXCLUDE 0x1000 /* Exclusive access. */
struct termios t_init_in; /* ... init ingoing */ #define TF_BYPASS 0x2000 /* Optimized input path. */
struct termios t_init_out; /* ... outgoing */ #define TF_ZOMBIE 0x4000 /* Modem disconnect received. */
struct termios t_lock_in; /* ... lock ingoing */ unsigned int t_revokecnt; /* (t) revoke() count. */
struct termios t_lock_out; /* ... outgoing */
struct winsize t_winsize; /* Window size. */
void *t_sc; /* driver private softc pointer. */
void *t_lsc; /* linedisc private softc pointer. */
int t_column; /* Tty output column. */
int t_rocount, t_rocol; /* Tty. */
int t_ififosize; /* Total size of upstream fifos. */
int t_ihiwat; /* High water mark for input. */
int t_ilowat; /* Low water mark for input. */
speed_t t_ispeedwat; /* t_ispeed override for watermarks. */
int t_ohiwat; /* High water mark for output. */
int t_olowat; /* Low water mark for output. */
speed_t t_ospeedwat; /* t_ospeed override for watermarks. */
int t_gen; /* Generation number. */
TAILQ_ENTRY(tty) t_list; /* Global chain of ttys for pstat(8) */
int t_actout; /* Outbound device open */
int t_wopeners; /* #threads waiting for DCD in open */
struct mtx t_mtx; /* Buffering mechanisms. */
int t_refcnt; struct ttyinq t_inq; /* (t) Input queue. */
int t_hotchar; /* linedisc preferred hot char */ size_t t_inlow; /* (t) Input low watermark. */
int t_dtr_wait; /* Inter-session DTR holddown [hz] */ struct ttyoutq t_outq; /* (t) Output queue. */
int t_do_timestamp; /* flag instead ? */ size_t t_outlow; /* (t) Output low watermark. */
struct timeval t_timestamp; /* char timestamp */
struct pps_state *t_pps; /* PPS-API stuff */
/* Driver supplied methods */ /* Sleeping mechanisms. */
t_oproc_t *t_oproc; /* Start output. */ struct cv t_inwait; /* (t) Input wait queue. */
t_stop_t *t_stop; /* Stop output. */ struct cv t_outwait; /* (t) Output wait queue. */
t_param_t *t_param; /* Set parameters. */ struct cv t_bgwait; /* (t) Background wait queue. */
t_modem_t *t_modem; /* Set modem state (optional). */ struct cv t_dcdwait; /* (t) Carrier Detect wait queue. */
t_break_t *t_break; /* Set break state (optional). */
t_ioctl_t *t_ioctl; /* Set ioctl handling (optional). */ /* Polling mechanisms. */
t_open_t *t_open; /* First open */ struct selinfo t_inpoll; /* (t) Input poll queue. */
t_purge_t *t_purge; /* Purge threads */ struct selinfo t_outpoll; /* (t) Output poll queue. */
t_close_t *t_close; /* Last close */ struct sigio *t_sigio; /* (t) Asynchronous I/O. */
__d_ioctl_t *t_cioctl; /* Ioctl on control devices */
struct termios t_termios; /* (t) I/O processing flags. */
struct winsize t_winsize; /* (t) Window size. */
unsigned int t_column; /* (t) Current cursor position. */
unsigned int t_writepos; /* (t) Where input was interrupted. */
/* Init/lock-state devices. */
struct termios t_termios_init_in; /* tty%s.init. */
struct termios t_termios_lock_in; /* tty%s.lock. */
struct termios t_termios_init_out; /* cua%s.init. */
struct termios t_termios_lock_out; /* cua%s.lock. */
struct ttydevsw *t_devsw; /* (c) Driver hooks. */
/* Process signal delivery. */
struct pgrp *t_pgrp; /* (t) Foreground process group. */
struct session *t_session; /* (t) Associated session. */
unsigned int t_sessioncnt; /* (t) Backpointing sessions. */
void *t_softc; /* (c) Soft config, for drivers. */
struct cdev *t_dev; /* (c) Primary character device. */
}; };
#define t_cc t_termios.c_cc
#define t_cflag t_termios.c_cflag
#define t_iflag t_termios.c_iflag
#define t_ispeed t_termios.c_ispeed
#define t_lflag t_termios.c_lflag
#define t_min t_termios.c_min
#define t_oflag t_termios.c_oflag
#define t_ospeed t_termios.c_ospeed
#define t_time t_termios.c_time
#define TTIPRI (PSOCK + 1) /* Sleep priority for tty reads. */
#define TTOPRI (PSOCK + 2) /* Sleep priority for tty writes. */
/* /*
* Userland version of struct tty, for sysctl. * Userland version of struct tty, for sysctl kern.ttys
*/ */
struct xtty { struct xtty {
size_t xt_size; /* Structure size. */ size_t xt_size; /* Structure size. */
long xt_rawcc; /* Raw input queue statistics. */ size_t xt_insize; /* Input queue size. */
long xt_cancc; /* Canonical queue statistics. */ size_t xt_incc; /* Canonicalized characters. */
long xt_outcc; /* Output queue statistics. */ size_t xt_inlc; /* Input line charaters. */
int xt_line; /* Interface to device drivers. */ size_t xt_inlow; /* Input low watermark. */
dev_t xt_dev; /* Userland (sysctl) instance. */ size_t xt_outsize; /* Output queue size. */
int xt_state; /* Device and driver (TS*) state. */ size_t xt_outcc; /* Output queue usage. */
int xt_flags; /* Tty flags. */ size_t xt_outlow; /* Output low watermark. */
int xt_timeout; /* Timeout for ttywait(). */ unsigned int xt_column; /* Current column position. */
pid_t xt_pgid; /* Process group ID. */ pid_t xt_pgid; /* Foreground process group. */
pid_t xt_sid; /* Session ID. */ pid_t xt_sid; /* Session. */
struct termios xt_termios; /* Termios state. */ unsigned int xt_flags; /* Terminal option flags. */
struct winsize xt_winsize; /* Window size. */ dev_t xt_dev; /* Userland device. */
int xt_column; /* Tty output column. */
int xt_rocount, xt_rocol; /* Tty. */
int xt_ififosize; /* Total size of upstream fifos. */
int xt_ihiwat; /* High water mark for input. */
int xt_ilowat; /* Low water mark for input. */
speed_t xt_ispeedwat; /* t_ispeed override for watermarks. */
int xt_ohiwat; /* High water mark for output. */
int xt_olowat; /* Low water mark for output. */
speed_t xt_ospeedwat; /* t_ospeed override for watermarks. */
}; };
/*
* User data unfortunately has to be copied through buffers on the way to
* and from clists. The buffers are on the stack so their sizes must be
* fairly small.
*/
#define IBUFSIZ 384 /* Should be >= max value of MIN. */
#define OBUFSIZ 100
#ifndef TTYHOG
#define TTYHOG 8192
#endif
#ifdef _KERNEL #ifdef _KERNEL
#define TTMAXHIWAT roundup(2048, CBSIZE)
#define TTMINHIWAT roundup(100, CBSIZE)
#define TTMAXLOWAT 256
#define TTMINLOWAT 32
#endif
/* These flags are kept in t_state. */ /* Allocation and deallocation. */
#define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */ struct tty *tty_alloc(struct ttydevsw *, void *, struct mtx *);
#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */ void tty_rel_pgrp(struct tty *, struct pgrp *);
#define TS_BUSY 0x00004 /* Draining output. */ void tty_rel_sess(struct tty *, struct session *);
#define TS_CARR_ON 0x00008 /* Carrier is present. */ void tty_rel_gone(struct tty *);
#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
#define TS_ISOPEN 0x00020 /* Open has completed. */
#define TS_TBLOCK 0x00040 /* Further input blocked. */
#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
#define TS_TTSTOP 0x00100 /* Output paused. */
#ifdef notyet
#define TS_WOPEN 0x00200 /* Open in progress. */
#endif
#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
/* State for intra-line fancy editing work. */ #define tty_lock(tp) mtx_lock((tp)->t_mtx)
#define TS_BKSL 0x00800 /* State for lowercase \ work. */ #define tty_unlock(tp) mtx_unlock((tp)->t_mtx)
#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */ #define tty_lock_assert(tp,ma) mtx_assert((tp)->t_mtx, (ma))
#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
#define TS_LNCH 0x04000 /* Next character is literal. */
#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
/* Extras. */ /* Device node creation. */
#define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */ void tty_makedev(struct tty *, struct ucred *, const char *, ...)
#define TS_CONNECTED 0x020000 /* Connection open. */ __printflike(3, 4);
#define TS_SNOOP 0x040000 /* Device is being snooped on. */ #define tty_makealias(tp,fmt,...) \
#define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */ make_dev_alias((tp)->t_dev, fmt, ## __VA_ARGS__)
#define TS_ZOMBIE 0x100000 /* Connection lost. */
/* Hardware flow-control-invoked bits. */ /* Signalling processes. */
#define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */ void tty_signal_sessleader(struct tty *, int);
#ifdef notyet void tty_signal_pgrp(struct tty *, int);
#define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */ /* Waking up readers/writers. */
#define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */ int tty_wait(struct tty *, struct cv *);
#endif int tty_timedwait(struct tty *, struct cv *, int);
void tty_wakeup(struct tty *, int);
#define TS_DTR_WAIT 0x1000000 /* DTR hold-down between sessions */ /* System messages. */
#define TS_GONE 0x2000000 /* Hardware detached */ int tty_checkoutq(struct tty *);
#define TS_CALLOUT 0x4000000 /* Callout devices */ int tty_putchar(struct tty *, char);
/* Character type information. */ int tty_ioctl(struct tty *, u_long, void *, struct thread *);
#define ORDINARY 0 int tty_ioctl_compat(struct tty *, u_long, caddr_t, struct thread *);
#define CONTROL 1 void tty_init_console(struct tty *, speed_t);
#define BACKSPACE 2 void tty_flush(struct tty *, int);
#define NEWLINE 3 void tty_hiwat_in_block(struct tty *);
#define TAB 4 void tty_hiwat_in_unblock(struct tty *);
#define VTAB 5 dev_t tty_udev(struct tty *);
#define RETURN 6 #define tty_opened(tp) ((tp)->t_flags & TF_OPENED)
#define tty_gone(tp) ((tp)->t_flags & TF_GONE)
#define tty_softc(tp) ((tp)->t_softc)
#define tty_devname(tp) devtoname((tp)->t_dev)
struct speedtab { /* Status line printing. */
int sp_speed; /* Speed. */ void tty_info(struct tty *);
int sp_code; /* Code. */
};
/* Modem control commands (driver). */ /* Pseudo-terminal hooks. */
#define DMSET 0 int pts_alloc_external(int, struct thread *, struct file *,
#define DMBIS 1 struct cdev *, const char *);
#define DMBIC 2
#define DMGET 3
/* Flags on a character passed to ttyinput. */
#define TTY_CHARMASK 0x000000ff /* Character mask */
#define TTY_QUOTE 0x00000100 /* Character quoted */
#define TTY_ERRORMASK 0xff000000 /* Error mask */
#define TTY_FE 0x01000000 /* Framing error */
#define TTY_PE 0x02000000 /* Parity error */
#define TTY_OE 0x04000000 /* Overrun error */
#define TTY_BI 0x08000000 /* Break condition */
/* Is tp controlling terminal for p? */
#define isctty(p, tp) \
((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
/* Is p in background of tp? */
#define isbackground(p, tp) \
(isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
/* Unique sleep addresses. */
#define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq)
#define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cf)
#define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_cl)
#define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq)
#ifdef _KERNEL
#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_TTYS);
#endif
/* Minor number flag bits */
#define MINOR_CALLOUT 0x80000000
#define MINOR_INIT 0x40000000
#define MINOR_LOCK 0x20000000
#define ISCALLOUT(dev) (minor(dev) & MINOR_CALLOUT)
#define ISINIT(dev) (minor(dev) & MINOR_INIT)
#define ISLOCK(dev) (minor(dev) & MINOR_LOCK)
extern long tk_cancc;
extern long tk_nin;
extern long tk_nout;
extern long tk_rawcc;
void nottystop(struct tty *tp, int rw);
void termioschars(struct termios *t);
int tputchar(int c, struct tty *tp);
int ttcompat(struct tty *tp, u_long com, caddr_t data, int flag);
int ttioctl(struct tty *tp, u_long com, void *data, int flag);
int ttread(struct tty *tp, struct uio *uio, int flag);
void ttrstrt(void *tp);
void ttsetwater(struct tty *tp);
int ttspeedtab(int speed, struct speedtab *table);
int ttstart(struct tty *tp);
void ttwakeup(struct tty *tp);
int ttwrite(struct tty *tp, struct uio *uio, int flag);
void ttwwakeup(struct tty *tp);
struct tty *ttyalloc(void);
void ttyblock(struct tty *tp);
void ttychars(struct tty *tp);
int ttycheckoutq(struct tty *tp, int wait);
void ttyconsolemode(struct tty *tp, int speed);
int tty_close(struct tty *tp);
int ttycreate(struct tty *tp, int flags, const char *fmt, ...) __printflike(3, 4);
int ttydtrwaitsleep(struct tty *tp);
void ttydtrwaitstart(struct tty *tp);
void ttyflush(struct tty *tp, int rw);
void ttyfree(struct tty *tp);
void ttygone(struct tty *tp);
void ttyinfo(struct tty *tp);
void ttyinitmode(struct tty *tp, int echo, int speed);
int ttyinput(int c, struct tty *tp);
int ttylclose(struct tty *tp, int flag);
void ttyldoptim(struct tty *tp);
int ttymodem(struct tty *tp, int flag);
int tty_open(struct cdev *device, struct tty *tp);
int ttyref(struct tty *tp);
int ttyrel(struct tty *tp);
int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg, int timo);
int ttywait(struct tty *tp);
static __inline int
tt_open(struct tty *t, struct cdev *c)
{
if (t->t_open == NULL)
return (0);
return (t->t_open(t, c));
}
static __inline void
tt_close(struct tty *t)
{
if (t->t_close != NULL)
return (t->t_close(t));
}
static __inline void
tt_oproc(struct tty *t)
{
if (t->t_oproc != NULL) /* XXX: Kludge for pty. */
t->t_oproc(t);
}
static __inline void
tt_purge(struct tty *t)
{
if (t->t_purge != NULL)
t->t_purge(t);
}
static __inline void
tt_stop(struct tty *t, int i)
{
t->t_stop(t, i);
}
static __inline int
tt_param(struct tty *t, struct termios *s)
{
if (t->t_param == NULL)
return (0);
return (t->t_param(t, s));
}
static __inline int
tt_modem(struct tty *t, int i, int j)
{
if (t->t_modem == NULL)
return (0);
return (t->t_modem(t, i, j));
}
static __inline int
tt_break(struct tty *t, int i)
{
if (t->t_break == NULL)
return (ENOIOCTL);
t->t_break(t, i);
return (0);
}
static __inline int
tt_ioctl(struct tty *t, u_long cmd, void *data,
int fflag, struct thread *td)
{
return (t->t_ioctl(t, cmd, data, fflag, td));
}
/*
* XXX: temporary
*/
#include <sys/linedisc.h>
/* Drivers and line disciplines also need to call these. */
#include <sys/ttydevsw.h>
#include <sys/ttydisc.h>
#endif /* _KERNEL */ #endif /* _KERNEL */
#endif /* !_SYS_TTY_H_ */ #endif /* !_SYS_TTY_H_ */