Final 0.6.2 release; misc. bug fixes & Windows version
This commit is contained in:
5
Makefile
5
Makefile
@@ -1,16 +1,13 @@
|
|||||||
CC=gcc
|
CC=gcc
|
||||||
CXX=g++
|
CXX=g++
|
||||||
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
|
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
|
||||||
CXXFLAGS=-O2 -Wuninitialized -Wreturn-type -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
|
CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
|
||||||
LIB_NAMES=crc32 support gptpart mbr gpt bsd parttypes attributes diskio diskio-unix
|
LIB_NAMES=crc32 support gptpart mbr gpt bsd parttypes attributes diskio diskio-unix
|
||||||
LIB_SRCS=$(NAMES:=.cc)
|
LIB_SRCS=$(NAMES:=.cc)
|
||||||
LIB_OBJS=$(LIB_NAMES:=.o)
|
LIB_OBJS=$(LIB_NAMES:=.o)
|
||||||
LIB_HEADERS=$(LIB_NAMES:=.h)
|
LIB_HEADERS=$(LIB_NAMES:=.h)
|
||||||
DEPEND= makedepend $(CFLAGS)
|
DEPEND= makedepend $(CFLAGS)
|
||||||
|
|
||||||
#$(APPNAME): $(MBR2GPT_OBJS)
|
|
||||||
# $(CC) $(MBR2GPT_OBJS) -o $@
|
|
||||||
|
|
||||||
all: gdisk sgdisk
|
all: gdisk sgdisk
|
||||||
|
|
||||||
gdisk: $(LIB_OBJS) gdisk.o
|
gdisk: $(LIB_OBJS) gdisk.o
|
||||||
|
|||||||
@@ -2,16 +2,13 @@ CC=/usr/bin/i586-mingw32msvc-gcc
|
|||||||
CXX=/usr/bin/i586-mingw32msvc-g++
|
CXX=/usr/bin/i586-mingw32msvc-g++
|
||||||
STRIP=/usr/bin/i586-mingw32msvc-strip
|
STRIP=/usr/bin/i586-mingw32msvc-strip
|
||||||
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
|
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
|
||||||
CXXFLAGS=-O2 -Wuninitialized -Wreturn-type -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
|
CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
|
||||||
LIB_NAMES=gptpart bsd parttypes attributes crc32 mbr gpt support diskio diskio-windows
|
LIB_NAMES=gptpart bsd parttypes attributes crc32 mbr gpt support diskio diskio-windows
|
||||||
LIB_SRCS=$(NAMES:=.cc)
|
LIB_SRCS=$(NAMES:=.cc)
|
||||||
LIB_OBJS=$(LIB_NAMES:=.o)
|
LIB_OBJS=$(LIB_NAMES:=.o)
|
||||||
LIB_HEADERS=$(LIB_NAMES:=.h)
|
LIB_HEADERS=$(LIB_NAMES:=.h)
|
||||||
DEPEND= makedepend $(CFLAGS)
|
DEPEND= makedepend $(CFLAGS)
|
||||||
|
|
||||||
#$(APPNAME): $(MBR2GPT_OBJS)
|
|
||||||
# $(CC) $(MBR2GPT_OBJS) -o $@
|
|
||||||
|
|
||||||
all: gdisk
|
all: gdisk
|
||||||
|
|
||||||
gdisk: $(LIB_OBJS) gdisk.o
|
gdisk: $(LIB_OBJS) gdisk.o
|
||||||
|
|||||||
4
bsd.cc
4
bsd.cc
@@ -65,7 +65,7 @@ int BSDData::ReadBSDData(const string & device, uint64_t startSector, uint64_t e
|
|||||||
// file, starting with the specified sector number.
|
// file, starting with the specified sector number.
|
||||||
int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSector) {
|
int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSector) {
|
||||||
uint8_t buffer[4096]; // I/O buffer
|
uint8_t buffer[4096]; // I/O buffer
|
||||||
int i, err, foundSig = 0, bigEnd = 0, allOK = 1;
|
int i, foundSig = 0, bigEnd = 0, allOK = 1;
|
||||||
int relative = 0; // assume absolute partition sector numbering
|
int relative = 0; // assume absolute partition sector numbering
|
||||||
uint32_t realSig;
|
uint32_t realSig;
|
||||||
uint32_t* temp32;
|
uint32_t* temp32;
|
||||||
@@ -73,7 +73,6 @@ int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSect
|
|||||||
BSDRecord* tempRecords;
|
BSDRecord* tempRecords;
|
||||||
int offset[NUM_OFFSETS] = { LABEL_OFFSET1, LABEL_OFFSET2 };
|
int offset[NUM_OFFSETS] = { LABEL_OFFSET1, LABEL_OFFSET2 };
|
||||||
|
|
||||||
// myDisk = theDisk;
|
|
||||||
labelFirstLBA = startSector;
|
labelFirstLBA = startSector;
|
||||||
labelLastLBA = endSector;
|
labelLastLBA = endSector;
|
||||||
offset[1] = theDisk->GetBlockSize();
|
offset[1] = theDisk->GetBlockSize();
|
||||||
@@ -263,7 +262,6 @@ int BSDData::GetNumParts(void) {
|
|||||||
GPTPart BSDData::AsGPT(int i) {
|
GPTPart BSDData::AsGPT(int i) {
|
||||||
GPTPart guid; // dump data in here, then return it
|
GPTPart guid; // dump data in here, then return it
|
||||||
uint64_t sectorOne, sectorEnd; // first & last sectors of partition
|
uint64_t sectorOne, sectorEnd; // first & last sectors of partition
|
||||||
char tempStr[NAME_SIZE]; // temporary string for holding GPT name
|
|
||||||
int passItOn = 1; // Set to 0 if partition is empty or invalid
|
int passItOn = 1; // Set to 0 if partition is empty or invalid
|
||||||
|
|
||||||
guid.BlankPartition();
|
guid.BlankPartition();
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ int DiskIO::Seek(uint64_t sector) {
|
|||||||
// size with the number of bytes read.
|
// size with the number of bytes read.
|
||||||
// Returns the number of bytes read into buffer.
|
// Returns the number of bytes read into buffer.
|
||||||
int DiskIO::Read(void* buffer, int numBytes) {
|
int DiskIO::Read(void* buffer, int numBytes) {
|
||||||
int blockSize = 512, i, numBlocks, retval = 0;
|
int blockSize = 512, numBlocks, retval = 0;
|
||||||
char* tempSpace;
|
char* tempSpace;
|
||||||
|
|
||||||
// If disk isn't open, try to open it....
|
// If disk isn't open, try to open it....
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ using namespace std;
|
|||||||
|
|
||||||
// Returns the official Windows name for a shortened version of same.
|
// Returns the official Windows name for a shortened version of same.
|
||||||
void DiskIO::MakeRealName(void) {
|
void DiskIO::MakeRealName(void) {
|
||||||
int colonPos;
|
size_t colonPos;
|
||||||
|
|
||||||
colonPos = userFilename.find(':', 0);
|
colonPos = userFilename.find(':', 0);
|
||||||
if ((colonPos != string::npos) && (colonPos <= 3)) {
|
if ((colonPos != string::npos) && (colonPos <= 3)) {
|
||||||
@@ -183,8 +183,6 @@ void DiskIO::DiskSync(void) {
|
|||||||
int DiskIO::Seek(uint64_t sector) {
|
int DiskIO::Seek(uint64_t sector) {
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
LARGE_INTEGER seekTo;
|
LARGE_INTEGER seekTo;
|
||||||
uint32_t lowBits, highBits;
|
|
||||||
uint64_t bytePos;
|
|
||||||
|
|
||||||
// If disk isn't open, try to open it....
|
// If disk isn't open, try to open it....
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ int DiskIO::FindAlignment(void) {
|
|||||||
|
|
||||||
// The same as FindAlignment(int), but opens and closes a device by filename
|
// The same as FindAlignment(int), but opens and closes a device by filename
|
||||||
int DiskIO::FindAlignment(const string & filename) {
|
int DiskIO::FindAlignment(const string & filename) {
|
||||||
int fd;
|
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
|
|
||||||
if (!isOpen)
|
if (!isOpen)
|
||||||
|
|||||||
59
gpt.cc
59
gpt.cc
@@ -96,9 +96,10 @@ GPTData::~GPTData(void) {
|
|||||||
// do *NOT* recover from these problems. Returns the total number of
|
// do *NOT* recover from these problems. Returns the total number of
|
||||||
// problems identified.
|
// problems identified.
|
||||||
int GPTData::Verify(void) {
|
int GPTData::Verify(void) {
|
||||||
int problems = 0, numSegments, i;
|
int problems = 0;
|
||||||
uint64_t totalFree, largestSegment, firstSector;
|
uint32_t i, numSegments;
|
||||||
char tempStr[255], siTotal[255], siLargest[255];
|
uint64_t totalFree, largestSegment;
|
||||||
|
char siTotal[255], siLargest[255];
|
||||||
|
|
||||||
// First, check for CRC errors in the GPT data....
|
// First, check for CRC errors in the GPT data....
|
||||||
if (!mainCrcOk) {
|
if (!mainCrcOk) {
|
||||||
@@ -458,7 +459,8 @@ void GPTData::RebuildSecondHeader(void) {
|
|||||||
// Search for hybrid MBR entries that have no corresponding GPT partition.
|
// Search for hybrid MBR entries that have no corresponding GPT partition.
|
||||||
// Returns number of such mismatches found
|
// Returns number of such mismatches found
|
||||||
int GPTData::FindHybridMismatches(void) {
|
int GPTData::FindHybridMismatches(void) {
|
||||||
int i, j, found, numFound = 0;
|
int i, found, numFound = 0;
|
||||||
|
uint32_t j;
|
||||||
uint64_t mbrFirst, mbrLast;
|
uint64_t mbrFirst, mbrLast;
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
@@ -493,7 +495,8 @@ int GPTData::FindHybridMismatches(void) {
|
|||||||
// Find overlapping partitions and warn user about them. Returns number of
|
// Find overlapping partitions and warn user about them. Returns number of
|
||||||
// overlapping partitions.
|
// overlapping partitions.
|
||||||
int GPTData::FindOverlaps(void) {
|
int GPTData::FindOverlaps(void) {
|
||||||
int i, j, problems = 0;
|
int problems = 0;
|
||||||
|
uint32_t i, j;
|
||||||
|
|
||||||
for (i = 1; i < mainHeader.numParts; i++) {
|
for (i = 1; i < mainHeader.numParts; i++) {
|
||||||
for (j = 0; j < i; j++) {
|
for (j = 0; j < i; j++) {
|
||||||
@@ -551,8 +554,8 @@ void GPTData::PartitionScan(void) {
|
|||||||
|
|
||||||
// Read GPT data from a disk.
|
// Read GPT data from a disk.
|
||||||
int GPTData::LoadPartitions(const string & deviceFilename) {
|
int GPTData::LoadPartitions(const string & deviceFilename) {
|
||||||
int err;
|
int err, allOK = 1;
|
||||||
int allOK = 1, i;
|
uint32_t i;
|
||||||
uint64_t firstBlock, lastBlock;
|
uint64_t firstBlock, lastBlock;
|
||||||
BSDData bsdDisklabel;
|
BSDData bsdDisklabel;
|
||||||
MBRValidity mbrState;
|
MBRValidity mbrState;
|
||||||
@@ -568,11 +571,9 @@ int GPTData::LoadPartitions(const string & deviceFilename) {
|
|||||||
<< "program.\n";
|
<< "program.\n";
|
||||||
#endif
|
#endif
|
||||||
cout << "\n";
|
cout << "\n";
|
||||||
// justLooking = 1;
|
|
||||||
} // if
|
} // if
|
||||||
myDisk.Close();
|
myDisk.Close();
|
||||||
|
|
||||||
// if ((fd = open(deviceFilename, O_RDONLY)) != -1) {
|
|
||||||
if (myDisk.OpenForRead(deviceFilename)) {
|
if (myDisk.OpenForRead(deviceFilename)) {
|
||||||
// store disk information....
|
// store disk information....
|
||||||
diskSize = myDisk.DiskSize(&err);
|
diskSize = myDisk.DiskSize(&err);
|
||||||
@@ -737,7 +738,7 @@ int GPTData::ForceLoadGPTData(void) {
|
|||||||
if ((myDisk.Seek(seekTo)) && (secondCrcOk)) {
|
if ((myDisk.Seek(seekTo)) && (secondCrcOk)) {
|
||||||
sizeOfParts = secondHeader.numParts * secondHeader.sizeOfPartitionEntries;
|
sizeOfParts = secondHeader.numParts * secondHeader.sizeOfPartitionEntries;
|
||||||
storage = (uint8_t*) malloc(sizeOfParts);
|
storage = (uint8_t*) malloc(sizeOfParts);
|
||||||
if (myDisk.Read(storage, sizeOfParts) != sizeOfParts) {
|
if (myDisk.Read(storage, sizeOfParts) != (int) sizeOfParts) {
|
||||||
cerr << "Warning! Error " << errno << " reading backup partition table!\n";
|
cerr << "Warning! Error " << errno << " reading backup partition table!\n";
|
||||||
} // if
|
} // if
|
||||||
newCRC = chksum_crc32((unsigned char*) storage, sizeOfParts);
|
newCRC = chksum_crc32((unsigned char*) storage, sizeOfParts);
|
||||||
@@ -770,7 +771,7 @@ int GPTData::ForceLoadGPTData(void) {
|
|||||||
// sensible!
|
// sensible!
|
||||||
// Returns 1 on success, 0 on failure. CRC errors do NOT count as failure.
|
// Returns 1 on success, 0 on failure. CRC errors do NOT count as failure.
|
||||||
int GPTData::LoadMainTable(void) {
|
int GPTData::LoadMainTable(void) {
|
||||||
int fd, retval = 1;
|
int retval = 1;
|
||||||
uint32_t newCRC, sizeOfParts;
|
uint32_t newCRC, sizeOfParts;
|
||||||
|
|
||||||
if (myDisk.OpenForRead(device)) {
|
if (myDisk.OpenForRead(device)) {
|
||||||
@@ -782,7 +783,7 @@ int GPTData::LoadMainTable(void) {
|
|||||||
if (!myDisk.Seek(mainHeader.partitionEntriesLBA))
|
if (!myDisk.Seek(mainHeader.partitionEntriesLBA))
|
||||||
retval = 0;
|
retval = 0;
|
||||||
sizeOfParts = mainHeader.numParts * mainHeader.sizeOfPartitionEntries;
|
sizeOfParts = mainHeader.numParts * mainHeader.sizeOfPartitionEntries;
|
||||||
if (myDisk.Read(partitions, sizeOfParts) != sizeOfParts) {
|
if (myDisk.Read(partitions, sizeOfParts) != (int) sizeOfParts) {
|
||||||
cerr << "Warning! Error " << errno << " when loading the main partition table!\n";
|
cerr << "Warning! Error " << errno << " when loading the main partition table!\n";
|
||||||
retval = 0;
|
retval = 0;
|
||||||
} // if
|
} // if
|
||||||
@@ -809,7 +810,7 @@ int GPTData::LoadSecondTableAsMain(void) {
|
|||||||
if (retval == 1) {
|
if (retval == 1) {
|
||||||
SetGPTSize(secondHeader.numParts);
|
SetGPTSize(secondHeader.numParts);
|
||||||
sizeOfParts = secondHeader.numParts * secondHeader.sizeOfPartitionEntries;
|
sizeOfParts = secondHeader.numParts * secondHeader.sizeOfPartitionEntries;
|
||||||
if (myDisk.Read(partitions, sizeOfParts) != sizeOfParts) {
|
if (myDisk.Read(partitions, sizeOfParts) != (int) sizeOfParts) {
|
||||||
cerr << "Warning! Read error " << errno << "! Misbehavior now likely!\n";
|
cerr << "Warning! Read error " << errno << "! Misbehavior now likely!\n";
|
||||||
retval = 0;
|
retval = 0;
|
||||||
} // if
|
} // if
|
||||||
@@ -836,7 +837,7 @@ int GPTData::LoadSecondTableAsMain(void) {
|
|||||||
// write, 0 if there was a problem.
|
// write, 0 if there was a problem.
|
||||||
int GPTData::SaveGPTData(int quiet) {
|
int GPTData::SaveGPTData(int quiet) {
|
||||||
int allOK = 1;
|
int allOK = 1;
|
||||||
char answer, line[256];
|
char answer;
|
||||||
uint64_t secondTable;
|
uint64_t secondTable;
|
||||||
uint32_t numParts;
|
uint32_t numParts;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
@@ -1128,7 +1129,7 @@ int GPTData::LoadGPTBackup(const string & filename) {
|
|||||||
// Load main partition table, and record whether its CRC
|
// Load main partition table, and record whether its CRC
|
||||||
// matches the stored value
|
// matches the stored value
|
||||||
sizeOfParts = numParts * sizeOfEntries;
|
sizeOfParts = numParts * sizeOfEntries;
|
||||||
if (backupFile.Read(partitions, sizeOfParts) != sizeOfParts) {
|
if (backupFile.Read(partitions, sizeOfParts) != (int) sizeOfParts) {
|
||||||
cerr << "Warning! Read error " << errno << "; strange behavior now likely!\n";
|
cerr << "Warning! Read error " << errno << "; strange behavior now likely!\n";
|
||||||
} // if
|
} // if
|
||||||
|
|
||||||
@@ -1184,8 +1185,7 @@ void GPTData::ShowGPTState(void) {
|
|||||||
|
|
||||||
// Display the basic GPT data
|
// Display the basic GPT data
|
||||||
void GPTData::DisplayGPTData(void) {
|
void GPTData::DisplayGPTData(void) {
|
||||||
int i;
|
uint32_t i;
|
||||||
// char tempStr[255];
|
|
||||||
uint64_t temp, totalFree;
|
uint64_t temp, totalFree;
|
||||||
|
|
||||||
cout << "Disk " << device << ": " << diskSize << " sectors, "
|
cout << "Disk " << device << ": " << diskSize << " sectors, "
|
||||||
@@ -1274,8 +1274,9 @@ void GPTData::ResizePartitionTable(void) {
|
|||||||
// Interactively create a partition
|
// Interactively create a partition
|
||||||
void GPTData::CreatePartition(void) {
|
void GPTData::CreatePartition(void) {
|
||||||
uint64_t firstBlock, firstInLargest, lastBlock, sector;
|
uint64_t firstBlock, firstInLargest, lastBlock, sector;
|
||||||
|
uint32_t firstFreePart = 0;
|
||||||
char prompt[255];
|
char prompt[255];
|
||||||
int partNum, firstFreePart = 0;
|
int partNum;
|
||||||
|
|
||||||
// Find first free partition...
|
// Find first free partition...
|
||||||
while (partitions[firstFreePart].GetFirstLBA() != 0) {
|
while (partitions[firstFreePart].GetFirstLBA() != 0) {
|
||||||
@@ -1372,7 +1373,7 @@ void GPTData::SetAttributes(uint32_t partNum) {
|
|||||||
// If prompt == -1, don't ask user about proceeding and DO wipe out
|
// If prompt == -1, don't ask user about proceeding and DO wipe out
|
||||||
// MBR.
|
// MBR.
|
||||||
int GPTData::DestroyGPT(int prompt) {
|
int GPTData::DestroyGPT(int prompt) {
|
||||||
int fd, i, sum, tableSize;
|
int i, sum, tableSize;
|
||||||
uint8_t blankSector[512], goOn = 'Y', blank = 'N';
|
uint8_t blankSector[512], goOn = 'Y', blank = 'N';
|
||||||
uint8_t* emptyTable;
|
uint8_t* emptyTable;
|
||||||
|
|
||||||
@@ -1590,7 +1591,7 @@ int GPTData::XFormDisklabel(int i) {
|
|||||||
BSDData disklabel;
|
BSDData disklabel;
|
||||||
|
|
||||||
if (GetPartRange(&low, &high) != 0) {
|
if (GetPartRange(&low, &high) != 0) {
|
||||||
if ((i < low) || (i > high))
|
if ((i < (int) low) || (i > (int) high))
|
||||||
partNum = GetPartNum();
|
partNum = GetPartNum();
|
||||||
else
|
else
|
||||||
partNum = (uint32_t) i;
|
partNum = (uint32_t) i;
|
||||||
@@ -1608,7 +1609,7 @@ int GPTData::XFormDisklabel(int i) {
|
|||||||
|
|
||||||
// If all is OK, read the disklabel and convert it.
|
// If all is OK, read the disklabel and convert it.
|
||||||
if (goOn) {
|
if (goOn) {
|
||||||
goOn = disklabel.ReadBSDData(device, partitions[partNum].GetFirstLBA(),
|
goOn = disklabel.ReadBSDData(&myDisk, partitions[partNum].GetFirstLBA(),
|
||||||
partitions[partNum].GetLastLBA());
|
partitions[partNum].GetLastLBA());
|
||||||
if ((goOn) && (disklabel.IsDisklabel())) {
|
if ((goOn) && (disklabel.IsDisklabel())) {
|
||||||
numDone = XFormDisklabel(&disklabel, startPart);
|
numDone = XFormDisklabel(&disklabel, startPart);
|
||||||
@@ -1630,7 +1631,7 @@ int GPTData::XFormDisklabel(int i) {
|
|||||||
} // GPTData::XFormDisklable(int i)
|
} // GPTData::XFormDisklable(int i)
|
||||||
|
|
||||||
// Transform the partitions on an already-loaded BSD disklabel...
|
// Transform the partitions on an already-loaded BSD disklabel...
|
||||||
int GPTData::XFormDisklabel(BSDData* disklabel, int startPart) {
|
int GPTData::XFormDisklabel(BSDData* disklabel, uint32_t startPart) {
|
||||||
int i, numDone = 0;
|
int i, numDone = 0;
|
||||||
|
|
||||||
if ((disklabel->IsDisklabel()) && (startPart >= 0) &&
|
if ((disklabel->IsDisklabel()) && (startPart >= 0) &&
|
||||||
@@ -1710,8 +1711,8 @@ int GPTData::OnePartToMBR(uint32_t gptPart, int mbrPart) {
|
|||||||
int GPTData::XFormToMBR(void) {
|
int GPTData::XFormToMBR(void) {
|
||||||
char line[255];
|
char line[255];
|
||||||
char* junk;
|
char* junk;
|
||||||
int i, j, numParts, numConverted = 0;
|
int j, numParts, numConverted = 0;
|
||||||
uint32_t partNums[4];
|
uint32_t i, partNums[4];
|
||||||
|
|
||||||
// Get the numbers of up to four partitions to add to the
|
// Get the numbers of up to four partitions to add to the
|
||||||
// hybrid MBR....
|
// hybrid MBR....
|
||||||
@@ -1737,7 +1738,7 @@ int GPTData::XFormToMBR(void) {
|
|||||||
} // while
|
} // while
|
||||||
} // if/else
|
} // if/else
|
||||||
|
|
||||||
for (i = 0; i < numParts; i++) {
|
for (i = 0; i < (uint32_t) numParts; i++) {
|
||||||
j = partNums[i] - 1;
|
j = partNums[i] - 1;
|
||||||
cout << "\nCreating entry for partition #" << j + 1 << "\n";
|
cout << "\nCreating entry for partition #" << j + 1 << "\n";
|
||||||
numConverted += OnePartToMBR(j, i);
|
numConverted += OnePartToMBR(j, i);
|
||||||
@@ -1937,7 +1938,7 @@ int GPTData::DeletePartition(uint32_t partNum) {
|
|||||||
// with another of the same name but different parameters; that one prompts
|
// with another of the same name but different parameters; that one prompts
|
||||||
// the user for data. This one returns 1 if the operation was successful, 0
|
// the user for data. This one returns 1 if the operation was successful, 0
|
||||||
// if a problem was discovered.
|
// if a problem was discovered.
|
||||||
int GPTData::CreatePartition(uint32_t partNum, uint64_t startSector, uint64_t endSector) {
|
uint32_t GPTData::CreatePartition(uint32_t partNum, uint64_t startSector, uint64_t endSector) {
|
||||||
int retval = 1; // assume there'll be no problems
|
int retval = 1; // assume there'll be no problems
|
||||||
|
|
||||||
if (IsFreePartNum(partNum)) {
|
if (IsFreePartNum(partNum)) {
|
||||||
@@ -2195,7 +2196,7 @@ int GPTData::GetPartRange(uint32_t *low, uint32_t *high) {
|
|||||||
|
|
||||||
// Returns the number of defined partitions.
|
// Returns the number of defined partitions.
|
||||||
uint32_t GPTData::CountParts(void) {
|
uint32_t GPTData::CountParts(void) {
|
||||||
int i, counted = 0;
|
uint32_t i, counted = 0;
|
||||||
|
|
||||||
for (i = 0; i < mainHeader.numParts; i++) {
|
for (i = 0; i < mainHeader.numParts; i++) {
|
||||||
if (partitions[i].GetFirstLBA() > 0)
|
if (partitions[i].GetFirstLBA() > 0)
|
||||||
@@ -2312,13 +2313,13 @@ uint64_t GPTData::FindLastInFree(uint64_t start) {
|
|||||||
|
|
||||||
// Finds the total number of free blocks, the number of segments in which
|
// Finds the total number of free blocks, the number of segments in which
|
||||||
// they reside, and the size of the largest of those segments
|
// they reside, and the size of the largest of those segments
|
||||||
uint64_t GPTData::FindFreeBlocks(int *numSegments, uint64_t *largestSegment) {
|
uint64_t GPTData::FindFreeBlocks(uint32_t *numSegments, uint64_t *largestSegment) {
|
||||||
uint64_t start = UINT64_C(0); // starting point for each search
|
uint64_t start = UINT64_C(0); // starting point for each search
|
||||||
uint64_t totalFound = UINT64_C(0); // running total
|
uint64_t totalFound = UINT64_C(0); // running total
|
||||||
uint64_t firstBlock; // first block in a segment
|
uint64_t firstBlock; // first block in a segment
|
||||||
uint64_t lastBlock; // last block in a segment
|
uint64_t lastBlock; // last block in a segment
|
||||||
uint64_t segmentSize; // size of segment in blocks
|
uint64_t segmentSize; // size of segment in blocks
|
||||||
int num = 0;
|
uint32_t num = 0;
|
||||||
|
|
||||||
*largestSegment = UINT64_C(0);
|
*largestSegment = UINT64_C(0);
|
||||||
do {
|
do {
|
||||||
|
|||||||
8
gpt.h
8
gpt.h
@@ -16,7 +16,7 @@
|
|||||||
#ifndef __GPTSTRUCTS
|
#ifndef __GPTSTRUCTS
|
||||||
#define __GPTSTRUCTS
|
#define __GPTSTRUCTS
|
||||||
|
|
||||||
#define GPTFDISK_VERSION "0.6.2-pre2"
|
#define GPTFDISK_VERSION "0.6.2"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ public:
|
|||||||
WhichToUse UseWhichPartitions(void);
|
WhichToUse UseWhichPartitions(void);
|
||||||
int XFormPartitions(void);
|
int XFormPartitions(void);
|
||||||
int XFormDisklabel(int OnGptPart = -1);
|
int XFormDisklabel(int OnGptPart = -1);
|
||||||
int XFormDisklabel(BSDData* disklabel, int startPart);
|
int XFormDisklabel(BSDData* disklabel, uint32_t startPart);
|
||||||
int OnePartToMBR(uint32_t gptPart, int mbrPart); // add one partition to MBR. Returns 1 if successful
|
int OnePartToMBR(uint32_t gptPart, int mbrPart); // add one partition to MBR. Returns 1 if successful
|
||||||
int XFormToMBR(void); // convert GPT to MBR, wiping GPT afterwards. Returns 1 if successful
|
int XFormToMBR(void); // convert GPT to MBR, wiping GPT afterwards. Returns 1 if successful
|
||||||
void MakeHybrid(void);
|
void MakeHybrid(void);
|
||||||
@@ -133,7 +133,7 @@ public:
|
|||||||
int SetGPTSize(uint32_t numEntries);
|
int SetGPTSize(uint32_t numEntries);
|
||||||
void BlankPartitions(void);
|
void BlankPartitions(void);
|
||||||
int DeletePartition(uint32_t partNum);
|
int DeletePartition(uint32_t partNum);
|
||||||
int CreatePartition(uint32_t partNum, uint64_t startSector, uint64_t endSector);
|
uint32_t CreatePartition(uint32_t partNum, uint64_t startSector, uint64_t endSector);
|
||||||
void SortGPT(void);
|
void SortGPT(void);
|
||||||
int ClearGPTData(void);
|
int ClearGPTData(void);
|
||||||
void MoveSecondHeaderToEnd();
|
void MoveSecondHeaderToEnd();
|
||||||
@@ -158,7 +158,7 @@ public:
|
|||||||
uint64_t FindFirstInLargest(void);
|
uint64_t FindFirstInLargest(void);
|
||||||
uint64_t FindLastAvailable(uint64_t start);
|
uint64_t FindLastAvailable(uint64_t start);
|
||||||
uint64_t FindLastInFree(uint64_t start);
|
uint64_t FindLastInFree(uint64_t start);
|
||||||
uint64_t FindFreeBlocks(int *numSegments, uint64_t *largestSegment);
|
uint64_t FindFreeBlocks(uint32_t *numSegments, uint64_t *largestSegment);
|
||||||
int IsFree(uint64_t sector);
|
int IsFree(uint64_t sector);
|
||||||
int IsFreePartNum(uint32_t partNum);
|
int IsFreePartNum(uint32_t partNum);
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,6 @@ string GPTPart::GetName(void) {
|
|||||||
// name *IF* the current name is the generic one for the current partition
|
// name *IF* the current name is the generic one for the current partition
|
||||||
// type.
|
// type.
|
||||||
void GPTPart::SetType(struct GUIDData t) {
|
void GPTPart::SetType(struct GUIDData t) {
|
||||||
int nameSame = 1, currentLength, i;
|
|
||||||
|
|
||||||
if (GetName() == typeHelper.GUIDToName(partitionType)) {
|
if (GetName() == typeHelper.GUIDToName(partitionType)) {
|
||||||
SetName(typeHelper.GUIDToName(t));
|
SetName(typeHelper.GUIDToName(t));
|
||||||
} // if
|
} // if
|
||||||
@@ -157,7 +155,7 @@ void GPTPart::ShowSummary(int partNum, uint32_t blockSize) {
|
|||||||
cout.width(14);
|
cout.width(14);
|
||||||
cout << lastLBA << " ";
|
cout << lastLBA << " ";
|
||||||
cout << BytesToSI(blockSize * (lastLBA - firstLBA + 1)) << " ";
|
cout << BytesToSI(blockSize * (lastLBA - firstLBA + 1)) << " ";
|
||||||
for (i = 0; i < 9 - sizeInSI.length(); i++) cout << " ";
|
for (i = 0; i < 9 - (int) sizeInSI.length(); i++) cout << " ";
|
||||||
cout.fill('0');
|
cout.fill('0');
|
||||||
cout.width(4);
|
cout.width(4);
|
||||||
cout.setf(ios::uppercase);
|
cout.setf(ios::uppercase);
|
||||||
|
|||||||
6
mbr.cc
6
mbr.cc
@@ -72,7 +72,7 @@ MBRData::~MBRData(void) {
|
|||||||
// Read data from MBR. Returns 1 if read was successful (even if the
|
// Read data from MBR. Returns 1 if read was successful (even if the
|
||||||
// data isn't a valid MBR), 0 if the read failed.
|
// data isn't a valid MBR), 0 if the read failed.
|
||||||
int MBRData::ReadMBRData(const string & deviceFilename) {
|
int MBRData::ReadMBRData(const string & deviceFilename) {
|
||||||
int fd, allOK = 1;
|
int allOK = 1;
|
||||||
|
|
||||||
if (myDisk == NULL)
|
if (myDisk == NULL)
|
||||||
myDisk = new DiskIO;
|
myDisk = new DiskIO;
|
||||||
@@ -348,7 +348,6 @@ int MBRData::WriteMBRData(const string & deviceFilename) {
|
|||||||
// Show the MBR data to the user....
|
// Show the MBR data to the user....
|
||||||
void MBRData::DisplayMBRData(void) {
|
void MBRData::DisplayMBRData(void) {
|
||||||
int i;
|
int i;
|
||||||
char tempStr[255];
|
|
||||||
char bootCode;
|
char bootCode;
|
||||||
|
|
||||||
cout << "MBR disk identifier: 0x";
|
cout << "MBR disk identifier: 0x";
|
||||||
@@ -378,7 +377,7 @@ void MBRData::DisplayMBRData(void) {
|
|||||||
cout.fill(' ');
|
cout.fill(' ');
|
||||||
} // for
|
} // for
|
||||||
cout << "\nDisk size is " << diskSize << " sectors ("
|
cout << "\nDisk size is " << diskSize << " sectors ("
|
||||||
<< BytesToSI(diskSize * (uint64_t) blockSize) << "\n";
|
<< BytesToSI(diskSize * (uint64_t) blockSize) << ")\n";
|
||||||
} // MBRData::DisplayMBRData()
|
} // MBRData::DisplayMBRData()
|
||||||
|
|
||||||
// Displays the state, as a word, on stdout. Used for debugging & to
|
// Displays the state, as a word, on stdout. Used for debugging & to
|
||||||
@@ -814,7 +813,6 @@ GPTPart MBRData::AsGPT(int i) {
|
|||||||
GPTPart newPart;
|
GPTPart newPart;
|
||||||
uint8_t origType;
|
uint8_t origType;
|
||||||
uint64_t firstSector, lastSector;
|
uint64_t firstSector, lastSector;
|
||||||
char tempStr[NAME_SIZE];
|
|
||||||
|
|
||||||
newPart.BlankPartition();
|
newPart.BlankPartition();
|
||||||
origPart = GetPartition(i);
|
origPart = GetPartition(i);
|
||||||
|
|||||||
16
parttypes.cc
16
parttypes.cc
@@ -204,9 +204,9 @@ PartTypes::~PartTypes(void) {
|
|||||||
} // destructor
|
} // destructor
|
||||||
|
|
||||||
// Add a single type to the linked list of types. Returns 1 if operation
|
// Add a single type to the linked list of types. Returns 1 if operation
|
||||||
// succeeds, 0 otherwise
|
// succeeds, 0 otherwise.
|
||||||
int PartTypes::AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
int PartTypes::AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
||||||
const char* n, int toDisplay) {
|
const char * n, int toDisplay) {
|
||||||
AType* tempType;
|
AType* tempType;
|
||||||
int allOK = 1;
|
int allOK = 1;
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ int PartTypes::AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
|||||||
tempType->MBRType = mbrType;
|
tempType->MBRType = mbrType;
|
||||||
tempType->GUIDType.data1 = guidData1;
|
tempType->GUIDType.data1 = guidData1;
|
||||||
tempType->GUIDType.data2 = guidData2;
|
tempType->GUIDType.data2 = guidData2;
|
||||||
strncpy(tempType->name, n, PNAME_SIZE);
|
tempType->name = n;
|
||||||
tempType->display = toDisplay;
|
tempType->display = toDisplay;
|
||||||
tempType->next = NULL;
|
tempType->next = NULL;
|
||||||
if (allTypes == NULL) { // first entry
|
if (allTypes == NULL) { // first entry
|
||||||
@@ -236,7 +236,7 @@ int PartTypes::AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
|||||||
// in an ugly way.
|
// in an ugly way.
|
||||||
void PartTypes::ShowTypes(void) {
|
void PartTypes::ShowTypes(void) {
|
||||||
int colCount = 1; // column count
|
int colCount = 1; // column count
|
||||||
int i;
|
size_t i;
|
||||||
AType* thisType = allTypes;
|
AType* thisType = allTypes;
|
||||||
|
|
||||||
cout.unsetf(ios::uppercase);
|
cout.unsetf(ios::uppercase);
|
||||||
@@ -245,10 +245,12 @@ void PartTypes::ShowTypes(void) {
|
|||||||
cout.fill('0');
|
cout.fill('0');
|
||||||
cout.width(4);
|
cout.width(4);
|
||||||
cout << hex << thisType->MBRType << " ";
|
cout << hex << thisType->MBRType << " ";
|
||||||
cout << ((string) thisType->name).substr(0, 19) << " ";
|
cout << thisType->name.substr(0, 20);
|
||||||
for (i = 0; i < (19 - ((string) thisType->name).substr(0, 19).length()); i ++) cout << " ";
|
for (i = 0; i < (20 - (thisType->name.substr(0, 20).length())); i++) cout << " ";
|
||||||
if ((colCount % 3) == 0)
|
if ((colCount % 3) == 0)
|
||||||
cout << "\n";
|
cout << "\n";
|
||||||
|
else
|
||||||
|
cout << " ";
|
||||||
colCount++;
|
colCount++;
|
||||||
} // if
|
} // if
|
||||||
thisType = thisType->next;
|
thisType = thisType->next;
|
||||||
@@ -280,7 +282,6 @@ string PartTypes::GUIDToName(struct GUIDData typeCode) {
|
|||||||
while ((theItem != NULL) && (!found)) {
|
while ((theItem != NULL) && (!found)) {
|
||||||
if ((theItem->GUIDType.data1 == typeCode.data1) &&
|
if ((theItem->GUIDType.data1 == typeCode.data1) &&
|
||||||
(theItem->GUIDType.data2 == typeCode.data2)) { // found it!
|
(theItem->GUIDType.data2 == typeCode.data2)) { // found it!
|
||||||
// strcpy(typeName, theItem->name);
|
|
||||||
typeName = theItem->name;
|
typeName = theItem->name;
|
||||||
found = 1;
|
found = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -289,7 +290,6 @@ string PartTypes::GUIDToName(struct GUIDData typeCode) {
|
|||||||
} // while
|
} // while
|
||||||
if (!found) {
|
if (!found) {
|
||||||
typeName = "Unknown";
|
typeName = "Unknown";
|
||||||
// strcpy(typeName, (char*) "Unknown");
|
|
||||||
} // if (!found)
|
} // if (!found)
|
||||||
return typeName;
|
return typeName;
|
||||||
} // PartTypes::GUIDToName()
|
} // PartTypes::GUIDToName()
|
||||||
|
|||||||
@@ -10,9 +10,6 @@
|
|||||||
#ifndef __PARTITION_TYPES
|
#ifndef __PARTITION_TYPES
|
||||||
#define __PARTITION_TYPES
|
#define __PARTITION_TYPES
|
||||||
|
|
||||||
// Set the size of the name string
|
|
||||||
#define PNAME_SIZE 80
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// A partition type
|
// A partition type
|
||||||
@@ -22,7 +19,7 @@ struct AType {
|
|||||||
// codes required by GPT
|
// codes required by GPT
|
||||||
uint16_t MBRType;
|
uint16_t MBRType;
|
||||||
struct GUIDData GUIDType;
|
struct GUIDData GUIDType;
|
||||||
char name[PNAME_SIZE];
|
string name;
|
||||||
int display; // 1 to show to users as available type, 0 not to
|
int display; // 1 to show to users as available type, 0 not to
|
||||||
AType* next;
|
AType* next;
|
||||||
}; // struct AType
|
}; // struct AType
|
||||||
@@ -36,7 +33,7 @@ public:
|
|||||||
PartTypes(void);
|
PartTypes(void);
|
||||||
~PartTypes(void);
|
~PartTypes(void);
|
||||||
int AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
int AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
||||||
const char* name, int toDisplay = 1);
|
const char * name, int toDisplay = 1);
|
||||||
void ShowTypes(void);
|
void ShowTypes(void);
|
||||||
int Valid(uint16_t);
|
int Valid(uint16_t);
|
||||||
string GUIDToName(struct GUIDData typeCode);
|
string GUIDToName(struct GUIDData typeCode);
|
||||||
|
|||||||
16
sgdisk.cc
16
sgdisk.cc
@@ -28,14 +28,14 @@ string GetString(char* Info, int itemNum);
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
GPTData theGPT;
|
GPTData theGPT;
|
||||||
int opt, i, numOptions = 0, saveData = 0, neverSaveData = 0;
|
int opt, numOptions = 0, saveData = 0, neverSaveData = 0;
|
||||||
int partNum = 0, deletePartNum = 0, infoPartNum = 0, bsdPartNum = 0, saveNonGPT = 1;
|
int partNum = 0, deletePartNum = 0, infoPartNum = 0, bsdPartNum = 0, saveNonGPT = 1;
|
||||||
int alignment = 8, retval = 0, pretend = 0;
|
int alignment = 8, retval = 0, pretend = 0;
|
||||||
uint16_t hexCode;
|
unsigned int hexCode;
|
||||||
uint32_t tableSize = 128;
|
uint32_t tableSize = 128;
|
||||||
uint64_t startSector, endSector;
|
uint64_t startSector, endSector;
|
||||||
char* device = NULL;
|
char *device = NULL;
|
||||||
char *argument = NULL, *newPartInfo = NULL, *typeCode = NULL, *partName;
|
char *newPartInfo = NULL, *typeCode = NULL, *partName;
|
||||||
char *backupFile = NULL;
|
char *backupFile = NULL;
|
||||||
PartTypes typeHelper;
|
PartTypes typeHelper;
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case 't':
|
case 't':
|
||||||
theGPT.JustLooking(0);
|
theGPT.JustLooking(0);
|
||||||
partNum = (int) GetInt(typeCode, 1) - 1;
|
partNum = (int) GetInt(typeCode, 1) - 1;
|
||||||
sscanf(GetString(typeCode, 2).c_str(), "%x", &hexCode);
|
sscanf(GetString(typeCode, 2).c_str(), "%ux", &hexCode);
|
||||||
if (theGPT.ChangePartType(partNum, hexCode)) {
|
if (theGPT.ChangePartType(partNum, hexCode)) {
|
||||||
saveData = 1;
|
saveData = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -255,7 +255,7 @@ int main(int argc, char *argv[]) {
|
|||||||
// Extract integer data from argument string, which should be colon-delimited
|
// Extract integer data from argument string, which should be colon-delimited
|
||||||
uint64_t GetInt(char* argument, int itemNum) {
|
uint64_t GetInt(char* argument, int itemNum) {
|
||||||
int startPos = -1, endPos = -1;
|
int startPos = -1, endPos = -1;
|
||||||
uint64_t retval = 0;
|
unsigned long long retval = 0;
|
||||||
string Info;
|
string Info;
|
||||||
|
|
||||||
Info = argument;
|
Info = argument;
|
||||||
@@ -263,7 +263,7 @@ uint64_t GetInt(char* argument, int itemNum) {
|
|||||||
startPos = endPos + 1;
|
startPos = endPos + 1;
|
||||||
endPos = Info.find(':', startPos);
|
endPos = Info.find(':', startPos);
|
||||||
}
|
}
|
||||||
if (endPos == string::npos)
|
if (endPos == (int) string::npos)
|
||||||
endPos = Info.length();
|
endPos = Info.length();
|
||||||
endPos--;
|
endPos--;
|
||||||
|
|
||||||
@@ -281,7 +281,7 @@ string GetString(char* argument, int itemNum) {
|
|||||||
startPos = endPos + 1;
|
startPos = endPos + 1;
|
||||||
endPos = Info.find(':', startPos);
|
endPos = Info.find(':', startPos);
|
||||||
}
|
}
|
||||||
if (endPos == string::npos)
|
if (endPos == (int) string::npos)
|
||||||
endPos = Info.length();
|
endPos = Info.length();
|
||||||
endPos--;
|
endPos--;
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ string BytesToSI(uint64_t size) {
|
|||||||
// Convert a GUID to a string representation, suitable for display
|
// Convert a GUID to a string representation, suitable for display
|
||||||
// to humans....
|
// to humans....
|
||||||
string GUIDToStr(struct GUIDData theGUID) {
|
string GUIDToStr(struct GUIDData theGUID) {
|
||||||
unsigned long long blocks[11], block;
|
unsigned long long blocks[11];
|
||||||
char theString[40];
|
char theString[40];
|
||||||
|
|
||||||
theString[0] = '\0';;
|
theString[0] = '\0';;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ struct GUIDData {
|
|||||||
uint64_t data2;
|
uint64_t data2;
|
||||||
}; // struct GUIDData
|
}; // struct GUIDData
|
||||||
|
|
||||||
static char theFile[255];
|
// static char theFile[255];
|
||||||
|
|
||||||
int GetNumber(int low, int high, int def, const string & prompt);
|
int GetNumber(int low, int high, int def, const string & prompt);
|
||||||
char GetYN(void);
|
char GetYN(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user