0001
0002 #ifndef _LINUX_TTY_H
0003 #define _LINUX_TTY_H
0004
0005 #include <linux/fs.h>
0006 #include <linux/major.h>
0007 #include <linux/termios.h>
0008 #include <linux/workqueue.h>
0009 #include <linux/tty_buffer.h>
0010 #include <linux/tty_driver.h>
0011 #include <linux/tty_ldisc.h>
0012 #include <linux/tty_port.h>
0013 #include <linux/mutex.h>
0014 #include <linux/tty_flags.h>
0015 #include <uapi/linux/tty.h>
0016 #include <linux/rwsem.h>
0017 #include <linux/llist.h>
0018
0019
0020
0021
0022
0023
0024 #define NR_UNIX98_PTY_DEFAULT 4096
0025 #define NR_UNIX98_PTY_RESERVE 1024
0026 #define NR_UNIX98_PTY_MAX (1 << MINORBITS)
0027
0028
0029
0030
0031
0032
0033 #define __DISABLED_CHAR '\0'
0034
0035 #define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
0036 #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
0037 #define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
0038 #define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
0039 #define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
0040 #define TIME_CHAR(tty) ((tty)->termios.c_cc[VTIME])
0041 #define MIN_CHAR(tty) ((tty)->termios.c_cc[VMIN])
0042 #define SWTC_CHAR(tty) ((tty)->termios.c_cc[VSWTC])
0043 #define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
0044 #define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
0045 #define SUSP_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
0046 #define EOL_CHAR(tty) ((tty)->termios.c_cc[VEOL])
0047 #define REPRINT_CHAR(tty) ((tty)->termios.c_cc[VREPRINT])
0048 #define DISCARD_CHAR(tty) ((tty)->termios.c_cc[VDISCARD])
0049 #define WERASE_CHAR(tty) ((tty)->termios.c_cc[VWERASE])
0050 #define LNEXT_CHAR(tty) ((tty)->termios.c_cc[VLNEXT])
0051 #define EOL2_CHAR(tty) ((tty)->termios.c_cc[VEOL2])
0052
0053 #define _I_FLAG(tty, f) ((tty)->termios.c_iflag & (f))
0054 #define _O_FLAG(tty, f) ((tty)->termios.c_oflag & (f))
0055 #define _C_FLAG(tty, f) ((tty)->termios.c_cflag & (f))
0056 #define _L_FLAG(tty, f) ((tty)->termios.c_lflag & (f))
0057
0058 #define I_IGNBRK(tty) _I_FLAG((tty), IGNBRK)
0059 #define I_BRKINT(tty) _I_FLAG((tty), BRKINT)
0060 #define I_IGNPAR(tty) _I_FLAG((tty), IGNPAR)
0061 #define I_PARMRK(tty) _I_FLAG((tty), PARMRK)
0062 #define I_INPCK(tty) _I_FLAG((tty), INPCK)
0063 #define I_ISTRIP(tty) _I_FLAG((tty), ISTRIP)
0064 #define I_INLCR(tty) _I_FLAG((tty), INLCR)
0065 #define I_IGNCR(tty) _I_FLAG((tty), IGNCR)
0066 #define I_ICRNL(tty) _I_FLAG((tty), ICRNL)
0067 #define I_IUCLC(tty) _I_FLAG((tty), IUCLC)
0068 #define I_IXON(tty) _I_FLAG((tty), IXON)
0069 #define I_IXANY(tty) _I_FLAG((tty), IXANY)
0070 #define I_IXOFF(tty) _I_FLAG((tty), IXOFF)
0071 #define I_IMAXBEL(tty) _I_FLAG((tty), IMAXBEL)
0072 #define I_IUTF8(tty) _I_FLAG((tty), IUTF8)
0073
0074 #define O_OPOST(tty) _O_FLAG((tty), OPOST)
0075 #define O_OLCUC(tty) _O_FLAG((tty), OLCUC)
0076 #define O_ONLCR(tty) _O_FLAG((tty), ONLCR)
0077 #define O_OCRNL(tty) _O_FLAG((tty), OCRNL)
0078 #define O_ONOCR(tty) _O_FLAG((tty), ONOCR)
0079 #define O_ONLRET(tty) _O_FLAG((tty), ONLRET)
0080 #define O_OFILL(tty) _O_FLAG((tty), OFILL)
0081 #define O_OFDEL(tty) _O_FLAG((tty), OFDEL)
0082 #define O_NLDLY(tty) _O_FLAG((tty), NLDLY)
0083 #define O_CRDLY(tty) _O_FLAG((tty), CRDLY)
0084 #define O_TABDLY(tty) _O_FLAG((tty), TABDLY)
0085 #define O_BSDLY(tty) _O_FLAG((tty), BSDLY)
0086 #define O_VTDLY(tty) _O_FLAG((tty), VTDLY)
0087 #define O_FFDLY(tty) _O_FLAG((tty), FFDLY)
0088
0089 #define C_BAUD(tty) _C_FLAG((tty), CBAUD)
0090 #define C_CSIZE(tty) _C_FLAG((tty), CSIZE)
0091 #define C_CSTOPB(tty) _C_FLAG((tty), CSTOPB)
0092 #define C_CREAD(tty) _C_FLAG((tty), CREAD)
0093 #define C_PARENB(tty) _C_FLAG((tty), PARENB)
0094 #define C_PARODD(tty) _C_FLAG((tty), PARODD)
0095 #define C_HUPCL(tty) _C_FLAG((tty), HUPCL)
0096 #define C_CLOCAL(tty) _C_FLAG((tty), CLOCAL)
0097 #define C_CIBAUD(tty) _C_FLAG((tty), CIBAUD)
0098 #define C_CRTSCTS(tty) _C_FLAG((tty), CRTSCTS)
0099 #define C_CMSPAR(tty) _C_FLAG((tty), CMSPAR)
0100
0101 #define L_ISIG(tty) _L_FLAG((tty), ISIG)
0102 #define L_ICANON(tty) _L_FLAG((tty), ICANON)
0103 #define L_XCASE(tty) _L_FLAG((tty), XCASE)
0104 #define L_ECHO(tty) _L_FLAG((tty), ECHO)
0105 #define L_ECHOE(tty) _L_FLAG((tty), ECHOE)
0106 #define L_ECHOK(tty) _L_FLAG((tty), ECHOK)
0107 #define L_ECHONL(tty) _L_FLAG((tty), ECHONL)
0108 #define L_NOFLSH(tty) _L_FLAG((tty), NOFLSH)
0109 #define L_TOSTOP(tty) _L_FLAG((tty), TOSTOP)
0110 #define L_ECHOCTL(tty) _L_FLAG((tty), ECHOCTL)
0111 #define L_ECHOPRT(tty) _L_FLAG((tty), ECHOPRT)
0112 #define L_ECHOKE(tty) _L_FLAG((tty), ECHOKE)
0113 #define L_FLUSHO(tty) _L_FLAG((tty), FLUSHO)
0114 #define L_PENDIN(tty) _L_FLAG((tty), PENDIN)
0115 #define L_IEXTEN(tty) _L_FLAG((tty), IEXTEN)
0116 #define L_EXTPROC(tty) _L_FLAG((tty), EXTPROC)
0117
0118 struct device;
0119 struct signal_struct;
0120 struct tty_operations;
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195 struct tty_struct {
0196 int magic;
0197 struct kref kref;
0198 struct device *dev;
0199 struct tty_driver *driver;
0200 const struct tty_operations *ops;
0201 int index;
0202
0203 struct ld_semaphore ldisc_sem;
0204 struct tty_ldisc *ldisc;
0205
0206 struct mutex atomic_write_lock;
0207 struct mutex legacy_mutex;
0208 struct mutex throttle_mutex;
0209 struct rw_semaphore termios_rwsem;
0210 struct mutex winsize_mutex;
0211 struct ktermios termios, termios_locked;
0212 char name[64];
0213 unsigned long flags;
0214 int count;
0215 struct winsize winsize;
0216
0217 struct {
0218 spinlock_t lock;
0219 bool stopped;
0220 bool tco_stopped;
0221 unsigned long unused[0];
0222 } __aligned(sizeof(unsigned long)) flow;
0223
0224 struct {
0225 spinlock_t lock;
0226 struct pid *pgrp;
0227 struct pid *session;
0228 unsigned char pktstatus;
0229 bool packet;
0230 unsigned long unused[0];
0231 } __aligned(sizeof(unsigned long)) ctrl;
0232
0233 int hw_stopped;
0234 unsigned int receive_room;
0235 int flow_change;
0236
0237 struct tty_struct *link;
0238 struct fasync_struct *fasync;
0239 wait_queue_head_t write_wait;
0240 wait_queue_head_t read_wait;
0241 struct work_struct hangup_work;
0242 void *disc_data;
0243 void *driver_data;
0244 spinlock_t files_lock;
0245 struct list_head tty_files;
0246
0247 #define N_TTY_BUF_SIZE 4096
0248
0249 int closing;
0250 unsigned char *write_buf;
0251 int write_cnt;
0252 struct work_struct SAK_work;
0253 struct tty_port *port;
0254 } __randomize_layout;
0255
0256
0257 struct tty_file_private {
0258 struct tty_struct *tty;
0259 struct file *file;
0260 struct list_head list;
0261 };
0262
0263
0264 #define TTY_MAGIC 0x5401
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320 #define TTY_THROTTLED 0
0321 #define TTY_IO_ERROR 1
0322 #define TTY_OTHER_CLOSED 2
0323 #define TTY_EXCLUSIVE 3
0324 #define TTY_DO_WRITE_WAKEUP 5
0325 #define TTY_LDISC_OPEN 11
0326 #define TTY_PTY_LOCK 16
0327 #define TTY_NO_WRITE_SPLIT 17
0328 #define TTY_HUPPED 18
0329 #define TTY_HUPPING 19
0330 #define TTY_LDISC_CHANGING 20
0331 #define TTY_LDISC_HALTED 22
0332
0333 static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file)
0334 {
0335 return file->f_flags & O_NONBLOCK ||
0336 test_bit(TTY_LDISC_CHANGING, &tty->flags);
0337 }
0338
0339 static inline bool tty_io_error(struct tty_struct *tty)
0340 {
0341 return test_bit(TTY_IO_ERROR, &tty->flags);
0342 }
0343
0344 static inline bool tty_throttled(struct tty_struct *tty)
0345 {
0346 return test_bit(TTY_THROTTLED, &tty->flags);
0347 }
0348
0349 #ifdef CONFIG_TTY
0350 void tty_kref_put(struct tty_struct *tty);
0351 struct pid *tty_get_pgrp(struct tty_struct *tty);
0352 void tty_vhangup_self(void);
0353 void disassociate_ctty(int priv);
0354 dev_t tty_devnum(struct tty_struct *tty);
0355 void proc_clear_tty(struct task_struct *p);
0356 struct tty_struct *get_current_tty(void);
0357
0358 int __init tty_init(void);
0359 const char *tty_name(const struct tty_struct *tty);
0360 struct tty_struct *tty_kopen_exclusive(dev_t device);
0361 struct tty_struct *tty_kopen_shared(dev_t device);
0362 void tty_kclose(struct tty_struct *tty);
0363 int tty_dev_name_to_number(const char *name, dev_t *number);
0364 #else
0365 static inline void tty_kref_put(struct tty_struct *tty)
0366 { }
0367 static inline struct pid *tty_get_pgrp(struct tty_struct *tty)
0368 { return NULL; }
0369 static inline void tty_vhangup_self(void)
0370 { }
0371 static inline void disassociate_ctty(int priv)
0372 { }
0373 static inline dev_t tty_devnum(struct tty_struct *tty)
0374 { return 0; }
0375 static inline void proc_clear_tty(struct task_struct *p)
0376 { }
0377 static inline struct tty_struct *get_current_tty(void)
0378 { return NULL; }
0379
0380 static inline int __init tty_init(void)
0381 { return 0; }
0382 static inline const char *tty_name(const struct tty_struct *tty)
0383 { return "(none)"; }
0384 static inline struct tty_struct *tty_kopen_exclusive(dev_t device)
0385 { return ERR_PTR(-ENODEV); }
0386 static inline void tty_kclose(struct tty_struct *tty)
0387 { }
0388 static inline int tty_dev_name_to_number(const char *name, dev_t *number)
0389 { return -ENOTSUPP; }
0390 #endif
0391
0392 extern struct ktermios tty_std_termios;
0393
0394 int vcs_init(void);
0395
0396 extern struct class *tty_class;
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407 static inline struct tty_struct *tty_kref_get(struct tty_struct *tty)
0408 {
0409 if (tty)
0410 kref_get(&tty->kref);
0411 return tty;
0412 }
0413
0414 const char *tty_driver_name(const struct tty_struct *tty);
0415 void tty_wait_until_sent(struct tty_struct *tty, long timeout);
0416 void stop_tty(struct tty_struct *tty);
0417 void start_tty(struct tty_struct *tty);
0418 void tty_write_message(struct tty_struct *tty, char *msg);
0419 int tty_send_xchar(struct tty_struct *tty, char ch);
0420 int tty_put_char(struct tty_struct *tty, unsigned char c);
0421 unsigned int tty_chars_in_buffer(struct tty_struct *tty);
0422 unsigned int tty_write_room(struct tty_struct *tty);
0423 void tty_driver_flush_buffer(struct tty_struct *tty);
0424 void tty_unthrottle(struct tty_struct *tty);
0425 int tty_throttle_safe(struct tty_struct *tty);
0426 int tty_unthrottle_safe(struct tty_struct *tty);
0427 int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
0428 int tty_get_icount(struct tty_struct *tty,
0429 struct serial_icounter_struct *icount);
0430 int is_current_pgrp_orphaned(void);
0431 void tty_hangup(struct tty_struct *tty);
0432 void tty_vhangup(struct tty_struct *tty);
0433 int tty_hung_up_p(struct file *filp);
0434 void do_SAK(struct tty_struct *tty);
0435 void __do_SAK(struct tty_struct *tty);
0436 void no_tty(void);
0437 speed_t tty_termios_baud_rate(struct ktermios *termios);
0438 void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud,
0439 speed_t obaud);
0440 void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud,
0441 speed_t obaud);
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453 static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
0454 {
0455 return tty_termios_baud_rate(&tty->termios);
0456 }
0457
0458 unsigned char tty_get_char_size(unsigned int cflag);
0459 unsigned char tty_get_frame_size(unsigned int cflag);
0460
0461 void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
0462 int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
0463 int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
0464
0465 void tty_wakeup(struct tty_struct *tty);
0466
0467 int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
0468 int tty_perform_flush(struct tty_struct *tty, unsigned long arg);
0469 struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
0470 void tty_release_struct(struct tty_struct *tty, int idx);
0471 void tty_init_termios(struct tty_struct *tty);
0472 void tty_save_termios(struct tty_struct *tty);
0473 int tty_standard_install(struct tty_driver *driver,
0474 struct tty_struct *tty);
0475
0476 extern struct mutex tty_mutex;
0477
0478
0479 void n_tty_inherit_ops(struct tty_ldisc_ops *ops);
0480 #ifdef CONFIG_TTY
0481 void __init n_tty_init(void);
0482 #else
0483 static inline void n_tty_init(void) { }
0484 #endif
0485
0486
0487 #ifdef CONFIG_AUDIT
0488 void tty_audit_exit(void);
0489 void tty_audit_fork(struct signal_struct *sig);
0490 int tty_audit_push(void);
0491 #else
0492 static inline void tty_audit_exit(void)
0493 {
0494 }
0495 static inline void tty_audit_fork(struct signal_struct *sig)
0496 {
0497 }
0498 static inline int tty_audit_push(void)
0499 {
0500 return 0;
0501 }
0502 #endif
0503
0504
0505 int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd,
0506 unsigned long arg);
0507
0508
0509
0510 int vt_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
0511
0512 long vt_compat_ioctl(struct tty_struct *tty, unsigned int cmd,
0513 unsigned long arg);
0514
0515
0516
0517 void tty_lock(struct tty_struct *tty);
0518 int tty_lock_interruptible(struct tty_struct *tty);
0519 void tty_unlock(struct tty_struct *tty);
0520 void tty_lock_slave(struct tty_struct *tty);
0521 void tty_unlock_slave(struct tty_struct *tty);
0522 void tty_set_lock_subclass(struct tty_struct *tty);
0523
0524 #endif