cgpt: Fully write out primary GPT before starting to write secondary
authorJulius Werner <jwerner@chromium.org>
Tue, 19 Apr 2016 20:20:52 +0000 (13:20 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Mon, 25 Apr 2016 22:15:32 +0000 (15:15 -0700)
commit5de0000ece70bf419130db9bdbaf444ffc98bf30
tree8deb87e570769bfd20775bbef5859a30ea377ce1
parentff9c2b2e8b49a948ecc6ca640a0400450fd16f4f
cgpt: Fully write out primary GPT before starting to write secondary

The point of having two GPTs is to always have a known good one if one
of them gets corrupted. One of the most obvious ways that could happen
is if the write stopped half-way through (e.g. due to a crash or random
power loss).

Unfortunately, the way we currently save modified GPTs can leave both
copies invalid if we stop writing at just the wrong time. Since a GPT
header contains a checksum over the GPT entries, we need to write both
the header and entries for one GPT (and make sure they're synced to
disk) before we start writing the other.

BRANCH=None
BUG=chrome-os-partner:52595
TEST=None

Change-Id: I2d4b56bcfba9a94395af5896f274ebade9e39081
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/340071
Reviewed-by: Nam Nguyen <namnguyen@google.com>
cgpt/cgpt_common.c