diskutil

package
v0.0.0-...-4ddf654 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package diskutil provides the functionality necessary for interacting with macOS's diskutil CLI.

Index

Constants

This section is empty.

Variables

View Source
var ErrReadOnly = errors.New("read-only mode")

ErrReadOnly identifies errors due to dry-run not being able to continue without mutating changes.

Functions

func Dryrun

func Dryrun(impl DiskUtil) *readonlyWrapper

Dryrun takes a DiskUtil implementation and wraps the mutating methods with dryrun alternatives.

func GrowContainer

func GrowContainer(ctx context.Context, u DiskUtil, container *types.DiskInfo) error

GrowContainer grows a container to its maximum size by performing the following operations:

  1. Verify that the given types.DiskInfo is an APFS container that can be resized.
  2. Fetch the types.DiskInfo for the underlying physical disk (if the container isn't a physical device).
  3. Repair the parent disk to force the kernel to get the latest GPT information for the disk.
  4. Check if there's enough free space on the disk to perform an APFS.ResizeContainer.
  5. Resize the container to its maximum size.

Types

type APFS

type APFS interface {
	// ResizeContainer attempts to grow the APFS container with the given device identifier
	// to the specified size. If the given size is 0, ResizeContainer will attempt to grow
	// the disk to its maximum size.
	ResizeContainer(ctx context.Context, id string, size string) (string, error)
}

APFS outlines the functionality necessary for wrapping diskutil's "apfs" verb.

type APFSImpl

type APFSImpl interface {
	// ResizeContainer attempts to grow the APFS container with the given device identifier
	// to the specified size. If the given size is 0, ResizeContainer will attempt to grow
	// the disk to its maximum size.
	ResizeContainer(ctx context.Context, id string, size string) (string, error)
}

APFSImpl outlines the functionality necessary for wrapping diskutil's APFS verb.

type Decoder

type Decoder interface {
	// DecodeSystemPartitions takes an io.ReadSeeker for the raw plist data of all disks and partition information
	// and decodes it into a new types.SystemPartitions struct.
	DecodeSystemPartitions(reader io.ReadSeeker) (*types.SystemPartitions, error)

	// DecodeDiskInfo takes an io.ReadSeeker for the raw plist data of disk information and decodes it into
	// a new types.DiskInfo struct.
	DecodeDiskInfo(reader io.ReadSeeker) (*types.DiskInfo, error)
}

Decoder outlines the functionality necessary for decoding plist output from the macOS diskutil command.

type DiskUtil

type DiskUtil interface {
	// APFS outlines the functionality necessary for wrapping diskutil's "apfs" verb.
	APFS
	// Info fetches raw disk information for the specified device identifier.
	Info(ctx context.Context, id string) (*types.DiskInfo, error)
	// List fetches all disk and partition information for the system.
	// This output will be filtered based on the args provided.
	List(ctx context.Context, args []string) (*types.SystemPartitions, error)
	// RepairDisk attempts to repair the disk for the specified device identifier.
	// This process requires root access.
	RepairDisk(ctx context.Context, id string) (string, error)
}

DiskUtil outlines the functionality necessary for wrapping macOS's diskutil tool.

func ForProduct

func ForProduct(p *system.Product) (DiskUtil, error)

ForProduct creates a new diskutil controller for the given product.

type DiskUtilityCmd

type DiskUtilityCmd struct{}

DiskUtilityCmd is an empty struct that provides the implementation for the DiskUtility interface.

func (*DiskUtilityCmd) Info

func (d *DiskUtilityCmd) Info(ctx context.Context, id string) (string, error)

Info uses the macOS diskutil info command to get detailed information about a disk, partition, or container format by passing the -plist arg.

func (*DiskUtilityCmd) List

func (d *DiskUtilityCmd) List(ctx context.Context, args []string) (string, error)

List uses the macOS diskutil list command to list disks and partitions in a plist format by passing the -plist arg. List also appends any given args to fully support the diskutil list verb.

func (*DiskUtilityCmd) RepairDisk

func (d *DiskUtilityCmd) RepairDisk(ctx context.Context, id string) (string, error)

RepairDisk uses the macOS diskutil diskRepair command to repair the specified volume and get updated information (e.g. amount of free space).

func (*DiskUtilityCmd) ResizeContainer

func (d *DiskUtilityCmd) ResizeContainer(ctx context.Context, id string, size string) (string, error)

ResizeContainer uses the macOS diskutil apfs resizeContainer command to change the size of the specific container ID.

type FreeSpaceError

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

FreeSpaceError defines an error to distinguish when there's not enough space to grow the specified container.

func (FreeSpaceError) Error

func (e FreeSpaceError) Error() string

type PlistDecoder

type PlistDecoder struct{}

PlistDecoder provides the plist Decoder implementation.

func (*PlistDecoder) DecodeDiskInfo

func (d *PlistDecoder) DecodeDiskInfo(reader io.ReadSeeker) (*types.DiskInfo, error)

DecodeDiskInfo assumes the io.ReadSeeker it's given contains raw plist data and attempts to decode that.

func (*PlistDecoder) DecodeSystemPartitions

func (d *PlistDecoder) DecodeSystemPartitions(reader io.ReadSeeker) (*types.SystemPartitions, error)

DecodeSystemPartitions assumes the io.ReadSeeker it's given contains raw plist data and attempts to decode that.

type UtilImpl

type UtilImpl interface {
	// APFSImpl outlines the functionality necessary for wrapping diskutil's APFS verb.
	APFSImpl
	// Info fetches raw disk information for the specified device identifier.
	Info(ctx context.Context, id string) (string, error)
	// List fetches all disk and partition information for the system.
	// This output will be filtered based on the args provided.
	List(ctx context.Context, args []string) (string, error)
	// RepairDisk attempts to repair the disk for the specified device identifier.
	// This process requires root access.
	RepairDisk(ctx context.Context, id string) (string, error)
}

UtilImpl outlines the functionality necessary for wrapping macOS's diskutil tool. The methods are intentionally named to correspond to diskutil(8)'s subcommand names as its API.

Directories

Path Synopsis
Package mock_diskutil is a generated GoMock package.
Package mock_diskutil is a generated GoMock package.

Jump to

Keyboard shortcuts

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