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 ¶
- func PartitionEqualBytes(b1, b2 []byte) bool
- type Partition
- func (p *Partition) Equal(p2 *Partition) bool
- func (p *Partition) GetSize() int64
- func (p *Partition) GetStart() int64
- func (p *Partition) ReadContents(f util.File, out io.Writer) (int64, error)
- func (p *Partition) UUID() string
- func (p *Partition) WriteContents(f util.File, contents io.Reader) (uint64, error)
- type Table
- func (t *Table) Equal(t2 *Table) bool
- func (t *Table) GetPartitions() []part.Partition
- func (t *Table) Repair(diskSize uint64) error
- func (t *Table) Type() string
- func (t *Table) UUID() string
- func (t *Table) Verify(f util.File, diskSize uint64) error
- func (t *Table) Write(f util.File, size int64) error
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PartitionEqualBytes ¶
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 ¶
Equal compares if another partition is equal to this one, ignoring the UUID and CHS start and end
func (*Partition) ReadContents ¶
readContents reads the contents of the partition into a writer streams the entire partition to the writer
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 ¶
Read read a partition table from a disk, given the logical block size and physical block size
func (*Table) Equal ¶
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 ¶
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