Struct wasmer_wasix::fs::WasiFs
source · pub struct WasiFs {
pub preopen_fds: RwLock<Vec<u32>>,
pub fd_map: Arc<RwLock<FdList>>,
pub current_dir: Mutex<String>,
pub root_fs: WasiFsRoot,
pub root_inode: InodeGuard,
pub has_unioned: Arc<Mutex<HashSet<PackageId>>>,
is_wasix: AtomicBool,
pub(crate) init_preopens: Vec<PreopenedDir>,
pub(crate) init_vfs_preopens: Vec<String>,
}
Expand description
Warning, modifying these fields directly may cause invariants to break and should be considered unsafe. These fields may be made private in a future release
Fields§
§preopen_fds: RwLock<Vec<u32>>
§fd_map: Arc<RwLock<FdList>>
§current_dir: Mutex<String>
§root_fs: WasiFsRoot
§root_inode: InodeGuard
§has_unioned: Arc<Mutex<HashSet<PackageId>>>
§is_wasix: AtomicBool
§init_preopens: Vec<PreopenedDir>
§init_vfs_preopens: Vec<String>
Implementations§
source§impl WasiFs
impl WasiFs
pub fn is_wasix(&self) -> bool
pub fn set_is_wasix(&self, is_wasix: bool)
sourcepub async fn conditional_union(
&self,
binary: &BinaryPackage,
) -> Result<(), FsError>
pub async fn conditional_union( &self, binary: &BinaryPackage, ) -> Result<(), FsError>
Will conditionally union the binary file system with this one if it has not already been unioned
sourcepub(crate) fn new_with_preopen(
inodes: &WasiInodes,
preopens: &[PreopenedDir],
vfs_preopens: &[String],
fs_backing: WasiFsRoot,
) -> Result<Self, String>
pub(crate) fn new_with_preopen( inodes: &WasiInodes, preopens: &[PreopenedDir], vfs_preopens: &[String], fs_backing: WasiFsRoot, ) -> Result<Self, String>
Created for the builder API. like new
but with more information
sourcepub(crate) fn relative_path_to_absolute(&self, path: String) -> String
pub(crate) fn relative_path_to_absolute(&self, path: String) -> String
Converts a relative path into an absolute path
sourcefn new_init(
fs_backing: WasiFsRoot,
inodes: &WasiInodes,
st_ino: Inode,
) -> Result<Self, String>
fn new_init( fs_backing: WasiFsRoot, inodes: &WasiInodes, st_ino: Inode, ) -> Result<Self, String>
Private helper function to init the filesystem, called in new
and
new_with_preopen
sourcepub unsafe fn open_dir_all(
&mut self,
inodes: &WasiInodes,
base: WasiFd,
name: String,
rights: Rights,
rights_inheriting: Rights,
flags: Fdflags,
) -> Result<WasiFd, FsError>
pub unsafe fn open_dir_all( &mut self, inodes: &WasiInodes, base: WasiFd, name: String, rights: Rights, rights_inheriting: Rights, flags: Fdflags, ) -> Result<WasiFd, FsError>
This function is like create dir all, but it also opens it. Function is unsafe because it may break invariants and hasn’t been tested. This is an experimental function and may be removed
§Safety
- Virtual directories created with this function must not conflict with the standard operation of the WASI filesystem. This is vague and unlikely in pratice. Join the discussion for what the newer, safer WASI FS APIs should look like.
sourcepub fn open_file_at(
&mut self,
inodes: &WasiInodes,
base: WasiFd,
file: Box<dyn VirtualFile + Send + Sync + 'static>,
open_flags: u16,
name: String,
rights: Rights,
rights_inheriting: Rights,
flags: Fdflags,
) -> Result<WasiFd, FsError>
pub fn open_file_at( &mut self, inodes: &WasiInodes, base: WasiFd, file: Box<dyn VirtualFile + Send + Sync + 'static>, open_flags: u16, name: String, rights: Rights, rights_inheriting: Rights, flags: Fdflags, ) -> Result<WasiFd, FsError>
Opens a user-supplied file in the directory specified with the name and flags given
sourcepub fn swap_file(
&self,
fd: WasiFd,
file: Box<dyn VirtualFile + Send + Sync + 'static>,
) -> Result<Option<Box<dyn VirtualFile + Send + Sync + 'static>>, FsError>
pub fn swap_file( &self, fd: WasiFd, file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> Result<Option<Box<dyn VirtualFile + Send + Sync + 'static>>, FsError>
Change the backing of a given file descriptor Returns the old backing TODO: add examples
sourcepub fn filestat_resync_size(&self, fd: WasiFd) -> Result<Filesize, Errno>
pub fn filestat_resync_size(&self, fd: WasiFd) -> Result<Filesize, Errno>
refresh size from filesystem
sourcepub fn set_current_dir(&self, path: &str)
pub fn set_current_dir(&self, path: &str)
Changes the current directory
sourcepub fn get_current_dir(
&self,
inodes: &WasiInodes,
base: WasiFd,
) -> Result<(InodeGuard, String), Errno>
pub fn get_current_dir( &self, inodes: &WasiInodes, base: WasiFd, ) -> Result<(InodeGuard, String), Errno>
Gets the current directory
pub(crate) fn get_current_dir_inner( &self, inodes: &WasiInodes, base: WasiFd, symlink_count: u32, ) -> Result<(InodeGuard, String), Errno>
sourcefn get_inode_at_path_inner(
&self,
inodes: &WasiInodes,
cur_inode: InodeGuard,
path_str: &str,
symlink_count: u32,
follow_symlinks: bool,
) -> Result<InodeGuard, Errno>
fn get_inode_at_path_inner( &self, inodes: &WasiInodes, cur_inode: InodeGuard, path_str: &str, symlink_count: u32, follow_symlinks: bool, ) -> Result<InodeGuard, Errno>
Internal part of the core path resolution function which implements path
traversal logic such as resolving relative path segments (such as
.
and ..
) and resolving symlinks (while preventing infinite
loops/stack overflows).
TODO: expand upon exactly what the state of the returned value is, explaining lazy-loading from the real file system and synchronizing between them.
This is where a lot of the magic happens, be very careful when editing this code.
TODO: write more tests for this code
sourcefn path_into_pre_open_and_relative_path<'path>(
&self,
path: &'path Path,
) -> Result<(WasiFd, &'path Path), Errno>
fn path_into_pre_open_and_relative_path<'path>( &self, path: &'path Path, ) -> Result<(WasiFd, &'path Path), Errno>
Finds the preopened directory that is the “best match” for the given path and returns a path relative to this preopened directory.
The “best match” is the preopened directory that has the longest prefix of the
given path. For example, given preopened directories [a
, a/b
, a/c
] and
the path a/b/c/file
, we will return the fd corresponding to the preopened
directory, a/b
and the relative path c/file
.
In the case of a tie, the later preopened fd is preferred.
sourcepub(crate) fn path_depth_from_fd(
&self,
fd: WasiFd,
inode: InodeGuard,
) -> Result<usize, Errno>
pub(crate) fn path_depth_from_fd( &self, fd: WasiFd, inode: InodeGuard, ) -> Result<usize, Errno>
finds the number of directories between the fd and the inode if they’re connected expects inode to point to a directory
sourcepub(crate) fn get_inode_at_path(
&self,
inodes: &WasiInodes,
base: WasiFd,
path: &str,
follow_symlinks: bool,
) -> Result<InodeGuard, Errno>
pub(crate) fn get_inode_at_path( &self, inodes: &WasiInodes, base: WasiFd, path: &str, follow_symlinks: bool, ) -> Result<InodeGuard, Errno>
gets a host file from a base directory and a path this function ensures the fs remains sandboxed
sourcepub(crate) fn get_parent_inode_at_path(
&self,
inodes: &WasiInodes,
base: WasiFd,
path: &Path,
follow_symlinks: bool,
) -> Result<(InodeGuard, String), Errno>
pub(crate) fn get_parent_inode_at_path( &self, inodes: &WasiInodes, base: WasiFd, path: &Path, follow_symlinks: bool, ) -> Result<(InodeGuard, String), Errno>
Returns the parent Dir or Root that the file at a given path is in and the file name stripped off
pub fn get_fd(&self, fd: WasiFd) -> Result<Fd, Errno>
pub fn get_fd_inode(&self, fd: WasiFd) -> Result<InodeGuard, Errno>
pub fn filestat_fd(&self, fd: WasiFd) -> Result<Filestat, Errno>
pub fn fdstat(&self, fd: WasiFd) -> Result<Fdstat, Errno>
pub fn prestat_fd(&self, fd: WasiFd) -> Result<Prestat, Errno>
pub(crate) fn prestat_fd_inner(&self, inode_val: &InodeVal) -> Prestat
pub async fn flush(&self, fd: WasiFd) -> Result<(), Errno>
sourcepub(crate) fn create_inode(
&self,
inodes: &WasiInodes,
kind: Kind,
is_preopened: bool,
name: String,
) -> Result<InodeGuard, Errno>
pub(crate) fn create_inode( &self, inodes: &WasiInodes, kind: Kind, is_preopened: bool, name: String, ) -> Result<InodeGuard, Errno>
Creates an inode and inserts it given a Kind and some extra data
sourcepub(crate) fn create_inode_with_default_stat(
&self,
inodes: &WasiInodes,
kind: Kind,
is_preopened: bool,
name: Cow<'static, str>,
) -> InodeGuard
pub(crate) fn create_inode_with_default_stat( &self, inodes: &WasiInodes, kind: Kind, is_preopened: bool, name: Cow<'static, str>, ) -> InodeGuard
Creates an inode and inserts it given a Kind, does not assume the file exists.
sourcepub(crate) fn create_inode_with_stat(
&self,
inodes: &WasiInodes,
kind: Kind,
is_preopened: bool,
name: Cow<'static, str>,
stat: Filestat,
) -> InodeGuard
pub(crate) fn create_inode_with_stat( &self, inodes: &WasiInodes, kind: Kind, is_preopened: bool, name: Cow<'static, str>, stat: Filestat, ) -> InodeGuard
Creates an inode with the given filestat and inserts it.
pub fn create_fd( &self, rights: Rights, rights_inheriting: Rights, flags: Fdflags, open_flags: u16, inode: InodeGuard, ) -> Result<WasiFd, Errno>
pub fn with_fd( &self, rights: Rights, rights_inheriting: Rights, flags: Fdflags, open_flags: u16, inode: InodeGuard, idx: WasiFd, ) -> Result<(), Errno>
pub fn create_fd_ext( &self, rights: Rights, rights_inheriting: Rights, flags: Fdflags, open_flags: u16, inode: InodeGuard, idx: Option<WasiFd>, exclusive: bool, ) -> Result<WasiFd, Errno>
pub fn clone_fd(&self, fd: WasiFd) -> Result<WasiFd, Errno>
sourcepub unsafe fn remove_inode(
&self,
inodes: &WasiInodes,
ino: Inode,
) -> Option<Arc<InodeVal>>
pub unsafe fn remove_inode( &self, inodes: &WasiInodes, ino: Inode, ) -> Option<Arc<InodeVal>>
Low level function to remove an inode, that is it deletes the WASI FS’s knowledge of a file.
This function returns the inode if it existed and was removed.
§Safety
- The caller must ensure that all references to the specified inode have been removed from the filesystem.
pub(crate) fn create_stdout(&self, inodes: &WasiInodes)
pub(crate) fn create_stdin(&self, inodes: &WasiInodes)
pub(crate) fn create_stderr(&self, inodes: &WasiInodes)
pub(crate) fn create_rootfd(&self) -> Result<(), String>
pub(crate) fn create_preopens( &self, inodes: &WasiInodes, ignore_duplicates: bool, ) -> Result<(), String>
pub(crate) fn create_std_dev_inner( &self, inodes: &WasiInodes, handle: Box<dyn VirtualFile + Send + Sync + 'static>, name: &'static str, raw_fd: WasiFd, rights: Rights, fd_flags: Fdflags, st_ino: Inode, )
pub fn get_stat_for_kind(&self, kind: &Kind) -> Result<Filestat, Errno>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WasiFs
impl !RefUnwindSafe for WasiFs
impl Send for WasiFs
impl Sync for WasiFs
impl Unpin for WasiFs
impl !UnwindSafe for WasiFs
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more