Documentation
¶
Overview ¶
Package bat provides Block Allocation Table (BAT) parsing and lookup logic.
Index ¶
- func BlockCountVHD(bat *types.VHDBlockAllocationTable) uint32
- func BlockCountVHDX(bat *types.VHDXBlockAllocationTable) uint32
- func BlockOffsetVHD(bat *types.VHDBlockAllocationTable, index uint32) (int64, error)
- func BlockOffsetVHDX(bat *types.VHDXBlockAllocationTable, index uint32) (int64, error)
- func IsAllocatedVHD(bat *types.VHDBlockAllocationTable, index uint32) (bool, error)
- func IsAllocatedVHDX(bat *types.VHDXBlockAllocationTable, index uint32) (bool, error)
- type SectorBitmap
- type VHDBATParser
- type VHDXBATParser
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 ¶
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.