diff options
author | Rod Smith <rodsmith@rodsbooks.com> | 2022-01-29 10:51:02 -0500 |
---|---|---|
committer | Rod Smith <rodsmith@rodsbooks.com> | 2022-01-29 10:51:02 -0500 |
commit | fd60f743628e16180daf3b1719974fa4dadf8f90 (patch) | |
tree | dcad6ad1cc1d304a2c4c3d1bd1d4315e4dad62e6 /gpttext.cc | |
parent | 43b3df969cbbf3da0c043afdc9939da97bbd8d68 (diff) | |
download | sgdisk-fd60f743628e16180daf3b1719974fa4dadf8f90.tar.gz |
Add end-alignment feature.
Diffstat (limited to 'gpttext.cc')
-rw-r--r-- | gpttext.cc | 36 |
1 files changed, 29 insertions, 7 deletions
@@ -1,5 +1,5 @@ /* - Copyright (C) 2010-2018 <Roderick W. Smith> + Copyright (C) 2010-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 @@ -199,7 +199,7 @@ void GPTDataTextUI::MoveMainTable(void) { // Interactively create a partition void GPTDataTextUI::CreatePartition(void) { - uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector; + uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector, lastAligned; uint32_t firstFreePart = 0; ostringstream prompt1, prompt2, prompt3; int partNum; @@ -229,7 +229,7 @@ void GPTDataTextUI::CreatePartition(void) { prompt2 << "First sector (" << firstBlock << "-" << lastBlock << ", default = " << firstInLargest << ") or {+-}size{KMGTP}: "; do { - sector = GetSectorNum(firstBlock, lastBlock, firstInLargest, blockSize, prompt2.str()); + sector = GetSectorNum(firstBlock, lastBlock, firstInLargest, prompt2.str()); } while (IsFree(sector) == 0); origSector = sector; if (Align(§or)) { @@ -239,15 +239,15 @@ void GPTDataTextUI::CreatePartition(void) { if (!beQuiet) cout << "Use 'l' on the experts' menu to adjust alignment\n"; } // if - // Align(§or); // Align sector to correct multiple firstBlock = sector; // Get last block for new partitions... - lastBlock = FindLastInFree(firstBlock); + lastBlock = FindLastInFree(firstBlock, false); + lastAligned = FindLastInFree(firstBlock, true); prompt3 << "Last sector (" << firstBlock << "-" << lastBlock << ", default = " - << lastBlock << ") or {+-}size{KMGTP}: "; + << lastAligned << ") or {+-}size{KMGTP}: "; do { - sector = GetSectorNum(firstBlock, lastBlock, lastBlock, blockSize, prompt3.str()); + sector = GetSectorNum(firstBlock, lastBlock, lastAligned, prompt3.str()); } while (IsFree(sector) == 0); lastBlock = sector; @@ -548,6 +548,28 @@ int GPTDataTextUI::XFormToMBR(void) { return protectiveMBR.DoMenu(); } // GPTDataTextUI::XFormToMBR() +// Obtains a sector number, between low and high, from the +// user, accepting values prefixed by "+" to add sectors to low, +// or the same with "K", "M", "G", "T", or "P" as suffixes to add +// kibibytes, mebibytes, gibibytes, tebibytes, or pebibytes, +// respectively. If a "-" prefix is used, use the high value minus +// the user-specified number of sectors (or KiB, MiB, etc.). Use the +// def value as the default if the user just hits Enter. +uint64_t GPTDataTextUI::GetSectorNum(uint64_t low, uint64_t high, uint64_t def, + const string & prompt) { + uint64_t response; + char line[255]; + + do { + cout << prompt; + cin.getline(line, 255); + if (!cin.good()) + exit(5); + response = IeeeToInt(line, blockSize, low, high, sectorAlignment, def); + } while ((response < low) || (response > high)); + return response; +} // GPTDataTextUI::GetSectorNum() + /****************************************************** * * * Display informational messages for the user.... * |