mbr

package
v1.0.1-0...-a4bacf2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 5 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
}

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 CHS start and end

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 CHS start and end for the partitions

func (*Table) GetPartitionSize

func (t *Table) GetPartitionSize(partition int) (int64, error)

GetPartitionSize returns the size in bytes of a single partition

func (*Table) GetPartitionStart

func (t *Table) GetPartitionStart(partition int) (int64, error)

GetPartitionStart returns the start position in bytes of a single partition

func (*Table) ReadPartitionContents

func (t *Table) ReadPartitionContents(partition int, f util.File, writer io.Writer) (int64, error)

ReadPartitionContents read the entire contents of a partition into an io.Writer

If successul, returns the number of bytes read. If the partition does not exist, returns an error.

func (*Table) Type

func (t *Table) Type() string

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

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

func (*Table) WritePartitionContents

func (t *Table) WritePartitionContents(partition int, f util.File, reader io.Reader) (uint64, error)

WritePartitionContents fill a partition with the available data from an io.Reader. This command is destructive; it will replace the contents of the partition with the contents read from the io.Reader.

If successful, returns the number of bytes written. If the partition does not exist, returns an error.

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
	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 = 0xef
	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