mbr

package
v0.0.0-...-22a2222 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mbr provides an interface to Master Boot Record (MBR) partitioned disks.

You can use this package to manipulate existing MBR disks, read existing disks, or create entirely new partition tables on disks or disk files.

mbr.Table implements the Table interface in github.com/diskfs/go-diskfs/partition

Normally, the best way to interact with a disk is to use the github.com/diskfs/go-diskfs package, which, when necessary, will call this one. When creating a new disk or manipulating an existing one, You will, however, need to interact with an mbr.Table and mbr.Partition structs.

Here is a simple example of an MBR Table with a single 10MB Linux partition:

table := &mbr.Table{
  LogicalSectorSize:  512,
  PhysicalSectorSize: 512,
  Partitions: []*mbr.Partition{
    {
      Bootable:      false,
      Type:          Linux,
      Start:         2048,
      Size:          20480,
    },
  },
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PartitionEqualBytes

func PartitionEqualBytes(b1, b2 []byte) bool

PartitionEqualBytes compares if the bytes for 2 partitions are equal, ignoring CHS start and end

Types

type Partition

type Partition struct {
	Bootable      bool
	Type          Type   //
	Start         uint32 // Start first absolute LBA sector for partition
	Size          uint32 // Size number of sectors in partition
	StartCylinder byte
	StartHead     byte
	StartSector   byte
	EndCylinder   byte
	EndHead       byte
	EndSector     byte
	// contains filtered or unexported fields
}

Partition represents the structure of a single partition on the disk note that start and end cylinder, head, sector (CHS) are ignored, for the most part. godiskfs works with disks that support [Logical Block Addressing (LBA)](https://en.wikipedia.org/wiki/Logical_block_addressing)

func (*Partition) Equal

func (p *Partition) Equal(p2 *Partition) bool

Equal compares if another partition is equal to this one, ignoring the UUID and CHS start and end

func (*Partition) GetSize

func (p *Partition) GetSize() int64

func (*Partition) GetStart

func (p *Partition) GetStart() int64

func (*Partition) ReadContents

func (p *Partition) ReadContents(f util.File, out io.Writer) (int64, error)

readContents reads the contents of the partition into a writer streams the entire partition to the writer

func (*Partition) UUID

func (p *Partition) UUID() string

UUID returns the partitions UUID. For MBR based partition tables this is the partition table UUID with the partition number as a suffix.

func (*Partition) WriteContents

func (p *Partition) WriteContents(f util.File, contents io.Reader) (uint64, error)

WriteContents fills the partition with the contents provided reads from beginning of reader to exactly size of partition in bytes

type Table

type Table struct {
	Partitions         []*Partition
	LogicalSectorSize  int // logical size of a sector
	PhysicalSectorSize int // physical size of the sector
	// contains filtered or unexported fields
}

Table represents an MBR partition table to be applied to a disk or read from a disk

func Read

func Read(f util.File, logicalBlockSize, physicalBlockSize int) (*Table, error)

Read read a partition table from a disk, given the logical block size and physical block size

func (*Table) Equal

func (t *Table) Equal(t2 *Table) bool

Equal check if another table is equal to this one, ignoring the partition table UUID and CHS start and end for the partitions

func (*Table) GetPartitions

func (t *Table) GetPartitions() []part.Partition

func (*Table) Repair

func (t *Table) Repair(diskSize uint64) error

Repair will attempt to repair a broken Master Boot Record

func (*Table) Type

func (t *Table) Type() string

Type report the type of table, always the string "mbr"

func (*Table) UUID

func (t *Table) UUID() string

UUID returns the partition table UUID used to identify disks

func (*Table) Verify

func (t *Table) Verify(f util.File, diskSize uint64) error

Verify will attempt to evaluate the headers

func (*Table) Write

func (t *Table) Write(f util.File, size int64) error

Write writes a given MBR Table to disk. Must be passed the util.File to write to and the size of the disk

type Type

type Type byte

Type constants for the GUID for type of partition, see https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries

const (
	Empty         Type = 0x00
	Fat12         Type = 0x01
	XenixRoot     Type = 0x02
	XenixUsr      Type = 0x03
	Fat16         Type = 0x04
	ExtendedCHS   Type = 0x05
	Fat16b        Type = 0x06
	NTFS          Type = 0x07
	CommodoreFAT  Type = 0x08
	Fat32CHS      Type = 0x0b
	Fat32LBA      Type = 0x0c
	Fat16bLBA     Type = 0x0e
	ExtendedLBA   Type = 0x0f
	LinuxSwap     Type = 0x82
	Linux         Type = 0x83
	LinuxExtended Type = 0x85
	LinuxLVM      Type = 0x8e
	Iso9660       Type = 0x96
	MacOSXUFS     Type = 0xa8
	MacOSXBoot    Type = 0xab
	HFS           Type = 0xaf
	Solaris8Boot  Type = 0xbe
	GPTProtective Type = 0xee
	EFISystem     Type = 0xef
	VMWareFS      Type = 0xfb
	VMWareSwap    Type = 0xfc
)

List of GUID partition types

Jump to

Keyboard shortcuts

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