bat

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 bat provides Block Allocation Table (BAT) parsing and lookup logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockCountVHD

func BlockCountVHD(bat *types.VHDBlockAllocationTable) uint32

BlockCountVHD returns the total number of blocks in a VHD BAT.

func BlockCountVHDX

func BlockCountVHDX(bat *types.VHDXBlockAllocationTable) uint32

BlockCountVHDX returns the total number of blocks in a VHDX BAT.

func BlockOffsetVHD

func BlockOffsetVHD(bat *types.VHDBlockAllocationTable, index uint32) (int64, error)

BlockOffset returns the physical file offset for a block in a VHD BAT.

func BlockOffsetVHDX

func BlockOffsetVHDX(bat *types.VHDXBlockAllocationTable, index uint32) (int64, error)

BlockOffsetVHDX returns the physical file offset for a block in a VHDX BAT.

func IsAllocatedVHD

func IsAllocatedVHD(bat *types.VHDBlockAllocationTable, index uint32) (bool, error)

IsAllocatedVHD checks if a block is allocated in a VHD BAT.

func IsAllocatedVHDX

func IsAllocatedVHDX(bat *types.VHDXBlockAllocationTable, index uint32) (bool, error)

IsAllocatedVHDX checks if a block is allocated in a VHDX BAT.

Types

type SectorBitmap

type SectorBitmap struct {
	// contains filtered or unexported fields
}

SectorBitmap provides methods to work with VHD block bitmaps.

A VHD block bitmap holds one bit per 512-byte sector of the block, stored most-significant-bit first: the first sector of the block is bit 7 of byte 0. This is the ordering used by the VHD specification, the reference libvhdi C implementation and qemu's vpc driver.

VHDX sector bitmaps use the opposite (least-significant-bit first) ordering and are handled separately; do not use this type for them.

func NewSectorBitmap

func NewSectorBitmap(data []byte) *SectorBitmap

NewSectorBitmap creates a new sector bitmap from raw data.

func ReadSectorBitmap

func ReadSectorBitmap(reader io.ReaderAt, offset int64, bitmapSize uint32) (*SectorBitmap, error)

ReadSectorBitmap reads a sector bitmap from file.

func (*SectorBitmap) GetAllocatedSectorRanges

func (sb *SectorBitmap) GetAllocatedSectorRanges() []types.SectorRangeDescriptor

GetAllocatedSectorRanges returns a list of contiguous allocated sector ranges.

func (*SectorBitmap) IsSectorAllocated

func (sb *SectorBitmap) IsSectorAllocated(sectorIndex uint32) bool

IsSectorAllocated checks if a sector (within a block) is allocated.

Bits are read most-significant-bit first, per the VHD specification.

type VHDBATParser

type VHDBATParser struct {
	// contains filtered or unexported fields
}

VHDBATParser provides functionality to parse VHD Block Allocation Tables.

func NewVHDBATParser

func NewVHDBATParser(r io.ReaderAt) *VHDBATParser

NewVHDBATParser creates a new VHD BAT parser.

func (*VHDBATParser) ReadBAT

func (p *VHDBATParser) ReadBAT(offset int64, blockCount uint32, blockSize uint32) (*types.VHDBlockAllocationTable, error)

ReadBAT reads the VHD BAT from the specified offset and block count.

type VHDXBATParser

type VHDXBATParser struct {
	// contains filtered or unexported fields
}

VHDXBATParser provides functionality to parse VHDX Block Allocation Tables.

func NewVHDXBATParser

func NewVHDXBATParser(r io.ReaderAt) *VHDXBATParser

NewVHDXBATParser creates a new VHDX BAT parser.

func (*VHDXBATParser) ReadBAT

func (p *VHDXBATParser) ReadBAT(offset int64, blockCount uint32, blockSize uint32, sectorSize uint32) (*types.VHDXBlockAllocationTable, error)

ReadBAT reads the VHDX BAT from the specified offset and block count. For VHDX, the block size should be obtained from metadata (typically 1MB or 32MB). sectorSize is the logical sector size (typically 512 or 4096); pass 0 to default to 512.

The VHDX BAT interleaves sector bitmap entries: for every chunkRatio data block entries there is one sector bitmap entry:

[data_0..data_(chunkRatio-1)] [sbitmap_0] [data_chunkRatio..] [sbitmap_1] ...

where chunkRatio = (2^23 × logical_sector_size) / block_size.

Jump to

Keyboard shortcuts

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