Documentation
¶
Overview ¶
Package diff implements differencing (child) disk resolution over a parent chain.
Index ¶
- Variables
- type BlockKind
- type Config
- type Resolver
- func (r *Resolver) BlockCount() uint32
- func (r *Resolver) BlockKind(blockIndex uint32) (BlockKind, error)
- func (r *Resolver) HasParent() bool
- func (r *Resolver) ReadAt(p []byte, virtualOffset int64) (int, error)
- func (r *Resolver) SectorRuns(blockIndex uint32, firstSector, lastSector int64) ([]SectorRun, error)
- func (r *Resolver) SetParent(parent io.ReaderAt)
- func (r *Resolver) VirtualSize() int64
- type SectorRun
Constants ¶
This section is empty.
Variables ¶
var ErrNoBitmapSource = errors.New("libvhdi: sector bitmap resolution requires the child's backing reader")
ErrNoBitmapSource is returned when a block can only be resolved by consulting a sector bitmap but the resolver was built without access to the child's backing file, meaning Config.Source was nil.
Erroring is the only safe response. Both VHD and VHDX represent a partially written block with a bitmap saying which sectors the child actually holds; without it, the alternatives are to return the child's zero-filled holes as though they were data, or the parent's bytes where the child has overwritten them. Both produce a plausible device that is wrong.
var ErrParentRequired = errors.New("libvhdi: differencing disk requires a parent")
ErrParentRequired is returned when a read resolves to a parent disk but no parent has been attached. Differencing disks fail closed: returning zeroes would be indistinguishable from genuine disk contents.
Functions ¶
This section is empty.
Types ¶
type BlockKind ¶
type BlockKind int
BlockKind describes where a block's bytes live.
const ( // BlockFromChild: the whole block is present in this disk. BlockFromChild BlockKind = iota // BlockFromParent: the whole block must be read from the parent chain. BlockFromParent // BlockZero: the block reads as zeroes and is not parent-backed. BlockZero // BlockPerSector: the block's sector bitmap decides sector by sector, so // SectorRuns is needed to resolve it. BlockPerSector )
type Config ¶
type Config struct {
// Source is the child's raw backing reader. It is required to read sector
// bitmaps; without it, blocks needing per-sector resolution error out.
Source io.ReaderAt
// Child is the decoded child block reader (virtual address space).
Child io.ReaderAt
// Parent is the next disk in the chain, or nil if none is attached yet.
// A nil Parent makes parent-backed reads return ErrParentRequired.
Parent io.ReaderAt
BlockSize uint32
SectorSize uint32
VirtualSize uint64
// Exactly one of VHDBAT / VHDXBAT must be set.
VHDBAT *types.VHDBlockAllocationTable
VHDXBAT *types.VHDXBlockAllocationTable
}
Config describes a differencing disk and its resolution inputs.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves reads on a child (differencing) disk against a parent chain, at sector granularity.
Both VHD and VHDX represent partially-written blocks with a sector bitmap: sectors whose bit is set live in the child, and sectors whose bit is clear must be served from the parent. Resolving at whole-block granularity returns the child's zero-filled holes instead of the parent's data.
func (*Resolver) BlockCount ¶
BlockCount returns the number of blocks the child's BAT describes.
func (*Resolver) BlockKind ¶
BlockKind reports where the given block's bytes live, without reading them.
func (*Resolver) ReadAt ¶
ReadAt implements io.ReaderAt over the child's virtual address space, resolving each region to the child, the parent chain, or zeroes.
func (*Resolver) SectorRuns ¶
func (r *Resolver) SectorRuns(blockIndex uint32, firstSector, lastSector int64) ([]SectorRun, error)
SectorRuns groups the sectors in [firstSector, lastSector] of a BlockPerSector block into runs sharing a backing.
The bitmap bytes covering the range are read once, so this costs one I/O regardless of how many sectors the range spans.
func (*Resolver) VirtualSize ¶
VirtualSize returns the total size of the differencing disk in bytes.
type SectorRun ¶
type SectorRun struct {
First, Last int64
// InChild is true when the run is present in this disk, false when it must
// come from the parent chain.
InChild bool
}
SectorRun is a contiguous run of sectors within one block that share a backing. Sector indices are inclusive and relative to the block.