diff --git a/crates/wasi-c2/src/virt/pipe.rs b/crates/wasi-c2/src/virt/pipe.rs index 2ae7edaedc..d8b1b4f8d1 100644 --- a/crates/wasi-c2/src/virt/pipe.rs +++ b/crates/wasi-c2/src/virt/pipe.rs @@ -97,10 +97,10 @@ impl From<&str> for ReadPipe> { impl FileIoExt for ReadPipe { fn advise(&self, offset: u64, len: u64, advice: Advice) -> io::Result<()> { - todo!() // advice cant be taken. do we ignore or throw error? + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn allocate(&self, offset: u64, len: u64) -> io::Result<()> { - todo!() // error: requires write, seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read(&self, buf: &mut [u8]) -> io::Result { self.borrow().read(buf) @@ -109,10 +109,10 @@ impl FileIoExt for ReadPipe { self.borrow().read_exact(buf) } fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> io::Result<()> { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_vectored(&self, bufs: &mut [io::IoSliceMut]) -> io::Result { self.borrow().read_vectored(bufs) @@ -124,37 +124,37 @@ impl FileIoExt for ReadPipe { self.borrow().read_to_string(buf) } fn bytes(self) -> io::Bytes { - todo!() // impossible to construct this concrete iterator, fix in system-interface + panic!("impossible to implement, removing from trait") } fn take(self, limit: u64) -> io::Take { - todo!() // impossible to construct this concrete iterator, fix in system-interface + panic!("impossible to implement, removing from trait") } fn write(&self, buf: &[u8]) -> io::Result { - todo!() // error: requires write + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_all(&self, buf: &[u8]) -> io::Result<()> { - todo!() // error: requires write + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { - todo!() // error: requires write, seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_all_at(&self, buf: &[u8], offset: u64) -> io::Result<()> { - todo!() // error: requires write, seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_vectored(&self, bufs: &[io::IoSlice]) -> io::Result { - todo!() // error: requires write + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_fmt(&mut self, fmt: std::fmt::Arguments) -> io::Result<()> { - todo!() // error: requires write + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn flush(&self) -> io::Result<()> { - todo!() // error: requires write + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } - fn seek(&self, pos: std::io::SeekFrom) -> io::Result { - todo!() // error: requires seek + fn seek(&self, _pos: std::io::SeekFrom) -> io::Result { + Err(std::io::Error::from_raw_os_error(libc::ESPIPE)) } fn stream_position(&self) -> io::Result { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::ESPIPE)) } } @@ -178,22 +178,31 @@ impl WasiFile for ReadPipe { Ok(Filetype::CharacterDevice) // XXX wrong } fn get_fdflags(&self) -> Result { - todo!() // do later + Ok(FdFlags::empty()) } fn set_fdflags(&self, _fdflags: FdFlags) -> Result<(), Error> { - todo!() + Err(Error::Perm) } fn get_oflags(&self) -> Result { - todo!() // do later + Ok(OFlags::empty()) } fn set_oflags(&self, _flags: OFlags) -> Result<(), Error> { - todo!() // impossible? + Err(Error::Perm) } fn get_filestat(&self) -> Result { - todo!() // do later + Ok(Filestat { + device_id: 0, + inode: 0, + filetype: self.get_filetype()?, + nlink: 0, + size: 0, // XXX no way to get a size out of a Read :( + atim: None, + mtim: None, + ctim: None, + }) } fn set_filestat_size(&self, _size: u64) -> Result<(), Error> { - todo!() // impossible? + Err(Error::Perm) } } @@ -253,37 +262,37 @@ impl WritePipe>> { impl FileIoExt for WritePipe { fn advise(&self, offset: u64, len: u64, advice: Advice) -> io::Result<()> { - todo!() + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn allocate(&self, offset: u64, len: u64) -> io::Result<()> { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read(&self, buf: &mut [u8]) -> io::Result { - todo!() // error: requires read + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_exact(&self, buf: &mut [u8]) -> io::Result<()> { - todo!() // error: requires read + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { - todo!() // error: requires read, seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> io::Result<()> { - todo!() // error: requires read, seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_vectored(&self, bufs: &mut [io::IoSliceMut]) -> io::Result { - todo!() // error: requires read + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_to_end(&self, buf: &mut Vec) -> io::Result { - todo!() // error: requires read + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn read_to_string(&self, buf: &mut String) -> io::Result { - todo!() // error: requires read + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn bytes(self) -> io::Bytes { - todo!() // error: requires read + todo!() // removing from trait } fn take(self, limit: u64) -> io::Take { - todo!() // error::requires read + todo!() // removing from trait } fn write(&self, buf: &[u8]) -> io::Result { self.borrow().write(buf) @@ -292,10 +301,10 @@ impl FileIoExt for WritePipe { self.borrow().write_all(buf) } fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_all_at(&self, buf: &[u8], offset: u64) -> io::Result<()> { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::EBADF)) } fn write_vectored(&self, bufs: &[io::IoSlice]) -> io::Result { self.borrow().write_vectored(bufs) @@ -307,10 +316,10 @@ impl FileIoExt for WritePipe { self.borrow().flush() } fn seek(&self, pos: std::io::SeekFrom) -> io::Result { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::ESPIPE)) } fn stream_position(&self) -> io::Result { - todo!() // error: requires seek + Err(std::io::Error::from_raw_os_error(libc::ESPIPE)) } } @@ -335,21 +344,30 @@ impl WasiFile for WritePipe { Ok(Filetype::CharacterDevice) // XXX } fn get_fdflags(&self) -> Result { - todo!() + Ok(FdFlags::APPEND) } fn set_fdflags(&self, _fdflags: FdFlags) -> Result<(), Error> { - todo!() + Err(Error::Perm) } fn get_oflags(&self) -> Result { - todo!() + Ok(OFlags::empty()) } fn set_oflags(&self, _flags: OFlags) -> Result<(), Error> { - todo!() + Err(Error::Perm) } fn get_filestat(&self) -> Result { - todo!() + Ok(Filestat { + device_id: 0, + inode: 0, + filetype: self.get_filetype()?, + nlink: 0, + size: 0, // XXX no way to get a size out of a Write :( + atim: None, + mtim: None, + ctim: None, + }) } fn set_filestat_size(&self, _size: u64) -> Result<(), Error> { - todo!() + Err(Error::Perm) } }