gpt

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderSignature = 0x5452415020494645

The signature of GPT Header. "EFI PART".

Variables

This section is empty.

Functions

This section is empty.

Types

type Chs

type Chs struct {
	Body [3]byte
}

Chs represents Cylinder head sector ref: https://en.wikipedia.org/wiki/Cylinder-head-sector

func NewChs

func NewChs(h uint, s uint, c uint) (*Chs, error)

NewChs returns Chs from head, sector and cylinder value.

func (Chs) Cylinder

func (c Chs) Cylinder() uint

Cylinder returns the sector of disk

func (Chs) Head

func (c Chs) Head() uint

Head returns the head of disk.

func (Chs) Sector

func (c Chs) Sector() uint

Sector returns the sector of disk.

func (Chs) String

func (c Chs) String() string

String implements fmt.Stringer interface

type Entry

type Entry struct {
	TypeGuid   Guid
	UniqueGuid Guid
	FirstLBA   uint64
	LastLBA    uint64
	AttrFlags  uint64
	Name       [36]uint16
}

Entry represents a partition entries of GPT. ref: https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries_(LBA_2%E2%80%9333)

func ReadEntry

func ReadEntry(r io.Reader) (*Entry, error)

ReadEntry reads GPT Entry from r. It returns GPT Entry pointer or error if error occured.

func (Entry) IsBlank

func (e Entry) IsBlank() bool

func (Entry) ReadName

func (e Entry) ReadName() string

ReadName returns partition name string. It converts from UTF-16 name string.

func (*Entry) WriteName

func (e *Entry) WriteName(s string) error

WriteName writes s as UTF16 string.

type Gpt

type Gpt struct {
	Mbr           Mbr
	Header        Header
	Entries       []Entry
	BackupEntries []Entry
	BackupHeader  Header
}

GPT represents MBR, GPT header and each partition entries. It also contains backup header and entries.

func ReadGpt

func ReadGpt(rs io.ReadSeeker) (*Gpt, error)

ReadGpt reads GPT from rs.

type Guid

type Guid [16]byte
var EspGuid *Guid
var ZeroGuid *Guid

ZeroGuid 00000000-0000-0000-0000-00000000000

func NewGuidFromBytes

func NewGuidFromBytes(b []byte) (*Guid, error)

NewGuidFromBytes returns guid from b.

func NewGuidFromString

func NewGuidFromString(s string) (*Guid, error)

NewGuidFromString returns guid grom s. Format is 00112233-4455-6677-8899-aabbccddeeff

func (Guid) Equal

func (g Guid) Equal(gg Guid) bool

Equal check if gg is same guid.

func (Guid) String

func (g Guid) String() string

String implements Stringer interface.

type Header struct {
	Signature      uint64
	Revision       uint32
	Size           uint32
	Crc32OfHeader  uint32
	Reserved       uint32
	CurrentLBA     uint64
	BackupLBA      uint64
	FirstUsableLBA uint64
	LastUsableLBA  uint64
	DiskGuid       Guid
	StartingLBA    uint64
	NumOfEntries   uint32
	SizeOfEntry    uint32
	Crc32OfEntries uint32
	Reserved2      [420]byte
}

Header reprensents the partition table header of GPT. ref: https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_table_header_(LBA_1)

func ReadHeader

func ReadHeader(r io.Reader) (*Header, error)

ReadHeader reads GPT Header from r. This function treats sector size is 512 byte. It returns GPT Header pointer or error if error occured.

func (Header) IsValid

func (h Header) IsValid() bool

IsValid reports whether h is valid. It checks if

The signature is valid.
Crc32 of header is valid.

type Mbr

type Mbr struct {
	BootCode  [446]byte
	Entries   [4]MbrEntry
	Signature uint16
}

Mbr represents entier MBR. refs: https://en.wikipedia.org/wiki/Master_boot_record

func ReadMbr

func ReadMbr(r io.Reader) (*Mbr, error)

ReadMbr reads MBR from r.

func (Mbr) IsValid

func (m Mbr) IsValid() bool

IsValid check if the Mbr is valid.

The signature is 0xaa55

type MbrEntry

type MbrEntry struct {
	BootFlag byte
	FirstChs Chs
	Id       byte
	LastChs  Chs
	FirstLBA uint32
	AllLBA   uint32
}

MbrEntry represents the partition entry.

func (MbrEntry) IdString

func (m MbrEntry) IdString() string

type RChs added in v0.0.2

type RChs struct {
	Head     uint
	Sector   uint
	Cylinder uint
}

RChs represents Chs for human readable format.

func NewRChs added in v0.0.2

func NewRChs(c Chs) *RChs

type REntry added in v0.0.2

type REntry struct {
	TypeGuid   string
	UniqueGuid string
	FirstLBA   uint64
	LastLBA    uint64
	AttrFlags  uint64
	Name       string
}

REntry represents Entry for human readable format.

TypeGuid/UniqueGuid/Name are string type.

func NewREntry added in v0.0.2

func NewREntry(e Entry) *REntry

type RGpt added in v0.0.2

type RGpt struct {
	Mbr           RMbr
	Header        RHeader
	Entries       map[uint]REntry
	BackupEntries map[uint]REntry
	BackupHeader  RHeader
}

RMbr represents RGpt for human readable format.

func NewRGpt added in v0.0.2

func NewRGpt(g Gpt) *RGpt

type RHeader added in v0.0.2

type RHeader struct {
	Signature      uint64
	Revision       uint32
	Size           uint32
	Crc32OfHeader  uint32
	Reserved       uint32
	CurrentLBA     uint64
	BackupLBA      uint64
	FirstUsableLBA uint64
	LastUsableLBA  uint64
	DiskGuid       string
	StartingLBA    uint64
	NumOfEntries   uint32
	SizeOfEntry    uint32
	Crc32OfEntries uint32
}

RHeader represents Header for human readable format.

DiskGuid is string type.

func NewRHeader added in v0.0.2

func NewRHeader(h Header) *RHeader

type RMbr added in v0.0.2

type RMbr struct {
	Entries   [4]RMbrEntry
	Signature uint16
}

RMbr represents Mbr for human readable format.

func NewRMbr added in v0.0.2

func NewRMbr(m Mbr) *RMbr

type RMbrEntry added in v0.0.2

type RMbrEntry struct {
	BootFlag byte
	FirstChs RChs
	Id       byte
	LastChs  RChs
	FirstLBA uint32
	AllLBA   uint32
}

RMbrEntry represents MbrEntry for human readable format.

func NewRMbrEntry added in v0.0.2

func NewRMbrEntry(m MbrEntry) *RMbrEntry

Jump to

Keyboard shortcuts

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