gpt

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 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 JsonChs

type JsonChs struct {
	Head     uint
	Sector   uint
	Cylinder uint
}

JsonChs represents Chs for json.

func NewJsonChs

func NewJsonChs(c Chs) *JsonChs

type JsonEntry

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

JsonEntry represents Entry for json.

TypeGuid/UniqueGuid/Name are string type.

func NewJsonEntry

func NewJsonEntry(e Entry) *JsonEntry

type JsonGpt

type JsonGpt struct {
	Mbr           JsonMbr
	Header        JsonHeader
	Entries       map[uint]JsonEntry
	BackupEntries map[uint]JsonEntry
	BackupHeader  JsonHeader
}

JsonMbr represents JsonGpt for json.

func NewJsonGpt

func NewJsonGpt(g Gpt) *JsonGpt

type JsonHeader

type JsonHeader 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
}

JsonHeader represents Header for json.

DiskGuid is string type.

func NewJsonHeader

func NewJsonHeader(h Header) *JsonHeader

type JsonMbr

type JsonMbr struct {
	Entries   [4]JsonMbrEntry
	Signature uint16
}

JsonMbr represents Mbr for json.

func NewJsonMbr

func NewJsonMbr(m Mbr) *JsonMbr

type JsonMbrEntry

type JsonMbrEntry struct {
	BootFlag byte
	FirstChs JsonChs
	Id       byte
	LastChs  JsonChs
	FirstLBA uint32
	AllLBA   uint32
}

JsonMbrEntry represents MbrEntry for json.

func NewJsonMbrEntry

func NewJsonMbrEntry(m MbrEntry) *JsonMbrEntry

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

Jump to

Keyboard shortcuts

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