aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gptcl.cc10
-rw-r--r--gptcl.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/gptcl.cc b/gptcl.cc
index 9834788..f80db25 100644
--- a/gptcl.cc
+++ b/gptcl.cc
@@ -364,6 +364,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
if (partNum < 0)
partNum = newPartNum;
if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
+ // Remember the original hex value requested
+ typeRaw[partNum] = GetString(typeCode, 2);
typeHelper = GetString(typeCode, 2);
if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") &&
(ChangePartType(partNum, typeHelper))) {
@@ -494,6 +496,14 @@ int GPTDataCL::BuildMBR(char* argument, int isHybrid) {
operator[](origPartNum).GetLengthLBA());
newPart.SetStatus(0);
newPart.SetType((uint8_t)(operator[](origPartNum).GetHexType() / 0x0100));
+ // If we were created with a specific hex type, use that instead
+ // of risking fidelity loss by doing a GUID-based lookup
+ if (typeRaw.count(origPartNum) == 1) {
+ string raw = typeRaw[origPartNum];
+ if (raw.size() == 4) {
+ newPart.SetType(StrToHex(raw, 0));
+ }
+ }
newMBR.AddPart(i + isHybrid, newPart);
} else {
cerr << "Original partition " << origPartNum + 1 << " does not exist or is too big! Aborting operation!\n";
diff --git a/gptcl.h b/gptcl.h
index 610ca5f..7484a49 100644
--- a/gptcl.h
+++ b/gptcl.h
@@ -24,6 +24,7 @@
#include "gpt.h"
#include <popt.h>
+#include <map>
using namespace std;
@@ -36,6 +37,7 @@ class GPTDataCL : public GPTData {
int alignment, deletePartNum, infoPartNum, largestPartNum, bsdPartNum;
uint32_t tableSize;
poptContext poptCon;
+ std::map<int, string> typeRaw;
int BuildMBR(char* argument, int isHybrid);
public: