diff

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diff implements differencing (child) disk resolution over a parent chain.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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 New

func New(cfg Config) (*Resolver, error)

New creates a differencing disk resolver.

func (*Resolver) BlockCount

func (r *Resolver) BlockCount() uint32

BlockCount returns the number of blocks the child's BAT describes.

func (*Resolver) BlockKind

func (r *Resolver) BlockKind(blockIndex uint32) (BlockKind, error)

BlockKind reports where the given block's bytes live, without reading them.

func (*Resolver) HasParent

func (r *Resolver) HasParent() bool

HasParent reports whether this resolver has a parent disk attached.

func (*Resolver) ReadAt

func (r *Resolver) ReadAt(p []byte, virtualOffset int64) (int, error)

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) SetParent

func (r *Resolver) SetParent(parent io.ReaderAt)

SetParent attaches or replaces the parent disk.

func (*Resolver) VirtualSize

func (r *Resolver) VirtualSize() int64

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL