diff options
author | Roderick W. Smith <rodsmith@rodsbooks.com> | 2014-02-17 12:01:51 -0500 |
---|---|---|
committer | Roderick W. Smith <rodsmith@rodsbooks.com> | 2014-02-17 12:01:51 -0500 |
commit | 5435fcf5c47caf8c77034f7a277642d1e23e90f8 (patch) | |
tree | 6e0cfe32938c6871970efc578646caee4b711d07 /gpt.cc | |
parent | 4a702a2e26420e14592cba64701d85ec9f1f70dc (diff) | |
download | sgdisk-5435fcf5c47caf8c77034f7a277642d1e23e90f8.tar.gz |
Checks on backup GPT data structures added to GPTData::DestroyGPT().
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" |