Documentation ¶
Overview ¶
package mbr implements a Master Boot Record parser and writer.
Index ¶
- Constants
- type BootSector
- func (mbr *BootSector) BootSignature() uint16
- func (mbr *BootSector) Bootstrap() []byte
- func (mbr *BootSector) IsGPTProtective() bool
- func (mbr *BootSector) PartitionTable(idx int) PartitionTableEntry
- func (mbr *BootSector) SetPartitionTable(idx int, pte PartitionTableEntry)
- func (mbr *BootSector) UniqueDiskID() uint32
- type CHS
- type DriveAttributes
- type PartitionTableEntry
- func (pte *PartitionTableEntry) Attributes() DriveAttributes
- func (pte *PartitionTableEntry) CHSLast() CHS
- func (pte *PartitionTableEntry) CHSStart() CHS
- func (pte *PartitionTableEntry) NumberOfLBA() uint32
- func (pte *PartitionTableEntry) PartitionType() PartitionType
- func (pte *PartitionTableEntry) StartLBA() uint32
- type PartitionType
Constants ¶
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.
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 )