Skip to content

Commit febd2fe

Browse files
committed
tty: Implement TCFLSH
1 parent 7244997 commit febd2fe

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

kernel/src/device/tty/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ impl FileOps for TtyFileOps {
631631
let new_termios = ptr.read().ok_or(Errno::EFAULT)?;
632632
self.tty.ldisc.lock().termios = new_termios;
633633
}
634+
uapi::ioctls::TCFLSH => {
635+
let queue = arg.value();
636+
if queue != TCIFLUSH && queue != TCOFLUSH && queue != TCIOFLUSH {
637+
return Err(Errno::EINVAL);
638+
}
639+
if queue == TCIFLUSH || queue == TCIOFLUSH {
640+
let mut ldisc = self.tty.ldisc.lock();
641+
ldisc.read_buf.clear();
642+
ldisc.canon_buf.clear();
643+
}
644+
}
634645
uapi::ioctls::TIOCGWINSZ => {
635646
let mut ptr = UserPtr::new(arg);
636647
let ws = *self.tty.winsize.lock();

kernel/src/uapi/termios.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ pub const NOFLSH: u32 = 0o000200;
9797
pub const TOSTOP: u32 = 0o000400;
9898
pub const IEXTEN: u32 = 0o100000;
9999

100+
pub const TCIFLUSH: usize = 0;
101+
pub const TCOFLUSH: usize = 1;
102+
pub const TCIOFLUSH: usize = 2;
103+
100104
pub const EXTA: u32 = 0o000016;
101105
pub const EXTB: u32 = 0o000017;
102106
pub const CBAUD: u32 = 0o010017;

0 commit comments

Comments
 (0)