gpt

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: 10 Imported by: 0

Documentation

Overview

Package gpt provides an interface to GUID Partition Table (GPT) partitioned disks.

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

gpt.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 gpt.Table and gpt.Partition structs.

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

table := &gpt.Table{
  LogicalSectorSize:  512,
  PhysicalSectorSize: 512,
  Partitions: []*mbr.Partition{
    {
      LogicalSectorSize:  512,
      PhysicalSectorSize: 512,
      ProtectiveMBR:      true,
      GUID:               "43E51892-3273-42F7-BCDA-B43B80CDFC48",
    },
  },
}

Index

Constants

View Source
const PartitionEntrySize = 128

PartitionEntrySize fixed size of a GPT partition entry

Variables

This section is empty.

Functions

This section is empty.

Types

type Partition

type Partition struct {
	Start      uint64 // start sector for the partition
	End        uint64 // end sector for the partition
	Size       uint64 // size of the partition in bytes
	Type       Type   // parttype for the partition
	Name       string // name for the partition
	GUID       string // partition GUID, can be left blank to auto-generate
	Attributes uint64 // Attributes flags
}

Partition represents the structure of a single partition on the disk

type Table

type Table struct {
	Partitions         []*Partition // slice of Partition
	LogicalSectorSize  int          // logical size of a sector
	PhysicalSectorSize int          // physical size of the sector
	GUID               string       // disk GUID, can be left blank to auto-generate
	ProtectiveMBR      bool         // whether or not a protective MBR is in place
	// contains filtered or unexported fields
}

Table represents a 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 must be passed the util.File from which to read, and the logical and physical block sizes

if successful, returns a gpt.Table struct returns errors if fails at any stage reading the disk or processing the bytes on disk as a GPT

func (*Table) Equal

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

Equal check if another table is functionally equal to this one

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 contents of a partition into an io.Writer

Requires the partition to which to write, the util.File to which to write, and the io.Writer

if successful, returns number of bytes read

returns error if there are any errors reading the file, writing to the writer or the partition number is invalid

func (*Table) Type

func (t *Table) Type() string

Type report the type of table, always "gpt"

func (*Table) Write

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

Write writes a GPT to disk Must be passed the util.File to which to write 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

requires the partition to which to write, the util.File on which the partition exists, and the io.Reader from which to read the bytes

if successful, returns number of bytes written

returns error if there are any issues writing to the util.File, reading from the io.Reader, or the partition number is invalid

type Type

type Type string

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

const (
	Unused                   Type = "00000000-0000-0000-0000-000000000000"
	MbrBoot                  Type = "024DEE41-33E7-11D3-9D69-0008C781F39F"
	EFISystemPartition       Type = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"
	BiosBoot                 Type = "21686148-6449-6E6F-744E-656564454649"
	MicrosoftReserved        Type = "E3C9E316-0B5C-4DB8-817D-F92DF00215AE"
	MicrosoftBasicData       Type = "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7"
	MicrosoftLDMMetadata     Type = "5808C8AA-7E8F-42E0-85D2-E1E90434CFB3"
	MicrosoftLDMData         Type = "AF9B60A0-1431-4F62-BC68-3311714A69AD"
	MicrosoftWindowsRecovery Type = "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC"
	LinuxFilesystem          Type = "0FC63DAF-8483-4772-8E79-3D69D8477DE4"
	LinuxRaid                Type = "A19D880F-05FC-4D3B-A006-743F0F84911E"
	LinuxRootX86             Type = "44479540-F297-41B2-9AF7-D131D5F0458A"
	LinuxRootX86_64          Type = "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709"
	LinuxRootArm32           Type = "69DAD710-2CE4-4E3C-B16C-21A1D49ABED3"
	LinuxRootArm64           Type = "B921B045-1DF0-41C3-AF44-4C6F280D3FAE"
	LinuxSwap                Type = "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F"
	LinuxLVM                 Type = "E6D6D379-F507-44C2-A23C-238F2A3DF928"
	LinuxDMCrypt             Type = "7FFEC5C9-2D00-49B7-8941-3EA10A5586B7"
	LinuxLUKS                Type = "CA7D7CCB-63ED-4C53-861C-1742536059CC"
	VMWareFilesystem         Type = "AA31E02A-400F-11DB-9590-000C2911D1B8"
)

List of GUID partition types

Jump to

Keyboard shortcuts

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