XenevaOS
Loading...
Searching...
No Matches
tty.h
Go to the documentation of this file.
1#ifndef _LINUX_TTY_H
2#define _LINUX_TTY_H
3
4/*
5 * DCL <linux/tty.h> -- struct tty_struct and the tty core's public surface.
6 *
7 * Ported from mainline v7.2. This used to declare exactly one thing (tty_init,
8 * the placeholder in DCL/linux_mm_shim.c); it is now the real header, because
9 * tty_buffer.c is the first staged file that needs a tty to look like a tty.
10 *
11 * Three deliberate departures, each for a reason that is visible in the code:
12 *
13 * 1. The CONFIG_TTY / CONFIG_AUDIT conditionals are written out in the
14 * "enabled" direction. DCL's configuration lives in <linux/autoconf.h>
15 * and has no CONFIG_TTY -- it was never needed, because tty_init() was a
16 * stub. Writing only the enabled branch means the declarations that
17 * tty_io.c and serial_core.c call always exist, instead of silently
18 * becoming static inline stubs that return -ENODEV. CONFIG_AUDIT's block
19 * is written out as the "not enabled" (inline no-op) branch: there is no
20 * audit subsystem here at all, so tty_audit_* must be a no-op rather than
21 * a link error.
22 *
23 * 2. tty_termios_baud_rate()/tty_termios_encode_baud_rate()/tty_termios_
24 * copy_hw() are *not* re-declared here. mainline declares them in this
25 * header and defines them in drivers/tty/tty_termios.c; DCL defines them
26 * as static inline in <linux/linux/termios.h> (one shared table, both
27 * directions). An external declaration next to a static inline definition
28 * of the same name is a compile error -- "non-static declaration follows
29 * static declaration" -- so the declaration goes away and the definition
30 * stays where it can be shared by every caller.
31 *
32 * 3. The N_* line discipline numbers come from uapi/linux/tty.h in mainline.
33 * DCL has no uapi layer, so they live here. n_tty.c and tty_ldisc.c are
34 * the only staged files that need them, and both include this header.
35 *
36 * The struct below is mainline's, field for field, including the two anonymous
37 * sub-structs (flow, ctrl) -- they are grouped exactly as mainline groups them
38 * because tty_io.c, n_tty.c and serial_core.c all reach for them by member
39 * name, and a field that is present but differently named is indistinguishable
40 * from a missing one at compile time until the error message.
41 */
42
43#include <linux/fs.h>
44#include <linux/termios.h>
45/* O_NONBLOCK, used by tty_io_nonblock() below */
46#include <linux/fcntl.h>
47#include <linux/workqueue.h>
48#include <linux/tty_driver.h>
49#include <linux/tty_ldisc.h>
50#include <linux/tty_port.h>
51#include <linux/mutex.h>
52#include <linux/rwsem.h>
53#include <linux/wait.h>
54#include <linux/list.h>
55#include <linux/kref.h>
56#include <linux/capability.h>
57
58/*
59 * Line disciplines. mainline: include/uapi/linux/tty.h. NR_LDISCS is one past
60 * the newest -- tty_ldisc.c sizes its ops array with it, so a DCL that grows a
61 * discipline has to grow this too.
62 */
63#define N_TTY 0
64#define N_SLIP 1
65#define N_MOUSE 2
66#define N_PPP 3
67#define N_STRIP 4
68#define N_AX25 5
69#define N_X25 6
70#define N_6PACK 7
71#define N_MASC 8
72#define N_R3964 9
73#define N_PROFIBUS_FDL 10
74#define N_IRDA 11
75#define N_SMSBLOCK 12
76#define N_HDLC 13
77#define N_SYNC_PPP 14
78#define N_HCI 15
79#define N_GIGASET_M101 16
80#define N_SLCAN 17
81#define N_PPS 18
82#define N_V253 19
83#define N_CAIF 20
84#define N_GSM0710 21
85#define N_TI_WL 22
86#define N_TRACESINK 23
87#define N_TRACEROUTER 24
88#define N_NCI 25
89#define N_SPEAKUP 26
90#define N_NULL 27
91#define N_MCTP 28
92#define N_DEVELOPMENT 29
93#define N_CAN327 30
94#define NR_LDISCS 31
95
96/*
97 * This character is the same as _POSIX_VDISABLE: it cannot be used as
98 * a c_cc[] character, but indicates that a particular special character
99 * isn't in use (eg VINTR has no character etc)
100 */
101#define __DISABLED_CHAR '\0'
102
103#define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
104#define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
105#define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
106#define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
107#define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
108#define TIME_CHAR(tty) ((tty)->termios.c_cc[VTIME])
109#define MIN_CHAR(tty) ((tty)->termios.c_cc[VMIN])
110#define SWTC_CHAR(tty) ((tty)->termios.c_cc[VSWTC])
111#define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
112#define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
113#define SUSP_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
114#define EOL_CHAR(tty) ((tty)->termios.c_cc[VEOL])
115#define REPRINT_CHAR(tty) ((tty)->termios.c_cc[VREPRINT])
116#define DISCARD_CHAR(tty) ((tty)->termios.c_cc[VDISCARD])
117#define WERASE_CHAR(tty) ((tty)->termios.c_cc[VWERASE])
118#define LNEXT_CHAR(tty) ((tty)->termios.c_cc[VLNEXT])
119#define EOL2_CHAR(tty) ((tty)->termios.c_cc[VEOL2])
120
121#define _I_FLAG(tty, f) ((tty)->termios.c_iflag & (f))
122#define _O_FLAG(tty, f) ((tty)->termios.c_oflag & (f))
123#define _C_FLAG(tty, f) ((tty)->termios.c_cflag & (f))
124#define _L_FLAG(tty, f) ((tty)->termios.c_lflag & (f))
125
126#define I_IGNBRK(tty) _I_FLAG((tty), IGNBRK)
127#define I_BRKINT(tty) _I_FLAG((tty), BRKINT)
128#define I_IGNPAR(tty) _I_FLAG((tty), IGNPAR)
129#define I_PARMRK(tty) _I_FLAG((tty), PARMRK)
130#define I_INPCK(tty) _I_FLAG((tty), INPCK)
131#define I_ISTRIP(tty) _I_FLAG((tty), ISTRIP)
132#define I_INLCR(tty) _I_FLAG((tty), INLCR)
133#define I_IGNCR(tty) _I_FLAG((tty), IGNCR)
134#define I_ICRNL(tty) _I_FLAG((tty), ICRNL)
135#define I_IUCLC(tty) _I_FLAG((tty), IUCLC)
136#define I_IXON(tty) _I_FLAG((tty), IXON)
137#define I_IXANY(tty) _I_FLAG((tty), IXANY)
138#define I_IXOFF(tty) _I_FLAG((tty), IXOFF)
139#define I_IMAXBEL(tty) _I_FLAG((tty), IMAXBEL)
140#define I_IUTF8(tty) _I_FLAG((tty), IUTF8)
141
142#define O_OPOST(tty) _O_FLAG((tty), OPOST)
143#define O_OLCUC(tty) _O_FLAG((tty), OLCUC)
144#define O_ONLCR(tty) _O_FLAG((tty), ONLCR)
145#define O_OCRNL(tty) _O_FLAG((tty), OCRNL)
146#define O_ONOCR(tty) _O_FLAG((tty), ONOCR)
147#define O_ONLRET(tty) _O_FLAG((tty), ONLRET)
148#define O_OFILL(tty) _O_FLAG((tty), OFILL)
149#define O_OFDEL(tty) _O_FLAG((tty), OFDEL)
150#define O_NLDLY(tty) _O_FLAG((tty), NLDLY)
151#define O_CRDLY(tty) _O_FLAG((tty), CRDLY)
152#define O_TABDLY(tty) _O_FLAG((tty), TABDLY)
153#define O_BSDLY(tty) _O_FLAG((tty), BSDLY)
154#define O_VTDLY(tty) _O_FLAG((tty), VTDLY)
155#define O_FFDLY(tty) _O_FLAG((tty), FFDLY)
156
157#define C_BAUD(tty) _C_FLAG((tty), CBAUD)
158#define C_CSIZE(tty) _C_FLAG((tty), CSIZE)
159#define C_CSTOPB(tty) _C_FLAG((tty), CSTOPB)
160#define C_CREAD(tty) _C_FLAG((tty), CREAD)
161#define C_PARENB(tty) _C_FLAG((tty), PARENB)
162#define C_PARODD(tty) _C_FLAG((tty), PARODD)
163#define C_HUPCL(tty) _C_FLAG((tty), HUPCL)
164#define C_CLOCAL(tty) _C_FLAG((tty), CLOCAL)
165#define C_CIBAUD(tty) _C_FLAG((tty), CIBAUD)
166#define C_CRTSCTS(tty) _C_FLAG((tty), CRTSCTS)
167#define C_CMSPAR(tty) _C_FLAG((tty), CMSPAR)
168
169#define L_ISIG(tty) _L_FLAG((tty), ISIG)
170#define L_ICANON(tty) _L_FLAG((tty), ICANON)
171#define L_XCASE(tty) _L_FLAG((tty), XCASE)
172#define L_ECHO(tty) _L_FLAG((tty), ECHO)
173#define L_ECHOE(tty) _L_FLAG((tty), ECHOE)
174#define L_ECHOK(tty) _L_FLAG((tty), ECHOK)
175#define L_ECHONL(tty) _L_FLAG((tty), ECHONL)
176#define L_NOFLSH(tty) _L_FLAG((tty), NOFLSH)
177#define L_TOSTOP(tty) _L_FLAG((tty), TOSTOP)
178#define L_ECHOCTL(tty) _L_FLAG((tty), ECHOCTL)
179#define L_ECHOPRT(tty) _L_FLAG((tty), ECHOPRT)
180#define L_ECHOKE(tty) _L_FLAG((tty), ECHOKE)
181#define L_FLUSHO(tty) _L_FLAG((tty), FLUSHO)
182#define L_PENDIN(tty) _L_FLAG((tty), PENDIN)
183#define L_IEXTEN(tty) _L_FLAG((tty), IEXTEN)
184#define L_EXTPROC(tty) _L_FLAG((tty), EXTPROC)
185
186struct device;
187struct signal_struct;
188struct tty_operations;
189struct pid;
190struct task_struct;
191struct class;
192struct fasync_struct;
193
259
260/* Each of a tty's open files has private data */
263 struct file* file;
265};
266
267/* Bits in tty_struct::flags -- mainline's enum tty_struct_flags */
282
283static inline bool tty_io_nonblock(struct tty_struct* tty, struct file* file)
284{
285 return file->f_flags & O_NONBLOCK ||
287}
288
289static inline bool tty_io_error(struct tty_struct* tty)
290{
291 return test_bit(TTY_IO_ERROR, &tty->flags);
292}
293
294static inline bool tty_throttled(struct tty_struct* tty)
295{
296 return test_bit(TTY_THROTTLED, &tty->flags);
297}
298
299/* --- tty_kref_get / tty_get_baud_rate: mainline keeps these inline ------ */
300
309static inline struct tty_struct* tty_kref_get(struct tty_struct* tty)
310{
311 if (tty)
312 kref_get(&tty->kref);
313 return tty;
314}
315
323static inline speed_t tty_get_baud_rate(const struct tty_struct* tty)
324{
325 return tty_termios_baud_rate(&tty->termios);
326}
327
328/* --- tty core ----------------------------------------------------------- */
329
330void tty_kref_put(struct tty_struct* tty);
331struct pid* tty_get_pgrp(struct tty_struct* tty);
333void disassociate_ctty(int priv);
337
338/* tty_io.c */
339int tty_init(void);
340const char* tty_name(const struct tty_struct* tty);
341const char* tty_driver_name(const struct tty_struct* tty);
344void tty_kclose(struct tty_struct* tty);
345int tty_dev_name_to_number(const char* name, dev_t* number);
346
347void tty_wait_until_sent(struct tty_struct* tty, long timeout);
348void stop_tty(struct tty_struct* tty);
349void start_tty(struct tty_struct* tty);
350void tty_write_message(struct tty_struct* tty, char* msg);
351int tty_send_xchar(struct tty_struct* tty, u8 ch);
352int tty_put_char(struct tty_struct* tty, u8 c);
353unsigned int tty_chars_in_buffer(struct tty_struct* tty);
354unsigned int tty_write_room(struct tty_struct* tty);
356void tty_unthrottle(struct tty_struct* tty);
359int tty_do_resize(struct tty_struct* tty, struct winsize* ws);
361 struct serial_icounter_struct* icount);
362int tty_get_tiocm(struct tty_struct* tty);
364void tty_hangup(struct tty_struct* tty);
365void tty_vhangup(struct tty_struct* tty);
366int tty_hung_up_p(struct file* filp);
367void do_SAK(struct tty_struct* tty);
368void __do_SAK(struct tty_struct* tty);
369void no_tty(void);
371 speed_t obaud);
372
373unsigned char tty_get_char_size(unsigned int cflag);
374unsigned char tty_get_frame_size(unsigned int cflag);
375bool tty_termios_hw_change(const struct ktermios* a, const struct ktermios* b);
376int tty_set_termios(struct tty_struct* tty, struct ktermios* kt);
377
378void tty_wakeup(struct tty_struct* tty);
379
380int tty_mode_ioctl(struct tty_struct* tty, unsigned int cmd, unsigned long arg);
381int tty_perform_flush(struct tty_struct* tty, unsigned long arg);
382struct tty_struct* tty_init_dev(struct tty_driver* driver, int idx);
383void tty_release_struct(struct tty_struct* tty, int idx);
384void tty_init_termios(struct tty_struct* tty);
385void tty_save_termios(struct tty_struct* tty);
387
388extern struct mutex tty_mutex;
389
390/* n_tty.c */
392void n_tty_init(void);
393
394/* tty_audit.c -- no audit subsystem in DCL: these are the inline no-ops
395 * mainline writes under #else. */
396static inline void tty_audit_exit(void) { }
397static inline void tty_audit_fork(struct signal_struct* sig) { (void)sig; }
398static inline int tty_audit_push(void) { return 0; }
399
400/* tty_ioctl.c */
401int n_tty_ioctl_helper(struct tty_struct* tty, unsigned int cmd,
402 unsigned long arg);
403
404/* vt.c */
405int vt_ioctl(struct tty_struct* tty, unsigned int cmd, unsigned long arg);
406long vt_compat_ioctl(struct tty_struct* tty, unsigned int cmd,
407 unsigned long arg);
408
409/* tty_mutex.c */
410void tty_lock(struct tty_struct* tty);
412void tty_unlock(struct tty_struct* tty);
413void tty_lock_slave(struct tty_struct* tty);
414void tty_unlock_slave(struct tty_struct* tty);
416
417#endif /* _LINUX_TTY_H */
#define O_NONBLOCK
Definition fcntl.h:65
size_t a
Definition main.cpp:156
size_t b
Definition main.cpp:156
#define test_bit(nr, addr)
Definition bitops.h:124
struct drm_crtc struct drm_plane struct drm_plane const struct drm_crtc_funcs const char * name
Definition drm_crtc.h:1242
uint32_t dev_t
Definition kernel.h:52
uint8_t u8
Definition kernel.h:14
int spinlock_t
Definition kernel.h:44
unsigned int speed_t
Definition termios.h:79
void tty_write_message(struct tty_struct *tty, char *msg)
void tty_vhangup(struct tty_struct *tty)
void tty_kref_put(struct tty_struct *tty)
struct tty_struct * tty_kopen_exclusive(dev_t device)
void tty_unthrottle(struct tty_struct *tty)
int tty_lock_interruptible(struct tty_struct *tty)
long vt_compat_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
const char * tty_driver_name(const struct tty_struct *tty)
int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty)
void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud)
void tty_lock_slave(struct tty_struct *tty)
void tty_vhangup_self(void)
int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
void disassociate_ctty(int priv)
bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
int tty_init(void)
bool tty_unthrottle_safe(struct tty_struct *tty)
void tty_unlock_slave(struct tty_struct *tty)
int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
int tty_send_xchar(struct tty_struct *tty, u8 ch)
bool tty_throttle_safe(struct tty_struct *tty)
void tty_kclose(struct tty_struct *tty)
struct tty_struct * tty_init_dev(struct tty_driver *driver, int idx)
void tty_wait_until_sent(struct tty_struct *tty, long timeout)
int tty_put_char(struct tty_struct *tty, u8 c)
int tty_get_icount(struct tty_struct *tty, struct serial_icounter_struct *icount)
void do_SAK(struct tty_struct *tty)
void proc_clear_tty(struct task_struct *p)
void tty_driver_flush_buffer(struct tty_struct *tty)
unsigned int tty_write_room(struct tty_struct *tty)
struct tty_struct * tty_kopen_shared(dev_t device)
void tty_release_struct(struct tty_struct *tty, int idx)
unsigned char tty_get_frame_size(unsigned int cflag)
void tty_set_lock_subclass(struct tty_struct *tty)
void tty_save_termios(struct tty_struct *tty)
dev_t tty_devnum(struct tty_struct *tty)
void no_tty(void)
void tty_init_termios(struct tty_struct *tty)
int tty_set_termios(struct tty_struct *tty, struct ktermios *kt)
int tty_do_resize(struct tty_struct *tty, struct winsize *ws)
void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
const char * tty_name(const struct tty_struct *tty)
unsigned char tty_get_char_size(unsigned int cflag)
struct pid * tty_get_pgrp(struct tty_struct *tty)
void stop_tty(struct tty_struct *tty)
int tty_get_tiocm(struct tty_struct *tty)
struct tty_struct * get_current_tty(void)
int tty_dev_name_to_number(const char *name, dev_t *number)
void __do_SAK(struct tty_struct *tty)
void n_tty_init(void)
struct mutex tty_mutex
int vt_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
void tty_lock(struct tty_struct *tty)
tty_struct_flags
Definition tty.h:268
@ TTY_LDISC_CHANGING
Definition tty.h:279
@ TTY_IO_ERROR
Definition tty.h:270
@ TTY_OTHER_CLOSED
Definition tty.h:271
@ TTY_LDISC_OPEN
Definition tty.h:274
@ TTY_DO_WRITE_WAKEUP
Definition tty.h:273
@ TTY_NO_WRITE_SPLIT
Definition tty.h:276
@ TTY_HUPPED
Definition tty.h:277
@ TTY_EXCLUSIVE
Definition tty.h:272
@ TTY_LDISC_HALTED
Definition tty.h:280
@ TTY_THROTTLED
Definition tty.h:269
@ TTY_PTY_LOCK
Definition tty.h:275
@ TTY_HUPPING
Definition tty.h:278
void tty_wakeup(struct tty_struct *tty)
void start_tty(struct tty_struct *tty)
void tty_unlock(struct tty_struct *tty)
void tty_hangup(struct tty_struct *tty)
int tty_hung_up_p(struct file *filp)
unsigned int tty_chars_in_buffer(struct tty_struct *tty)
int is_current_pgrp_orphaned(void)
Definition device.h:38
Definition fs.h:255
Definition fs.h:142
unsigned int f_flags
Definition fs.h:149
Definition kref.h:44
Definition termios.h:250
Definition tty_ldisc.h:57
Definition list.h:11
Definition mutex.h:59
Definition rwsem.h:36
Definition serial.h:139
Definition sched.h:107
Definition sched.h:121
Definition termios.h:230
Definition tty_driver.h:122
Definition tty.h:261
struct file * file
Definition tty.h:263
struct tty_struct * tty
Definition tty.h:262
struct list_head list
Definition tty.h:264
Definition tty_ldisc.h:126
Definition tty_ldisc.h:164
Definition tty_driver.h:80
Definition tty_port.h:79
Definition tty.h:203
spinlock_t files_lock
Definition tty.h:251
struct fasync_struct * fasync
Definition tty.h:245
bool stopped
Definition tty.h:228
unsigned int receive_room
Definition tty.h:223
struct pid * pgrp
Definition tty.h:233
int count
Definition tty.h:222
struct tty_driver * driver
Definition tty.h:207
struct ktermios termios termios_locked
Definition tty.h:219
struct mutex legacy_mutex
Definition tty.h:215
char name[64]
Definition tty.h:220
struct mutex atomic_write_lock
Definition tty.h:214
struct mutex throttle_mutex
Definition tty.h:216
struct tty_struct::@94 flow
struct ld_semaphore ldisc_sem
Definition tty.h:212
spinlock_t lock
Definition tty.h:227
struct work_struct SAK_work
Definition tty.h:257
void * disc_data
Definition tty.h:249
unsigned long flags
Definition tty.h:221
u8 * write_buf
Definition tty.h:253
int flow_change
Definition tty.h:242
bool tco_stopped
Definition tty.h:229
struct pid * session
Definition tty.h:234
int index
Definition tty.h:205
struct list_head tty_files
Definition tty.h:255
struct tty_struct::@95 ctrl
wait_queue_head_t read_wait
Definition tty.h:247
struct mutex winsize_mutex
Definition tty.h:218
struct work_struct hangup_work
Definition tty.h:248
unsigned char pktstatus
Definition tty.h:236
struct tty_struct * link
Definition tty.h:244
bool packet
Definition tty.h:237
const struct tty_operations * ops
Definition tty.h:209
struct kref kref
Definition tty.h:204
struct rw_semaphore termios_rwsem
Definition tty.h:217
bool hw_stopped
Definition tty.h:240
void * driver_data
Definition tty.h:250
bool closing
Definition tty.h:241
wait_queue_head_t write_wait
Definition tty.h:246
struct device * dev
Definition tty.h:206
struct tty_ldisc * ldisc
Definition tty.h:211
int write_cnt
Definition tty.h:252
struct tty_port * port
Definition tty.h:208
Definition wait.h:75
Definition termios.h:281
Definition workqueue.h:44