Documentation ¶
Overview ¶
Package gpt implements read/write support for GPT partition tables.
Index ¶
- type Device
- type Option
- type Options
- type Partition
- type PartitionOption
- type PartitionOptions
- type Table
- func (t *Table) AllocatePartition(size uint64, name string, partType uuid.UUID, opts ...PartitionOption) (int, Partition, error)
- func (t *Table) AvailablePartitionGrowth(partition int) (uint64, error)
- func (t *Table) Clear()
- func (t *Table) Compact()
- func (t *Table) DeletePartition(partition int) error
- func (t *Table) GrowPartition(partition int, size uint64) error
- func (t *Table) LargestContiguousAllocatable() uint64
- func (t *Table) Partitions() []*Partition
- func (t *Table) Write() error
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.
type Option ¶
type Option func(*Options)
Option is a function that sets some option.
func WithDiskGUID ¶
WithDiskGUID is an option to set disk GUID.
func WithMarkPMBRBootable ¶
func WithMarkPMBRBootable() Option
WithMarkPMBRBootable is an option to mark protective MBR bootable.
func WithSkipLBAs ¶
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 ¶
PartitionOptions configure a partition.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a wrapper type around GPT partition table.
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 ¶
AvailablePartitionGrowth returns the number of bytes that can be added to the partition.
func (*Table) Compact ¶
func (t *Table) Compact()
Compact the partition table by removing empty entries.
func (*Table) DeletePartition ¶
DeletePartition deletes a partition from the table.
func (*Table) GrowPartition ¶
GrowPartition grows the partition by the specified number of bytes.
func (*Table) LargestContiguousAllocatable ¶
LargestContiguousAllocatable returns the size of the largest contiguous allocatable range.
func (*Table) Partitions ¶
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.