summaryrefslogtreecommitdiff
path: root/gptcl.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 /gptcl.cc
parent43b3df969cbbf3da0c043afdc9939da97bbd8d68 (diff)
downloadsgdisk-fd60f743628e16180daf3b1719974fa4dadf8f90.tar.gz
Add end-alignment feature.
Diffstat (limited to 'gptcl.cc')
-rw-r--r--gptcl.cc15
1 files changed, 10 insertions, 5 deletions
diff --git a/gptcl.cc b/gptcl.cc
index 2e75db7..3995093 100644
--- a/gptcl.cc
+++ b/gptcl.cc
@@ -1,7 +1,7 @@
/*
Implementation of GPTData class derivative with popt-based command
line processing
- Copyright (C) 2010-2014 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
@@ -30,6 +30,7 @@ GPTDataCL::GPTDataCL(void) {
attributeOperation = backupFile = partName = hybrids = newPartInfo = NULL;
mbrParts = twoParts = outDevice = typeCode = partGUID = diskGUID = NULL;
alignment = DEFAULT_ALIGNMENT;
+ alignEnd = false;
deletePartNum = infoPartNum = largestPartNum = bsdPartNum = 0;
tableSize = GPT_SIZE;
} // GPTDataCL constructor
@@ -90,6 +91,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
{"randomize-guids", 'G', POPT_ARG_NONE, NULL, 'G', "randomize disk and partition GUIDs", ""},
{"hybrid", 'h', POPT_ARG_STRING, &hybrids, 'h', "create hybrid MBR", "partnum[:partnum...][:EE]"},
{"info", 'i', POPT_ARG_INT, &infoPartNum, 'i', "show detailed information on partition", "partnum"},
+ {"align-end", 'I', POPT_ARG_NONE, NULL, 'I', "align partition end points", ""},
{"move-main-table", 'j', POPT_ARG_INT, &mainTableLBA, 'j', "adjust the location of the main partition table", "sector"},
{"load-backup", 'l', POPT_ARG_STRING, &backupFile, 'l', "load GPT backup from file", "file"},
{"list-types", 'L', POPT_ARG_NONE, NULL, 'L', "list known partition types", ""},
@@ -272,6 +274,9 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
case 'i':
ShowPartDetails(infoPartNum - 1);
break;
+ case 'I':
+ alignEnd = true;
+ break;
case 'j':
if (MoveMainTable(mainTableLBA)) {
JustLooking(0);
@@ -307,9 +312,9 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
newPartNum = FindFirstFreePart();
low = FindFirstInLargest();
Align(&low);
- high = FindLastInFree(low);
- startSector = IeeeToInt(GetString(newPartInfo, 2), sSize, low, high, low);
- endSector = IeeeToInt(GetString(newPartInfo, 3), sSize, startSector, high, high);
+ high = FindLastInFree(low, alignEnd);
+ startSector = IeeeToInt(GetString(newPartInfo, 2), sSize, low, high, sectorAlignment, low);
+ endSector = IeeeToInt(GetString(newPartInfo, 3), sSize, startSector, high, sectorAlignment, high);
if (CreatePartition(newPartNum, startSector, endSector)) {
saveData = 1;
} else {
@@ -323,7 +328,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
JustLooking(0);
startSector = FindFirstInLargest();
Align(&startSector);
- endSector = FindLastInFree(startSector);
+ endSector = FindLastInFree(startSector, alignEnd);
if (largestPartNum <= 0)
largestPartNum = FindFirstFreePart() + 1;
if (CreatePartition(largestPartNum - 1, startSector, endSector)) {