mbr

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 4 Imported by: 1

Documentation

Overview

Package mbr is a minimial implementation of Master Boot Record parsing and writing, implemented in support of GUID Partition Table parsing and writing. It is based on the UEFI Specification v2.6.

Index

Constants

View Source
const MBRSize = 512

MBRSize is the size of an MBR record without logical block size padding

Variables

This section is empty.

Functions

func WriteProtectiveMBR

func WriteProtectiveMBR(w io.Writer, blockSize, numBlocks uint64) error

WriteProtectiveMBR constructs and writes a protective MBR to w. It will only write the first block to w (that is, blockSize bytes).

Types

type MBR

type MBR struct {
	BootCode               [424]byte // 424 bytes should be enough for anybody...
	Pad                    [16]byte  // unnamed blank space in efi spec?
	UniqueMBRDiskSignature uint32
	Unknown                [2]byte
	PartitionRecord        [4]PartitionRecord
	Signature              Signature
}

MBR is a Go representation of a legacy Master Boot Record.

func NewProtectiveMBR

func NewProtectiveMBR(numBlocks uint64) MBR

NewProtectiveMBR constructs an MBR struct with fields conformant to the UEFI specification 2.6 "Protective MBR"

func ReadMBR

func ReadMBR(r io.Reader) (*MBR, error)

ReadMBR reads a MasterBootRecord from r.

func (*MBR) ReadFrom

func (m *MBR) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads from the given io.Reader into the receiver MBR. If an error occurs the returned bytes read may be incorrect.

func (MBR) String

func (m MBR) String() string

func (*MBR) WriteTo

func (m *MBR) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface for MBR. It writes the MBR to w in little endian as per the GPT specification.

type OSType

type OSType byte

OSType marks the partition type in an MBR Partition Record

const (
	FAT32               OSType = 0x0b
	UEFISystemPartition OSType = 0xEF
	GPTProtective       OSType = 0xEE
)

TODO(raggi): fill in other types and organize from: "Partition types" by Andries Brouwer: See "Links to UEFI-Related Documents" (http://uefi.org/uefi) under the heading "OS Type values used in the MBR disk layout".

func (OSType) String

func (i OSType) String() string

type PartitionRecord

type PartitionRecord struct {
	BootIndicator byte
	StartingCHS   [3]byte
	OSType        OSType
	EndingCHS     [3]byte
	StartingLBA   uint32
	SizeInLBA     uint32
}

PartitionRecord is a type representing a legacy MBR partition record

type Signature

type Signature uint16

Signature is an MBR Signature as two bytes in little endian.

const (
	// GPTSignature is the partition signature of a protective MBR partition
	GPTSignature Signature = 0xAA55
)

func (Signature) String

func (i Signature) String() string

Jump to

Keyboard shortcuts

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