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() (err error)
- func (g *GPT) Repair() error
- func (g *GPT) Resize(part *Partition) (bool, error)
- func (g *GPT) Write() (err error)
- type Header
- func (h *Header) DeserializeBackupLBA() (err error)
- func (h *Header) DeserializeCRC() (err error)
- func (h *Header) DeserializeCurrentLBA() (err error)
- func (h *Header) DeserializeFirstUsableLBA() (err error)
- func (h *Header) DeserializeGUUID() (err error)
- func (h *Header) DeserializeLastUsableLBA() (err error)
- func (h *Header) DeserializeNumberOfPartitionEntries() (err error)
- func (h *Header) DeserializePartitionEntriesCRC() (err error)
- func (h *Header) DeserializePartitionEntrySize() (err error)
- func (h *Header) DeserializeRevision() (err error)
- func (h *Header) DeserializeSignature() (err error)
- func (h *Header) DeserializeSize() (err error)
- func (h *Header) DeserializeStartingLBA() (err error)
- func (h *Header) Primary() (b []byte, err error)
- func (h *Header) Secondary() (b []byte, err error)
- func (h *Header) SerializeBackupLBA() (err error)
- func (h *Header) SerializeCRC() (err error)
- func (h *Header) SerializeCurrentLBA() (err error)
- func (h *Header) SerializeFirstUsableLBA() (err error)
- func (h *Header) SerializeGUUID() (err error)
- func (h *Header) SerializeLastUsableLBA() (err error)
- func (h *Header) SerializeNumberOfPartitionEntries() (err error)
- func (h *Header) SerializePartitionEntriesCRC() (err error)
- func (h *Header) SerializePartitionEntrySize() (err error)
- func (h *Header) SerializeRevision() (err error)
- func (h *Header) SerializeSignature() (err error)
- func (h *Header) SerializeSize() (err error)
- func (h *Header) SerializeStartingLBA() (err error)
- type Option
- type Options
- type Partition
- func (p *Partition) DeserializeAttributes(buf *lba.Buffer) (err error)
- func (p *Partition) DeserializeFirstLBA(buf *lba.Buffer) (err error)
- func (p *Partition) DeserializeID(buf *lba.Buffer) (err error)
- func (p *Partition) DeserializeLastLBA(buf *lba.Buffer) (err error)
- func (p *Partition) DeserializeName(buf *lba.Buffer) (err error)
- func (p *Partition) DeserializeType(buf *lba.Buffer) (err error)
- func (p *Partition) Filesystem() (string, error)
- func (p *Partition) Length() uint64
- func (p *Partition) Path() (string, error)
- func (p *Partition) SerializeAttributes(buf *lba.Buffer) (err error)
- func (p *Partition) SerializeFirstLBA(buf *lba.Buffer) (err error)
- func (p *Partition) SerializeID(buf *lba.Buffer) (err error)
- func (p *Partition) SerializeLastLBA(buf *lba.Buffer) (err error)
- func (p *Partition) SerializeName(buf *lba.Buffer) (err error)
- func (p *Partition) SerializeType(buf *lba.Buffer) (err error)
- 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("does not exist") // ErrHeaderCRCMismatch indicates that the header CRC does not match what is on disk. ErrHeaderCRCMismatch = errors.New("header CRC mismatch") // ErrEntriesCRCMismatch indicates that the partitions array CRC does not match what is on disk. ErrEntriesCRCMismatch = errors.New("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.Buffer *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.
nolint: maligned
func (*Header) DeserializeBackupLBA ¶
DeserializeBackupLBA deserializes the backup LBA (location of the other header copy).
func (*Header) DeserializeCRC ¶
DeserializeCRC deserializes the CRC32 of header (offset +0 up to header size) in little endian, with this field zeroed during calculation.
func (*Header) DeserializeCurrentLBA ¶
DeserializeCurrentLBA deserializes the current LBA (location of this header copy).
func (*Header) DeserializeFirstUsableLBA ¶
DeserializeFirstUsableLBA deserializes the first usable LBA for partitions (primary partition table last LBA + 1).
func (*Header) DeserializeGUUID ¶
DeserializeGUUID deserializes the disk GUID in mixed endian.
func (*Header) DeserializeLastUsableLBA ¶
DeserializeLastUsableLBA deserializes the last usable LBA (secondary partition table first LBA − 1).
func (*Header) DeserializeNumberOfPartitionEntries ¶
DeserializeNumberOfPartitionEntries deserializes the number of partition entries in array.
func (*Header) DeserializePartitionEntriesCRC ¶
DeserializePartitionEntriesCRC deserializes the CRC32 of partition entries array in little endian.
func (*Header) DeserializePartitionEntrySize ¶
DeserializePartitionEntrySize deserializes the size of a single partition entry (usually 80h or 128).
func (*Header) DeserializeRevision ¶
DeserializeRevision deserializes the revision (for GPT version 1.0 (through at least UEFI version 2.7 (May 2017)), the value is 00h 00h 01h 00h).
func (*Header) DeserializeSignature ¶
DeserializeSignature desirializes the signature ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL on little-endian machines).
func (*Header) DeserializeSize ¶
DeserializeSize deserializes the header size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes).
func (*Header) DeserializeStartingLBA ¶
DeserializeStartingLBA deserializes the starting LBA of array of partition entries (always 2 in primary copy).
func (*Header) SerializeBackupLBA ¶
SerializeBackupLBA serializes the backup LBA (location of the other header copy).
func (*Header) SerializeCRC ¶
SerializeCRC serializes the CRC32 of header (offset +0 up to header size) in little endian, with this field zeroed during calculation.
func (*Header) SerializeCurrentLBA ¶
SerializeCurrentLBA serializes the current LBA (location of this header copy).
func (*Header) SerializeFirstUsableLBA ¶
SerializeFirstUsableLBA serializes the first usable LBA for partitions (primary partition table last LBA + 1).
func (*Header) SerializeGUUID ¶
SerializeGUUID serializes the disk GUID in mixed endian.
func (*Header) SerializeLastUsableLBA ¶
SerializeLastUsableLBA serializes the last usable LBA (secondary partition table first LBA − 1).
func (*Header) SerializeNumberOfPartitionEntries ¶
SerializeNumberOfPartitionEntries serializes the number of partition entries in array.
func (*Header) SerializePartitionEntriesCRC ¶
SerializePartitionEntriesCRC serializes the CRC32 of partition entries array in little endian.
func (*Header) SerializePartitionEntrySize ¶
SerializePartitionEntrySize serializes the size of a single partition entry (usually 80h or 128).
func (*Header) SerializeRevision ¶
SerializeRevision serializes the revision (for GPT version 1.0 (through at least UEFI version 2.7 (May 2017)), the value is 00h 00h 01h 00h).
func (*Header) SerializeSignature ¶
SerializeSignature serializes the signature ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL on little-endian machines).
func (*Header) SerializeSize ¶
SerializeSize serializes the header size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes).
func (*Header) SerializeStartingLBA ¶
SerializeStartingLBA serializes the starting LBA of array of partition entries (always 2 in primary copy).
type Option ¶
Option is the functional option func.
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 ¶
type Options struct {
PartitionEntriesStartLBA uint64
}
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) DeserializeAttributes ¶
DeserializeAttributes deserializes the attribute flags (e.g. bit 60 denotes read-only).
func (*Partition) DeserializeFirstLBA ¶
DeserializeFirstLBA deserializes the first LBA (little endian).
func (*Partition) DeserializeID ¶
DeserializeID deserializes the unique partition GUID (mixed endian).
func (*Partition) DeserializeLastLBA ¶
DeserializeLastLBA deserializes the last LBA (inclusive, usually odd).
func (*Partition) DeserializeName ¶
DeserializeName deserializes partition name (36 UTF-16LE code units).
func (*Partition) DeserializeType ¶
DeserializeType deserializes the partition type GUID (mixed endian).
func (*Partition) Filesystem ¶
Filesystem returns partition filesystem type.
func (*Partition) SerializeAttributes ¶
SerializeAttributes serializes the attribute flags (e.g. bit 60 denotes read-only).
func (*Partition) SerializeFirstLBA ¶
SerializeFirstLBA serializes the first LBA (little endian).
func (*Partition) SerializeID ¶
SerializeID serializes the unique partition GUID (mixed endian).
func (*Partition) SerializeLastLBA ¶
SerializeLastLBA serializes the last LBA (inclusive, usually odd).
func (*Partition) SerializeName ¶
SerializeName serializes the partition name (36 UTF-16LE code units).
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 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 ¶
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.