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
impl VirtualFs
pub fn new() -> Self
Sourcepub fn insert(&mut self, path: &str, bytes: Vec<u8>)
pub fn insert(&mut self, path: &str, bytes: Vec<u8>)
Insert a file. Overwrites whatever was at path
before.
Sourcepub fn read(&self, path: &str) -> Option<&[u8]>
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.
Sourcepub fn write_path(&mut self, path: &str, bytes: Vec<u8>)
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.
Sourcepub fn list(&self) -> impl Iterator<Item = (&str, usize)>
pub fn list(&self) -> impl Iterator<Item = (&str, usize)>
Iterate over every (path, byte-count) pair.
Sourcepub fn open(&mut self, path: &str, access: FileAccess) -> Option<u32>
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.
Sourcepub fn close(&mut self, handle: u32) -> bool
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).
Sourcepub fn read_handle(&mut self, handle: u32, buf: &mut [u8]) -> Option<usize>
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.
Sourcepub fn write_handle(&mut self, handle: u32, data: &[u8]) -> Option<usize>
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.
Sourcepub fn seek(&mut self, handle: u32, pos: u64) -> Option<u64>
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.