summaryrefslogtreecommitdiff
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
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.
-rw-r--r--NEWS10
-rw-r--r--gptpart.cc5
-rw-r--r--gptpart.h1
-rw-r--r--gpttext.cc11
-rw-r--r--parttypes.cc2
-rw-r--r--support.h2
6 files changed, 25 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index c71c4b0..776ce9a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,13 @@
+0.8.10 (?/??/2014):
+-------------------
+
+- Fixed new (in 0.8.9) bug that caused a failure to create more than one
+ hybridized partition when creating a hybrid MBR.
+
+- Fixed bug that caused gdisk to create hybridized partitions that ended
+ above the 2^32 sector point with incorrect end values. The program now
+ refuses to create such hybridized partitions at all.
+
0.8.9 (2/17/2014):
------------------
diff --git a/gptpart.cc b/gptpart.cc
index 7c61569..d06145c 100644
--- a/gptpart.cc
+++ b/gptpart.cc
@@ -138,6 +138,11 @@ int GPTPart::IsUsed(void) {
return (partitionType != GUIDData("0x00"));
} // GPTPart::IsUsed()
+// Returns 1 if the partition's end point is under (2^32 - 1) sectors, 0 if it's over that value.
+int GPTPart::IsSizedForMBR(void) {
+ return (lastLBA < UINT32_MAX);
+} // GPTPart::IsSizedForMBR()
+
// Set the type code to the specified one. Also changes the partition
// name *IF* the current name is the generic one for the current partition
// type.
diff --git a/gptpart.h b/gptpart.h
index 67cba6b..f62d5b5 100644
--- a/gptpart.h
+++ b/gptpart.h
@@ -63,6 +63,7 @@ class GPTPart {
void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);}
UnicodeString GetDescription(void);
int IsUsed(void);
+ int IsSizedForMBR(void);
// Simple data assignment:
void SetType(PartType t);
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
diff --git a/parttypes.cc b/parttypes.cc
index 441508a..1745b76 100644
--- a/parttypes.cc
+++ b/parttypes.cc
@@ -2,7 +2,7 @@
// Class to manage partition type codes -- a slight variant on MBR type
// codes, GUID type codes, and associated names.
-/* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed
+/* This program is copyright (c) 2009-2014 by Roderick W. Smith. It is distributed
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
diff --git a/support.h b/support.h
index 9f00846..71fff50 100644
--- a/support.h
+++ b/support.h
@@ -8,7 +8,7 @@
#ifndef __GPTSUPPORT
#define __GPTSUPPORT
-#define GPTFDISK_VERSION "0.8.9"
+#define GPTFDISK_VERSION "0.8.9.1"
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
// Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64