qcow2

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CryptMethodNone = CryptMethod(0)
	CryptMethodAES  = CryptMethod(1)
	CryptMethodLUKS = CryptMethod(2)
)
View Source
const (
	IncompatibleFeaturesDirtyBit             = 0
	IncompatibleFeaturesCorruptBit           = 1
	IncompatibleFeaturesExternalDataFileBit  = 2
	IncompatibleFeaturesCompressionTypeBit   = 3
	IncompatibleFeaturesExtendedL2EntriesBit = 4
)
View Source
const (
	AutoclearFeaturesBitmapsExtensionBit = 0
	AutoclearFeaturesRawExternalBit      = 1
)
View Source
const (
	// CompressionTypeZlib is a misnomer. It is actually deflate without zlib header.
	CompressionTypeZlib = CompressionType(0)
	CompressionTypeZstd = CompressionType(1)
)
View Source
const (
	HeaderExtensionTypeEnd                             = HeaderExtensionType(0x00000000)
	HeaderExtensionTypeBackingFileFormatNameString     = HeaderExtensionType(0xe2792aca)
	HeaderExtensionTypeFeatureNameTable                = HeaderExtensionType(0x6803f857)
	HeaderExtensionTypeBitmapsExtension                = HeaderExtensionType(0x23852875)
	HeaderExtensionTypeFullDiskEncryptionHeaderPointer = HeaderExtensionType(0x0537be77)
	HeaderExtensionTypeExternalDataFileNameString      = HeaderExtensionType(0x44415441)
)
View Source
const (
	FeatureNameTableEntryTypeIncompatible = FeatureNameTableEntryType(0)
	FeatureNameTableEntryTypeCompatible   = FeatureNameTableEntryType(1)
	FeatureNameTableEntryTypeAutoclear    = FeatureNameTableEntryType(2)
)
View Source
const (
	CompatibleFeaturesLazyRefcountsBit = 0
)
View Source
const Magic = "QFI\xfb"

Magic is the qcow2 magic string.

View Source
const Type = "qcow2"

Variables

View Source
var (
	ErrNotQcow2               = fmt.Errorf("%w: image is not qcow2", image.ErrWrongType)
	ErrUnsupportedBackingFile = errors.New("unsupported backing file")
	ErrUnsupportedEncryption  = errors.New("unsupported encryption method")
	ErrUnsupportedCompression = errors.New("unsupported compression type")
	ErrUnsupportedFeature     = errors.New("unsupported feature")
)
View Source
var AutoclearFeaturesNames = []string{
	"bitmaps",
	"raw external data",
}
View Source
var CompatibleFeaturesNames = []string{
	"lazy refcounts",
}
View Source
var IncompatibleFeaturesNames = []string{
	"dirty bit",
	"corrupt bit",
	"external data file",
	"compression type",
	"extended L2 entries",
}

Functions

func SetDecompressor

func SetDecompressor(t CompressionType, d Decompressor)

SetDecompressor sets a custom decompressor. By default, flate.NewReader is registered for CompressionTypeZlib. No decompressor is registered by default for CompressionTypeZstd.

Types

type AutoclearFeatures

type AutoclearFeatures uint64

func (AutoclearFeatures) MarshalJSON

func (x AutoclearFeatures) MarshalJSON() ([]byte, error)

type CompatibleFeatures

type CompatibleFeatures uint64

func (CompatibleFeatures) MarshalJSON

func (x CompatibleFeatures) MarshalJSON() ([]byte, error)

type CompressionType

type CompressionType uint8

func (CompressionType) MarshalText

func (x CompressionType) MarshalText() ([]byte, error)

func (CompressionType) String

func (x CompressionType) String() string

type CryptMethod

type CryptMethod uint32

func (CryptMethod) MarshalText

func (x CryptMethod) MarshalText() ([]byte, error)

func (CryptMethod) String

func (x CryptMethod) String() string

type Decompressor

type Decompressor func(r io.Reader) (io.ReadCloser, error)

type FeatureName

type FeatureName [46]byte

type FeatureNameTableEntry

type FeatureNameTableEntry struct {
	Type FeatureNameTableEntryType `json:"type"`
	Bit  uint8                     `json:"bit"`
	Name string                    `json:"name"`
}

type FeatureNameTableEntryType

type FeatureNameTableEntryType uint8

func (FeatureNameTableEntryType) MarshalText

func (x FeatureNameTableEntryType) MarshalText() ([]byte, error)

func (FeatureNameTableEntryType) String

func (x FeatureNameTableEntryType) String() string

type Features

type Features struct {
	Raw   uint64   `json:"raw"`
	Names []string `json:"names"`
}

func (*Header) Length

func (header *Header) Length() int

func (*Header) Readable

func (header *Header) Readable() error

Readable returns nil if the image is readable, otherwise returns an error.

type HeaderExtension

type HeaderExtension struct {
	Type   HeaderExtensionType `json:"type"`
	Length uint32              `json:"length"`
	Data   interface{}         `json:"data,omitempty"`
}

type HeaderExtensionType

type HeaderExtensionType uint32

func (HeaderExtensionType) MarshalText

func (x HeaderExtensionType) MarshalText() ([]byte, error)

func (HeaderExtensionType) String

func (x HeaderExtensionType) String() string

type HeaderFieldsAdditional

type HeaderFieldsAdditional struct {
	CompressionType CompressionType `json:"compression_type"`
	// Pad is exposed to avoid `panic: reflect: reflect.Value.SetUint using value obtained using unexported field` during [binary.Read].
	Pad [7]byte `json:"-"`
}

type HeaderFieldsV2

type HeaderFieldsV2 struct {
	Magic                 MagicType   `json:"magic"`
	Version               uint32      `json:"version"`             // 2 or 3
	BackingFileOffset     uint64      `json:"backing_file_offset"` // offset of file name (not null terminated)
	BackingFileSize       uint32      `json:"backing_file_size"`   // length of file name (<= 1023)
	ClusterBits           uint32      `json:"cluster_bits"`
	Size                  uint64      `json:"size"` // Virtual disk size in bytes
	CryptMethod           CryptMethod `json:"crypt_method"`
	L1Size                uint32      `json:"l1_size"`         // Number of entries
	L1TableOffset         uint64      `json:"l1_table_offset"` // Offset into the image file
	RefcountTableOffset   uint64      `json:"refcount_table_offset"`
	RefcountTableClusters uint32      `json:"refcount_table_clusters"`
	NbSnapshots           uint32      `json:"nb_snapshots"` // Number of snapshots
	SnapshotsOffset       uint64      `json:"snapshots_offset"`
}

type HeaderFieldsV3

type HeaderFieldsV3 struct {
	IncompatibleFeatures IncompatibleFeatures `json:"incompatible_features"`
	CompatibleFeatures   CompatibleFeatures   `json:"compatible_features"`
	AutoclearFeatures    AutoclearFeatures    `json:"autoclear_features"`
	RefcountOrder        uint32               `json:"refcount_order"`
	HeaderLength         uint32               `json:"header_length"`
}

type IncompatibleFeatures

type IncompatibleFeatures uint64

func (IncompatibleFeatures) MarshalJSON

func (x IncompatibleFeatures) MarshalJSON() ([]byte, error)

type MagicType

type MagicType [4]byte

MagicType wraps magic bytes.

func (MagicType) MarshalText

func (x MagicType) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (MagicType) String

func (x MagicType) String() string

String implements fmt.Stringer.

type Namer

type Namer interface {
	Name() string
}

Namer is implemented by os.File.

type OffsetLengthPair64

type OffsetLengthPair64 struct {
	Offset uint64 `json:"offset"`
	Length uint64 `json:"length"`
}

type Qcow2

type Qcow2 struct {
	*Header          `json:"header"`
	HeaderExtensions []HeaderExtension `json:"header_extensions"`

	BackingFile         string     `json:"backing_file"`
	BackingFileFullPath string     `json:"backing_file_full_path"`
	BackingFileFormat   image.Type `json:"backing_file_format"`
	// contains filtered or unexported fields
}

Qcow2 implements image.Image.

func Open

func Open(ra io.ReaderAt, openWithType image.OpenWithType) (*Qcow2, error)

Open opens an qcow2 image.

To open an image with backing files, ra must implement Namer, and openWithType must be non-nil.

func (*Qcow2) Close

func (img *Qcow2) Close() error

func (*Qcow2) Extent added in v0.5.0

func (img *Qcow2) Extent(start, length int64) (image.Extent, error)

Extent returns the next extent starting at the specified offset. An extent describes one or more clusters having the same status. The maximum length of the returned extent is limited by the specified length. The minimum length of the returned extent is length of one cluster.

func (*Qcow2) ReadAt

func (img *Qcow2) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements io.ReaderAt.

func (*Qcow2) Readable

func (img *Qcow2) Readable() error

func (*Qcow2) Size

func (img *Qcow2) Size() int64

func (*Qcow2) Type

func (img *Qcow2) Type() image.Type

Jump to

Keyboard shortcuts

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