From 85ffd688e91103bdfad15353bc807d1133def876 Mon Sep 17 00:00:00 2001 From: nift4 Date: Sat, 1 Jul 2023 11:49:12 +0200 Subject: [PATCH] vold: fix failing to format zero-ed out SD card sgdisk --android-dump fails with error code 8 when there is no partition table. Don't stop us from creating a new partition table. Can be reproduced with 1. adb shell sm set-virtual-disk true 2. Format from UI 3. Observe fake "success" message with SD still unformatted Fixes: ad5b4f9 ("vold: skip first disk change when converting MBR to GPT") Test: CtsOsTestCases android.os.storage.cts.StorageManagerTest#testGetStorageVolumeSDCard Change-Id: I3262bb2e28de438beba541a97038a06432643a65 --- model/Disk.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/model/Disk.cpp b/model/Disk.cpp index efe9042..c1453b8 100644 --- a/model/Disk.cpp +++ b/model/Disk.cpp @@ -471,26 +471,23 @@ status_t Disk::partitionPublic() { std::vector output; res = ForkExecvp(cmd, &output); - if (res != OK) { - LOG(WARNING) << "sgdisk failed to scan " << mDevPath; - mJustPartitioned = false; - return res; - } - Table table = Table::kUnknown; - for (auto line : output) { - char* cline = (char*) line.c_str(); - char* token = strtok(cline, kSgdiskToken); - if (token == nullptr) continue; - - if (!strcmp(token, "DISK")) { - const char* type = strtok(nullptr, kSgdiskToken); - if (!strcmp(type, "mbr")) { - table = Table::kMbr; - break; - } else if (!strcmp(type, "gpt")) { - table = Table::kGpt; - break; + // fails when there is no partition table, it's okay + if (res == OK) { + for (auto line : output) { + char* cline = (char*) line.c_str(); + char* token = strtok(cline, kSgdiskToken); + if (token == nullptr) continue; + + if (!strcmp(token, "DISK")) { + const char* type = strtok(nullptr, kSgdiskToken); + if (!strcmp(type, "mbr")) { + table = Table::kMbr; + break; + } else if (!strcmp(type, "gpt")) { + table = Table::kGpt; + break; + } } } }