summaryrefslogtreecommitdiff
path: root/gpttext.cc
diff options
context:
space:
mode:
authorRoderick W. Smith <rodsmith@rodsbooks.com>2014-02-20 11:13:36 -0500
committerRoderick W. Smith <rodsmith@rodsbooks.com>2014-02-20 11:13:36 -0500
commit9b338c50f298d04f47205f7fad082d8c21797ed7 (patch)
tree9a2728cfc491cff9c1f1e42ae3e868a5c7619eb8 /gpttext.cc
parent84aaff6b9cf3b802c621781cf9acd006aa5a3e66 (diff)
downloadsgdisk-9b338c50f298d04f47205f7fad082d8c21797ed7.tar.gz
Fixed new bug with hybrid MBR creation in gdisk; couldn't do more than
one partition because of sscanf weirdness.
Diffstat (limited to 'gpttext.cc')
-rw-r--r--gpttext.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/gpttext.cc b/gpttext.cc
index 95ba850..b5e8ac2 100644
--- a/gpttext.cc
+++ b/gpttext.cc
@@ -396,7 +396,7 @@ void GPTDataTextUI::ShowDetails(void) {
void GPTDataTextUI::MakeHybrid(void) {
uint32_t partNums[3];
string line;
- int numPartsToCvt, i, j, mbrNum = 0;
+ int numPartsToCvt = 0, i, j, mbrNum = 0;
unsigned int hexCode = 0;
MBRPart hybridPart;
MBRData hybridMBR;
@@ -416,7 +416,10 @@ void GPTDataTextUI::MakeHybrid(void) {
cout << "Type from one to three GPT partition numbers, separated by spaces, to be\n"
<< "added to the hybrid MBR, in sequence: ";
line = ReadString();
- numPartsToCvt = sscanf(line.c_str(), "%ud %ud %ud", &partNums[0], &partNums[1], &partNums[2]);
+ istringstream inLine(line);
+ do {
+ inLine >> partNums[numPartsToCvt++];
+ } while (!inLine.eof() && (numPartsToCvt < 3));
if (numPartsToCvt > 0) {
cout << "Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? ";
@@ -425,7 +428,7 @@ void GPTDataTextUI::MakeHybrid(void) {
for (i = 0; i < numPartsToCvt; i++) {
j = partNums[i] - 1;
- if (partitions[j].IsUsed()) {
+ if (partitions[j].IsUsed() && partitions[j].IsSizedForMBR()) {
mbrNum = i + (eeFirst == 'Y');
cout << "\nCreating entry for GPT partition #" << j + 1
<< " (MBR partition #" << mbrNum + 1 << ")\n";
@@ -439,7 +442,7 @@ void GPTDataTextUI::MakeHybrid(void) {
hybridPart.SetStatus(0x00);
hybridPart.SetInclusion(PRIMARY);
} else {
- cerr << "\nGPT partition #" << j + 1 << " does not exist; skipping.\n";
+ cerr << "\nGPT partition #" << j + 1 << " does not exist or is too big; skipping.\n";
} // if/else
hybridMBR.AddPart(mbrNum, hybridPart);
} // for