diff options
Diffstat (limited to 'gpt.cc')
-rw-r--r-- | gpt.cc | 42 |
1 files changed, 24 insertions, 18 deletions
@@ -1327,8 +1327,8 @@ int GPTData::DestroyGPT(void) { 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 @@ int GPTData::DestroyGPT(void) { 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" |