Skip to main content

VmdkReader

Struct VmdkReader 

Source
pub struct VmdkReader<R: Read + Seek> { /* private fields */ }
Expand description

Read-only VMDK container reader, generic over any Read + Seek source.

Implements Read + Seek over the virtual sector stream.

§Examples

use std::fs::File;
use vmdk::VmdkReader;

let file = File::open("disk.vmdk").unwrap();
let mut reader = VmdkReader::open(file).unwrap();
println!("virtual disk size: {} bytes", reader.virtual_disk_size());

Implementations§

Source§

impl<R: Read + Seek> VmdkReader<R>

Source

pub fn enable_rgd_fallback(&mut self)

Enable opt-in RGD fallback: a read whose primary grain-table pointer is out of bounds is resolved through the redundant grain directory instead, recovering data from a damaged primary GD that qemu-img would simply fail on.

Source

pub fn rgd_recovery_count(&self) -> u64

Number of grains resolved via the redundant grain directory so far (pointer- or entry-level recovery). Zero on a healthy image; non-zero quantifies how much of a damaged image was reconstructed from the RGD.

Source§

impl<R: Read + Seek> VmdkReader<R>

Source

pub fn open(reader: R) -> Result<Self, VmdkError>

Open a binary VMDK (monolithic sparse or stream-optimised) from any Read + Seek source.

For multi-file flat VMDKs (text descriptor + extent files) use VmdkReader::open_path instead.

Source

pub fn virtual_disk_size(&self) -> u64

Virtual disk size in bytes.

Source

pub fn disk_type(&self) -> &str

createType from the embedded text descriptor (e.g. "monolithicSparse").

Returns an empty string when no embedded descriptor is present.

Source

pub fn cid(&self) -> u32

CID from the embedded descriptor; 0xffff_ffff when absent.

Source

pub fn parent_cid(&self) -> u32

Parent CID; 0xffff_ffff means this is a base image (no parent).

Source

pub fn sector_count(&self) -> u64

Virtual disk size in 512-byte sectors.

Source

pub fn descriptor_text(&self) -> &str

Raw embedded descriptor text; empty when no embedded descriptor is present.

Source

pub fn disk_database(&self) -> DiskDatabase

Parsed ddb.* disk database (geometry, adapter type, VM hardware / tools versions, UUID, long content ID, thin-provisioning, encoding).

Empty when the descriptor carries no disk database (e.g. a snapshot delta).

Source

pub fn change_track_path(&self) -> Option<String>

The descriptor’s changeTrackPath — the Change Block Tracking (-ctk.vmdk) file, if this disk has CBT enabled. The -ctk file maps which blocks changed between snapshots and is the basis for incremental forensic acquisition.

Source

pub fn effective_content_id(&self) -> String

The disk’s effective content identifier as a hex string.

When CID == 0xFFFFFFFE (the “use the long content identifier” sentinel), returns ddb.longContentID; otherwise the 8-hex-digit short CID.

Source

pub fn info(&self) -> VmdkInfo

Structured snapshot of all metadata for this image.

Source

pub fn is_allocated(&mut self, lba: u64) -> Result<bool>

Returns true if the 512-byte sector at lba is allocated (non-sparse).

An lba beyond the virtual disk boundary always returns false. For flat/raw-extent VMDKs every sector is implicitly allocated; returns true for any in-bounds LBA.

Source

pub fn iter_allocated_grains(&mut self) -> Result<Vec<AllocatedGrain>>

Iterate over all allocated (non-sparse) grain ranges in LBA order.

Each yielded AllocatedGrain covers exactly one grain; contiguous allocated grains are not coalesced so the caller can apply its own merging if desired. The iterator is eager — it collects all GTE reads upfront to avoid borrow issues.

Source

pub fn hash(&mut self) -> Result<VmdkDigest>

Compute SHA-256 and MD5 digests of the full virtual disk in one sequential pass.

Reads from the current seek position (normally the caller should seek to 0 first). Uses a 64 KiB streaming buffer to avoid loading the whole disk into memory.

Source§

impl VmdkReader<Box<dyn ReadSeek + Send>>

Source

pub fn extent_dependencies(path: &Path) -> Result<Vec<PathBuf>, VmdkError>

List the companion extent files this VMDK depends on, resolved relative to the descriptor’s directory.

For a self-contained binary VMDK (monolithicSparse, streamOptimized, …) this is empty — the single file holds everything. For multi-file formats (twoGbMaxExtent*, monolithicFlat, vmfsSparse, seSparse, custom, …) it returns every backing extent file in descriptor order. ZERO/NOACCESS extents carry no file and are excluded.

Forensic use: enumerate what must be collected before the disk can be read, without opening (or even possessing) the extents themselves.

Source

pub fn open_path(path: &Path) -> Result<Self, VmdkError>

Open any VMDK format from a file-system path.

Unlike VmdkReader::open, this constructor handles text-descriptor VMDKs (twoGbMaxExtentFlat) that reference external extent files, as well as binary VMDKs that can be opened from a single stream.

Trait Implementations§

Source§

impl<R: Read + Seek> Read for VmdkReader<R>

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
where Self: Sized,

🔬This is a nightly-only experimental API. (read_array)
Read and return a fixed array of bytes from this source. Read more
Source§

impl<R: Read + Seek> Seek for VmdkReader<R>

Source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more

Auto Trait Implementations§

§

impl<R> Freeze for VmdkReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for VmdkReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for VmdkReader<R>
where R: Send,

§

impl<R> Sync for VmdkReader<R>
where R: Sync,

§

impl<R> Unpin for VmdkReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for VmdkReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for VmdkReader<R>
where R: UnwindSafe,

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> 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> ReadSeek for T
where T: Read + Seek,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.