kernel_thread/fs/devfs/
stdio.rsuse fs::INodeInterface;
use libc_core::types::StatMode;
use sel4::debug_print;
use syscalls::Errno;
use crate::device::uart::get_char;
pub struct StdConsole(u8);
impl StdConsole {
pub const fn new(idx: u8) -> Self {
Self(idx)
}
}
impl INodeInterface for StdConsole {
fn readat(&self, _offset: usize, buffer: &mut [u8]) -> vfscore::VfsResult<usize> {
if self.0 != 0 && self.0 <= 2 {
return Err(Errno::EPERM);
}
match get_char() {
Some(c) => {
buffer[0] = c;
Ok(1)
}
None => Ok(0),
}
}
fn writeat(&self, _offset: usize, buffer: &[u8]) -> vfscore::VfsResult<usize> {
if self.0 == 0 {
return Err(Errno::EPERM);
}
buffer.iter().for_each(|x| debug_print!("{}", *x as char));
Ok(buffer.len())
}
fn stat(&self, stat: &mut libc_core::types::Stat) -> vfscore::VfsResult<()> {
stat.dev = 0;
stat.ino = 1; stat.mode = StatMode::CHAR; stat.nlink = 1;
stat.uid = 1000;
stat.gid = 1000;
stat.size = 0;
stat.blksize = 512;
stat.blocks = 0;
stat.rdev = 0; Ok(())
}
}