virtfs: import types from handle, drop types:: prefix

This commit is contained in:
Pat Hickey
2020-09-14 16:33:46 -07:00
parent 4763678be2
commit b72d5de86c
2 changed files with 100 additions and 128 deletions

View File

@@ -1,5 +1,8 @@
use crate::handle::{Handle, HandleRights}; use crate::handle::{
use crate::wasi::{self, types, RightsExt}; Advice, Dircookie, Dirent, Fdflags, Filesize, Filestat, Filetype, Fstflags, Handle,
HandleRights, Oflags, Rights, RightsExt, Size, DIRCOOKIE_START,
};
use crate::sched::Timestamp;
use crate::{Error, Result}; use crate::{Error, Result};
use std::any::Any; use std::any::Any;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@@ -39,44 +42,44 @@ pub(crate) trait MovableFile {
pub trait FileContents { pub trait FileContents {
/// The implementation-defined maximum size of the store corresponding to a `FileContents` /// The implementation-defined maximum size of the store corresponding to a `FileContents`
/// implementation. /// implementation.
fn max_size(&self) -> types::Filesize; fn max_size(&self) -> Filesize;
/// The current number of bytes this `FileContents` describes. /// The current number of bytes this `FileContents` describes.
fn size(&self) -> types::Filesize; fn size(&self) -> Filesize;
/// Resize to hold `new_size` number of bytes, or error if this is not possible. /// Resize to hold `new_size` number of bytes, or error if this is not possible.
fn resize(&mut self, new_size: types::Filesize) -> Result<()>; fn resize(&mut self, new_size: Filesize) -> Result<()>;
/// Write a list of `IoSlice` starting at `offset`. `offset` plus the total size of all `iovs` /// Write a list of `IoSlice` starting at `offset`. `offset` plus the total size of all `iovs`
/// is guaranteed to not exceed `max_size`. Implementations must not indicate more bytes have /// is guaranteed to not exceed `max_size`. Implementations must not indicate more bytes have
/// been written than can be held by `iovs`. /// been written than can be held by `iovs`.
fn pwritev(&mut self, iovs: &[io::IoSlice], offset: types::Filesize) -> Result<usize>; fn pwritev(&mut self, iovs: &[io::IoSlice], offset: Filesize) -> Result<usize>;
/// Read from the file from `offset`, filling a list of `IoSlice`. The returend size must not /// Read from the file from `offset`, filling a list of `IoSlice`. The returend size must not
/// be more than the capactiy of `iovs`, and must not exceed the limit reported by /// be more than the capactiy of `iovs`, and must not exceed the limit reported by
/// `self.max_size()`. /// `self.max_size()`.
fn preadv(&self, iovs: &mut [io::IoSliceMut], offset: types::Filesize) -> Result<usize>; fn preadv(&self, iovs: &mut [io::IoSliceMut], offset: Filesize) -> Result<usize>;
/// Write contents from `buf` to this file starting at `offset`. `offset` plus the length of /// Write contents from `buf` to this file starting at `offset`. `offset` plus the length of
/// `buf` is guaranteed to not exceed `max_size`. Implementations must not indicate more bytes /// `buf` is guaranteed to not exceed `max_size`. Implementations must not indicate more bytes
/// have been written than the size of `buf`. /// have been written than the size of `buf`.
fn pwrite(&mut self, buf: &[u8], offset: types::Filesize) -> Result<usize>; fn pwrite(&mut self, buf: &[u8], offset: Filesize) -> Result<usize>;
/// Read from the file at `offset`, filling `buf`. The returned size must not be more than the /// Read from the file at `offset`, filling `buf`. The returned size must not be more than the
/// capacity of `buf`, and `offset` plus the returned size must not exceed `self.max_size()`. /// capacity of `buf`, and `offset` plus the returned size must not exceed `self.max_size()`.
fn pread(&self, buf: &mut [u8], offset: types::Filesize) -> Result<usize>; fn pread(&self, buf: &mut [u8], offset: Filesize) -> Result<usize>;
} }
impl FileContents for VecFileContents { impl FileContents for VecFileContents {
fn max_size(&self) -> types::Filesize { fn max_size(&self) -> Filesize {
std::usize::MAX as types::Filesize std::usize::MAX as Filesize
} }
fn size(&self) -> types::Filesize { fn size(&self) -> Filesize {
self.content.len() as types::Filesize self.content.len() as Filesize
} }
fn resize(&mut self, new_size: types::Filesize) -> Result<()> { fn resize(&mut self, new_size: Filesize) -> Result<()> {
let new_size: usize = new_size.try_into().map_err(|_| Error::Inval)?; let new_size: usize = new_size.try_into().map_err(|_| Error::Inval)?;
self.content.resize(new_size, 0); self.content.resize(new_size, 0);
Ok(()) Ok(())
} }
fn preadv(&self, iovs: &mut [io::IoSliceMut], offset: types::Filesize) -> Result<usize> { fn preadv(&self, iovs: &mut [io::IoSliceMut], offset: Filesize) -> Result<usize> {
let mut read_total = 0usize; let mut read_total = 0usize;
for iov in iovs.iter_mut() { for iov in iovs.iter_mut() {
let skip: u64 = read_total.try_into().map_err(|_| Error::Inval)?; let skip: u64 = read_total.try_into().map_err(|_| Error::Inval)?;
@@ -86,7 +89,7 @@ impl FileContents for VecFileContents {
Ok(read_total) Ok(read_total)
} }
fn pwritev(&mut self, iovs: &[io::IoSlice], offset: types::Filesize) -> Result<usize> { fn pwritev(&mut self, iovs: &[io::IoSlice], offset: Filesize) -> Result<usize> {
let mut write_total = 0usize; let mut write_total = 0usize;
for iov in iovs.iter() { for iov in iovs.iter() {
let skip: u64 = write_total.try_into().map_err(|_| Error::Inval)?; let skip: u64 = write_total.try_into().map_err(|_| Error::Inval)?;
@@ -96,7 +99,7 @@ impl FileContents for VecFileContents {
Ok(write_total) Ok(write_total)
} }
fn pread(&self, buf: &mut [u8], offset: types::Filesize) -> Result<usize> { fn pread(&self, buf: &mut [u8], offset: Filesize) -> Result<usize> {
trace!(buffer_length = buf.len(), offset = offset, "pread"); trace!(buffer_length = buf.len(), offset = offset, "pread");
let offset: usize = offset.try_into().map_err(|_| Error::Inval)?; let offset: usize = offset.try_into().map_err(|_| Error::Inval)?;
@@ -109,7 +112,7 @@ impl FileContents for VecFileContents {
Ok(read_count) Ok(read_count)
} }
fn pwrite(&mut self, buf: &[u8], offset: types::Filesize) -> Result<usize> { fn pwrite(&mut self, buf: &[u8], offset: Filesize) -> Result<usize> {
let offset: usize = offset.try_into().map_err(|_| Error::Inval)?; let offset: usize = offset.try_into().map_err(|_| Error::Inval)?;
let write_end = offset.checked_add(buf.len()).ok_or(Error::Fbig)?; let write_end = offset.checked_add(buf.len()).ok_or(Error::Fbig)?;
@@ -141,9 +144,9 @@ impl VecFileContents {
/// of data and permissions on a filesystem. /// of data and permissions on a filesystem.
pub struct InMemoryFile { pub struct InMemoryFile {
rights: Cell<HandleRights>, rights: Cell<HandleRights>,
cursor: Cell<types::Filesize>, cursor: Cell<Filesize>,
parent: Rc<RefCell<Option<Box<dyn Handle>>>>, parent: Rc<RefCell<Option<Box<dyn Handle>>>>,
fd_flags: Cell<types::Fdflags>, fd_flags: Cell<Fdflags>,
data: Rc<RefCell<Box<dyn FileContents>>>, data: Rc<RefCell<Box<dyn FileContents>>>,
} }
@@ -154,14 +157,14 @@ impl InMemoryFile {
pub fn new(contents: Box<dyn FileContents>) -> Self { pub fn new(contents: Box<dyn FileContents>) -> Self {
let rights = HandleRights::new( let rights = HandleRights::new(
types::Rights::regular_file_base(), Rights::regular_file_base(),
types::Rights::regular_file_inheriting(), Rights::regular_file_inheriting(),
); );
let rights = Cell::new(rights); let rights = Cell::new(rights);
Self { Self {
rights, rights,
cursor: Cell::new(0), cursor: Cell::new(0),
fd_flags: Cell::new(types::Fdflags::empty()), fd_flags: Cell::new(Fdflags::empty()),
parent: Rc::new(RefCell::new(None)), parent: Rc::new(RefCell::new(None)),
data: Rc::new(RefCell::new(contents)), data: Rc::new(RefCell::new(contents)),
} }
@@ -187,8 +190,8 @@ impl Handle for InMemoryFile {
data: Rc::clone(&self.data), data: Rc::clone(&self.data),
})) }))
} }
fn get_file_type(&self) -> types::Filetype { fn get_file_type(&self) -> Filetype {
types::Filetype::RegularFile Filetype::RegularFile
} }
fn get_rights(&self) -> HandleRights { fn get_rights(&self) -> HandleRights {
self.rights.get() self.rights.get()
@@ -197,16 +200,11 @@ impl Handle for InMemoryFile {
self.rights.set(rights) self.rights.set(rights)
} }
// FdOps // FdOps
fn advise( fn advise(&self, _advice: Advice, _offset: Filesize, _len: Filesize) -> Result<()> {
&self,
_advice: types::Advice,
_offset: types::Filesize,
_len: types::Filesize,
) -> Result<()> {
// we'll just ignore advice for now, unless it's totally invalid // we'll just ignore advice for now, unless it's totally invalid
Ok(()) Ok(())
} }
fn allocate(&self, offset: types::Filesize, len: types::Filesize) -> Result<()> { fn allocate(&self, offset: Filesize, len: Filesize) -> Result<()> {
let new_limit = offset.checked_add(len).ok_or(Error::Fbig)?; let new_limit = offset.checked_add(len).ok_or(Error::Fbig)?;
let mut data = self.data.borrow_mut(); let mut data = self.data.borrow_mut();
@@ -220,15 +218,15 @@ impl Handle for InMemoryFile {
Ok(()) Ok(())
} }
fn fdstat_get(&self) -> Result<types::Fdflags> { fn fdstat_get(&self) -> Result<Fdflags> {
Ok(self.fd_flags.get()) Ok(self.fd_flags.get())
} }
fn fdstat_set_flags(&self, fdflags: types::Fdflags) -> Result<()> { fn fdstat_set_flags(&self, fdflags: Fdflags) -> Result<()> {
self.fd_flags.set(fdflags); self.fd_flags.set(fdflags);
Ok(()) Ok(())
} }
fn filestat_get(&self) -> Result<types::Filestat> { fn filestat_get(&self) -> Result<Filestat> {
let stat = types::Filestat { let stat = Filestat {
dev: 0, dev: 0,
ino: 0, ino: 0,
nlink: 0, nlink: 0,
@@ -240,17 +238,17 @@ impl Handle for InMemoryFile {
}; };
Ok(stat) Ok(stat)
} }
fn filestat_set_size(&self, st_size: types::Filesize) -> Result<()> { fn filestat_set_size(&self, st_size: Filesize) -> Result<()> {
let mut data = self.data.borrow_mut(); let mut data = self.data.borrow_mut();
if st_size > data.max_size() { if st_size > data.max_size() {
return Err(Error::Fbig); return Err(Error::Fbig);
} }
data.resize(st_size) data.resize(st_size)
} }
fn preadv(&self, buf: &mut [io::IoSliceMut], offset: types::Filesize) -> Result<usize> { fn preadv(&self, buf: &mut [io::IoSliceMut], offset: Filesize) -> Result<usize> {
self.data.borrow_mut().preadv(buf, offset) self.data.borrow_mut().preadv(buf, offset)
} }
fn pwritev(&self, buf: &[io::IoSlice], offset: types::Filesize) -> Result<usize> { fn pwritev(&self, buf: &[io::IoSlice], offset: Filesize) -> Result<usize> {
self.data.borrow_mut().pwritev(buf, offset) self.data.borrow_mut().pwritev(buf, offset)
} }
fn read_vectored(&self, iovs: &mut [io::IoSliceMut]) -> Result<usize> { fn read_vectored(&self, iovs: &mut [io::IoSliceMut]) -> Result<usize> {
@@ -262,7 +260,7 @@ impl Handle for InMemoryFile {
self.cursor.set(update); self.cursor.set(update);
Ok(read) Ok(read)
} }
fn seek(&self, offset: SeekFrom) -> Result<types::Filesize> { fn seek(&self, offset: SeekFrom) -> Result<Filesize> {
let content_len = self.data.borrow().size(); let content_len = self.data.borrow().size();
match offset { match offset {
SeekFrom::Current(offset) => { SeekFrom::Current(offset) => {
@@ -297,7 +295,7 @@ impl Handle for InMemoryFile {
trace!("write_vectored(iovs={:?})", iovs); trace!("write_vectored(iovs={:?})", iovs);
let mut data = self.data.borrow_mut(); let mut data = self.data.borrow_mut();
let append_mode = self.fd_flags.get().contains(&types::Fdflags::APPEND); let append_mode = self.fd_flags.get().contains(&Fdflags::APPEND);
trace!(" | fd_flags={}", self.fd_flags.get()); trace!(" | fd_flags={}", self.fd_flags.get());
// If this file is in append mode, we write to the end. // If this file is in append mode, we write to the end.
@@ -310,7 +308,7 @@ impl Handle for InMemoryFile {
let max_size = iovs let max_size = iovs
.iter() .iter()
.map(|iov| { .map(|iov| {
let cast_iovlen: types::Size = iov let cast_iovlen: Size = iov
.len() .len()
.try_into() .try_into()
.expect("iovec are bounded by wasi max sizes"); .expect("iovec are bounded by wasi max sizes");
@@ -319,7 +317,7 @@ impl Handle for InMemoryFile {
.fold(Some(0u32), |len, iov| len.and_then(|x| x.checked_add(iov))) .fold(Some(0u32), |len, iov| len.and_then(|x| x.checked_add(iov)))
.expect("write_vectored will not be called with invalid iovs"); .expect("write_vectored will not be called with invalid iovs");
if let Some(end) = write_start.checked_add(max_size as types::Filesize) { if let Some(end) = write_start.checked_add(max_size as Filesize) {
if end > data.max_size() { if end > data.max_size() {
return Err(Error::Fbig); return Err(Error::Fbig);
} }
@@ -348,10 +346,10 @@ impl Handle for InMemoryFile {
path: &str, path: &str,
_read: bool, _read: bool,
_write: bool, _write: bool,
oflags: types::Oflags, oflags: Oflags,
_fd_flags: types::Fdflags, _fd_flags: Fdflags,
) -> Result<Box<dyn Handle>> { ) -> Result<Box<dyn Handle>> {
if oflags.contains(&types::Oflags::DIRECTORY) { if oflags.contains(&Oflags::DIRECTORY) {
tracing::trace!( tracing::trace!(
"InMemoryFile::openat was passed oflags DIRECTORY, but {:?} is a file.", "InMemoryFile::openat was passed oflags DIRECTORY, but {:?} is a file.",
path path
@@ -411,10 +409,7 @@ pub struct VirtualDir {
impl VirtualDir { impl VirtualDir {
pub fn new(writable: bool) -> Self { pub fn new(writable: bool) -> Self {
let rights = HandleRights::new( let rights = HandleRights::new(Rights::directory_base(), Rights::directory_inheriting());
types::Rights::directory_base(),
types::Rights::directory_inheriting(),
);
let rights = Cell::new(rights); let rights = Cell::new(rights);
Self { Self {
rights, rights,
@@ -480,8 +475,8 @@ impl Handle for VirtualDir {
entries: Rc::clone(&self.entries), entries: Rc::clone(&self.entries),
})) }))
} }
fn get_file_type(&self) -> types::Filetype { fn get_file_type(&self) -> Filetype {
types::Filetype::Directory Filetype::Directory
} }
fn get_rights(&self) -> HandleRights { fn get_rights(&self) -> HandleRights {
self.rights.get() self.rights.get()
@@ -490,8 +485,8 @@ impl Handle for VirtualDir {
self.rights.set(rights) self.rights.set(rights)
} }
// FdOps // FdOps
fn filestat_get(&self) -> Result<types::Filestat> { fn filestat_get(&self) -> Result<Filestat> {
let stat = types::Filestat { let stat = Filestat {
dev: 0, dev: 0,
ino: 0, ino: 0,
nlink: 0, nlink: 0,
@@ -505,36 +500,36 @@ impl Handle for VirtualDir {
} }
fn readdir( fn readdir(
&self, &self,
cookie: types::Dircookie, cookie: Dircookie,
) -> Result<Box<dyn Iterator<Item = Result<(types::Dirent, String)>>>> { ) -> Result<Box<dyn Iterator<Item = Result<(Dirent, String)>>>> {
struct VirtualDirIter { struct VirtualDirIter {
start: u32, start: u32,
entries: Rc<RefCell<HashMap<PathBuf, Box<dyn Handle>>>>, entries: Rc<RefCell<HashMap<PathBuf, Box<dyn Handle>>>>,
} }
impl Iterator for VirtualDirIter { impl Iterator for VirtualDirIter {
type Item = Result<(types::Dirent, String)>; type Item = Result<(Dirent, String)>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
tracing::trace!("VirtualDirIter::next continuing from {}", self.start); tracing::trace!("VirtualDirIter::next continuing from {}", self.start);
if self.start == SELF_DIR_COOKIE { if self.start == SELF_DIR_COOKIE {
self.start += 1; self.start += 1;
let name = ".".to_owned(); let name = ".".to_owned();
let dirent = types::Dirent { let dirent = Dirent {
d_next: self.start as u64, d_next: self.start as u64,
d_ino: 0, d_ino: 0,
d_namlen: name.len() as _, d_namlen: name.len() as _,
d_type: types::Filetype::Directory, d_type: Filetype::Directory,
}; };
return Some(Ok((dirent, name))); return Some(Ok((dirent, name)));
} }
if self.start == PARENT_DIR_COOKIE { if self.start == PARENT_DIR_COOKIE {
self.start += 1; self.start += 1;
let name = "..".to_owned(); let name = "..".to_owned();
let dirent = types::Dirent { let dirent = Dirent {
d_next: self.start as u64, d_next: self.start as u64,
d_ino: 0, d_ino: 0,
d_namlen: name.len() as _, d_namlen: name.len() as _,
d_type: types::Filetype::Directory, d_type: Filetype::Directory,
}; };
return Some(Ok((dirent, name))); return Some(Ok((dirent, name)));
} }
@@ -559,8 +554,8 @@ impl Handle for VirtualDir {
.to_str() .to_str()
.expect("wasi paths are valid utf8 strings") .expect("wasi paths are valid utf8 strings")
.to_owned(); .to_owned();
let dirent = || -> Result<types::Dirent> { let dirent = || -> Result<Dirent> {
let dirent = types::Dirent { let dirent = Dirent {
d_namlen: name.len().try_into()?, d_namlen: name.len().try_into()?,
d_type: file.get_file_type(), d_type: file.get_file_type(),
d_ino: 0, d_ino: 0,
@@ -601,33 +596,21 @@ impl Handle for VirtualDir {
} }
} }
} }
fn filestat_get_at(&self, path: &str, _follow: bool) -> Result<types::Filestat> { fn filestat_get_at(&self, path: &str, _follow: bool) -> Result<Filestat> {
let stat = self let stat = self
.openat( .openat(path, false, false, Oflags::empty(), Fdflags::empty())?
path,
false,
false,
types::Oflags::empty(),
types::Fdflags::empty(),
)?
.filestat_get()?; .filestat_get()?;
Ok(stat) Ok(stat)
} }
fn filestat_set_times_at( fn filestat_set_times_at(
&self, &self,
path: &str, path: &str,
atim: types::Timestamp, atim: Timestamp,
mtim: types::Timestamp, mtim: Timestamp,
fst_flags: types::Fstflags, fst_flags: Fstflags,
_follow: bool, _follow: bool,
) -> Result<()> { ) -> Result<()> {
self.openat( self.openat(path, false, false, Oflags::empty(), Fdflags::empty())?
path,
false,
false,
types::Oflags::empty(),
types::Fdflags::empty(),
)?
.filestat_set_times(atim, mtim, fst_flags)?; .filestat_set_times(atim, mtim, fst_flags)?;
Ok(()) Ok(())
} }
@@ -636,8 +619,8 @@ impl Handle for VirtualDir {
path: &str, path: &str,
_read: bool, _read: bool,
_write: bool, _write: bool,
oflags: types::Oflags, oflags: Oflags,
fd_flags: types::Fdflags, fd_flags: Fdflags,
) -> Result<Box<dyn Handle>> { ) -> Result<Box<dyn Handle>> {
if path == "." { if path == "." {
return self.try_clone().map_err(Into::into); return self.try_clone().map_err(Into::into);
@@ -659,14 +642,14 @@ impl Handle for VirtualDir {
let entry_count = entries.len(); let entry_count = entries.len();
match entries.entry(Path::new(file_name).to_path_buf()) { match entries.entry(Path::new(file_name).to_path_buf()) {
Entry::Occupied(e) => { Entry::Occupied(e) => {
let creat_excl_mask = types::Oflags::CREAT | types::Oflags::EXCL; let creat_excl_mask = Oflags::CREAT | Oflags::EXCL;
if (oflags & creat_excl_mask) == creat_excl_mask { if (oflags & creat_excl_mask) == creat_excl_mask {
tracing::trace!("VirtualDir::openat was passed oflags CREAT|EXCL, but the file {:?} exists.", file_name); tracing::trace!("VirtualDir::openat was passed oflags CREAT|EXCL, but the file {:?} exists.", file_name);
return Err(Error::Exist); return Err(Error::Exist);
} }
if oflags.contains(&types::Oflags::DIRECTORY) if oflags.contains(&Oflags::DIRECTORY)
&& e.get().get_file_type() != types::Filetype::Directory && e.get().get_file_type() != Filetype::Directory
{ {
tracing::trace!( tracing::trace!(
"VirtualDir::openat was passed oflags DIRECTORY, but {:?} is a file.", "VirtualDir::openat was passed oflags DIRECTORY, but {:?} is a file.",
@@ -709,12 +692,12 @@ impl Handle for VirtualDir {
match entries.entry(Path::new(trimmed_path).to_path_buf()) { match entries.entry(Path::new(trimmed_path).to_path_buf()) {
Entry::Occupied(e) => { Entry::Occupied(e) => {
// first, does this name a directory? // first, does this name a directory?
if e.get().get_file_type() != types::Filetype::Directory { if e.get().get_file_type() != Filetype::Directory {
return Err(Error::Notdir); return Err(Error::Notdir);
} }
// Okay, but is the directory empty? // Okay, but is the directory empty?
let iter = e.get().readdir(wasi::DIRCOOKIE_START)?; let iter = e.get().readdir(DIRCOOKIE_START)?;
if iter.skip(RESERVED_ENTRY_COUNT as usize).next().is_some() { if iter.skip(RESERVED_ENTRY_COUNT as usize).next().is_some() {
return Err(Error::Notempty); return Err(Error::Notempty);
} }
@@ -757,7 +740,7 @@ impl Handle for VirtualDir {
match entries.entry(Path::new(trimmed_path).to_path_buf()) { match entries.entry(Path::new(trimmed_path).to_path_buf()) {
Entry::Occupied(e) => { Entry::Occupied(e) => {
// Directories must be removed through `remove_directory`, not `unlink_file`. // Directories must be removed through `remove_directory`, not `unlink_file`.
if e.get().get_file_type() == types::Filetype::Directory { if e.get().get_file_type() == Filetype::Directory {
return Err(Error::Isdir); return Err(Error::Isdir);
} }

View File

@@ -9,8 +9,9 @@
//! //!
//! Note that `poll_oneoff` is not supported for these types, so they do not match the behavior of //! Note that `poll_oneoff` is not supported for these types, so they do not match the behavior of
//! real pipes exactly. //! real pipes exactly.
use crate::handle::{Handle, HandleRights}; use crate::handle::{
use crate::wasi::types; Advice, Fdflags, Filesize, Filestat, Filetype, Handle, HandleRights, Oflags, Rights,
};
use crate::{Error, Result}; use crate::{Error, Result};
use std::any::Any; use std::any::Any;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
@@ -54,7 +55,6 @@ impl<R: Read + Any> ReadPipe<R> {
/// ///
/// All `Handle` read operations delegate to reading from this underlying reader. /// All `Handle` read operations delegate to reading from this underlying reader.
pub fn from_shared(reader: Arc<RwLock<R>>) -> Self { pub fn from_shared(reader: Arc<RwLock<R>>) -> Self {
use types::Rights;
Self { Self {
rights: RwLock::new(HandleRights::from_base( rights: RwLock::new(HandleRights::from_base(
Rights::FD_DATASYNC Rights::FD_DATASYNC
@@ -115,8 +115,8 @@ impl<R: Read + Any> Handle for ReadPipe<R> {
Ok(Box::new(self.clone())) Ok(Box::new(self.clone()))
} }
fn get_file_type(&self) -> types::Filetype { fn get_file_type(&self) -> Filetype {
types::Filetype::Unknown Filetype::Unknown
} }
fn get_rights(&self) -> HandleRights { fn get_rights(&self) -> HandleRights {
@@ -127,26 +127,21 @@ impl<R: Read + Any> Handle for ReadPipe<R> {
*self.rights.write().unwrap() = rights; *self.rights.write().unwrap() = rights;
} }
fn advise( fn advise(&self, _advice: Advice, _offset: Filesize, _len: Filesize) -> Result<()> {
&self,
_advice: types::Advice,
_offset: types::Filesize,
_len: types::Filesize,
) -> Result<()> {
Err(Error::Spipe) Err(Error::Spipe)
} }
fn allocate(&self, _offset: types::Filesize, _len: types::Filesize) -> Result<()> { fn allocate(&self, _offset: Filesize, _len: Filesize) -> Result<()> {
Err(Error::Spipe) Err(Error::Spipe)
} }
fn fdstat_set_flags(&self, _fdflags: types::Fdflags) -> Result<()> { fn fdstat_set_flags(&self, _fdflags: Fdflags) -> Result<()> {
// do nothing for now // do nothing for now
Ok(()) Ok(())
} }
fn filestat_get(&self) -> Result<types::Filestat> { fn filestat_get(&self) -> Result<Filestat> {
let stat = types::Filestat { let stat = Filestat {
dev: 0, dev: 0,
ino: 0, ino: 0,
nlink: 0, nlink: 0,
@@ -159,18 +154,18 @@ impl<R: Read + Any> Handle for ReadPipe<R> {
Ok(stat) Ok(stat)
} }
fn filestat_set_size(&self, _st_size: types::Filesize) -> Result<()> { fn filestat_set_size(&self, _st_size: Filesize) -> Result<()> {
Err(Error::Spipe) Err(Error::Spipe)
} }
fn preadv(&self, buf: &mut [io::IoSliceMut], offset: types::Filesize) -> Result<usize> { fn preadv(&self, buf: &mut [io::IoSliceMut], offset: Filesize) -> Result<usize> {
if offset != 0 { if offset != 0 {
return Err(Error::Spipe); return Err(Error::Spipe);
} }
Ok(self.reader.write().unwrap().read_vectored(buf)?) Ok(self.reader.write().unwrap().read_vectored(buf)?)
} }
fn seek(&self, _offset: io::SeekFrom) -> Result<types::Filesize> { fn seek(&self, _offset: io::SeekFrom) -> Result<Filesize> {
Err(Error::Spipe) Err(Error::Spipe)
} }
@@ -187,8 +182,8 @@ impl<R: Read + Any> Handle for ReadPipe<R> {
_path: &str, _path: &str,
_read: bool, _read: bool,
_write: bool, _write: bool,
_oflags: types::Oflags, _oflags: Oflags,
_fd_flags: types::Fdflags, _fd_flags: Fdflags,
) -> Result<Box<dyn Handle>> { ) -> Result<Box<dyn Handle>> {
Err(Error::Notdir) Err(Error::Notdir)
} }
@@ -256,7 +251,6 @@ impl<W: Write + Any> WritePipe<W> {
/// ///
/// All `Handle` write operations delegate to writing to this underlying writer. /// All `Handle` write operations delegate to writing to this underlying writer.
pub fn from_shared(writer: Arc<RwLock<W>>) -> Self { pub fn from_shared(writer: Arc<RwLock<W>>) -> Self {
use types::Rights;
Self { Self {
rights: RwLock::new(HandleRights::from_base( rights: RwLock::new(HandleRights::from_base(
Rights::FD_DATASYNC Rights::FD_DATASYNC
@@ -300,8 +294,8 @@ impl<W: Write + Any> Handle for WritePipe<W> {
Ok(Box::new(self.clone())) Ok(Box::new(self.clone()))
} }
fn get_file_type(&self) -> types::Filetype { fn get_file_type(&self) -> Filetype {
types::Filetype::Unknown Filetype::Unknown
} }
fn get_rights(&self) -> HandleRights { fn get_rights(&self) -> HandleRights {
@@ -312,26 +306,21 @@ impl<W: Write + Any> Handle for WritePipe<W> {
*self.rights.write().unwrap() = rights; *self.rights.write().unwrap() = rights;
} }
fn advise( fn advise(&self, _advice: Advice, _offset: Filesize, _len: Filesize) -> Result<()> {
&self,
_advice: types::Advice,
_offset: types::Filesize,
_len: types::Filesize,
) -> Result<()> {
Err(Error::Spipe) Err(Error::Spipe)
} }
fn allocate(&self, _offset: types::Filesize, _len: types::Filesize) -> Result<()> { fn allocate(&self, _offset: Filesize, _len: Filesize) -> Result<()> {
Err(Error::Spipe) Err(Error::Spipe)
} }
fn fdstat_set_flags(&self, _fdflags: types::Fdflags) -> Result<()> { fn fdstat_set_flags(&self, _fdflags: Fdflags) -> Result<()> {
// do nothing for now // do nothing for now
Ok(()) Ok(())
} }
fn filestat_get(&self) -> Result<types::Filestat> { fn filestat_get(&self) -> Result<Filestat> {
let stat = types::Filestat { let stat = Filestat {
dev: 0, dev: 0,
ino: 0, ino: 0,
nlink: 0, nlink: 0,
@@ -344,18 +333,18 @@ impl<W: Write + Any> Handle for WritePipe<W> {
Ok(stat) Ok(stat)
} }
fn filestat_set_size(&self, _st_size: types::Filesize) -> Result<()> { fn filestat_set_size(&self, _st_size: Filesize) -> Result<()> {
Err(Error::Spipe) Err(Error::Spipe)
} }
fn pwritev(&self, buf: &[io::IoSlice], offset: types::Filesize) -> Result<usize> { fn pwritev(&self, buf: &[io::IoSlice], offset: Filesize) -> Result<usize> {
if offset != 0 { if offset != 0 {
return Err(Error::Spipe); return Err(Error::Spipe);
} }
Ok(self.writer.write().unwrap().write_vectored(buf)?) Ok(self.writer.write().unwrap().write_vectored(buf)?)
} }
fn seek(&self, _offset: io::SeekFrom) -> Result<types::Filesize> { fn seek(&self, _offset: io::SeekFrom) -> Result<Filesize> {
Err(Error::Spipe) Err(Error::Spipe)
} }
@@ -372,8 +361,8 @@ impl<W: Write + Any> Handle for WritePipe<W> {
_path: &str, _path: &str,
_read: bool, _read: bool,
_write: bool, _write: bool,
_oflags: types::Oflags, _oflags: Oflags,
_fd_flags: types::Fdflags, _fd_flags: Fdflags,
) -> Result<Box<dyn Handle>> { ) -> Result<Box<dyn Handle>> {
Err(Error::Notdir) Err(Error::Notdir)
} }