Documentation
¶
Overview ¶
Package gpt provides a package for reading GPT partition tables from a block device in Go
The cmd/gpt subdirectory contains a simple tool to read the existing GPT header/partition table and demonstrate how to use this package.
Index ¶
Constants ¶
const ( GPTPartitionSystem = GPTPartitionAttribute(iota) GPTPartitionNoBlockIOProtocol GPTPartitionLegacyBIOSBootable )
Masks for bits in GPTPartitionAttribute. Bits 3-47 are reserved and must be zero. Bits 48-63 are reserved for GUID specific use and must be preserved by tools which modify the GPT header
const LogicalBlockSize uint64 = 512
Size of a block on the hard drive.
TODO: This should be a variable and handle different sizes, but then the padding in GPT can't be built into the struct definition, and the LogicalBlock would need to be a slice instead of an array. BUG(driusan): Only 512 byte logical block sizes are currently supported.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GPTHeader ¶
type GPTHeader struct { // Signature for this header. // Must be "EFI PART" Signature [8]byte // GPT version that this header is encoded with Revision uint32 // must be >= 92 and <= logical block size HeaderSize uint32 // A CRC32 check for this header. The CRC is encoded with this field HeaderCRC32 uint32 // Must be zero (given a field name instead of _ so that it can // be verified.) Reserved uint32 // The logical block address of this header // Should be "1" for the primary header, and AltLBA of the primary // header for the secondary header MyLBA uint64 // The logical block address of the secondary/backup GPT header // (or the primary, if this header is the secondary) AltLBA uint64 // The first block of the hard drive useable by GPT partitions FirstUseableLBA uint64 // The last block of the hard drive useable by GPT partitions (there // must leave enough space for the secondary GPT header.) LastUseableLBA uint64 // A unique GUID for this disk. Disk GUID // The block at which the GPT partition table starts PartitionEntryLBA uint64 // The maximum number of partitions that can be stored in the GPT // partition table pointed to by PartitionEntryLBA. (May span multiple // blocks) MaxNumberPartitionEntries uint32 // The size of a single GPT partition entry SizeOfPartitionEntry uint32 // A CRC32 check of the partition entry array. PartitionEntryArrayCRC32 uint32 // Zero padding to ensure that the GPTHeader takes up exactly 1 block. // Must be zero. Padding [LogicalBlockSize - 92]byte }
GPTHeader represents a GPT header. There should be two copies of this: one at block 1 (0-indexed, block 0 is for a protective MBR), and one at the address AltLBA. A GPTHeader should be exactly one LogicalBlock in size.
func (GPTHeader) GetPartitions ¶
func (g GPTHeader) GetPartitions(hd io.ReadSeeker) ([]GPTPartitionEntry, error)
Reads the GPT Partitions from the location pointed to from the GPT header hd should be a io.ReadSeeker (usually an os.File) pointing to the block device for the drive being read.
type GPTPartitionAttribute ¶
type GPTPartitionAttribute uint64
type GPTPartitionEntry ¶
type GPTPartitionEntry struct { // The type of partition PartitionType GUID // A unique GUID for this instance of this partition UniqueParitition GUID // Starting and ending Logical Block Address of this partition. StartingLBA uint64 EndingLBA uint64 // Attributes for this GPT partition Attributes GPTPartitionAttribute // A UTF16 encoded (yes, UEFI is really that stupid) string for the // name of this partition. May be empty. Use GetName() method to // get this value as a Go string type. PartitionName [36]uint16 }
Represents a single GPT partition. When reading a GPT partition from the disk, it's followed by len(sizeOfPartitionEntry)-128 zeros, which can't be encoded in this struct since SizeOfPartitionEntry is a variable encoded in the GPT Header
func (GPTPartitionEntry) GetName ¶
func (e GPTPartitionEntry) GetName() string
Returns the name of the GPT partition.
func (GPTPartitionEntry) Size ¶
func (e GPTPartitionEntry) Size() uint64
Returns the size of a GPT partition in number of logical blocks
type GUID ¶
type GUID struct { TimeLow uint32 TimeMid uint16 TimeHighAndVersion uint16 ClockSeqAndReserved uint8 ClockSeqLow uint8 Node [6]byte }
Represents a RFC 4122 GUID.
The ZeroGUID is a nil GUID that can be used for comparison
func (GUID) HumanString ¶
Converts a partition type GUID to a human readable string. BUG(driusan): Converting PartitionTypeGUID to a human readable string only supports partition types which are used on my computer, because I don't have time to transcribe every one on wikipedia.
Notes ¶
Bugs ¶
Only 512 byte logical block sizes are currently supported.
HeaderCRC32 not verified.
PartitionEntryArrayCRC32 not verified
Secondary header is not verified
Converting PartitionTypeGUID to a human readable string only supports partition types which are used on my computer, because I don't have time to transcribe every one on wikipedia.