gpt

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MPL-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package gpt implements read/write support for GPT partition tables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	io.ReaderAt
	io.WriterAt

	GetSectorSize() uint
	GetSize() uint64
	GetIOSize() (uint, error)
	Sync() error

	GetKernelLastPartitionNum() (int, error)
	KernelPartitionAdd(no int, start, length uint64) error
	KernelPartitionResize(no int, first, length uint64) error
	KernelPartitionDelete(no int) error
}

Device is an interface around actual block device.

func DeviceFromBlockDevice

func DeviceFromBlockDevice(dev *block.Device) (Device, error)

DeviceFromBlockDevice creates a new Device from a block.Device.

type Option

type Option func(*Options)

Option is a function that sets some option.

func WithDiskGUID

func WithDiskGUID(guid uuid.UUID) Option

WithDiskGUID is an option to set disk GUID.

func WithMarkPMBRBootable

func WithMarkPMBRBootable() Option

WithMarkPMBRBootable is an option to mark protective MBR bootable.

func WithSkipLBAs

func WithSkipLBAs(n uint) Option

WithSkipLBAs is an option to skip writing partition entries.

func WithSkipPMBR

func WithSkipPMBR() Option

WithSkipPMBR is an option to skip writing protective MBR.

type Options

type Options struct {
	SkipPMBR         bool
	MarkPMBRBootable bool

	// Number of LBAs to skip before the writing partition entries.
	SkipLBAs uint

	// DiskGUID is a GUID for the disk.
	//
	// If not set, on partition table creation, a new GUID is generated.
	DiskGUID uuid.UUID
}

Options is a set of options for creating a new partition table.

type Partition

type Partition struct {
	Name string

	TypeGUID uuid.UUID
	PartGUID uuid.UUID

	FirstLBA uint64
	LastLBA  uint64

	Flags uint64
}

Partition is a single partition entry in GPT.

type PartitionOption

type PartitionOption func(*PartitionOptions)

PartitionOption is a function that sets some option.

func WithLegacyBIOSBootableAttribute

func WithLegacyBIOSBootableAttribute(val bool) PartitionOption

WithLegacyBIOSBootableAttribute marks the partition as bootable.

func WithUniqueGUID

func WithUniqueGUID(guid uuid.UUID) PartitionOption

WithUniqueGUID is an option to set a unique GUID for the partition.

type PartitionOptions

type PartitionOptions struct {
	UniqueGUID uuid.UUID
	Flags      uint64
}

PartitionOptions configure a partition.

type Table

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

Table is a wrapper type around GPT partition table.

func New

func New(dev Device, opts ...Option) (*Table, error)

New creates a new (empty) partition table for a specified device.

func Read

func Read(dev Device, opts ...Option) (*Table, error)

Read reads the partition table from the device.

func (*Table) AllocatePartition

func (t *Table) AllocatePartition(size uint64, name string, partType uuid.UUID, opts ...PartitionOption) (int, Partition, error)

AllocatePartition adds a new partition to the table.

If successful, returns the partition number (1-indexed) and the partition entry created.

func (*Table) AvailablePartitionGrowth

func (t *Table) AvailablePartitionGrowth(partition int) (uint64, error)

AvailablePartitionGrowth returns the number of bytes that can be added to the partition.

func (*Table) Clear

func (t *Table) Clear()

Clear the partition table.

func (*Table) Compact

func (t *Table) Compact()

Compact the partition table by removing empty entries.

func (*Table) DeletePartition

func (t *Table) DeletePartition(partition int) error

DeletePartition deletes a partition from the table.

func (*Table) GrowPartition

func (t *Table) GrowPartition(partition int, size uint64) error

GrowPartition grows the partition by the specified number of bytes.

func (*Table) LargestContiguousAllocatable

func (t *Table) LargestContiguousAllocatable() uint64

LargestContiguousAllocatable returns the size of the largest contiguous allocatable range.

func (*Table) Partitions

func (t *Table) Partitions() []*Partition

Partitions returns the list of partitions in the table.

The returned list should not be modified. Partitions in the list are zero-indexed, while Linux kernel partitions are one-indexed.

func (*Table) Write

func (t *Table) Write() error

Write writes the partition table to the device.

Jump to

Keyboard shortcuts

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