From dcfb02c51443d9a35800ce37f188000588120865 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Fri, 24 May 2019 20:53:13 +0800 Subject: [PATCH] Add EAGAIN for nonblocking io and poll for file in read_at() --- kernel/Cargo.lock | 4 ++-- kernel/src/drivers/bus/pci.rs | 4 +--- kernel/src/fs/file.rs | 16 +++++++++------- kernel/src/fs/file_like.rs | 2 +- kernel/src/fs/pseudo.rs | 1 + kernel/src/fs/stdio.rs | 2 +- kernel/src/fs/vga.rs | 1 + kernel/src/syscall/fs.rs | 3 +++ user | 2 +- 9 files changed, 20 insertions(+), 15 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index b4870cf..f95c60c 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -409,7 +409,7 @@ dependencies = [ [[package]] name = "rcore-fs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs#585eb6197aa687320618ee8c3c550a4e32aa9d15" +source = "git+https://github.com/rcore-os/rcore-fs#ee0d0b31a1cea4c905100cef501a3bc522ded00d" dependencies = [ "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -417,7 +417,7 @@ dependencies = [ [[package]] name = "rcore-fs-sfs" version = "0.1.0" -source = "git+https://github.com/rcore-os/rcore-fs#585eb6197aa687320618ee8c3c550a4e32aa9d15" +source = "git+https://github.com/rcore-os/rcore-fs#ee0d0b31a1cea4c905100cef501a3bc522ded00d" dependencies = [ "bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/kernel/src/drivers/bus/pci.rs b/kernel/src/drivers/bus/pci.rs index 48a254f..c122646 100644 --- a/kernel/src/drivers/bus/pci.rs +++ b/kernel/src/drivers/bus/pci.rs @@ -175,9 +175,7 @@ pub fn init_driver(dev: &PCIDevice) { assert!(len as usize <= PAGE_SIZE); let vaddr = phys_to_virt(addr as usize); if let Some(driver) = ahci::init(irq, vaddr, len as usize) { - PCI_DRIVERS - .lock() - .insert(dev.loc, driver); + PCI_DRIVERS.lock().insert(dev.loc, driver); } } } diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index 538b53c..1f409a0 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -50,21 +50,23 @@ impl FileHandle { return Err(FsError::InvalidParam); // FIXME: => EBADF } let mut len: usize = 0; - /* if !self.options.nonblock { // block loop { - len = self.inode.read_at(offset, buf)?; - if len > 0 { - break; + match self.inode.read_at(offset, buf) { + Ok(read_len) => { + len = read_len; + break; + } + Err(FsError::Again) => {} + Err(err) => { + return Err(err); + } } } } else { len = self.inode.read_at(offset, buf)?; } - */ - // TODO: handle block/nonblock correctly - len = self.inode.read_at(offset, buf)?; Ok(len) } diff --git a/kernel/src/fs/file_like.rs b/kernel/src/fs/file_like.rs index d489e01..bd45dc8 100644 --- a/kernel/src/fs/file_like.rs +++ b/kernel/src/fs/file_like.rs @@ -32,7 +32,7 @@ impl FileLike { } pub fn ioctl(&mut self, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult { match request { - // TODO: place flags & path in FileLike in stead of FileHandle/Socket + // TODO: place flags & path in FileLike instead of FileHandle/Socket FIOCLEX => Ok(0), FIONBIO => Ok(0), _ => { diff --git a/kernel/src/fs/pseudo.rs b/kernel/src/fs/pseudo.rs index fdcc535..273a200 100644 --- a/kernel/src/fs/pseudo.rs +++ b/kernel/src/fs/pseudo.rs @@ -72,6 +72,7 @@ impl INode for Pseudo { nlinks: 0, uid: 0, gid: 0, + rdev: 0, }) } impl_inode!(); diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index fae5dc7..a3f84a1 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -95,7 +95,7 @@ impl INode for Stdin { buf[0] = self.pop() as u8; Ok(1) } else { - Ok(0) + Err(FsError::Again) } } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index b3faa6b..3f34116 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -64,6 +64,7 @@ impl INode for Vga { nlinks: 0, uid: 0, gid: 0, + rdev: 0, }) } fn io_control(&self, cmd: u32, data: usize) -> Result<()> { diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 5e3c46f..27f8464 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -948,6 +948,9 @@ impl From for SysError { FsError::DirNotEmpty => SysError::ENOTEMPTY, FsError::WrongFs => SysError::EINVAL, FsError::DeviceError => SysError::EIO, + FsError::IOCTLError => SysError::EINVAL, + FsError::NoDevice => SysError::EINVAL, + FsError::Again => SysError::EAGAIN, } } } diff --git a/user b/user index bf02e72..4f90dd0 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit bf02e72b85784af3555c7abe6b985aefc215023e +Subproject commit 4f90dd042bacdb7eee61ae35ab60b9e17bc70cf7