A few miscellaneous changes
This commit is contained in:
2
NEWS
2
NEWS
@@ -1,7 +1,7 @@
|
|||||||
0.7.1 (?/?/2011):
|
0.7.1 (?/?/2011):
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Integrated a number of code cleanups contributed by Florian Zumbiehl.
|
||||||
|
|
||||||
0.7.0 (3/11/2011):
|
0.7.0 (3/11/2011):
|
||||||
------------------
|
------------------
|
||||||
|
|||||||
62
basicmbr.cc
62
basicmbr.cc
@@ -18,6 +18,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
#include "mbr.h"
|
#include "mbr.h"
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
|
|
||||||
@@ -1110,65 +1111,10 @@ int BasicMBRData::SwapPartitions(uint32_t partNum1, uint32_t partNum2) {
|
|||||||
return allOK;
|
return allOK;
|
||||||
} // BasicMBRData::SwapPartitions()
|
} // BasicMBRData::SwapPartitions()
|
||||||
|
|
||||||
// Sort the MBR entries, eliminating gaps and making for a logical
|
|
||||||
// ordering. Relies on QuickSortMBR() for the bulk of the work
|
|
||||||
void BasicMBRData::SortMBR(int start) {
|
void BasicMBRData::SortMBR(int start) {
|
||||||
int i, numFound, firstPart, lastPart;
|
if ((start < MAX_MBR_PARTS) && (start >= 0))
|
||||||
uint32_t fp, lp;
|
sort(partitions + start, partitions + MAX_MBR_PARTS);
|
||||||
|
} // BasicMBRData::SortMBR()
|
||||||
// First, find the last partition with data, so as not to
|
|
||||||
// spend needless time sorting empty entries....
|
|
||||||
numFound = GetPartRange(&fp, &lp);
|
|
||||||
firstPart = (int) fp;
|
|
||||||
lastPart = (int) lp;
|
|
||||||
if (firstPart < start)
|
|
||||||
firstPart = start;
|
|
||||||
|
|
||||||
// Now swap empties with the last partitions, to simplify the logic
|
|
||||||
// in the Quicksort function....
|
|
||||||
i = start;
|
|
||||||
while (i < lastPart) {
|
|
||||||
if (partitions[i].GetStartLBA() == 0) {
|
|
||||||
SwapPartitions(i, lastPart);
|
|
||||||
do {
|
|
||||||
lastPart--;
|
|
||||||
} while ((lastPart > 0) && (partitions[lastPart].GetStartLBA() == 0));
|
|
||||||
} // if
|
|
||||||
i++;
|
|
||||||
} // while
|
|
||||||
|
|
||||||
// If there are more empties than partitions in the range from 0 to lastPart,
|
|
||||||
// the above leaves lastPart set too high, so we've got to adjust it to
|
|
||||||
// prevent empties from migrating to the top of the list....
|
|
||||||
GetPartRange(&fp, &lp);
|
|
||||||
lastPart = (int) lp;
|
|
||||||
|
|
||||||
// Now call the recursive quick sort routine to do the real work....
|
|
||||||
QuickSortMBR(start, lastPart);
|
|
||||||
} // GPTData::SortGPT()
|
|
||||||
|
|
||||||
// Recursive quick sort algorithm for MBR partitions. Note that if there
|
|
||||||
// are any empties in the specified range, they'll be sorted to the
|
|
||||||
// start, resulting in a sorted set of partitions that begins with
|
|
||||||
// partition 2, 3, or higher.
|
|
||||||
void BasicMBRData::QuickSortMBR(int start, int finish) {
|
|
||||||
uint64_t starterValue; // starting location of median partition
|
|
||||||
int left, right;
|
|
||||||
|
|
||||||
left = start;
|
|
||||||
right = finish;
|
|
||||||
starterValue = partitions[(start + finish) / 2].GetStartLBA();
|
|
||||||
do {
|
|
||||||
while (partitions[left].GetStartLBA() < starterValue)
|
|
||||||
left++;
|
|
||||||
while (partitions[right].GetStartLBA() > starterValue)
|
|
||||||
right--;
|
|
||||||
if (left <= right)
|
|
||||||
SwapPartitions(left++, right--);
|
|
||||||
} while (left <= right);
|
|
||||||
if (start < right) QuickSortMBR(start, right);
|
|
||||||
if (finish > left) QuickSortMBR(left, finish);
|
|
||||||
} // BasicMBRData::QuickSortMBR()
|
|
||||||
|
|
||||||
// Delete any partitions that are too big to fit on the disk
|
// Delete any partitions that are too big to fit on the disk
|
||||||
// or that are too big for MBR (32-bit limits).
|
// or that are too big for MBR (32-bit limits).
|
||||||
|
|||||||
@@ -125,11 +125,10 @@ public:
|
|||||||
void RecomputeCHS(int partNum);
|
void RecomputeCHS(int partNum);
|
||||||
int SwapPartitions(uint32_t partNum1, uint32_t partNum2);
|
int SwapPartitions(uint32_t partNum1, uint32_t partNum2);
|
||||||
void SortMBR(int start = 0);
|
void SortMBR(int start = 0);
|
||||||
void QuickSortMBR(int start, int finish);
|
// void QuickSortMBR(int start, int finish);
|
||||||
int DeleteOversizedParts();
|
int DeleteOversizedParts();
|
||||||
int DeleteExtendedParts();
|
int DeleteExtendedParts();
|
||||||
void OmitOverlaps(void);
|
void OmitOverlaps(void);
|
||||||
// void OmitAll(void);
|
|
||||||
void MaximizeLogicals();
|
void MaximizeLogicals();
|
||||||
void MaximizePrimaries();
|
void MaximizePrimaries();
|
||||||
void TrimPrimaries();
|
void TrimPrimaries();
|
||||||
@@ -143,7 +142,6 @@ public:
|
|||||||
uint64_t FindFirstAvailable(uint64_t start = 1);
|
uint64_t FindFirstAvailable(uint64_t start = 1);
|
||||||
uint64_t FindLastInFree(uint64_t start);
|
uint64_t FindLastInFree(uint64_t start);
|
||||||
uint64_t FindFirstInFree(uint64_t start);
|
uint64_t FindFirstInFree(uint64_t start);
|
||||||
// int IsFree(uint64_t sector, int topPartNum = MAX_MBR_PARTS);
|
|
||||||
int SectorUsedAs(uint64_t sector, int topPartNum = MAX_MBR_PARTS);
|
int SectorUsedAs(uint64_t sector, int topPartNum = MAX_MBR_PARTS);
|
||||||
|
|
||||||
// Functions to extract data on specific partitions....
|
// Functions to extract data on specific partitions....
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ GPTPart & GPTPart::operator=(const GPTPart & orig) {
|
|||||||
// we return the opposite of the usual arithmetic result when either
|
// we return the opposite of the usual arithmetic result when either
|
||||||
// firstLBA value is 0.
|
// firstLBA value is 0.
|
||||||
bool GPTPart::operator<(const GPTPart &other) const {
|
bool GPTPart::operator<(const GPTPart &other) const {
|
||||||
|
|
||||||
if (firstLBA && other.firstLBA)
|
if (firstLBA && other.firstLBA)
|
||||||
return (firstLBA < other.firstLBA);
|
return (firstLBA < other.firstLBA);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class GPTPart {
|
|||||||
uint64_t firstLBA;
|
uint64_t firstLBA;
|
||||||
uint64_t lastLBA;
|
uint64_t lastLBA;
|
||||||
Attributes attributes;
|
Attributes attributes;
|
||||||
// uint64_t attributes;
|
|
||||||
unsigned char name[NAME_SIZE];
|
unsigned char name[NAME_SIZE];
|
||||||
public:
|
public:
|
||||||
GPTPart(void);
|
GPTPart(void);
|
||||||
|
|||||||
12
mbrpart.cc
12
mbrpart.cc
@@ -102,6 +102,18 @@ MBRPart& MBRPart::operator=(const struct MBRRecord& orig) {
|
|||||||
return *this;
|
return *this;
|
||||||
} // MBRPart::operator=(const struct MBRRecord& orig)
|
} // MBRPart::operator=(const struct MBRRecord& orig)
|
||||||
|
|
||||||
|
// Compare the values, and return a bool result.
|
||||||
|
// Because this is intended for sorting and a lengthLBA value of 0 denotes
|
||||||
|
// a partition that's not in use and so that should be sorted upwards,
|
||||||
|
// we return the opposite of the usual arithmetic result when either
|
||||||
|
// lengthLBA value is 0.
|
||||||
|
bool MBRPart::operator<(const MBRPart &other) const {
|
||||||
|
if (lengthLBA && other.lengthLBA)
|
||||||
|
return (firstLBA < other.firstLBA);
|
||||||
|
else
|
||||||
|
return (other.firstLBA < firstLBA);
|
||||||
|
} // operator<()
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
* *
|
* *
|
||||||
* Set information on partitions or disks without *
|
* Set information on partitions or disks without *
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
virtual ~MBRPart();
|
virtual ~MBRPart();
|
||||||
virtual MBRPart& operator=(const MBRPart& orig);
|
virtual MBRPart& operator=(const MBRPart& orig);
|
||||||
virtual MBRPart& operator=(const struct MBRRecord& orig);
|
virtual MBRPart& operator=(const struct MBRRecord& orig);
|
||||||
|
bool operator<(const MBRPart &other) const;
|
||||||
|
|
||||||
// Set information on partitions or disks...
|
// Set information on partitions or disks...
|
||||||
void SetGeometry(uint32_t heads, uint32_t sectors, uint64_t diskSize, uint32_t blockSize);
|
void SetGeometry(uint32_t heads, uint32_t sectors, uint64_t diskSize, uint32_t blockSize);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
#include "parttypes.h"
|
#include "parttypes.h"
|
||||||
//#include "gptpartnotes.h"
|
|
||||||
#include "attributes.h"
|
#include "attributes.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -316,7 +315,6 @@ int main(int argc, char *argv[]) {
|
|||||||
secondDevice = theGPT;
|
secondDevice = theGPT;
|
||||||
secondDevice.SetDisk(outDevice);
|
secondDevice.SetDisk(outDevice);
|
||||||
secondDevice.JustLooking(0);
|
secondDevice.JustLooking(0);
|
||||||
// secondDevice.FixupMBR();
|
|
||||||
secondDevice.SaveGPTData(1);
|
secondDevice.SaveGPTData(1);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
@@ -432,8 +430,6 @@ int main(int argc, char *argv[]) {
|
|||||||
// Create a hybrid or regular MBR from GPT data structures
|
// Create a hybrid or regular MBR from GPT data structures
|
||||||
int BuildMBR(GPTData & theGPT, char* argument, int isHybrid) {
|
int BuildMBR(GPTData & theGPT, char* argument, int isHybrid) {
|
||||||
int numParts, allOK = 1, i, origPartNum;
|
int numParts, allOK = 1, i, origPartNum;
|
||||||
// GptPartNotes notes;
|
|
||||||
// struct PartInfo *newNote;
|
|
||||||
MBRPart newPart;
|
MBRPart newPart;
|
||||||
BasicMBRData newMBR;
|
BasicMBRData newMBR;
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ using namespace std;
|
|||||||
|
|
||||||
void ReadCString(char *inStr, int numchars) {
|
void ReadCString(char *inStr, int numchars) {
|
||||||
if (!fgets(inStr, numchars, stdin)) {
|
if (!fgets(inStr, numchars, stdin)) {
|
||||||
cerr << "Critical error! Failed fgets() in ReadCString()\n";
|
cerr << "Error! Failed fgets() in ReadCString()\n";
|
||||||
exit(1);
|
if ((numchars > 0) && (inStr != NULL))
|
||||||
|
inStr[0] = '\0';
|
||||||
} // if
|
} // if
|
||||||
} // ReadCString()
|
} // ReadCString()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user