summaryrefslogtreecommitdiff
path: root/mbr.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-02-04 00:55:30 -0500
committersrs5694 <srs5694@users.sourceforge.net>2010-02-04 00:55:30 -0500
commit6699b01eda84d24bfaf80ad725304fef2b0e1b2a (patch)
treed1bdfd45d748bdc1a87b45dcd043c51e75ab6945 /mbr.cc
parent20e2a97ae67f2bbe31b354255671b3aed3793ee3 (diff)
downloadsgdisk-6699b01eda84d24bfaf80ad725304fef2b0e1b2a.tar.gz
Version 0.6.3 release. Big-endian bug fix, new GUID generation method,
architectural changes.
Diffstat (limited to 'mbr.cc')
-rw-r--r--mbr.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/mbr.cc b/mbr.cc
index 214fcb0..2417d77 100644
--- a/mbr.cc
+++ b/mbr.cc
@@ -39,6 +39,7 @@ MBRData::MBRData(void) {
numHeads = MAX_HEADS;
numSecspTrack = MAX_SECSPERTRACK;
myDisk = NULL;
+ canDeleteMyDisk = 0;
EmptyMBR();
} // MBRData default constructor
@@ -50,6 +51,7 @@ MBRData::MBRData(string filename) {
numHeads = MAX_HEADS;
numSecspTrack = MAX_SECSPERTRACK;
myDisk = NULL;
+ canDeleteMyDisk = 0;
srand((unsigned int) time(NULL));
// Try to read the specified partition table, but if it fails....
@@ -59,8 +61,12 @@ MBRData::MBRData(string filename) {
} // if
} // MBRData(string filename) constructor
+// Free space used by myDisk only if that's OK -- sometimes it will be
+// copied from an outside source, in which case that source should handle
+// it!
MBRData::~MBRData(void) {
-// delete myDisk;
+ if (canDeleteMyDisk)
+ delete myDisk;
} // MBRData destructor
/**********************
@@ -74,8 +80,10 @@ MBRData::~MBRData(void) {
int MBRData::ReadMBRData(const string & deviceFilename) {
int allOK = 1;
- if (myDisk == NULL)
+ if (myDisk == NULL) {
myDisk = new DiskIO;
+ canDeleteMyDisk = 1;
+ } // if
if (myDisk->OpenForRead(deviceFilename)) {
ReadMBRData(myDisk);
} else {
@@ -98,8 +106,10 @@ void MBRData::ReadMBRData(DiskIO * theDisk, int checkBlockSize) {
int err = 1;
TempMBR tempMBR;
- if (myDisk != NULL)
+ if ((myDisk != NULL) && (canDeleteMyDisk)) {
delete myDisk;
+ canDeleteMyDisk = 0;
+ } // if
myDisk = theDisk;
@@ -831,9 +841,9 @@ GPTPart MBRData::AsGPT(int i) {
if (lastSector > 0) lastSector--;
newPart.SetLastLBA(lastSector);
newPart.SetType(((uint16_t) origType) * 0x0100);
- newPart.SetUniqueGUID(1);
+ newPart.RandomizeUniqueGUID();
newPart.SetAttributes(0);
- newPart.SetName(newPart.GetNameType());
+ newPart.SetName(newPart.GetTypeName());
} // if not extended, protective, or non-existent
} // if (origPart != NULL)
return newPart;