gpt

package module
v0.0.0-...-7da10ae Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 7 Imported by: 43

README

Library for direct work with GPT table.

Documentation:
https://godoc.org/github.com/rekby/gpt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GUID_LVM = PartType([16]byte{0x79, 0xd3, 0xd6, 0xe6, 0x7, 0xf5, 0xc2, 0x44, 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28}) // E6D6D379-F507-44C2-A23C-238F2A3DF928
)

Functions

func StringToGuid

func StringToGuid(guid string) (res [16]byte, err error)

Use for create guid predefined values in snippet http://play.golang.org/p/uOd_WQtiwE

Types

type Flags

type Flags [8]byte

type Guid

type Guid [16]byte

func NewGUID

func NewGUID() Guid

func (Guid) String

func (this Guid) String() string
type Header struct {
	Signature               [8]byte // Offset  0. "EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h
	Revision                uint32  // Offset  8
	Size                    uint32  // Offset 12
	CRC                     uint32  // Offset 16. Autocalc when save Header.
	Reserved                uint32  // Offset 20
	HeaderStartLBA          uint64  // Offset 24
	HeaderCopyStartLBA      uint64  // Offset 32
	FirstUsableLBA          uint64  // Offset 40
	LastUsableLBA           uint64  // Offset 48
	DiskGUID                Guid    // Offset 56
	PartitionsTableStartLBA uint64  // Offset 72
	PartitionsArrLen        uint32  // Offset 80
	PartitionEntrySize      uint32  // Offset 84
	PartitionsCRC           uint32  // Offset 88. Autocalc when save Table.
	TrailingBytes           []byte  // Offset 92
}

https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_table_header_.28LBA_1.29

type NewTableArgs

type NewTableArgs struct {
	SectorSize uint64
	DiskGuid   Guid
}

NewTableArgs - arguments NewTable creation.

type PartType

type PartType Guid

func (PartType) String

func (this PartType) String() string

type Partition

type Partition struct {
	Type          PartType // Offset 0
	Id            Guid     // Offset 16
	FirstLBA      uint64   // Offset 32
	LastLBA       uint64   // Offset 40
	Flags         Flags    // Offset 68
	PartNameUTF16 [72]byte // Offset 56
	TrailingBytes []byte   // Offset 128. Usually it is empty
}

https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries

func (Partition) IsEmpty

func (this Partition) IsEmpty() bool

func (Partition) Name

func (this Partition) Name() string

type Table

type Table struct {
	SectorSize uint64 // in bytes
	Header     Header
	Partitions []Partition
}

func NewTable

func NewTable(diskSize uint64, args *NewTableArgs) Table

NewTable - return a valid empty Table for given sectorSize and diskSize

Note that a Protective MBR is needed for lots of software to read the GPT table.

func ReadTable

func ReadTable(reader io.ReadSeeker, SectorSize uint64) (table Table, err error)

Read GPT partition Have to set to first byte of GPT Header (usually start of second sector on disk)

func (Table) CreateOtherSideTable

func (this Table) CreateOtherSideTable() (res Table)

func (Table) CreateTableForNewDiskSize

func (this Table) CreateTableForNewDiskSize(size uint64) (res Table)

Create primary table for resized disk size - in sectors

func (Table) Write

func (this Table) Write(writer io.WriteSeeker) (err error)

Calc header and partitions CRC. Save Header and partition entries to the disk. It independent of start position: writer will be seek to position from Table.Header.

Jump to

Keyboard shortcuts

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