image_qcow2

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

README

qcow2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToRaw

func ConvertToRaw(src, dst string, w io.Writer) error

ConvertToRaw reads a QCOW2 v2/v3 image at src and writes an equivalent raw disk image to dst. It writes "N%\n" progress lines to w.

Supported features:

  • Compressed clusters: deflate (type 0, default)

Unsupported features (return an error):

  • Encryption (encryption_method != 0 in the header)
  • ZSTD compression (QCOW2 v3 with compression_type=1)

Backing files are not followed: unallocated clusters are written as zeros.

func Create

func Create(path string, sizeBytes int64) error

Create writes a new empty QCOW2 v2 image at path with the given virtual size in bytes. The file contains no allocated data clusters; reads from the raw image will return zeros.

func IsQCOW2File

func IsQCOW2File(path string) bool

IsQCOW2File returns true if path starts with the QCOW2 magic bytes (0x514649fb = "QFI\xfb").

Types

type Device

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

Device provides read-write block device access to a QCOW2 v2/v3 image. Unallocated virtual clusters are allocated lazily on first write (COW append). Compressed clusters are supported for reading; writing to a compressed cluster returns an error (re-compression is not implemented).

func OpenDevice

func OpenDevice(path string) (*Device, error)

OpenDevice opens the QCOW2 image at path as a read-write block device.

func (*Device) Close

func (d *Device) Close() error

Close closes the underlying file.

func (*Device) Fd

func (d *Device) Fd() uintptr

Fd returns the underlying file descriptor. Useful for callers that need to pass the QCOW2 container to syscall- or sparse-tools-flavoured APIs (note the fd is the container, not the virtual disk — random reads via the fd yield QCOW2-format bytes, not raw guest data; use ReadAt for the latter).

func (*Device) ReadAt

func (d *Device) ReadAt(p []byte, off int64) (int, error)

ReadAt implements io.ReaderAt for the virtual disk address space.

func (*Device) Size

func (d *Device) Size() (int64, error)

Size returns the virtual size of the QCOW2 image.

func (*Device) Sync

func (d *Device) Sync() error

Sync flushes all writes to the underlying file.

func (*Device) Truncate

func (d *Device) Truncate(size int64) error

Truncate is not supported; the virtual size is fixed at image creation.

func (*Device) WriteAt

func (d *Device) WriteAt(p []byte, off int64) (int, error)

WriteAt implements io.WriterAt for the virtual disk address space. Compressed clusters cannot be overwritten; use uncompressed images for read-write access.

type Format

type Format struct{}

Format is the QCOW2 disk image format. A Format value satisfies the diskimage_format.Format interface defined in github.com/go-diskimages/interface without requiring an import of that module (Go structural typing).

func (Format) Create

func (Format) Create(path string, sizeBytes int64) error

Create creates a new QCOW2 disk image. Delegates to the package-level Create.

func (Format) Detect

func (Format) Detect(path string) (bool, error)

Detect returns (true, nil) if path contains a QCOW2 image.

func (Format) Name

func (Format) Name() string

Name returns "qcow2".

func (Format) Resize

func (Format) Resize(path string, newSizeBytes int64) error

Resize changes the virtual size of the QCOW2 image at path. Only growing is supported; shrinking returns an error because it may silently discard data. The L1 table is extended in-place when the new size requires more entries.

func (Format) ToRaw

func (Format) ToRaw(src, dst string, w io.Writer) error

ToRaw converts the QCOW2 image at src to a raw disk image at dst. Progress messages are written to w.

Jump to

Keyboard shortcuts

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