Documentation
¶
Overview ¶
Package qflash reads QCOW2 virtual disk images and writes them to block devices or files.
Index ¶
- Variables
- func HumanSize(bytes uint64) string
- func ListPartitions(chain []*QCOWLayer) error
- func ReadVirtualBytes(chain []*QCOWLayer, offset, length uint64) ([]byte, error)
- func WritePartitions(chain []*QCOWLayer, targets []PartitionTarget) error
- func WriteToDevice(chain []*QCOWLayer, dst *os.File) error
- type HTTPReaderAt
- type L1Entry
- type L2Entry
- type PartitionInfo
- type PartitionTarget
- type QCOWHeader
- type QCOWLayer
Constants ¶
This section is empty.
Variables ¶
var DebugMode bool
DebugMode enables verbose QCOW2 internal diagnostics.
Functions ¶
func ListPartitions ¶
ListPartitions prints the MBR or GPT partition table from the virtual disk.
func ReadVirtualBytes ¶
ReadVirtualBytes reads length bytes from the virtual disk starting at offset, spanning cluster boundaries as needed.
func WritePartitions ¶
func WritePartitions(chain []*QCOWLayer, targets []PartitionTarget) error
WritePartitions writes each partition specified in targets from the virtual disk to its device.
func WriteToDevice ¶
WriteToDevice streams the virtual disk contents through the layer chain to dst using a pool of parallel workers — one per logical CPU. ReadAt and WriteAt are safe for concurrent use (pread/pwrite), and decompression is CPU-bound, so the worker pool gives near-linear throughput scaling.
Types ¶
type HTTPReaderAt ¶ added in v1.0.2
type HTTPReaderAt struct {
// contains filtered or unexported fields
}
HTTPReaderAt implements io.ReaderAt against a remote URL using HTTP range requests. Fetched chunks are cached in memory to avoid redundant requests when the same region is read multiple times (e.g. repeated L2 table lookups).
func NewHTTPReaderAt ¶ added in v1.0.2
func NewHTTPReaderAt(url string) *HTTPReaderAt
NewHTTPReaderAt creates an HTTPReaderAt for the given URL using the default HTTP client and a 1 MiB chunk size.
func NewHTTPReaderAtWithClient ¶ added in v1.0.2
func NewHTTPReaderAtWithClient(url string, client *http.Client, chunkSize int64) *HTTPReaderAt
NewHTTPReaderAtWithClient creates an HTTPReaderAt with a custom HTTP client and chunk size.
type L1Entry ¶
L1Entry holds a parsed L1 table entry. L2TableOffset is a direct byte offset into the image file. NeedsCOW is true when bit 63 of the raw entry is 0 (refcount != 1).
type L2Entry ¶
type L2Entry struct {
// Standard cluster fields
HostClusterOffset uint64 // direct byte offset; 0 = unallocated
IsZero bool // cluster reads as all zeros (bit 0 of standard descriptor)
// Compressed cluster fields
IsCompressed bool
CompressedOffset uint64
AdditionalSectors uint64
RawValue uint64
}
L2Entry holds a parsed L2 table entry for a guest cluster.
type PartitionInfo ¶
PartitionInfo describes a partition in the virtual disk.
func GetPartitionTable ¶
func GetPartitionTable(chain []*QCOWLayer) ([]PartitionInfo, error)
GetPartitionTable reads the MBR or GPT partition table from the virtual disk.
type PartitionTarget ¶
PartitionTarget maps a partition number (1-based) to a destination device or file.
type QCOWHeader ¶
type QCOWHeader struct {
Magic string
Version uint32
BackingFileOffset uint64
BackingFileSize uint32
ClusterBits uint32
Size uint64
CryptMethod uint32
ClusterSize uint64
L1Size uint32
L1TableOffset uint64
RefcountTableOffset uint64
RefcountTableClusters uint32
NbSnapshots uint32
SnapshotsOffset uint64
IncompatibleFeatures uint64
CompatibleFeatures uint64
AutoclearFeatures uint64
RefcountOrder uint32
HeaderLength uint32
ExtL2 bool // true when incompatible feature bit 4 is set (128-bit L2 entries)
CompressionType uint8 // 0=deflate (default), 1=zstd; present at header offset 104 (v3+)
}
type QCOWLayer ¶
type QCOWLayer struct {
File io.ReaderAt
Path string // source path, used to resolve relative backing file references
Header *QCOWHeader
L1 []L1Entry
// contains filtered or unexported fields
}
QCOWLayer is one image in a backing-file chain (overlay → ... → base).
func OpenLayerChain ¶
OpenLayerChain opens src and recursively opens any backing files, returning the full chain with the overlay first and the base image last. srcPath is used to resolve relative backing file references; pass an empty string to disable backing file support (e.g. for HTTP sources).