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
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
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
case\-sensitively.
case\-insensitively.
.TP
.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
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
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
performed case\-sensitively.
performed case\-insensitively.
.TP
.B n

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,9 @@
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
@@ -16,6 +18,8 @@
#include <string.h>
#include <sys/stat.h>
#include <string>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <sstream>
#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);
if (!cin.good())
exit(5);
num = sscanf(line, "%lld", &response);
num = sscanf(line, "%" PRIu64, &response);
if (num == 1) { // user provided a response
if ((response < low) || (response > high))
cout << "Value out of range\n";
@@ -358,3 +362,11 @@ void WinWarning(void) {
exit(0);
#endif
} // 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
void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
void WinWarning(void);
string ToLower(const string& input);
#endif