project-machine / disko

Disk Operations API in Go
Apache License 2.0
13 stars 9 forks source link

Always update Protective MBR and Secondary GPT Table when writing GPT. #73

Closed smoser closed 4 years ago

smoser commented 4 years ago

Both the GPT table and ProtectiveMBR need to be updated or re-written if the disk size changes. That is not a very common event with real disks (disks don't magically get more bytes). But, it is common for virtual disks to be "grown" (zeros added to the end).

The GPT header at the beginning of a disk contains a reference to the location of a copy (HeaderCopyStartLBA) which is typically at the end of the disk. The ProtectiveMBR is supposed to span the entire disk. So both of these things have to be updated if the disk changes size.

The change here is just to make sure we update both whenever we write a GPT partition table.

A simple 'diff' doesn't show it well, but what happened is:

a.) move writeProtectiveMBR from writeNewGPTTable to writeGPTTable b.) pass a disk size into writeGPTTable so that it can pass it through to writeProtectiveMBR when it needs it.

writeProtectiveMBR doesn't actually need the size, because most partition table writers will just write a partition length of 0xFFFFFFFF independent of the size of the disk. But for now we can't just do that because the MBR package will return error from Check(). I've tried to get that fixed. See conversation on https://github.com/rekby/mbr/pull/2/files and https://github.com/karelzak/util-linux/issues/485

codecov[bot] commented 4 years ago

Codecov Report

Merging #73 into master will decrease coverage by 0.09%. The diff coverage is 35.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #73      +/-   ##
==========================================
- Coverage   53.76%   53.67%   -0.10%     
==========================================
  Files          16       16              
  Lines        1873     1880       +7     
==========================================
+ Hits         1007     1009       +2     
- Misses        770      772       +2     
- Partials       96       99       +3     
Impacted Files Coverage Δ
linux/disk.go 43.08% <35.71%> (-0.24%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8270997...cdc3ca8. Read the comment docs.