diff options
author | Roderick W. Smith <allura@localhost> | 2020-02-10 14:29:43 +0000 |
---|---|---|
committer | Roderick W. Smith <allura@localhost> | 2020-02-10 14:29:43 +0000 |
commit | 7ffe16f06275edffd09394d5e8cb55a494f45665 (patch) | |
tree | 65f5cd17f113b4dc561752c2a867a62fb4d0da8c | |
parent | b319a6ebea88b5ed6b63d1a2670100b4278de91e (diff) | |
parent | d4e560771b8a0fc72538d50b4510a31ab1e00a64 (diff) | |
download | sgdisk-7ffe16f06275edffd09394d5e8cb55a494f45665.tar.gz |
Merge /u/geoffwilliams/gptfdisk/ branch hybrid_part_order into master
https://sourceforge.net/p/gptfdisk/code/merge-requests/16/
-rw-r--r-- | gptcl.cc | 20 | ||||
-rw-r--r-- | sgdisk.8 | 14 |
2 files changed, 24 insertions, 10 deletions
@@ -86,7 +86,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { {"first-aligned-in-largest", 'F', POPT_ARG_NONE, NULL, 'F', "show start of the largest free block, aligned", ""}, {"mbrtogpt", 'g', POPT_ARG_NONE, NULL, 'g', "convert MBR to GPT", ""}, {"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...]"}, + {"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"}, {"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"}, @@ -490,33 +490,47 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { // Create a hybrid or regular MBR from GPT data structures int GPTDataCL::BuildMBR(char* argument, int isHybrid) { int numParts, allOK = 1, i, origPartNum; + int eeLast, mbrNum = 0; MBRPart newPart; BasicMBRData newMBR; if (argument != NULL) { numParts = CountColons(argument) + 1; + if (isHybrid) { + eeLast = GetString(argument, numParts) == "EE"; + if (eeLast) { + numParts--; + } + } + if (numParts <= (4 - isHybrid)) { newMBR.SetDisk(GetDisk()); for (i = 0; i < numParts; i++) { origPartNum = GetInt(argument, i + 1) - 1; if (IsUsedPartNum(origPartNum) && (partitions[origPartNum].IsSizedForMBR() == MBR_SIZED_GOOD)) { + mbrNum = i + (isHybrid && ! eeLast); newPart.SetInclusion(PRIMARY); newPart.SetLocation(operator[](origPartNum).GetFirstLBA(), operator[](origPartNum).GetLengthLBA()); newPart.SetStatus(0); newPart.SetType((uint8_t)(operator[](origPartNum).GetHexType() / 0x0100)); - newMBR.AddPart(i + isHybrid, newPart); + newMBR.AddPart(mbrNum, newPart); } else { cerr << "Original partition " << origPartNum + 1 << " does not exist or is too big! Aborting operation!\n"; allOK = 0; } // if/else } // for if (isHybrid) { + if (eeLast) { + mbrNum = i; + } else { + mbrNum = 0; + } newPart.SetInclusion(PRIMARY); newPart.SetLocation(1, newMBR.FindLastInFree(1)); newPart.SetStatus(0); newPart.SetType(0xEE); - newMBR.AddPart(0, newPart); + newMBR.AddPart(mbrNum, newPart); } // if if (allOK) SetProtectiveMBR(newMBR); @@ -264,13 +264,13 @@ in order to render all GUIDs once again unique. .TP .B \-h, \-\-hybrid Create a hybrid MBR. This option takes from one to three partition numbers, -separated by colons, as arguments. The created hybrid MBR places an EFI GPT -(type 0xEE) partition first in the table, followed by the partition(s) you -specify. Their type codes are based on the GPT fdisk type codes divided by -0x0100, which is usually correct for Windows partitions. If the -active/bootable flag should be set, you must do so in another program, such -as \fBfdisk\fR. The \fBgdisk\fR program offers additional hybrid MBR -creation options. +separated by colons, as arguments. You may optionally specify a final partition +"EE" to indicate that the EFI GPT (type 0xEE) should be placed last in the table, +otherwise it will be placed first, followed by the partition(s) you specify. +Their type codes are based on the GPT fdisk type codes divided by 0x0100, which +is usually correct for Windows partitions. If the active/bootable flag should +be set, you must do so in another program, such as \fBfdisk\fR. The \fBgdisk\fR +program offers additional hybrid MBR creation options. .TP .B \-i, \-\-info=partnum |