mbr

package
v0.0.0-...-6180576 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

package mbr implements a Master Boot Record parser and writer.

Index

Constants

View Source
const (
	BootSignature = 0xAA55
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BootSector

type BootSector struct {
	// contains filtered or unexported fields
}

BootSector is a Master Boot Record. It contains the bootstrap code, the partition table and a boot signature.

func ToBootSector

func ToBootSector(start []byte) (BootSector, error)

ToBootSector converts a byte slice to an MBR BootSector while maintaining a reference to the original byte slice. The byte slice must be at least 512 bytes long and the first byte of the slice must be the first byte of the MBR.

func (*BootSector) BootSignature

func (mbr *BootSector) BootSignature() uint16

BootSignature returns the boot signature of the MBR. This is a magic number (0xAA55) that indicates that this is a valid MBR.

func (*BootSector) Bootstrap

func (mbr *BootSector) Bootstrap() []byte

Bootstrap returns bytes 0..439 of the MBR containing the binary executable code.

func (*BootSector) IsGPTProtective

func (mbr *BootSector) IsGPTProtective() bool

IsProtectiveMBR returns true if the first partition of the MBR is a GPT protective MBR. In this case the MBR is not used for booting and the GUID Partition Table can be found in the next LBA.

func (*BootSector) PartitionTable

func (mbr *BootSector) PartitionTable(idx int) PartitionTableEntry

PartitionTable returns the idx'th partition table entry of the MBR.

func (*BootSector) SetPartitionTable

func (mbr *BootSector) SetPartitionTable(idx int, pte PartitionTableEntry)

SetPartitionTable sets the idx'th partition table entry of the MBR.

func (*BootSector) UniqueDiskID

func (mbr *BootSector) UniqueDiskID() uint32

type CHS

type CHS uint32

CHS is a cylinder-head-sector address. This addressing scheme is deprecated by modern operating systems in favor of LBA, or Logical Block Addressing.

func NewCHS

func NewCHS(cylinder, head, sector uint8) CHS

NewCHS creates a new CHS address from the cylinder, head and sector numbers. See "CHS addressing".

func (CHS) Tuple

func (chs CHS) Tuple() (cylinder, head, sector uint8)

type DriveAttributes

type DriveAttributes byte

DriveAttributes refers to the first byte of a Partition Table Entry. It specifies if the partition is bootable.

const (
	DriveAttrsBootable DriveAttributes = 1 << 7
)

func (DriveAttributes) IsBootable

func (attrs DriveAttributes) IsBootable() bool

IsBootable returns true if the partition the PTE refers to is bootable.

type PartitionTableEntry

type PartitionTableEntry struct {
	// contains filtered or unexported fields
}

PartitionTableEntry represents one of the four partition table entries in the MBR. It contains information about the partition, such as the type, size, location and if it is bootable. See https://en.wikipedia.org/wiki/Master_boot_record#PTE for more information.

func MakePTE

func MakePTE(attrs DriveAttributes, Type PartitionType, startLBA, numLBA uint32, startCHS, lastCHS CHS) PartitionTableEntry

MakePTE creates a new partition table entry from the given parameters.

func (*PartitionTableEntry) Attributes

func (pte *PartitionTableEntry) Attributes() DriveAttributes

Attributes returns the attributes of the partition the PTE refers to.

func (*PartitionTableEntry) CHSLast

func (pte *PartitionTableEntry) CHSLast() CHS

CHSLast returns the last sector of the partition in CHS format.

func (*PartitionTableEntry) CHSStart

func (pte *PartitionTableEntry) CHSStart() CHS

CHSStart returns the starting sector of the partition in CHS format. Is not used by modern operating systems.

func (*PartitionTableEntry) NumberOfLBA

func (pte *PartitionTableEntry) NumberOfLBA() uint32

NumberOfLBA returns the number of sectors (logical block addresses) in the partition.

func (*PartitionTableEntry) PartitionType

func (pte *PartitionTableEntry) PartitionType() PartitionType

ParitionType returns the type the partition refers to, such as if the partition is formatted as a FAT32, NTFS, exFAT, Linux etc.

func (*PartitionTableEntry) StartLBA

func (pte *PartitionTableEntry) StartLBA() uint32

StartLBA returns the starting sector of the partition in LBA format (logical block address).

type PartitionType

type PartitionType byte

PartitionType refers to the type of partition the Partition Table Entry refers to.

const (
	PartitionTypeUnused   PartitionType = 0x00
	PartitionTypeFAT12    PartitionType = 0x01
	PartitionTypeFAT16    PartitionType = 0x04
	PartitionTypeExtended PartitionType = 0x05
	PartitionTypeFAT32CHS PartitionType = 0x0B
	PartitionTypeFAT32LBA PartitionType = 0x0C
	PartitionTypeNTFS     PartitionType = 0x07 // Also includes exFAT.
	PartitionTypeLinux    PartitionType = 0x83
	PartitionTypeFreeBSD  PartitionType = 0xA5
	PartitionTypeAppleHFS PartitionType = 0xAF

	PartitionTypeGPTProtective PartitionType = 0xEE
)

Jump to

Keyboard shortcuts

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