日期:2014-05-16 浏览次数:21170 次

一. tty结构体
1.tty_driver
struct tty_driver {
int magic;
struct kref kref; //参考计数
struct cdev cdev; //字符设备
struct module *owner; //模块所有者
const char *driver_name; //驱动名
const char *name; //设备名
int name_base;
int major; //主设备号
int minor_start; //起始次设备号
int minor_num; //设备个数
int num; //分配了的tty设备个数
short type; //tty设备的类型
short subtype; //tty设备子类型
struct ktermios init_termios; //初始化的ktermios
int flags; //tty驱动标志
struct proc_dir_entry *proc_entry; //procfs入口
struct tty_driver *other;
struct tty_struct **ttys;
struct ktermios **termios;
struct ktermios **termios_locked;
void *driver_state;
const struct tty_operations *ops; //操作函数集
struct list_head tty_drivers; //驱动链表
};
1.1 tty->flag
#define TTY_DRIVER_INSTALLED 0x0001 #define TTY_DRIVER_RESET_TERMIOS 0x0002 #define TTY_DRIVER_REAL_RAW 0x0004 #define TTY_DRIVER_DYNAMIC_DEV 0x0008 #define TTY_DRIVER_DEVPTS_MEM 0x0010 #define TTY_DRIVER_HARDWARE_BREAK 0x0020
1.2 tty->type tty设备类型
#define TTY_DRIVER_TYPE_SYSTEM 0x0001 #define TTY_DRIVER_TYPE_CONSOLE 0x0002 #define TTY_DRIVER_TYPE_SERIAL 0x0003 #define TTY_DRIVER_TYPE_PTY 0x0004 #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */ #define TTY_DRIVER_TYPE_SYSCONS 0x0006
2.ktermios结构体
struct ktermios {
tcflag_t c_iflag; /* input mode flags */ //输入模式标志
tcflag_t c_oflag; /* output mode flags */ //输出模式标志
tcflag_t c_cflag; /* control mode flags */ //控制模式标志
tcflag_t c_lflag; /* local mode flags */ //本地模式标志
cc_t c_line; /* line discipline */ //线路规程类型
cc_t c_cc[NCCS]; /* control characters */ //控制字符
speed_t c_ispeed; /* input speed */ //输入速度
speed_t c_ospeed; /* output speed */ //输出速度
};
3.tty_struct
struct tty_struct {
int magic; //魔数
struct kref kref; //参考计数
struct device *dev; //设备文件
struct tty_driver *driver; //tty驱动
const struct tty_operations *ops; //tty操作函数集
int index;
struct mutex ldisc_mutex;
struct tty_ldisc *ldisc; //线路规程
struct mutex termios_mutex;
spinlock_t ctrl_lock;
struct ktermios *termios, *termios_locked;
struct termiox *termiox;
char name[64]; //名字
struct pid *pgrp;
struct pid *session;
unsigned long flags;
int count;
struct winsize winsize;
unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1;
unsigned char low_latency:1, warned:1;
unsigned char ctrl_status;
unsigned int receive_room;
struct tty_struct *link;
struct fasync_struct *fasync;
struct tty_bufhead buf;
int alt_speed;
wait_queue_head_t write_wait;
wait_queue_head_t read_wait;
struct work_struct hangup_work;
void *disc_data;
void *driver_data;
struct list_head tty_files;
#define N_TTY_BUF_SIZE 4096
unsigned int column;
unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
unsigned char closing:1;
unsigned char echo_overrun:1;
unsigned short minimum_to_wake;
unsigned long overrun_time;
int num_overrun;
unsigned long process_char_map[256/(8*sizeof(unsigned long))];
char *read_buf;
int read_head;
int read_tail;
int read_cnt;
unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))];
unsigned char *echo_buf;
unsigned int echo_pos;
unsigned int echo_cnt;
int canon_data;
unsigned long canon_head;
unsigned int canon_column;
struct mutex atomic_read_lock;
struct mutex atomic_write_lock;
struct mutex output_lock;
struct mutex echo_lock;
unsigned char *write_buf;
int write_cnt;
spinlock_t read_lock;
struct work_struct SAK_work;
struct tty_port *port;
};
4.tty_ldisc线路规程
struct tty_ldisc {
struct tty_ldisc_ops *ops;
atomic_t users;
};
4.1 线路规程操作函数集
struct tty_ldisc_ops {
int magic;
char *name;
int num;
int flags;
int (*open)(struct tty_struct *);
void (*close)(struct tty_struct *);