Struct qcow::TranslationTable

source ·
pub struct TranslationTable { /* private fields */ }
Expand description

QCOW uses a 2-level translation table to map guest-clusters to host clusters.

The translation table is a way of mapping a linear disk address to a physical offset in the QCOW file. Not every linear address may be mapped in the QCOW file, in which case reads to those regions would read-as-zero. These mappings are done with ‘cluster’ granularity such that a single, contiguous linear cluster maps to a contiguous region in the host file. The exact size of clusters used is determined by a field in the QCOW header.

Ex: a linear address can be decomposed into 3 parts:

  • l1_index - The index into the top-level L1 translation table. The entry in the L1 table can either be a pointer to an L2 translation table, or the entry can indicate that the entire region is un-mapped, regardless of l2_index or cluster_offset.
  • l2_index - If the l1_index indicates that there is a valid L2 table for a translation, the l2_index is offset into that L2 table that defines the per-cluster mapping for a translation. This mapping can either indicate there is a physical cluster allocated for a linear cluster or it can indicate that the cluster is unmapped and no translation exists.
  • cluster_offset - If there is a valid l1_table entry and a valid l2_table entry for a linear disk address, that means there is physical cluster that has been allocated to the linear cluster. The cluster_offset is then the remaining byte-offset into this cluster.

Implementations§

source§

impl TranslationTable

source

pub fn load(file: &mut File) -> Result<Self, Error>

source

pub fn linear_size(&self) -> u64

The logical size of the QCOW disk as specified in the header.

source

pub fn translate<'a>(&'a self, linear_range: Range<u64>) -> Translation<'a>

Looks up translations for a linear disk range.

This takes a linear_range describing a region of the qcow file to read from and returns an iterator over Mappings of that region.

The returned iterator will yield mappings that indicate how the linear rante is represented in the qcow file. This can be a combination of physical cluster mappings and also unmapped regions if the translation table contains no data for the linear range.

If any part of linear_range extends beyond the disk (bounded by linear_size()) then the iterator will not yield any mappings for those regions. In other words, no Mapping is a distinct situation for a Mapping::Unmapped. The former means there is no logical disk backing the range and the latter means that the linear range is valid but no physical disk clusters have been allocated to it.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.