summaryrefslogtreecommitdiff
path: root/gptcurses.cc
diff options
context:
space:
mode:
authorRod Smith <rodsmith@rodsbooks.com>2022-01-29 10:51:02 -0500
committerRod Smith <rodsmith@rodsbooks.com>2022-01-29 10:51:02 -0500
commitfd60f743628e16180daf3b1719974fa4dadf8f90 (patch)
treedcad6ad1cc1d304a2c4c3d1bd1d4315e4dad62e6 /gptcurses.cc
parent43b3df969cbbf3da0c043afdc9939da97bbd8d68 (diff)
downloadsgdisk-fd60f743628e16180daf3b1719974fa4dadf8f90.tar.gz
Add end-alignment feature.
Diffstat (limited to 'gptcurses.cc')
-rw-r--r--gptcurses.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/gptcurses.cc b/gptcurses.cc
index 1fbaad2..2ffcf4f 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
@@ -430,12 +430,18 @@ 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)) {
move(LINES - 4, 0);
clrtoeol();
@@ -445,10 +451,13 @@ void GPTDataCurses::MakeNewPart(void) {
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();
@@ -456,7 +465,7 @@ void GPTDataCurses::MakeNewPart(void) {
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....