Add EAGAIN for nonblocking io and poll for file in read_at()

master
Jiajie Chen 6 years ago
parent 22946c699d
commit dcfb02c514

4
kernel/Cargo.lock generated

@ -409,7 +409,7 @@ dependencies = [
[[package]] [[package]]
name = "rcore-fs" name = "rcore-fs"
version = "0.1.0" 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 = [ dependencies = [
"spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -417,7 +417,7 @@ dependencies = [
[[package]] [[package]]
name = "rcore-fs-sfs" name = "rcore-fs-sfs"
version = "0.1.0" 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 = [ dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

@ -175,9 +175,7 @@ pub fn init_driver(dev: &PCIDevice) {
assert!(len as usize <= PAGE_SIZE); assert!(len as usize <= PAGE_SIZE);
let vaddr = phys_to_virt(addr as usize); let vaddr = phys_to_virt(addr as usize);
if let Some(driver) = ahci::init(irq, vaddr, len as usize) { if let Some(driver) = ahci::init(irq, vaddr, len as usize) {
PCI_DRIVERS PCI_DRIVERS.lock().insert(dev.loc, driver);
.lock()
.insert(dev.loc, driver);
} }
} }
} }

@ -50,21 +50,23 @@ impl FileHandle {
return Err(FsError::InvalidParam); // FIXME: => EBADF return Err(FsError::InvalidParam); // FIXME: => EBADF
} }
let mut len: usize = 0; let mut len: usize = 0;
/*
if !self.options.nonblock { if !self.options.nonblock {
// block // block
loop { loop {
len = self.inode.read_at(offset, buf)?; match self.inode.read_at(offset, buf) {
if len > 0 { Ok(read_len) => {
len = read_len;
break; break;
} }
Err(FsError::Again) => {}
Err(err) => {
return Err(err);
}
}
} }
} else { } else {
len = self.inode.read_at(offset, buf)?; len = self.inode.read_at(offset, buf)?;
} }
*/
// TODO: handle block/nonblock correctly
len = self.inode.read_at(offset, buf)?;
Ok(len) Ok(len)
} }

@ -72,6 +72,7 @@ impl INode for Pseudo {
nlinks: 0, nlinks: 0,
uid: 0, uid: 0,
gid: 0, gid: 0,
rdev: 0,
}) })
} }
impl_inode!(); impl_inode!();

@ -95,7 +95,7 @@ impl INode for Stdin {
buf[0] = self.pop() as u8; buf[0] = self.pop() as u8;
Ok(1) Ok(1)
} else { } else {
Ok(0) Err(FsError::Again)
} }
} }
fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize> { fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize> {

@ -64,6 +64,7 @@ impl INode for Vga {
nlinks: 0, nlinks: 0,
uid: 0, uid: 0,
gid: 0, gid: 0,
rdev: 0,
}) })
} }
fn io_control(&self, cmd: u32, data: usize) -> Result<()> { fn io_control(&self, cmd: u32, data: usize) -> Result<()> {

@ -948,6 +948,9 @@ impl From<FsError> for SysError {
FsError::DirNotEmpty => SysError::ENOTEMPTY, FsError::DirNotEmpty => SysError::ENOTEMPTY,
FsError::WrongFs => SysError::EINVAL, FsError::WrongFs => SysError::EINVAL,
FsError::DeviceError => SysError::EIO, FsError::DeviceError => SysError::EIO,
FsError::IOCTLError => SysError::EINVAL,
FsError::NoDevice => SysError::EINVAL,
FsError::Again => SysError::EAGAIN,
} }
} }
} }

@ -1 +1 @@
Subproject commit bf02e72b85784af3555c7abe6b985aefc215023e Subproject commit 4f90dd042bacdb7eee61ae35ab60b9e17bc70cf7
Loading…
Cancel
Save