Struct VirtualFs
pub struct VirtualFs { /* private fields */ }Expand description
A sandboxed virtual filesystem backed by CowFile instances.
Provides file access for emulated .NET code (e.g., FileStream, File.Exists)
without touching the real filesystem. Each entry is a CowFile that can be
read via the existing stream/BinaryReader hooks.
Implementations§
§impl VirtualFs
impl VirtualFs
pub fn new() -> Self
pub fn new() -> Self
Creates an empty virtual filesystem with no mapped files.
pub fn map_cow(&mut self, vfs_path: &str, cow: CowFile)
pub fn map_cow(&mut self, vfs_path: &str, cow: CowFile)
Maps a virtual file by taking ownership of an existing CowFile.
For mmap-backed CowFiles (loaded from disk), the entry shares OS pages with the source. Pending writes on the source are not carried over.
§Arguments
vfs_path- Virtual path to register (normalized: case-insensitive, slash-normalized)cow- TheCowFileinstance to store
pub fn map_disk_file(
&mut self,
vfs_path: &str,
disk_path: &Path,
) -> Result<(), Error>
pub fn map_disk_file( &mut self, vfs_path: &str, disk_path: &Path, ) -> Result<(), Error>
Maps a virtual file from a disk path (mmap’d directly).
The file is opened via CowFile::open, which creates a MAP_PRIVATE
mmap. Reads share physical pages with the OS cache; writes are
copy-on-write.
§Arguments
vfs_path- Virtual path to registerdisk_path- Path to the file on disk
§Errors
Returns an error if the file cannot be opened or memory-mapped.
pub fn get(&self, vfs_path: &str) -> Option<&CowFile>
pub fn get(&self, vfs_path: &str) -> Option<&CowFile>
Looks up a virtual file by path (case-insensitive, slash-normalized).
First tries an exact (normalized) match. If that fails, falls back to
matching by filename component only, which handles cases where .NET code
uses a full path like C:\Windows\assembly.exe but the file was mapped
under just assembly.exe.
§Arguments
vfs_path- Path to look up (any format — Windows, Unix, or bare filename)
§Returns
A reference to the CowFile if found, or None.
pub fn exists(&self, vfs_path: &str) -> bool
pub fn exists(&self, vfs_path: &str) -> bool
Returns true if a virtual file exists at the given path.
Uses the same lookup logic as get, including
filename-only fallback matching.
pub fn fork(&self) -> Result<VirtualFs, Error>
pub fn fork(&self) -> Result<VirtualFs, Error>
Forks the virtual filesystem, creating an independent copy.
Each entry uses CowFile::fork():
- Mmap-backed entries re-open the same file (zero-copy OS CoW)
- Vec-backed entries clone the data
- Pending writes are not carried over — the fork starts clean
§Errors
Returns an error if any mmap-backed entry fails to re-open its file (e.g., the file was deleted since original mapping).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VirtualFs
impl RefUnwindSafe for VirtualFs
impl Send for VirtualFs
impl Sync for VirtualFs
impl Unpin for VirtualFs
impl UnsafeUnpin for VirtualFs
impl UnwindSafe for VirtualFs
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.