tty_operations
生活随笔
收集整理的這篇文章主要介紹了
tty_operations
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
struct tty_operations {struct tty_struct * (*lookup)(struct tty_driver *driver,struct inode *inode, int idx);
//返回對應的tty設備, 若為NULL則返回ERR_PTR, 在tty_mutex函數中調用
//該項可選,默認為使用ttys arrayint (*install)(struct tty_driver *driver, struct tty_struct *tty);
//install一個tty設備到tty驅動的內部表,與lookup和remove法相關聯
//該項可選,默認為使用ttys arrayvoid (*remove)(struct tty_driver *driver, struct tty_struct *tty);
//從tty驅動的內部表,remove一個關閉了的tty設備,與lookup和remove法相關聯
//該項可選,默認為使用ttys arrayint (*open)(struct tty_struct * tty, struct file * filp);
//當一個特別的tty設備open的時候,將調用該例程;該例程是強制性的,若該例程沒有加入operations,open tty的時候將返回ENODEV
//必須使用的方法void (*close)(struct tty_struct * tty, struct file * filp);
//當tty設備關閉時調用
//必須使用的方法void (*shutdown)(struct tty_struct *tty);
//在tty在關閉時,若仍持有一個帶鎖的特殊設備,需要調用該例程,想想我們經常使用的sudo shutdown -r/h/... now就明白了
//它執行在tty設備釋放資源之前,所以可能執行在另一個tty設備持有kref的時候void (*cleanup)(struct tty_struct *tty);
//當一個tty設備在最后一次被關閉和釋放資源時,異步地調用該例程,這個例程可以看成shutdown的可休眠的第二部分int (*write)(struct tty_struct * tty,const unsigned char *buf, int count);
//寫函數,不多說
//可選使用:在需要寫的設備中int (*put_char)(struct tty_struct *tty, unsigned char ch);
//當內核想寫單個字符到tty設備時,調用該例程(其實也可以調用write例程,調用時置count為1即可)
//可選使用:若設備在調用時未提供將使用write法
//注意:不要直接調用該例程,而應調用tty_put_charvoid (*flush_chars)(struct tty_struct *tty);
//這個例程調用在tty使用put_char輸出很多個字符后
//可選
//注意:不要直接調用,調用tty_driver_flush_charsint (*write_room)(struct tty_struct *tty);
//這個例程返回tty設備將被寫入的字符隊列長度
//這個數字受輸出緩沖區和輸出流的變化影響
//當有write函數時需要
//注意:不要直接調用,調用tty_write_roomint (*chars_in_buffer)(struct tty_struct *tty);
//在buffer區中的字符int (*ioctl)(struct tty_struct *tty,unsigned int cmd, unsigned long arg);
//該例程允許tty設備實施設備特殊的ioctl,若ioctl的數值在cmd中未被設備檢測到,將返回ENOIOCTLCMD
//可選long (*compat_ioctl)(struct tty_struct *tty,unsigned int cmd, unsigned long arg);
//在64位系統中執行32位的ioctl的例程
//可選void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
//該例程在設備的termios設置改變時通知驅動
//可選:在持termios lock的時候調用void (*throttle)(struct tty_struct * tty);
//當線程規劃快滿的時候提醒驅動程序,提示不要再輸入字符到tty中
//可選:通常在tty_throttle()函數中獲得termios lock時調用
void (*unthrottle)(struct tty_struct * tty);
//提醒驅動程序,可以輸入字符到tty中,因為線程規劃空間夠用
//可選:通常在tty_unthrottle()函數中,獲得termios lock時調用void (*stop)(struct tty_struct *tty);
//提醒驅動,停止輸出字符
//可選,注意:不是調用stop_ttyvoid (*start)(struct tty_struct *tty);
//提醒驅動,接著輸入字符
//可選,助于:不是調用start_ttyvoid (*hangup)(struct tty_struct *tty);
//掛起tty,可選int (*break_ctl)(struct tty_struct *tty, int state);
//打開或關閉RS-232口,state為-1則打開,state為0則關閉
//若該函數執行,則高一級的tty將處理四種ioctls:TCSBRK, TCSBRKP, TIOCSBRK, TIOCCBRK
//如果驅動程序設置了TTY_DRIVER_HARDWARE_BREAK,接著接口將被稱作實際時間,而硬件延遲工作
//可選:需要收到TCSBRK/BRKP/etcvoid (*flush_buffer)(struct tty_struct *tty);
//在使用put_char()寫入一串字符后,該函數被內核調用
//可選
//注意:調用是應為tty_driver_flush_buffervoid (*set_ldisc)(struct tty_struct *tty);
//該例程在設備的termios設置改變時通知驅動
//可選:有BKL (currently)時調用void (*wait_until_sent)(struct tty_struct *tty, int timeout);
//該例程等待設備將其所有字符寫入傳輸FIFO中
//可選:若設備有FIFO則需要
//注意:通常使用為tty_wait_until_sentvoid (*send_xchar)(struct tty_struct *tty, char ch);
//該例程發送一個大端的XON/XOFF給驅動程序
//可選:如果不提供,之后寫函數將被原子鎖調用來保持它的序列性int (*tiocmget)(struct tty_struct *tty);
//獲得tty的線路設置int (*tiocmset)(struct tty_struct *tty,unsigned int set, unsigned int clear);
//設置tty的線路設置int (*resize)(struct tty_struct *tty, struct winsize *ws);
//當一個termios的請求將改變 請求終端幾何(requested terminal geometry)時調用
//可選:默認行為是 無錯誤地更新termios structure......int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
//當收到一個termiox基于ioctl的信號時調用,將用戶空間的請求向下傳遞
//這個函數只有當tty包含tty->termiox指針的時候才會執行
//可選:持有termios lock的時候調用int (*get_icount)(struct tty_struct *tty,struct serial_icounter_struct *icount);
//當設備收到一個TIOCGICOUNT的信號時調用,將一個內核結構傳入使其完成。
//這個函數只有在提供的時候調用,否則將返回EINVAL
#ifdef CONFIG_CONSOLE_POLLint (*poll_init)(struct tty_driver *driver, int line, char *options);int (*poll_get_char)(struct tty_driver *driver, int line);void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
#endifconst struct file_operations *proc_fops;
};
?
?
?
轉載于:https://www.cnblogs.com/plinx/archive/2013/02/12/2910625.html
總結
以上是生活随笔為你收集整理的tty_operations的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线程高级应用-心得9-空中网的三道面试题
- 下一篇: 为什么我们不要 .NET 程序员