aboutsummaryrefslogtreecommitdiff
path: root/gptcurses.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gptcurses.cc')
-rw-r--r--gptcurses.cc63
1 files changed, 38 insertions, 25 deletions
diff --git a/gptcurses.cc b/gptcurses.cc
index 4ebfde1..64cc514 100644
--- a/gptcurses.cc
+++ b/gptcurses.cc
@@ -1,7 +1,7 @@
/*
* Implementation of GPTData class derivative with curses-based text-mode
* interaction
- * Copyright (C) 2011-2018 Roderick W. Smith
+ * Copyright (C) 2011-2022 Roderick W. Smith
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,11 @@
#include <iostream>
#include <string>
#include <sstream>
+#if defined (__APPLE__) || (__FreeBSD__)
#include <ncurses.h>
+#else
+#include <ncursesw/ncurses.h>
+#endif
#include "gptcurses.h"
#include "support.h"
@@ -86,7 +90,7 @@ void GPTDataCurses::EmptySpaces(void) {
// unpartitioned space on the disk.
// Returns the number of Spaces created.
int GPTDataCurses::MakeSpacesFromParts(void) {
- uint i;
+ uint32_t i;
Space *tempSpace;
EmptySpaces();
@@ -235,22 +239,22 @@ Space* GPTDataCurses::ShowSpace(int spaceNum, int lineNum) {
ClearLine(lineNum);
if (space->partNum == -1) { // space is empty
move(lineNum, 12);
- printw(BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str());
+ printw("%s", BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str());
move(lineNum, 24);
printw("free space");
} else { // space holds a partition
move(lineNum, 3);
printw("%d", space->partNum + 1);
move(lineNum, 12);
- printw(BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str());
+ printw("%s", BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str());
move(lineNum, 24);
- printw(space->origPart->GetTypeName().c_str());
+ printw("%s", space->origPart->GetTypeName().c_str());
move(lineNum, 50);
#ifdef USE_UTF16
space->origPart->GetDescription().extract(0, 39, temp, 39);
printw(temp);
#else
- printw(space->origPart->GetDescription().c_str());
+ printw("%s", space->origPart->GetDescription().c_str());
#endif
} // if/else
} // if
@@ -267,10 +271,10 @@ int GPTDataCurses::DisplayParts(int selected) {
move(lineNum++, 0);
theLine = "Part. # Size Partition Type Partition Name";
- printw(theLine.c_str());
+ printw("%s", theLine.c_str());
move(lineNum++, 0);
theLine = "----------------------------------------------------------------";
- printw(theLine.c_str());
+ printw("%s", theLine.c_str());
numToShow = LINES - RESERVED_TOP - RESERVED_BOTTOM;
pageNum = selected / numToShow;
for (i = pageNum * numToShow; i <= (pageNum + 1) * numToShow - 1; i++) {
@@ -329,13 +333,13 @@ void GPTDataCurses::ShowInfo(int partNum) {
printw("Partition GUID code: %s (%s)\n", partitions[partNum].GetType().AsString().c_str(),
partitions[partNum].GetTypeName().c_str());
printw("Partition unique GUID: %s\n", partitions[partNum].GetUniqueGUID().AsString().c_str());
- printw("First sector: %lld (at %s)\n", partitions[partNum].GetFirstLBA(),
+ printw("First sector: %llu (at %s)\n", (long long unsigned int) partitions[partNum].GetFirstLBA(),
BytesToIeee(partitions[partNum].GetFirstLBA(), blockSize).c_str());
- printw("Last sector: %lld (at %s)\n", partitions[partNum].GetLastLBA(),
+ printw("Last sector: %llu (at %s)\n", (long long unsigned int) partitions[partNum].GetLastLBA(),
BytesToIeee(partitions[partNum].GetLastLBA(), blockSize).c_str());
size = partitions[partNum].GetLastLBA() - partitions[partNum].GetFirstLBA() + 1;
- printw("Partition size: %lld sectors (%s)\n", size, BytesToIeee(size, blockSize).c_str());
- printw("Attribute flags: %016x\n", partitions[partNum].GetAttributes().GetAttributes());
+ printw("Partition size: %llu sectors (%s)\n", (long long unsigned int) size, BytesToIeee(size, blockSize).c_str());
+ printw("Attribute flags: %016llx\n", (long long unsigned int) partitions[partNum].GetAttributes().GetAttributes());
#ifdef USE_UTF16
partitions[partNum].GetDescription().extract(0, NAME_SIZE , temp, NAME_SIZE );
printw("Partition name: '%s'\n", temp);
@@ -426,34 +430,43 @@ void GPTDataCurses::Verify(void) {
// Create a new partition in the space pointed to by currentSpace.
void GPTDataCurses::MakeNewPart(void) {
- uint64_t size, newFirstLBA = 0, newLastLBA = 0;
+ uint64_t size, newFirstLBA = 0, newLastLBA = 0, lastAligned;
int partNum;
char inLine[80];
move(LINES - 4, 0);
clrtobot();
+ lastAligned = currentSpace->lastLBA + 1;
+ Align(&lastAligned);
+ lastAligned--;
+ // Discard end-alignment attempt if it's giving us an invalid end point....
+ if (!IsFree(lastAligned))
+ lastAligned = currentSpace->lastLBA;
while ((newFirstLBA < currentSpace->firstLBA) || (newFirstLBA > currentSpace->lastLBA)) {
- newFirstLBA = currentSpace->firstLBA;
move(LINES - 4, 0);
clrtoeol();
newFirstLBA = currentSpace->firstLBA;
Align(&newFirstLBA);
- printw("First sector (%lld-%lld, default = %lld): ", newFirstLBA, currentSpace->lastLBA, newFirstLBA);
+ printw("First sector (%llu-%llu, default = %llu): ", (long long unsigned int) newFirstLBA,
+ (long long unsigned int) currentSpace->lastLBA, (long long unsigned int) newFirstLBA);
echo();
getnstr(inLine, 79);
noecho();
- newFirstLBA = IeeeToInt(inLine, blockSize, currentSpace->firstLBA, currentSpace->lastLBA, newFirstLBA);
+ newFirstLBA = IeeeToInt(inLine, blockSize, currentSpace->firstLBA, currentSpace->lastLBA, sectorAlignment, newFirstLBA);
Align(&newFirstLBA);
} // while
- size = currentSpace->lastLBA - newFirstLBA + 1;
+ if (newFirstLBA > lastAligned)
+ size = currentSpace->lastLBA - newFirstLBA + 1;
+ else
+ size = lastAligned - newFirstLBA + 1;
while ((newLastLBA > currentSpace->lastLBA) || (newLastLBA < newFirstLBA)) {
move(LINES - 3, 0);
clrtoeol();
- printw("Size in sectors or {KMGTP} (default = %lld): ", size);
+ printw("Size in sectors or {KMGTP} (default = %llu): ", (long long unsigned int) size);
echo();
getnstr(inLine, 79);
noecho();
- newLastLBA = newFirstLBA + IeeeToInt(inLine, blockSize, 1, size, size) - 1;
+ newLastLBA = newFirstLBA + IeeeToInt(inLine, blockSize, 1, size, sectorAlignment, size) - 1;
} // while
partNum = FindFirstFreePart();
if (CreatePartition(partNum, newFirstLBA, newLastLBA)) { // created OK; set type code & name....
@@ -596,7 +609,7 @@ void GPTDataCurses::MoveSelection(int delta) {
// Show user's options. Refers to currentSpace to determine which options to show.
// Highlights the option with the key selectedKey; or a default if that's invalid.
void GPTDataCurses::DisplayOptions(char selectedKey) {
- uint i, j = 0, firstLine, numPerLine;
+ uint64_t i, j = 0, firstLine, numPerLine;
string optionName, optionDesc = "";
if (currentSpace != NULL) {
@@ -633,7 +646,7 @@ void GPTDataCurses::DisplayOptions(char selectedKey) {
} // if/else
} // for
move(LINES - 1, (COLS - optionDesc.length()) / 2);
- printw(optionDesc.c_str());
+ printw("%s", optionDesc.c_str());
currentKey = selectedKey;
} // if
} // GPTDataCurses::DisplayOptions()
@@ -745,11 +758,11 @@ void GPTDataCurses::DrawMenu(void) {
clear();
move(0, (COLS - title.length()) / 2);
- printw(title.c_str());
+ printw("%s", title.c_str());
move(2, (COLS - drive.length()) / 2);
- printw(drive.c_str());
+ printw("%s", drive.c_str());
move(3, (COLS - size.str().length()) / 2);
- printw(size.str().c_str());
+ printw("%s", size.str().c_str());
DisplayParts(currentSpaceNum);
} // DrawMenu
@@ -799,7 +812,7 @@ void PromptToContinue(void) {
void Report(string theText) {
clear();
move(0, 0);
- printw(theText.c_str());
+ printw("%s", theText.c_str());
move(LINES - 2, (COLS - 29) / 2);
printw("Press any key to continue....");
cbreak();