New partition type codes & "-a" option for cgdisk

This commit is contained in:
Roderick W. Smith
2013-07-06 22:52:58 -04:00
parent f5dfbfa418
commit 1eea9b0b51
12 changed files with 65 additions and 21 deletions

15
NEWS
View File

@@ -1,6 +1,14 @@
0.8.7 (?/?/2013):
-----------------
- Modified "converting MBR to GPT" message to clarify that the conversion
is being held in memory, since some people have mistakenly assumed that a
"gdisk -l" operation will change an MBR disk to a GPT disk without
prompting.
- Added partition type code for freedesktop.org's proposed $BOOT partition
(bc13c2ff-59e6-4262-a352-b275fd6f7172; GPT fdisk type code EA00)
- Adjusted alignment code when using -n or -N in sgdisk to keep the
requested partition size (if specified using +###{MGT} terminology)
as the requested value rather than relative to the requested start
@@ -13,10 +21,11 @@
- Removed stray debug message that would appear when reading MBR disks.
- Added partition type code for Intel Fast Flash (GUID
D3BFE2DE-3DAF-11DF-BA40-E3A556D89593, code EF03), used by systems that
- Added partition type code for Intel Rapid Start partition (GUID
D3BFE2DE-3DAF-11DF-BA40-E3A556D89593, code 8400), used by systems that
implement Intel's Rapid Start technology. See
http://blog.adios.tw/2012/10/funtoo-linux-and-intel-rapid-start.html.
http://blog.adios.tw/2012/10/funtoo-linux-and-intel-rapid-start.html or
http://mjg59.dreamwidth.org/26022.html.
- Added partition type code for Haiku BFS (GUID
42465331-3BA3-10F1-802A-4861696B7521; code EB00).

6
README
View File

@@ -163,8 +163,10 @@ Installing
To compile GPT fdisk, you must have appropriate development tools
installed, most notably the GNU Compiler Collection (GCC) and its g++
compiler for C++. (Under Windows, Microsoft Visual C++ 2008 can also be
used.) In addition, note these requirements:
compiler for C++. I've also tested compilation with Clang, which seems to
work; however, I've not done extensive testing of the resulting binaries,
beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can
be used instead. In addition, note these requirements:
* On Linux, FreeBSD, OS X, and Solaris, libuuid must be installed. This is
the standard for Linux and OS X, although you may need to install a

View File

@@ -20,7 +20,7 @@
/* This class implements an interactive curses-based interface atop the
GPTData class */
#include <string>
#include <string.h>
#include "gptcurses.h"
using namespace std;
@@ -29,6 +29,7 @@ using namespace std;
int main(int argc, char *argv[]) {
string device = "";
int displayType = USE_CURSES;
if (!SizesOK())
exit(1);
@@ -41,16 +42,28 @@ int main(int argc, char *argv[]) {
exit(0);
break;
case 2: // basic usage
device = argv[1];
device = (string) argv[1];
break;
case 3: // "-a" usage or illegal
if (strcmp(argv[1], "-a") == 0) {
device = (string) argv[2];
} else if (strcmp(argv[2], "-a") == 0) {
device = (string) argv[1];
} else {
cerr << "Usage: " << argv[0] << " [-a] device_file\n";
exit(1);
} // if/elseif/else
displayType = USE_ARROW;
break;
default:
cerr << "Usage: " << argv[0] << " device_file\n";
cerr << "Usage: " << argv[0] << " [-a] device_file\n";
exit(1);
break;
} // switch
GPTDataCurses theGPT;
theGPT.SetDisplayType(displayType);
if (theGPT.LoadPartitions(device)) {
if (theGPT.GetState() != use_gpt) {
Report("Warning! Non-GPT or damaged disk detected! This program will attempt to\n"

10
gpt.cc
View File

@@ -1429,12 +1429,14 @@ WhichToUse GPTData::UseWhichPartitions(void) {
if ((state == gpt_invalid) && ((mbrState == mbr) || (mbrState == hybrid))) {
cout << "\n***************************************************************\n"
<< "Found invalid GPT and valid MBR; converting MBR to GPT format.\n";
<< "Found invalid GPT and valid MBR; converting MBR to GPT format\n"
<< "in memory. ";
if (!justLooking) {
cout << "\aTHIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if\n"
<< "you don't want to convert your MBR partitions to GPT format!\n";
cout << "\aTHIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by\n"
<< "typing 'q' if you don't want to convert your MBR partitions\n"
<< "to GPT format!";
} // if
cout << "***************************************************************\n\n";
cout << "\n***************************************************************\n\n";
which = use_mbr;
} // if

2
gpt.h
View File

@@ -134,7 +134,7 @@ public:
// Convert between GPT and other formats
virtual WhichToUse UseWhichPartitions(void);
void XFormPartitions(void);
virtual int XFormDisklabel(uint32_t partNum);
int XFormDisklabel(uint32_t partNum);
int XFormDisklabel(BSDData* disklabel);
int OnePartToMBR(uint32_t gptPart, int mbrPart); // add one partition to MBR. Returns 1 if successful

View File

@@ -53,6 +53,7 @@ GPTDataCurses::GPTDataCurses(void) {
currentSpaceNum = -1;
whichOptions = ""; // current set of options
currentKey = 'b'; // currently selected option
displayType = USE_CURSES;
} // GPTDataCurses constructor
GPTDataCurses::~GPTDataCurses(void) {
@@ -273,10 +274,16 @@ int GPTDataCurses::DisplayParts(int selected) {
for (i = pageNum * numToShow; i <= (pageNum + 1) * numToShow - 1; i++) {
if (i < numSpaces) { // real space; show it
if (i == selected) {
attron(A_REVERSE);
currentSpaceNum = i;
if (displayType == USE_CURSES) {
attron(A_REVERSE);
currentSpace = ShowSpace(i, lineNum++);
attroff(A_REVERSE);
} else {
currentSpace = ShowSpace(i, lineNum);
move(lineNum++, 0);
printw(">");
}
DisplayOptions(i);
retval = selected;
} else {

View File

@@ -54,6 +54,9 @@ static struct MenuItem menuMain[] = {
#define EMPTY_SPACE_OPTIONS "abhlnqvw"
#define PARTITION_OPTIONS "abdhilmqtvw"
// Constants for how to highlight a selected menu item
#define USE_CURSES 1
#define USE_ARROW 2
// A "Space" is a partition or an unallocated chunk of disk space, maintained
// in a doubly-linked-list data structure to facilitate creating displays of
@@ -81,6 +84,7 @@ protected:
string whichOptions;
char currentKey;
int numSpaces;
int displayType;
// Functions relating to Spaces data structures
void EmptySpaces(void);
@@ -111,6 +115,7 @@ public:
void LoadBackup(void);
void ShowHelp(void);
// User input and menuing functions
void SetDisplayType(int dt) {displayType = dt;}
void ChangeSpaceSelection(int delta);
void MoveSelection(int delta);
void DisplayOptions(char selectedKey);

View File

@@ -91,7 +91,6 @@ string GPTPart::GetDescription(void) {
// Return 1 if the partition is in use
int GPTPart::IsUsed(void) {
return (partitionType != GUIDData("0x00"));
// return (firstLBA != UINT64_C(0));
} // GPTPart::IsUsed()
// Set the type code to the specified one. Also changes the partition

View File

@@ -132,7 +132,7 @@ int GPTDataTextUI::XFormDisklabel(void) {
numDone = GPTData::XFormDisklabel(partNum);
return numDone;
} // GPTData::XFormDisklabel(int i)
} // GPTData::XFormDisklabel(void)
/*********************************************************************

View File

@@ -319,7 +319,7 @@ void MBRPart::ReverseByteOrder(void) {
void MBRPart::ShowData(int isGpt) {
char bootCode = ' ';
if (status && 0x80) // it's bootable
if (status & 0x80) // it's bootable
bootCode = '*';
cout.fill(' ');
cout << bootCode << " ";

View File

@@ -110,6 +110,11 @@ void PartType::AddAllTypes(void) {
AddType(0x8200, "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", "Linux swap"); // Linux swap (or Solaris on MBR)
AddType(0x8300, "0FC63DAF-8483-4772-8E79-3D69D8477DE4", "Linux filesystem"); // Linux native
AddType(0x8301, "8DA63339-0007-60C0-C436-083AC8230908", "Linux reserved");
// Used by Intel Rapid Start technology
AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start");
// Another Linux type code....
AddType(0x8e00, "E6D6D379-F507-44C2-A23C-238F2A3DF928", "Linux LVM");
// FreeBSD partition types....
@@ -172,6 +177,9 @@ void PartType::AddAllTypes(void) {
AddType(0xc001, "75894C1E-3AEB-11D3-B7C1-7B03A0000000", "HP-UX data");
AddType(0xc002, "E2A1E728-32E3-11D6-A682-7B03A0000000", "HP-UX service");
// See http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec
AddType(0xea00, "BC13C2FF-59E6-4262-A352-B275FD6F7172", "Freedesktop $BOOT");
// Type code for Haiku; uses BeOS MBR code as hex code base
AddType(0xeb00, "42465331-3BA3-10F1-802A-4861696B7521", "Haiku BFS");
@@ -182,7 +190,6 @@ void PartType::AddAllTypes(void) {
AddType(0xef00, "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "EFI System"); // Parted identifies these as having the "boot flag" set
AddType(0xef01, "024DEE41-33E7-11D3-9D69-0008C781F39F", "MBR partition scheme"); // Used to nest MBR in GPT
AddType(0xef02, "21686148-6449-6E6F-744E-656564454649", "BIOS boot partition"); // Used by GRUB
AddType(0xef03, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Fast Flash"); // Used by Intel Rapid Start technology
// VMWare ESX partition types codes
AddType(0xfb00, "AA31E02A-400F-11DB-9590-000C2911D1B8", "VMWare VMFS");

View File

@@ -8,7 +8,7 @@
#ifndef __GPTSUPPORT
#define __GPTSUPPORT
#define GPTFDISK_VERSION "0.8.6.2"
#define GPTFDISK_VERSION "0.8.6.3"
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
// Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64