Documentation
¶
Overview ¶
Package diff implements differencing (child) disk resolution over a parent chain.
Index ¶
- Variables
- type BlockKind
- type Chain
- type Config
- type Resolver
- func BuildVHDResolver(links []io.ReaderAt, bats []*types.VHDBlockAllocationTable, blockSize uint32, ...) (*Resolver, error)
- func New(cfg Config) (*Resolver, error)
- func NewVHDResolver(child io.ReaderAt, parent io.ReaderAt, childBAT *types.VHDBlockAllocationTable, ...) *Resolverdeprecated
- func NewVHDXResolver(child io.ReaderAt, parent io.ReaderAt, ...) *Resolverdeprecated
- 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. Resolvers created through the deprecated NewVHDResolver and NewVHDXResolver constructors are in this state.
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 Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain represents an ordered slice of disk readers forming a parent chain, from child (index 0) to oldest ancestor (last index).
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 BuildVHDResolver ¶
func BuildVHDResolver(links []io.ReaderAt, bats []*types.VHDBlockAllocationTable, blockSize uint32, virtualSize uint64) (*Resolver, error)
BuildVHDResolver constructs a layered Resolver for VHD differencing disk chains. links[i] is the raw backing reader for disk i and bats[i] its BAT; blockSize and virtualSize come from the child's metadata.
Each layer resolves at sector granularity: sectors absent from a child's block bitmap are served by the next disk in the chain.
func NewVHDResolver
deprecated
func NewVHDResolver(child io.ReaderAt, parent io.ReaderAt, childBAT *types.VHDBlockAllocationTable, blockSize uint32, virtualSize uint64) *Resolver
NewVHDResolver creates a differencing disk resolver for VHD format.
Deprecated: this constructor cannot resolve partially-written blocks because it has no access to the child's backing reader, and so cannot read sector bitmaps. Such blocks return ErrNoBitmapSource rather than silently dropping parent data. Use New with a populated Config.Source instead.
func NewVHDXResolver
deprecated
func NewVHDXResolver(child io.ReaderAt, parent io.ReaderAt, childBAT *types.VHDXBlockAllocationTable, blockSize uint32, virtualSize uint64) *Resolver
NewVHDXResolver creates a differencing disk resolver for VHDX format.
Deprecated: this constructor cannot resolve partially-present blocks because it has no access to the child's backing reader, and so cannot read sector bitmaps. Such blocks return ErrNoBitmapSource rather than silently dropping parent data. Use New with a populated Config.Source instead.
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.