Merge /u/morisgi/gptfdisk/ branch enhancements into master

https://sourceforge.net/p/gptfdisk/code/merge-requests/15/
This commit is contained in:
Roderick W. Smith
2020-02-15 21:10:03 +00:00
8 changed files with 33 additions and 14 deletions

View File

@@ -263,9 +263,9 @@ two\-byte hexadecimal number. You may also enter a GUID directly, if you
have one and \fBcgdisk\fR doesn't know it. If you don't know the type code have one and \fBcgdisk\fR doesn't know it. If you don't know the type code
for your partition, you can type \fBL\fR to see a list of known type codes. for your partition, you can type \fBL\fR to see a list of known type codes.
The type code list may optionally be filtered by a search string; for The type code list may optionally be filtered by a search string; for
instance, entering \fI\fBLinux\fR\fR shows only partition type codes with instance, entering \fI\fBlinux\fR\fR shows only partition type codes with
descriptions that include the string \fILinux\fR. This search is performed descriptions that include the string \fILinux\fR. This search is performed
case\-sensitively. case\-insensitively.
.TP .TP
.B Verify .B Verify

View File

@@ -191,9 +191,9 @@ more codes in GPT. For these, \fBgdisk\fR adds code numbers sequentially,
such as 0xa500 for a FreeBSD disklabel, 0xa501 for FreeBSD boot, 0xa502 for such as 0xa500 for a FreeBSD disklabel, 0xa501 for FreeBSD boot, 0xa502 for
FreeBSD swap, and so on. Note that these two\-byte codes are unique to FreeBSD swap, and so on. Note that these two\-byte codes are unique to
\fBgdisk\fR. The type code list may optionally be filtered by a search \fBgdisk\fR. The type code list may optionally be filtered by a search
string; for instance, entering \fI\fBLinux\fR\fR shows only partition type string; for instance, entering \fI\fBlinux\fR\fR shows only partition type
codes with descriptions that include the string \fILinux\fR. This search is codes with descriptions that include the string \fILinux\fR. This search is
performed case\-sensitively. performed case\-insensitively.
.TP .TP
.B n .B n

View File

@@ -375,7 +375,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
partNum = newPartNum; partNum = newPartNum;
if ((partNum >= 0) && (partNum < (int) GetNumParts())) { if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
typeHelper = GetString(typeCode, 2); typeHelper = GetString(typeCode, 2);
if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") && if ((typeHelper != PartType::unusedPartType) &&
(ChangePartType(partNum, typeHelper))) { (ChangePartType(partNum, typeHelper))) {
saveData = 1; saveData = 1;
} else { } else {

View File

@@ -434,7 +434,7 @@ void GPTPart::ReversePartBytes(void) {
void GPTPart::ChangeType(void) { void GPTPart::ChangeType(void) {
string line; string line;
int changeName; int changeName;
PartType tempType = (GUIDData) "00000000-0000-0000-0000-000000000000"; PartType tempType = PartType::unusedPartType;
#ifdef USE_UTF16 #ifdef USE_UTF16
changeName = (GetDescription() == GetUTypeName()); changeName = (GetDescription() == GetUTypeName());
@@ -442,19 +442,19 @@ void GPTPart::ChangeType(void) {
changeName = (GetDescription() == GetTypeName()); changeName = (GetDescription() == GetTypeName());
#endif #endif
cout << "Current type is '" << GetTypeName() << "'\n"; cout << "Current type is " << hex << GetHexType() << dec << " (" << GetTypeName() << ")\n";
do { do {
cout << "Hex code or GUID (L to show codes, Enter = " << hex << DEFAULT_GPT_TYPE << dec << "): "; cout << "Hex code or GUID (L to show codes, Enter = " << hex << GetHexType() << dec << "): ";
line = ReadString(); line = ReadString();
if ((line[0] == 'L') || (line[0] == 'l')) { if ((line[0] == 'L') || (line[0] == 'l')) {
partitionType.ShowAllTypes(); partitionType.ShowAllTypes();
} else { } else {
if (line.length() == 0) if (line.length() == 0)
tempType = DEFAULT_GPT_TYPE; tempType = GetHexType();
else else
tempType = line; tempType = line;
} // if/else } // if/else
} while (tempType == (GUIDData) "00000000-0000-0000-0000-000000000000"); } while (tempType == PartType::unusedPartType);
partitionType = tempType; partitionType = tempType;
cout << "Changed type of partition to '" << partitionType.TypeName() << "'\n"; cout << "Changed type of partition to '" << partitionType.TypeName() << "'\n";
if (changeName) { if (changeName) {

View File

@@ -19,6 +19,7 @@ using namespace std;
int PartType::numInstances = 0; int PartType::numInstances = 0;
AType* PartType::allTypes = NULL; AType* PartType::allTypes = NULL;
AType* PartType::lastType = NULL; AType* PartType::lastType = NULL;
const PartType PartType::unusedPartType = (GUIDData) "00000000-0000-0000-0000-000000000000";
#define SCREEN_WIDTH 80 #define SCREEN_WIDTH 80
#define NUM_COLUMNS 2 #define NUM_COLUMNS 2
@@ -530,10 +531,10 @@ void PartType::ShowAllTypes(int maxLines) const {
cout.unsetf(ios::uppercase); cout.unsetf(ios::uppercase);
if (maxLines > 0) { if (maxLines > 0) {
cout << "Type search string, or <Enter> to show all codes: "; cout << "Type search string, or <Enter> to show all codes: ";
matchString = ReadString(); matchString = ToLower(ReadString());
} // if } // if
while (thisType != NULL) { while (thisType != NULL) {
found = thisType->name.find(matchString); found = ToLower(thisType->name).find(matchString);
if ((thisType->display == 1) && (found != string::npos)) { // show it if ((thisType->display == 1) && (found != string::npos)) { // show it
cout.fill('0'); cout.fill('0');
cout.width(4); cout.width(4);
@@ -545,8 +546,10 @@ void PartType::ShowAllTypes(int maxLines) const {
if (thisType->next) { if (thisType->next) {
cout << "\n"; cout << "\n";
if ((maxLines > 0) && (lineCount++ % maxLines) == 0) { if ((maxLines > 0) && (lineCount++ % maxLines) == 0) {
cout << "Press the <Enter> key to see more codes: "; cout << "Press the <Enter> key to see more codes, q to quit: ";
getline(cin, line); getline(cin, line);
if ((line[0] =='q') || (line[0] =='Q'))
break;
} // if reached screen line limit } // if reached screen line limit
} // if there's another entry following this one } // if there's another entry following this one
} else { } else {

View File

@@ -36,6 +36,9 @@ protected:
static AType* lastType; // Pointer to last entry in the list static AType* lastType; // Pointer to last entry in the list
void AddAllTypes(void); void AddAllTypes(void);
public: public:
// PartType with GUID "00000000-0000-0000-0000-000000000000"
static const PartType unusedPartType;
PartType(void); PartType(void);
PartType(const PartType & orig); PartType(const PartType & orig);
PartType(const GUIDData & orig); PartType(const GUIDData & orig);

View File

@@ -8,7 +8,9 @@
#define __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
@@ -16,6 +18,8 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string> #include <string>
#include <cctype>
#include <algorithm>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include "support.h" #include "support.h"
@@ -78,7 +82,7 @@ uint64_t GetNumber(uint64_t low, uint64_t high, uint64_t def, const string & pro
cin.getline(line, 255); cin.getline(line, 255);
if (!cin.good()) if (!cin.good())
exit(5); exit(5);
num = sscanf(line, "%lld", &response); num = sscanf(line, "%" PRIu64, &response);
if (num == 1) { // user provided a response if (num == 1) { // user provided a response
if ((response < low) || (response > high)) if ((response < low) || (response > high))
cout << "Value out of range\n"; cout << "Value out of range\n";
@@ -358,3 +362,11 @@ void WinWarning(void) {
exit(0); exit(0);
#endif #endif
} // WinWarning() } // WinWarning()
// Returns the input string in lower case
string ToLower(const string& input) {
string lower = input; // allocate correct size through copy
transform(input.begin(), input.end(), lower.begin(), ::tolower);
return lower;
} // ToLower()

View File

@@ -82,5 +82,6 @@ int IsHex(string input); // Returns 1 if input can be hexadecimal number....
int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
void WinWarning(void); void WinWarning(void);
string ToLower(const string& input);
#endif #endif