diskimages2

package
v0.0.0-...-eebc809 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package diskimages2 provides convenience wrappers around the generated DiskImages2 framework bindings. It offers a high-level Go API for disk image operations (attach, detach, create, resize, info) while delegating the low-level ObjC interop to the generated package.

Index

Constants

This section is empty.

Variables

View Source
var ErrFrameworkUnavailable = errors.New("diskimages2: framework not available")

ErrFrameworkUnavailable is returned when DiskImages2.framework cannot be loaded.

Functions

func AttachSimple

func AttachSimple(path string, readOnly, autoMount bool) (bsdName string, err error)

AttachSimple attaches a disk image using DICommonAttach's convenience method. Returns the BSD device name (e.g., "disk27").

func Available

func Available() bool

Available reports whether DiskImages2.framework is loaded and usable.

func CreateASIF

func CreateASIF(path string, sizeBytes int64) error

CreateASIF creates an Apple Sparse Image Format disk image at the given path. ASIF only allocates blocks on write (similar to QCOW2), making it efficient for VM disk images.

sizeBytes is the virtual size of the image. The on-disk size starts near zero and grows as data is written.

func Detach

func Detach(bsdName string) error

Detach detaches a previously attached disk image by BSD name. DiskImages2 does not expose a detach API; this calls hdiutil detach.

func DetachHandle

func DetachHandle(h *DeviceHandle) error

DetachHandle detaches using an existing DeviceHandle, then releases it.

func Resize

func Resize(path string, newSizeBytes int64) error

Resize resizes an existing disk image (ASIF or other supported format). newSizeBytes is the new virtual size.

Types

type AttachOptions

type AttachOptions struct {
	ReadOnly  bool
	AutoMount bool
	FileMode  int64 // 0 = default
}

AttachOptions configures disk image attachment behavior.

type AttachedDeviceInfo

type AttachedDeviceInfo struct {
	BSDName   string
	ImageURL  string
	MediaSize int64
}

AttachedDeviceInfo describes a currently attached disk image.

func ListAttached

func ListAttached() ([]AttachedDeviceInfo, error)

ListAttached returns info about all currently attached disk images.

type DeviceHandle

type DeviceHandle struct {
	BSDName    string // e.g., "disk27"
	RegEntryID uint64
	// contains filtered or unexported fields
}

DeviceHandle represents an attached disk image device. Call DeviceHandle.Release to free the underlying ObjC handle.

func Attach

func Attach(path string, opts AttachOptions) (*DeviceHandle, error)

Attach attaches a disk image at the given path using DIAttachParams. Returns a DeviceHandle with the BSD device name. The caller must call DeviceHandle.Release when done (or use DetachHandle).

func (*DeviceHandle) Release

func (h *DeviceHandle) Release()

Release releases the underlying ObjC handle.

type ImageInfo

type ImageInfo struct {
	// Raw is the NSDictionary returned by retrieveInfoWithParams:,
	// exposed as a map for callers that need framework-specific keys.
	Raw map[string]string
}

ImageInfo contains metadata about a disk image file.

func RetrieveInfo

func RetrieveInfo(path string) (*ImageInfo, error)

RetrieveInfo returns metadata about a disk image file using DIImageInfoParams. The returned ImageInfo.Raw contains the NSDictionary keys as strings.

Jump to

Keyboard shortcuts

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