Checks on backup GPT data structures added to GPTData::DestroyGPT().
diff --git a/NEWS b/NEWS
index 35a9902..d901828 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,13 @@
0.8.9 (??/??/2014):
-------------------
+- Added check for valid location of backup GPT data to GPT-destruction
+ options ('z' in gdisk, -z and -Z options to sgdisk). If the backup
+ GPT data structures aren't at the end of the disk, they aren't erased.
+ This is done to avoid wiping out data mid-disk that might not be backup
+ GPT data structures, which could otherwise occur if a RAID array was
+ resized in certain ways.
+
- Added check for an oversized 0xEE protective partition. The program now
auto-repairs this condition on loading if the GPT data seem otherwise
valid. This is done because I've been receiving reports of some disks
diff --git a/gpt.cc b/gpt.cc
index fa7b661..d584397 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -1327,8 +1327,8 @@
tableSize = numParts * mainHeader.sizeOfPartitionEntries;
emptyTable = new uint8_t[tableSize];
if (emptyTable == NULL) {
- cerr << "Could not allocate memory in GPTData::DestroyGPT()! Terminating!\n";
- exit(1);
+ cerr << "Could not allocate memory in GPTData::DestroyGPT()! Aborting operation!\n";
+ return(0);
} // if
memset(emptyTable, 0, tableSize);
if (allOK) {
@@ -1337,25 +1337,31 @@
cerr << "Warning! GPT main partition table not overwritten! Error is " << errno << "\n";
allOK = 0;
} // if write failed
- } // if
- if (!myDisk.Seek(secondHeader.partitionEntriesLBA))
- allOK = 0;
- if (allOK) {
- sum = myDisk.Write(emptyTable, tableSize);
- if (sum != tableSize) {
- cerr << "Warning! GPT backup partition table not overwritten! Error is "
- << errno << "\n";
- allOK = 0;
- } // if wrong size written
} // if
- if (!myDisk.Seek(secondHeader.currentLBA))
- allOK = 0;
- if (allOK) {
- if (myDisk.Write(blankSector, 512) != 512) { // blank it out
- cerr << "Warning! GPT backup header not overwritten! Error is " << errno << "\n";
+
+ if (secondHeader.currentLBA == (diskSize - UINT64_C(1))) {
+ if (!myDisk.Seek(secondHeader.partitionEntriesLBA))
allOK = 0;
+ if (allOK) {
+ sum = myDisk.Write(emptyTable, tableSize);
+ if (sum != tableSize) {
+ cerr << "Warning! GPT backup partition table not overwritten! Error is "
+ << errno << "\n";
+ allOK = 0;
+ } // if wrong size written
} // if
- } // if
+ if (!myDisk.Seek(secondHeader.currentLBA))
+ allOK = 0;
+ if (allOK) {
+ if (myDisk.Write(blankSector, 512) != 512) { // blank it out
+ cerr << "Warning! GPT backup header not overwritten! Error is " << errno << "\n";
+ allOK = 0;
+ } // if
+ } // if
+ } else {
+ cout << "Note: The GPT second header is not at the end of the disk end; therefore,\n"
+ << "it's not being erased.\n";
+ }
myDisk.DiskSync();
myDisk.Close();
cout << "GPT data structures destroyed! You may now partition the disk using fdisk or\n"
diff --git a/parttypes.cc b/parttypes.cc
index 1c12b5e..e624e54 100644
--- a/parttypes.cc
+++ b/parttypes.cc
@@ -92,7 +92,8 @@
AddType(0x2700, "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC", "Windows RE");
// Open Network Install Environment (ONIE) specific types.
- // See http://www.onie.org/
+ // See http://www.onie.org/ and
+ // https://github.com/onie/onie/blob/master/rootconf/x86_64/sysroot-lib-onie/onie-blkdev-common
AddType(0x3000, "7412F7D5-A156-4B13-81DC-867174929325", "ONIE boot");
AddType(0x3001, "D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149", "ONIE config");