Skip to content

Commit

Permalink
fix: keep contents of PMBR when writing it
Browse files Browse the repository at this point in the history
We shouldn't be overwriting it with zeroes.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira authored and talos-bot committed Dec 18, 2020
1 parent 2878460 commit f2728a5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions blockdevice/partition/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ func (g *GPT) Read() (err error) {
}

func (g *GPT) Write() (err error) {
pmbr := g.newPMBR(g.h)
var pmbr []byte

pmbr, err = g.newPMBR(g.h)
if err != nil {
return err
}

err = g.l.WriteAt(0, 0x00, pmbr)
if err != nil {
Expand Down Expand Up @@ -338,8 +343,11 @@ func (g *GPT) Repair() error {
// - https://en.wikipedia.org/wiki/GUID_Partition_Table#Protective_MBR_(LBA_0)
// - https://www.syslinux.org/wiki/index.php?title=Doc/gpt
// - https://en.wikipedia.org/wiki/Master_boot_record
func (g *GPT) newPMBR(h *Header) []byte {
p := make([]byte, 512)
func (g *GPT) newPMBR(h *Header) ([]byte, error) {
p, err := g.l.ReadAt(0, 0, 512)
if err != nil {
return nil, err
}

// Boot signature.
copy(p[510:], []byte{0x55, 0xaa})
Expand All @@ -357,7 +365,7 @@ func (g *GPT) newPMBR(h *Header) []byte {
// Partition length in sectors.
binary.LittleEndian.PutUint32(b[12:16], uint32(h.BackupLBA))

return p
return p, nil
}

func (g *GPT) renumberPartitions() {
Expand Down

0 comments on commit f2728a5

Please sign in to comment.