Support TCSETSW and TCSETSF for ioctl

This commit is contained in:
Jianfeng Jiang
2023-06-14 16:40:27 +08:00
committed by Tate, Hongliang Tian
parent 3eab9cea6e
commit 0018ac4d63
3 changed files with 24 additions and 0 deletions

View File

@ -328,6 +328,11 @@ impl LineDiscipline {
pub fn set_termios(&self, termios: KernelTermios) { pub fn set_termios(&self, termios: KernelTermios) {
*self.termios.lock_irq_disabled() = termios; *self.termios.lock_irq_disabled() = termios;
} }
pub fn drain_input(&self) {
self.current_line.lock().drain();
let _: Vec<_> = self.read_buffer.lock().pop_iter().collect();
}
} }
fn meet_new_line(item: u8, termios: &KernelTermios) -> bool { fn meet_new_line(item: u8, termios: &KernelTermios) -> bool {

View File

@ -114,6 +114,21 @@ impl Device for Tty {
self.ldisc.set_termios(termios); self.ldisc.set_termios(termios);
Ok(0) Ok(0)
} }
IoctlCmd::TCSETSW => {
let termios = read_val_from_user(arg)?;
debug!("set termios = {:?}", termios);
self.ldisc.set_termios(termios);
// TODO: drain output buffer
Ok(0)
}
IoctlCmd::TCSETSF => {
let termios = read_val_from_user(arg)?;
debug!("set termios = {:?}", termios);
self.ldisc.set_termios(termios);
self.ldisc.drain_input();
// TODO: drain output buffer
Ok(0)
}
IoctlCmd::TIOCGWINSZ => { IoctlCmd::TIOCGWINSZ => {
// TODO:get window size // TODO:get window size
Ok(0) Ok(0)

View File

@ -6,6 +6,10 @@ pub enum IoctlCmd {
// Get terminal attributes // Get terminal attributes
TCGETS = 0x5401, TCGETS = 0x5401,
TCSETS = 0x5402, TCSETS = 0x5402,
// Drain the output buffer and set attributes
TCSETSW = 0x5403,
// Drain the output buffer, and discard pending input, and set attributes
TCSETSF = 0x5404,
// Get the process group ID of the foreground process group on this terminal // Get the process group ID of the foreground process group on this terminal
TIOCGPGRP = 0x540f, TIOCGPGRP = 0x540f,
// Set the foreground process group ID of this terminal. // Set the foreground process group ID of this terminal.