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
|
||||
CXX=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_SRCS=$(NAMES:=.cc)
|
||||
LIB_OBJS=$(LIB_NAMES:=.o)
|
||||
LIB_HEADERS=$(LIB_NAMES:=.h)
|
||||
DEPEND= makedepend $(CFLAGS)
|
||||
|
||||
#$(APPNAME): $(MBR2GPT_OBJS)
|
||||
# $(CC) $(MBR2GPT_OBJS) -o $@
|
||||
|
||||
all: gdisk sgdisk
|
||||
|
||||
gdisk: $(LIB_OBJS) gdisk.o
|
||||
|
||||
@@ -2,16 +2,13 @@ CC=/usr/bin/i586-mingw32msvc-gcc
|
||||
CXX=/usr/bin/i586-mingw32msvc-g++
|
||||
STRIP=/usr/bin/i586-mingw32msvc-strip
|
||||
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_SRCS=$(NAMES:=.cc)
|
||||
LIB_OBJS=$(LIB_NAMES:=.o)
|
||||
LIB_HEADERS=$(LIB_NAMES:=.h)
|
||||
DEPEND= makedepend $(CFLAGS)
|
||||
|
||||
#$(APPNAME): $(MBR2GPT_OBJS)
|
||||
# $(CC) $(MBR2GPT_OBJS) -o $@
|
||||
|
||||
all: gdisk
|
||||
|
||||
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.
|
||||
int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSector) {
|
||||
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
|
||||
uint32_t realSig;
|
||||
uint32_t* temp32;
|
||||
@@ -73,7 +73,6 @@ int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSect
|
||||
BSDRecord* tempRecords;
|
||||
int offset[NUM_OFFSETS] = { LABEL_OFFSET1, LABEL_OFFSET2 };
|
||||
|
||||
// myDisk = theDisk;
|
||||
labelFirstLBA = startSector;
|
||||
labelLastLBA = endSector;
|
||||
offset[1] = theDisk->GetBlockSize();
|
||||
@@ -263,7 +262,6 @@ int BSDData::GetNumParts(void) {
|
||||
GPTPart BSDData::AsGPT(int i) {
|
||||
GPTPart guid; // dump data in here, then return it
|
||||
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
|
||||
|
||||
guid.BlankPartition();
|
||||
|
||||
@@ -208,7 +208,7 @@ int DiskIO::Seek(uint64_t sector) {
|
||||
// size with the number of bytes read.
|
||||
// Returns the number of bytes read into buffer.
|
||||
int DiskIO::Read(void* buffer, int numBytes) {
|
||||
int blockSize = 512, i, numBlocks, retval = 0;
|
||||
int blockSize = 512, numBlocks, retval = 0;
|
||||
char* tempSpace;
|
||||
|
||||
// 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.
|
||||
void DiskIO::MakeRealName(void) {
|
||||
int colonPos;
|
||||
size_t colonPos;
|
||||
|
||||
colonPos = userFilename.find(':', 0);
|
||||
if ((colonPos != string::npos) && (colonPos <= 3)) {
|
||||
@@ -183,8 +183,6 @@ void DiskIO::DiskSync(void) {
|
||||
int DiskIO::Seek(uint64_t sector) {
|
||||
int retval = 1;
|
||||
LARGE_INTEGER seekTo;
|
||||
uint32_t lowBits, highBits;
|
||||
uint64_t bytePos;
|
||||
|
||||
// If disk isn't open, try to open it....
|
||||
if (!isOpen) {
|
||||
|
||||
@@ -152,7 +152,6 @@ int DiskIO::FindAlignment(void) {
|
||||
|
||||
// The same as FindAlignment(int), but opens and closes a device by filename
|
||||
int DiskIO::FindAlignment(const string & filename) {
|
||||
int fd;
|
||||
int retval = 1;
|
||||
|
||||
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
|
||||
// problems identified.
|
||||
int GPTData::Verify(void) {
|
||||
int problems = 0, numSegments, i;
|
||||
uint64_t totalFree, largestSegment, firstSector;
|
||||
char tempStr[255], siTotal[255], siLargest[255];
|
||||
int problems = 0;
|
||||
uint32_t i, numSegments;
|
||||
uint64_t totalFree, largestSegment;
|
||||
char siTotal[255], siLargest[255];
|
||||
|
||||
// First, check for CRC errors in the GPT data....
|
||||
if (!mainCrcOk) {
|
||||
@@ -458,7 +459,8 @@ void GPTData::RebuildSecondHeader(void) {
|
||||
// Search for hybrid MBR entries that have no corresponding GPT partition.
|
||||
// Returns number of such mismatches found
|
||||
int GPTData::FindHybridMismatches(void) {
|
||||
int i, j, found, numFound = 0;
|
||||
int i, found, numFound = 0;
|
||||
uint32_t j;
|
||||
uint64_t mbrFirst, mbrLast;
|
||||
|
||||
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
|
||||
// overlapping partitions.
|
||||
int GPTData::FindOverlaps(void) {
|
||||
int i, j, problems = 0;
|
||||
int problems = 0;
|
||||
uint32_t i, j;
|
||||
|
||||
for (i = 1; i < mainHeader.numParts; i++) {
|
||||
for (j = 0; j < i; j++) {
|
||||
@@ -551,8 +554,8 @@ void GPTData::PartitionScan(void) {
|
||||
|
||||
// Read GPT data from a disk.
|
||||
int GPTData::LoadPartitions(const string & deviceFilename) {
|
||||
int err;
|
||||
int allOK = 1, i;
|
||||
int err, allOK = 1;
|
||||
uint32_t i;
|
||||
uint64_t firstBlock, lastBlock;
|
||||
BSDData bsdDisklabel;
|
||||
MBRValidity mbrState;
|
||||
@@ -568,11 +571,9 @@ int GPTData::LoadPartitions(const string & deviceFilename) {
|
||||
<< "program.\n";
|
||||
#endif
|
||||
cout << "\n";
|
||||
// justLooking = 1;
|
||||
} // if
|
||||
myDisk.Close();
|
||||
|
||||
// if ((fd = open(deviceFilename, O_RDONLY)) != -1) {
|
||||
if (myDisk.OpenForRead(deviceFilename)) {
|
||||
// store disk information....
|
||||
diskSize = myDisk.DiskSize(&err);
|
||||
@@ -737,7 +738,7 @@ int GPTData::ForceLoadGPTData(void) {
|
||||
if ((myDisk.Seek(seekTo)) && (secondCrcOk)) {
|
||||
sizeOfParts = secondHeader.numParts * secondHeader.sizeOfPartitionEntries;
|
||||
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";
|
||||
} // if
|
||||
newCRC = chksum_crc32((unsigned char*) storage, sizeOfParts);
|
||||
@@ -770,7 +771,7 @@ int GPTData::ForceLoadGPTData(void) {
|
||||
// sensible!
|
||||
// Returns 1 on success, 0 on failure. CRC errors do NOT count as failure.
|
||||
int GPTData::LoadMainTable(void) {
|
||||
int fd, retval = 1;
|
||||
int retval = 1;
|
||||
uint32_t newCRC, sizeOfParts;
|
||||
|
||||
if (myDisk.OpenForRead(device)) {
|
||||
@@ -782,7 +783,7 @@ int GPTData::LoadMainTable(void) {
|
||||
if (!myDisk.Seek(mainHeader.partitionEntriesLBA))
|
||||
retval = 0;
|
||||
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";
|
||||
retval = 0;
|
||||
} // if
|
||||
@@ -809,7 +810,7 @@ int GPTData::LoadSecondTableAsMain(void) {
|
||||
if (retval == 1) {
|
||||
SetGPTSize(secondHeader.numParts);
|
||||
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";
|
||||
retval = 0;
|
||||
} // if
|
||||
@@ -836,7 +837,7 @@ int GPTData::LoadSecondTableAsMain(void) {
|
||||
// write, 0 if there was a problem.
|
||||
int GPTData::SaveGPTData(int quiet) {
|
||||
int allOK = 1;
|
||||
char answer, line[256];
|
||||
char answer;
|
||||
uint64_t secondTable;
|
||||
uint32_t numParts;
|
||||
uint64_t offset;
|
||||
@@ -1128,7 +1129,7 @@ int GPTData::LoadGPTBackup(const string & filename) {
|
||||
// Load main partition table, and record whether its CRC
|
||||
// matches the stored value
|
||||
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";
|
||||
} // if
|
||||
|
||||
@@ -1184,8 +1185,7 @@ void GPTData::ShowGPTState(void) {
|
||||
|
||||
// Display the basic GPT data
|
||||
void GPTData::DisplayGPTData(void) {
|
||||
int i;
|
||||
// char tempStr[255];
|
||||
uint32_t i;
|
||||
uint64_t temp, totalFree;
|
||||
|
||||
cout << "Disk " << device << ": " << diskSize << " sectors, "
|
||||
@@ -1274,8 +1274,9 @@ void GPTData::ResizePartitionTable(void) {
|
||||
// Interactively create a partition
|
||||
void GPTData::CreatePartition(void) {
|
||||
uint64_t firstBlock, firstInLargest, lastBlock, sector;
|
||||
uint32_t firstFreePart = 0;
|
||||
char prompt[255];
|
||||
int partNum, firstFreePart = 0;
|
||||
int partNum;
|
||||
|
||||
// Find first free partition...
|
||||
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
|
||||
// MBR.
|
||||
int GPTData::DestroyGPT(int prompt) {
|
||||
int fd, i, sum, tableSize;
|
||||
int i, sum, tableSize;
|
||||
uint8_t blankSector[512], goOn = 'Y', blank = 'N';
|
||||
uint8_t* emptyTable;
|
||||
|
||||
@@ -1590,7 +1591,7 @@ int GPTData::XFormDisklabel(int i) {
|
||||
BSDData disklabel;
|
||||
|
||||
if (GetPartRange(&low, &high) != 0) {
|
||||
if ((i < low) || (i > high))
|
||||
if ((i < (int) low) || (i > (int) high))
|
||||
partNum = GetPartNum();
|
||||
else
|
||||
partNum = (uint32_t) i;
|
||||
@@ -1608,7 +1609,7 @@ int GPTData::XFormDisklabel(int i) {
|
||||
|
||||
// If all is OK, read the disklabel and convert it.
|
||||
if (goOn) {
|
||||
goOn = disklabel.ReadBSDData(device, partitions[partNum].GetFirstLBA(),
|
||||
goOn = disklabel.ReadBSDData(&myDisk, partitions[partNum].GetFirstLBA(),
|
||||
partitions[partNum].GetLastLBA());
|
||||
if ((goOn) && (disklabel.IsDisklabel())) {
|
||||
numDone = XFormDisklabel(&disklabel, startPart);
|
||||
@@ -1630,7 +1631,7 @@ int GPTData::XFormDisklabel(int i) {
|
||||
} // GPTData::XFormDisklable(int i)
|
||||
|
||||
// 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;
|
||||
|
||||
if ((disklabel->IsDisklabel()) && (startPart >= 0) &&
|
||||
@@ -1710,8 +1711,8 @@ int GPTData::OnePartToMBR(uint32_t gptPart, int mbrPart) {
|
||||
int GPTData::XFormToMBR(void) {
|
||||
char line[255];
|
||||
char* junk;
|
||||
int i, j, numParts, numConverted = 0;
|
||||
uint32_t partNums[4];
|
||||
int j, numParts, numConverted = 0;
|
||||
uint32_t i, partNums[4];
|
||||
|
||||
// Get the numbers of up to four partitions to add to the
|
||||
// hybrid MBR....
|
||||
@@ -1737,7 +1738,7 @@ int GPTData::XFormToMBR(void) {
|
||||
} // while
|
||||
} // if/else
|
||||
|
||||
for (i = 0; i < numParts; i++) {
|
||||
for (i = 0; i < (uint32_t) numParts; i++) {
|
||||
j = partNums[i] - 1;
|
||||
cout << "\nCreating entry for partition #" << j + 1 << "\n";
|
||||
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
|
||||
// the user for data. This one returns 1 if the operation was successful, 0
|
||||
// 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
|
||||
|
||||
if (IsFreePartNum(partNum)) {
|
||||
@@ -2195,7 +2196,7 @@ int GPTData::GetPartRange(uint32_t *low, uint32_t *high) {
|
||||
|
||||
// Returns the number of defined partitions.
|
||||
uint32_t GPTData::CountParts(void) {
|
||||
int i, counted = 0;
|
||||
uint32_t i, counted = 0;
|
||||
|
||||
for (i = 0; i < mainHeader.numParts; i++) {
|
||||
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
|
||||
// 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 totalFound = UINT64_C(0); // running total
|
||||
uint64_t firstBlock; // first block in a segment
|
||||
uint64_t lastBlock; // last block in a segment
|
||||
uint64_t segmentSize; // size of segment in blocks
|
||||
int num = 0;
|
||||
uint32_t num = 0;
|
||||
|
||||
*largestSegment = UINT64_C(0);
|
||||
do {
|
||||
|
||||
8
gpt.h
8
gpt.h
@@ -16,7 +16,7 @@
|
||||
#ifndef __GPTSTRUCTS
|
||||
#define __GPTSTRUCTS
|
||||
|
||||
#define GPTFDISK_VERSION "0.6.2-pre2"
|
||||
#define GPTFDISK_VERSION "0.6.2"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
WhichToUse UseWhichPartitions(void);
|
||||
int XFormPartitions(void);
|
||||
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 XFormToMBR(void); // convert GPT to MBR, wiping GPT afterwards. Returns 1 if successful
|
||||
void MakeHybrid(void);
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
int SetGPTSize(uint32_t numEntries);
|
||||
void BlankPartitions(void);
|
||||
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);
|
||||
int ClearGPTData(void);
|
||||
void MoveSecondHeaderToEnd();
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
uint64_t FindFirstInLargest(void);
|
||||
uint64_t FindLastAvailable(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 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
|
||||
// type.
|
||||
void GPTPart::SetType(struct GUIDData t) {
|
||||
int nameSame = 1, currentLength, i;
|
||||
|
||||
if (GetName() == typeHelper.GUIDToName(partitionType)) {
|
||||
SetName(typeHelper.GUIDToName(t));
|
||||
} // if
|
||||
@@ -157,7 +155,7 @@ void GPTPart::ShowSummary(int partNum, uint32_t blockSize) {
|
||||
cout.width(14);
|
||||
cout << lastLBA << " ";
|
||||
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.width(4);
|
||||
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
|
||||
// data isn't a valid MBR), 0 if the read failed.
|
||||
int MBRData::ReadMBRData(const string & deviceFilename) {
|
||||
int fd, allOK = 1;
|
||||
int allOK = 1;
|
||||
|
||||
if (myDisk == NULL)
|
||||
myDisk = new DiskIO;
|
||||
@@ -348,7 +348,6 @@ int MBRData::WriteMBRData(const string & deviceFilename) {
|
||||
// Show the MBR data to the user....
|
||||
void MBRData::DisplayMBRData(void) {
|
||||
int i;
|
||||
char tempStr[255];
|
||||
char bootCode;
|
||||
|
||||
cout << "MBR disk identifier: 0x";
|
||||
@@ -378,7 +377,7 @@ void MBRData::DisplayMBRData(void) {
|
||||
cout.fill(' ');
|
||||
} // for
|
||||
cout << "\nDisk size is " << diskSize << " sectors ("
|
||||
<< BytesToSI(diskSize * (uint64_t) blockSize) << "\n";
|
||||
<< BytesToSI(diskSize * (uint64_t) blockSize) << ")\n";
|
||||
} // MBRData::DisplayMBRData()
|
||||
|
||||
// Displays the state, as a word, on stdout. Used for debugging & to
|
||||
@@ -814,7 +813,6 @@ GPTPart MBRData::AsGPT(int i) {
|
||||
GPTPart newPart;
|
||||
uint8_t origType;
|
||||
uint64_t firstSector, lastSector;
|
||||
char tempStr[NAME_SIZE];
|
||||
|
||||
newPart.BlankPartition();
|
||||
origPart = GetPartition(i);
|
||||
|
||||
16
parttypes.cc
16
parttypes.cc
@@ -204,9 +204,9 @@ PartTypes::~PartTypes(void) {
|
||||
} // destructor
|
||||
|
||||
// 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,
|
||||
const char* n, int toDisplay) {
|
||||
const char * n, int toDisplay) {
|
||||
AType* tempType;
|
||||
int allOK = 1;
|
||||
|
||||
@@ -215,7 +215,7 @@ int PartTypes::AddType(uint16_t mbrType, uint64_t guidData1, uint64_t guidData2,
|
||||
tempType->MBRType = mbrType;
|
||||
tempType->GUIDType.data1 = guidData1;
|
||||
tempType->GUIDType.data2 = guidData2;
|
||||
strncpy(tempType->name, n, PNAME_SIZE);
|
||||
tempType->name = n;
|
||||
tempType->display = toDisplay;
|
||||
tempType->next = NULL;
|
||||
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.
|
||||
void PartTypes::ShowTypes(void) {
|
||||
int colCount = 1; // column count
|
||||
int i;
|
||||
size_t i;
|
||||
AType* thisType = allTypes;
|
||||
|
||||
cout.unsetf(ios::uppercase);
|
||||
@@ -245,10 +245,12 @@ void PartTypes::ShowTypes(void) {
|
||||
cout.fill('0');
|
||||
cout.width(4);
|
||||
cout << hex << thisType->MBRType << " ";
|
||||
cout << ((string) thisType->name).substr(0, 19) << " ";
|
||||
for (i = 0; i < (19 - ((string) thisType->name).substr(0, 19).length()); i ++) cout << " ";
|
||||
cout << thisType->name.substr(0, 20);
|
||||
for (i = 0; i < (20 - (thisType->name.substr(0, 20).length())); i++) cout << " ";
|
||||
if ((colCount % 3) == 0)
|
||||
cout << "\n";
|
||||
else
|
||||
cout << " ";
|
||||
colCount++;
|
||||
} // if
|
||||
thisType = thisType->next;
|
||||
@@ -280,7 +282,6 @@ string PartTypes::GUIDToName(struct GUIDData typeCode) {
|
||||
while ((theItem != NULL) && (!found)) {
|
||||
if ((theItem->GUIDType.data1 == typeCode.data1) &&
|
||||
(theItem->GUIDType.data2 == typeCode.data2)) { // found it!
|
||||
// strcpy(typeName, theItem->name);
|
||||
typeName = theItem->name;
|
||||
found = 1;
|
||||
} else {
|
||||
@@ -289,7 +290,6 @@ string PartTypes::GUIDToName(struct GUIDData typeCode) {
|
||||
} // while
|
||||
if (!found) {
|
||||
typeName = "Unknown";
|
||||
// strcpy(typeName, (char*) "Unknown");
|
||||
} // if (!found)
|
||||
return typeName;
|
||||
} // PartTypes::GUIDToName()
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
#ifndef __PARTITION_TYPES
|
||||
#define __PARTITION_TYPES
|
||||
|
||||
// Set the size of the name string
|
||||
#define PNAME_SIZE 80
|
||||
|
||||
using namespace std;
|
||||
|
||||
// A partition type
|
||||
@@ -22,7 +19,7 @@ struct AType {
|
||||
// codes required by GPT
|
||||
uint16_t MBRType;
|
||||
struct GUIDData GUIDType;
|
||||
char name[PNAME_SIZE];
|
||||
string name;
|
||||
int display; // 1 to show to users as available type, 0 not to
|
||||
AType* next;
|
||||
}; // struct AType
|
||||
@@ -36,7 +33,7 @@ public:
|
||||
PartTypes(void);
|
||||
~PartTypes(void);
|
||||
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);
|
||||
int Valid(uint16_t);
|
||||
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[]) {
|
||||
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 alignment = 8, retval = 0, pretend = 0;
|
||||
uint16_t hexCode;
|
||||
unsigned int hexCode;
|
||||
uint32_t tableSize = 128;
|
||||
uint64_t startSector, endSector;
|
||||
char* device = NULL;
|
||||
char *argument = NULL, *newPartInfo = NULL, *typeCode = NULL, *partName;
|
||||
char *device = NULL;
|
||||
char *newPartInfo = NULL, *typeCode = NULL, *partName;
|
||||
char *backupFile = NULL;
|
||||
PartTypes typeHelper;
|
||||
|
||||
@@ -205,7 +205,7 @@ int main(int argc, char *argv[]) {
|
||||
case 't':
|
||||
theGPT.JustLooking(0);
|
||||
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)) {
|
||||
saveData = 1;
|
||||
} else {
|
||||
@@ -255,7 +255,7 @@ int main(int argc, char *argv[]) {
|
||||
// Extract integer data from argument string, which should be colon-delimited
|
||||
uint64_t GetInt(char* argument, int itemNum) {
|
||||
int startPos = -1, endPos = -1;
|
||||
uint64_t retval = 0;
|
||||
unsigned long long retval = 0;
|
||||
string Info;
|
||||
|
||||
Info = argument;
|
||||
@@ -263,7 +263,7 @@ uint64_t GetInt(char* argument, int itemNum) {
|
||||
startPos = endPos + 1;
|
||||
endPos = Info.find(':', startPos);
|
||||
}
|
||||
if (endPos == string::npos)
|
||||
if (endPos == (int) string::npos)
|
||||
endPos = Info.length();
|
||||
endPos--;
|
||||
|
||||
@@ -281,7 +281,7 @@ string GetString(char* argument, int itemNum) {
|
||||
startPos = endPos + 1;
|
||||
endPos = Info.find(':', startPos);
|
||||
}
|
||||
if (endPos == string::npos)
|
||||
if (endPos == (int) string::npos)
|
||||
endPos = Info.length();
|
||||
endPos--;
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ string BytesToSI(uint64_t size) {
|
||||
// Convert a GUID to a string representation, suitable for display
|
||||
// to humans....
|
||||
string GUIDToStr(struct GUIDData theGUID) {
|
||||
unsigned long long blocks[11], block;
|
||||
unsigned long long blocks[11];
|
||||
char theString[40];
|
||||
|
||||
theString[0] = '\0';;
|
||||
|
||||
Reference in New Issue
Block a user