Documentation ¶
Overview ¶
gpt implements reading and writing of GUID Partition tables. GPTs are dumped in JSON format and written in same. One complication is that we frequently only want to write a very small subset of a GPT. For example, we might only want to change the GUID. As it happens it is simpler (and more useful) just to read and write the whole thing. In for a penny, in for a pound.
Index ¶
Constants ¶
const ( BlockSize = 512 HeaderOff = 0x200 HeaderSize = 0x5c // They claim it can vary. Give me a break. Signature uint64 = 0x5452415020494645 // ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h on little-endian machines) Revision = 0x10000 MaxNPart = 0x80 )
Variables ¶
This section is empty.
Functions ¶
func EqualHeader ¶
EqualHeader compares two headers and returns true if they match. Those fields which by definition must differ are ignored.
func EqualParts ¶
EqualParts compares the Parts arrays from two GPTs and returns an error if they differ. If they length differs we just give up, since there's no way to know which should have matched. Otherwise, we do a 1:1 comparison.
Types ¶
type GPT ¶
type Header ¶
type Header struct { Signature uint64 Revision uint32 // (for GPT version 1.0 (through at least UEFI version 2.7 (May 2017)), the value is 00h 00h 01h 00h) HeaderSize uint32 // size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes) CRC uint32 // CRC32/zlib of header (offset +0 up to header size) in little endian, with this field zeroed during calculation Reserved uint32 // ; must be zero CurrentLBA uint64 // (location of this header copy) BackupLBA uint64 // (location of the other header copy) FirstLBA uint64 // usable LBA for partitions (primary partition table last LBA + 1) LastLBA uint64 // usable LBA (secondary partition table first LBA - 1) DiskGUID GUID // (also referred as UUID on UNIXes) PartStart uint64 // LBA of array of partition entries (always 2 in primary copy) NPart uint32 // Number of partition entries in array PartSize uint32 // Size of a single partition entry (usually 80h or 128) PartCRC uint32 // CRC32/zlib of partition array in little endian }
type Part ¶
type Part struct { PartGUID GUID // Partition type GUID UniqueGUID GUID // Unique partition GUID FirstLBA uint64 // LBA (little endian) LastLBA uint64 // LBA (inclusive, usually odd) Attribute PartAttr // flags (e.g. bit 60 denotes read-only) Name PartName // Partition name (36 UTF-16LE code units) }
type PartitionTable ¶
PartitionTable defines all the partition table information. This includes the MBR and two GPTs. The GPTs are similar but not identical, as they contain "pointers" to each other in the BackupLBA in the Header. The design is defective in that if a given Header has an error, you are supposed to just assume that the BackupLBA is intact, which is a pretty bogus assumption. This is why you do standards like this in the open, not in hiding. I hope someone from Intel is reading this.
func New ¶
func New(r io.ReaderAt) (*PartitionTable, error)
New reads in the MBR, primary and backup GPT from a disk and returns a pointer to them. There are some checks it can apply. It can return with a one or more headers AND an error. Sorry. Experience with some real USB sticks is showing that we need to return data even if there are some things wrong.
func (*PartitionTable) String ¶
func (p *PartitionTable) String() string