Clean up any/all stale partition tables.
When formatting media as a public volume, we write an MBR, but we
might leave a stale GPT floating around. Some devices are configured
to aggressively prefer GPT when detected, even if the checksums
between primary/secondary don't match.
To work around this, nuke both MBR and GPT tables from the media
before we lay down our new MBR.
Bug: 24112219
Change-Id: Ibf1be466a6877cbab925a24db5e5dbab0613bea7
diff --git a/Disk.cpp b/Disk.cpp
index 1e76bee..d5f3e5d 100644
--- a/Disk.cpp
+++ b/Disk.cpp
@@ -340,10 +340,24 @@
}
status_t Disk::partitionPublic() {
+ int res;
+
// TODO: improve this code
destroyAllVolumes();
mJustPartitioned = true;
+ // First nuke any existing partition table
+ std::vector<std::string> cmd;
+ cmd.push_back(kSgdiskPath);
+ cmd.push_back("--zap-all");
+ cmd.push_back(mDevPath);
+
+ // Zap sometimes returns an error when it actually succeeded, so
+ // just log as warning and keep rolling forward.
+ if ((res = ForkExecvp(cmd)) != 0) {
+ LOG(WARNING) << "Failed to zap; status " << res;
+ }
+
struct disk_info dinfo;
memset(&dinfo, 0, sizeof(dinfo));