Skip to main content

VirtualFs

Struct VirtualFs 

Source
pub struct VirtualFs { /* private fields */ }
Expand description

In-memory filesystem the guest can read and write through the Win32 file APIs. Paths are normalised to lowercase + forward slashes internally so "C:\\Windows\\foo.ini", "c:/windows/foo.ini", and "C:/WINDOWS/Foo.INI" all reference the same file — matching the case-insensitive behaviour of Windows.

The handle space is local to the VFS; opened handles are returned as u32 values starting at HANDLE_BASE.

Implementations§

Source§

impl VirtualFs

Source

pub fn new() -> Self

Source

pub fn insert(&mut self, path: &str, bytes: Vec<u8>)

Insert a file. Overwrites whatever was at path before.

Source

pub fn read(&self, path: &str) -> Option<&[u8]>

Read a file by path. Returns None if not present. Doesn’t open a handle — just peeks.

Source

pub fn contains(&self, path: &str) -> bool

True iff a file exists at this path.

Source

pub fn write_path(&mut self, path: &str, bytes: Vec<u8>)

Replace a file’s bytes by path. Inserts if absent. Doesn’t go through a handle.

Source

pub fn remove(&mut self, path: &str) -> bool

Remove a file. Returns true if it was present.

Source

pub fn list(&self) -> impl Iterator<Item = (&str, usize)>

Iterate over every (path, byte-count) pair.

Source

pub fn open(&mut self, path: &str, access: FileAccess) -> Option<u32>

Open a handle to the file at path. Returns None when the file doesn’t exist (and the caller asked for read-only access). For write access, the file is created if absent.

Source

pub fn close(&mut self, handle: u32) -> bool

Close a handle. Returns true if the handle was known. Successive close calls are tolerated (they return false).

Source

pub fn read_handle(&mut self, handle: u32, buf: &mut [u8]) -> Option<usize>

Read up to buf.len() bytes from the file at the handle’s current position. Advances the position by the read length. Returns the number of bytes read (0 at EOF), or None if the handle is unknown or not readable.

Source

pub fn write_handle(&mut self, handle: u32, data: &[u8]) -> Option<usize>

Write data to the file at the handle’s current position. Extends the file as needed. Returns the number of bytes written, or None if the handle is unknown or not writable.

Source

pub fn seek(&mut self, handle: u32, pos: u64) -> Option<u64>

Move the handle’s file pointer to pos. Returns the new position, or None if the handle is unknown.

Source

pub fn size(&self, handle: u32) -> Option<u64>

Current size of the file the handle refers to. Returns None if the handle is unknown.

Source

pub fn owns(&self, handle: u32) -> bool

True iff handle was minted by this VFS (and still open). Used by the Win32 stubs to disambiguate VFS-backed handles from heap / event / semaphore handles when CloseHandle is called.

Trait Implementations§

Source§

impl Clone for VirtualFs

Source§

fn clone(&self) -> VirtualFs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VirtualFs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VirtualFs

Source§

fn default() -> VirtualFs

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.