Documentation ¶
Overview ¶
Package gpt provides a library for working with GPT partitions.
Index ¶
- Constants
- Variables
- type GPT
- func (g *GPT) Add(size uint64, setters ...PartitionOption) (*Partition, error)
- func (g *GPT) Delete(p *Partition) error
- func (g *GPT) Header() *Header
- func (g *GPT) InsertAt(idx int, size uint64, setters ...PartitionOption) (*Partition, error)
- func (g *GPT) Partitions() *Partitions
- func (g *GPT) Read() error
- func (g *GPT) Repair() error
- func (g *GPT) Resize(part *Partition) (bool, error)
- func (g *GPT) Write() error
- type Header
- type Option
- type Options
- type Partition
- type PartitionOption
- type PartitionOptions
- type Partitions
Constants ¶
const ( // MagicEFIPart is the magic string in the GPT header signature field. MagicEFIPart = "EFI PART" // HeaderSize is the GUID partition table header size in bytes. HeaderSize = 92 )
Variables ¶
var ( // ErrPartitionTableDoesNotExist indicates that the partition table does not exist. ErrPartitionTableDoesNotExist = errors.New("block device partition table does not exist") // ErrHeaderCRCMismatch indicates that the header CRC does not match what is on disk. ErrHeaderCRCMismatch = errors.New("block device partition table header CRC mismatch") // ErrEntriesCRCMismatch indicates that the partitions array CRC does not match what is on disk. ErrEntriesCRCMismatch = errors.New("block device partition table entries CRC mismatch") )
Functions ¶
This section is empty.
Types ¶
type GPT ¶
type GPT struct {
// contains filtered or unexported fields
}
GPT represents the GUID Partition Table.
func (*GPT) Add ¶
func (g *GPT) Add(size uint64, setters ...PartitionOption) (*Partition, error)
Add adds a partition to the end of the list.
func (*GPT) InsertAt ¶
InsertAt inserts partition before the partition at the position idx.
If idx == 0, it inserts new partition as the first partition, etc., idx == 1 as the second, etc.
func (*GPT) Partitions ¶
func (g *GPT) Partitions() *Partitions
Partitions returns the partition table partitions.
type Header ¶
type Header struct { *lba.LBA Signature string Revision uint32 Size uint32 Checksum uint32 CurrentLBA uint64 BackupLBA uint64 FirstUsableLBA uint64 LastUsableLBA uint64 GUUID uuid.UUID EntriesLBA uint64 NumberOfPartitionEntries uint32 PartitionEntrySize uint32 PartitionEntriesChecksum uint32 }
Header represents the GPT header.
type Option ¶
Option is the functional option func.
func WithMarkMBRBootable ¶
WithMarkMBRBootable marks MBR partition as bootable.
func WithPartitionEntriesStartLBA ¶
WithPartitionEntriesStartLBA sets the LBA to be used for specifying which LBA should be used for the start of the partition entries.
type Options ¶
Options is the functional options struct.
func NewDefaultOptions ¶
NewDefaultOptions initializes an `Options` struct with default values.
type Partition ¶
type Partition struct { Type uuid.UUID ID uuid.UUID FirstLBA uint64 LastLBA uint64 Attributes uint64 Name string Number int32 // contains filtered or unexported fields }
Partition represents a GPT partition.
func (*Partition) Filesystem ¶
Filesystem returns partition filesystem type. if partition is encrypted it will return /dev/mapper parition filesystem kind.
func (*Partition) SuperBlock ¶
func (p *Partition) SuperBlock() (filesystem.SuperBlocker, error)
SuperBlock read partition superblock. if partition is encrypted it will always return superblock of the physical partition, instead of a mapped device partition.
type PartitionOption ¶
type PartitionOption func(*PartitionOptions)
PartitionOption is the functional option func.
func WithLegacyBIOSBootableAttribute ¶
func WithLegacyBIOSBootableAttribute(o bool) PartitionOption
WithLegacyBIOSBootableAttribute marks the partition as bootable.
func WithMaximumSize ¶
func WithMaximumSize(o bool) PartitionOption
WithMaximumSize indicates if the partition should be created with the maximum size possible.
func WithOffset ¶
func WithOffset(o uint64) PartitionOption
WithOffset sets partition start offset in bytes.
func WithPartitionName ¶
func WithPartitionName(o string) PartitionOption
WithPartitionName sets the partition name.
func WithPartitionType ¶
func WithPartitionType(id string) PartitionOption
WithPartitionType sets the partition type.
type PartitionOptions ¶
type PartitionOptions struct { Type uuid.UUID Name string Offset uint64 MaximumSize bool Attibutes uint64 }
PartitionOptions represent the options available for partitions.
func NewDefaultPartitionOptions ¶
func NewDefaultPartitionOptions(setters ...PartitionOption) *PartitionOptions
NewDefaultPartitionOptions initializes a Options struct with default values.
type Partitions ¶
type Partitions struct {
// contains filtered or unexported fields
}
Partitions represents the GPT partitions array.
func (*Partitions) FindByName ¶
func (p *Partitions) FindByName(name string) *Partition
FindByName finds partition by label.