From dadcceea7a8e931eaf970d95a297d8c89a0ebe9d Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 23 Sep 2015 14:13:45 -0700 Subject: [PATCH] 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 --- Disk.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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::unmountAll() { } status_t Disk::partitionPublic() { + int res; + // TODO: improve this code destroyAllVolumes(); mJustPartitioned = true; + // First nuke any existing partition table + std::vector 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));