summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-09-22 10:50:24 -0400
committersrs5694 <srs5694@users.sourceforge.net>2010-09-22 10:50:24 -0400
commit82f3f0b529ec1bb936141ae41b03f95c72ce573a (patch)
treeb6233ff63f89d536a0cdf38b95e3a7cfb974b6b5
parent327129e9331f888a8fc08d688dcb0a739a3c17be (diff)
downloadsgdisk-82f3f0b529ec1bb936141ae41b03f95c72ce573a.tar.gz
Further refinements to GUID type code entry.
-rw-r--r--NEWS3
-rw-r--r--gpt.cc11
-rw-r--r--gpt.h3
-rw-r--r--gptpart.cc28
-rw-r--r--parttypes.cc20
-rw-r--r--parttypes.h6
-rw-r--r--sgdisk.cc12
7 files changed, 45 insertions, 38 deletions
diff --git a/NEWS b/NEWS
index 441c9f1..ea356c0 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
0.6.11 (??/??/2010):
--------------------
+- Changed partition type code entry in gdisk so that it directly
+ accepts GUID values rather than requiring typing "0" to do so.
+
- The -t option to sgdisk now accepts GUID values as well as the
sgdisk/gdisk-specific two-byte hex codes.
diff --git a/gpt.cc b/gpt.cc
index 85176b8..7ed1de3 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -1855,17 +1855,6 @@ void GPTData::RandomizeGUIDs(void) {
// Change partition type code non-interactively. Returns 1 if
// successful, 0 if not....
-int GPTData::ChangePartType(uint32_t partNum, uint16_t hexCode) {
- int retval = 1;
-
- if (!IsFreePartNum(partNum)) {
- partitions[partNum].SetType(hexCode);
- } else retval = 0;
- return retval;
-} // GPTData::ChangePartType()
-
-// Change partition type code non-interactively. Returns 1 if
-// successful, 0 if not....
int GPTData::ChangePartType(uint32_t partNum, PartType theGUID) {
int retval = 1;
diff --git a/gpt.h b/gpt.h
index 6566a64..2bf3acb 100644
--- a/gpt.h
+++ b/gpt.h
@@ -16,7 +16,7 @@
#ifndef __GPTSTRUCTS
#define __GPTSTRUCTS
-#define GPTFDISK_VERSION "0.6.11-pre1"
+#define GPTFDISK_VERSION "0.6.11-pre2"
// Constants used by GPTData::PartsToMBR(). MBR_EMPTY must be the lowest-
// numbered value to refer to partition numbers. (Most will be 0 or positive,
@@ -162,7 +162,6 @@ public:
void SetDiskGUID(GUIDData newGUID);
int SetPartitionGUID(uint32_t pn, GUIDData theGUID);
void RandomizeGUIDs(void);
- int ChangePartType(uint32_t pn, uint16_t hexCode);
int ChangePartType(uint32_t pn, PartType theGUID);
void MakeProtectiveMBR(void) {protectiveMBR.MakeProtectiveMBR();}
void RecomputeCHS(void);
diff --git a/gptpart.cc b/gptpart.cc
index a395646..f597ca0 100644
--- a/gptpart.cc
+++ b/gptpart.cc
@@ -243,26 +243,26 @@ void GPTPart::ReversePartBytes(void) {
void GPTPart::ChangeType(void) {
char line[255];
char* junk;
- unsigned int typeNum = 0xFFFF, changeName = 0;
+ unsigned int changeName = 0;
+ PartType tempType = (GUIDData) "00000000-0000-0000-0000-000000000000";
if (GetDescription() == GetTypeName())
- changeName = 1;
+ changeName = UINT16_C(1);
cout << "Current type is '" << GetTypeName() << "'\n";
- while ((!partitionType.Valid(typeNum)) && (typeNum != 0)) {
- cout << "Hex code (L to show codes, 0 to enter raw code, Enter = 0700): ";
+ do {
+ cout << "Hex code or GUID (L to show codes, Enter = 0700): ";
junk = fgets(line, 255, stdin);
- sscanf(line, "%X", &typeNum);
- if ((line[0] == 'L') || (line[0] == 'l'))
+ if ((line[0] == 'L') || (line[0] == 'l')) {
partitionType.ShowAllTypes();
- if (line[0] == '\n') {
- typeNum = 0x0700;
- } // if
- } // while
- if (typeNum != 0) // user entered a code, so convert it
- partitionType = typeNum;
- else // user wants to enter the GUID directly, so do that
- partitionType.GetGUIDFromUser();
+ } else {
+ if (strlen(line) == 1)
+ tempType = 0x0700;
+ else
+ tempType = line;
+ } // if/else
+ } while (tempType == (GUIDData) "00000000-0000-0000-0000-000000000000");
+ partitionType = tempType;
cout << "Changed type of partition to '" << partitionType.TypeName() << "'\n";
if (changeName) {
SetDefaultDescription();
diff --git a/parttypes.cc b/parttypes.cc
index 968be74..a9cdf79 100644
--- a/parttypes.cc
+++ b/parttypes.cc
@@ -190,6 +190,26 @@ int PartType::AddType(uint16_t mbrType, const char * guidData, const char * name
return allOK;
} // GUID::AddType(const char* variant)
+// Assignment operator by string. If the original string is short,
+// interpret it as a gdisk hex code; if it's longer, interpret it as
+// a direct entry of a GUID value....
+PartType & PartType::operator=(const string & orig) {
+ uint32_t hexCode;
+
+ if (orig.length() < 32) {
+ sscanf(orig.c_str(), "%x", &hexCode);
+ *this = hexCode;
+ } else {
+ GUIDData::operator=(orig);
+ } // if/else hexCode or GUID
+ return *this;
+} // PartType::operator=(const char * orig)
+
+// Assignment from C-style string; rely on C++ casting....
+PartType & PartType::operator=(const char * orig) {
+ return operator=((string) orig);
+} // PartType::operator=(const char * orig)
+
// Assign a GUID based on my custom 2-byte (16-bit) MBR hex ID variant
PartType & PartType::operator=(uint16_t ID) {
AType* theItem = allTypes;
diff --git a/parttypes.h b/parttypes.h
index bff92c1..4d6e547 100644
--- a/parttypes.h
+++ b/parttypes.h
@@ -39,10 +39,12 @@ public:
// Set up type information
int AddType(uint16_t mbrType, const char * guidData, const char * name, int toDisplay = 1);
+ // New assignment operators....
+ PartType & operator=(const string & orig);
+ PartType & operator=(const char * orig);
+
// Assignment operators based on base class....
GUIDData & operator=(const GUIDData & orig) {return GUIDData::operator=(orig);}
- GUIDData & operator=(const string & orig) {return GUIDData::operator=(orig);}
- GUIDData & operator=(const char * orig) {return GUIDData::operator=(orig);}
// New data assignment
PartType & operator=(uint16_t ID); // Use MBR type code times 0x0100 to assign GUID
diff --git a/sgdisk.cc b/sgdisk.cc
index 612c526..b829d3c 100644
--- a/sgdisk.cc
+++ b/sgdisk.cc
@@ -35,7 +35,6 @@ int main(int argc, char *argv[]) {
int saveNonGPT = 1;
uint32_t gptPartNum = 0;
int alignment = DEFAULT_ALIGNMENT, retval = 0, pretend = 0;
- unsigned int hexCode;
uint32_t tableSize = 128;
uint64_t startSector, endSector;
char *attributeOperation = NULL;
@@ -305,14 +304,9 @@ int main(int argc, char *argv[]) {
case 't':
theGPT.JustLooking(0);
partNum = (int) GetInt(typeCode, 1) - 1;
- cout << "Got string '" << GetString(typeCode, 2) << "'\n";
- if (GetString(typeCode, 2).length() < 10) {
- sscanf(GetString(typeCode, 2).c_str(), "%x", &hexCode);
- typeHelper = hexCode;
- } else {
- typeHelper = GetString(typeCode, 2);
- } // if/else hexCode or GUID
- if (theGPT.ChangePartType(partNum, typeHelper)) {
+ typeHelper = GetString(typeCode, 2);
+ if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") &&
+ (theGPT.ChangePartType(partNum, typeHelper))) {
saveData = 1;
} else {
cerr << "Could not change partition " << partNum + 1