Virtual file support (#701)
* Add support for virtual files (eg, not backed by an OS file). Virtual files are implemented through trait objects, with a default implementation that tries to behave like on-disk files, but entirely backed by in-memory structures. Co-authored-by: Dan Gohman <sunfish@mozilla.com>
This commit is contained in:
@@ -22,9 +22,9 @@ pub(crate) unsafe fn iovec_to_host_mut(iovec: &mut __wasi_iovec_t) -> io::IoSlic
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // trouble with sockets
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub(crate) enum FileType {
|
||||
pub enum FileType {
|
||||
Unknown = __WASI_FILETYPE_UNKNOWN,
|
||||
BlockDevice = __WASI_FILETYPE_BLOCK_DEVICE,
|
||||
CharacterDevice = __WASI_FILETYPE_CHARACTER_DEVICE,
|
||||
@@ -39,10 +39,25 @@ impl FileType {
|
||||
pub(crate) fn to_wasi(&self) -> __wasi_filetype_t {
|
||||
*self as __wasi_filetype_t
|
||||
}
|
||||
|
||||
pub(crate) fn from_wasi(wasi_filetype: u8) -> Option<Self> {
|
||||
use FileType::*;
|
||||
match wasi_filetype {
|
||||
__WASI_FILETYPE_UNKNOWN => Some(Unknown),
|
||||
__WASI_FILETYPE_BLOCK_DEVICE => Some(BlockDevice),
|
||||
__WASI_FILETYPE_CHARACTER_DEVICE => Some(CharacterDevice),
|
||||
__WASI_FILETYPE_DIRECTORY => Some(Directory),
|
||||
__WASI_FILETYPE_REGULAR_FILE => Some(RegularFile),
|
||||
__WASI_FILETYPE_SOCKET_DGRAM => Some(SocketDgram),
|
||||
__WASI_FILETYPE_SOCKET_STREAM => Some(SocketStream),
|
||||
__WASI_FILETYPE_SYMBOLIC_LINK => Some(Symlink),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Dirent {
|
||||
pub struct Dirent {
|
||||
pub name: String,
|
||||
pub ftype: FileType,
|
||||
pub ino: u64,
|
||||
|
||||
Reference in New Issue
Block a user