gpt

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MPL-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package gpt provides a library for working with GPT partitions.

Index

Constants

View Source
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

View Source
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 New

func New(f *os.File, setters ...Option) (*GPT, error)

New creates an in-memory partition table.

func Open

func Open(f *os.File) (*GPT, error)

Open attempts to open a partition table on f.

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) Delete

func (g *GPT) Delete(p *Partition) error

Delete deletes a partition.

func (*GPT) Header

func (g *GPT) Header() *Header

Header returns the partition table header.

func (*GPT) InsertAt

func (g *GPT) InsertAt(idx int, size uint64, setters ...PartitionOption) (*Partition, error)

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.

func (*GPT) Read

func (g *GPT) Read() error

Read reads the partition table on disk and updates the in-memory representation.

func (*GPT) Repair

func (g *GPT) Repair() error

Repair repairs the partition table.

func (*GPT) Resize

func (g *GPT) Resize(part *Partition) (bool, error)

Resize resizes a partition to next one if exists.

func (*GPT) Write

func (g *GPT) Write() error
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

type Option func(*Options) error

Option is the functional option func.

func WithMarkMBRBootable

func WithMarkMBRBootable(value bool) Option

WithMarkMBRBootable marks MBR partition as bootable.

func WithPartitionEntriesStartLBA

func WithPartitionEntriesStartLBA(o uint64) Option

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
	MarkMBRBootable          bool
}

Options is the functional options struct.

func NewDefaultOptions

func NewDefaultOptions(setters ...Option) (*Options, error)

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) Encrypted

func (p *Partition) Encrypted() (bool, error)

Encrypted checks if partition is encrypted.

func (*Partition) Filesystem

func (p *Partition) Filesystem() (string, error)

Filesystem returns partition filesystem type. if partition is encrypted it will return /dev/mapper parition filesystem kind.

func (*Partition) Length

func (p *Partition) Length() uint64

Length returns the partition's length in LBA.

func (*Partition) Path

func (p *Partition) Path() (string, error)

Path returns partition path.

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.

func (*Partitions) Items

func (p *Partitions) Items() []*Partition

Items returns the partitions.

Jump to

Keyboard shortcuts

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