2 Copyright (C) 2010-2011 <Roderick W. Smith>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /* This class implements an interactive text-mode interface atop the
31 #include "attributes.h"
37 /********************************************
39 * GPTDataText class and related structures *
41 ********************************************/
43 GPTDataTextUI::GPTDataTextUI(void) : GPTData() {
44 } // default constructor
46 GPTDataTextUI::GPTDataTextUI(string filename) : GPTData(filename) {
47 } // constructor passing filename
49 GPTDataTextUI::~GPTDataTextUI(void) {
50 } // default destructor
52 /*********************************************************************
54 * The following functions are extended (interactive) versions of *
55 * simpler functions in the base class.... *
57 *********************************************************************/
59 // Overridden function; calls base-class function and then makes
60 // additional queries of the user, if the base-class function can't
62 WhichToUse GPTDataTextUI::UseWhichPartitions(void) {
67 which = GPTData::UseWhichPartitions();
68 if ((which != use_abort) || beQuiet)
71 // If we get past here, it means that the non-interactive tests were
72 // inconclusive, so we must ask the user which table to use....
73 mbrState = protectiveMBR.GetValidity();
75 if ((state == gpt_valid) && (mbrState == mbr)) {
76 cout << "Found valid MBR and GPT. Which do you want to use?\n";
77 answer = GetNumber(1, 3, 2, " 1 - MBR\n 2 - GPT\n 3 - Create blank GPT\n\nYour answer: ");
80 } else if (answer == 2) {
82 cout << "Using GPT and creating fresh protective MBR.\n";
83 } else which = use_new;
86 // Nasty decisions here -- GPT is present, but corrupt (bad CRCs or other
88 if (state == gpt_corrupt) {
89 if ((mbrState == mbr) || (mbrState == hybrid)) {
90 cout << "Found valid MBR and corrupt GPT. Which do you want to use? (Using the\n"
91 << "GPT MAY permit recovery of GPT data.)\n";
92 answer = GetNumber(1, 3, 2, " 1 - MBR\n 2 - GPT\n 3 - Create blank GPT\n\nYour answer: ");
95 } else if (answer == 2) {
97 } else which = use_new;
98 } else if (mbrState == invalid) {
99 cout << "Found invalid MBR and corrupt GPT. What do you want to do? (Using the\n"
100 << "GPT MAY permit recovery of GPT data.)\n";
101 answer = GetNumber(1, 2, 1, " 1 - Use current GPT\n 2 - Create blank GPT\n\nYour answer: ");
104 } else which = use_new;
106 } // if (corrupt GPT)
109 } // UseWhichPartitions()
111 // Ask the user for a partition number; and prompt for verification
112 // if the requested partition isn't of a known BSD type.
113 // Lets the base-class function do the work, and returns its value (the
114 // number of converted partitions).
115 int GPTDataTextUI::XFormDisklabel(void) {
118 int goOn = 1, numDone = 0;
121 partNum = GetPartNum();
123 // Now see if the specified partition has a BSD type code....
124 hexCode = partitions[partNum].GetHexType();
125 if ((hexCode != 0xa500) && (hexCode != 0xa900)) {
126 cout << "Specified partition doesn't have a disklabel partition type "
127 << "code.\nContinue anyway? ";
128 goOn = (GetYN() == 'Y');
132 numDone = GPTData::XFormDisklabel(partNum);
135 } // GPTData::XFormDisklabel(int i)
138 /*********************************************************************
140 * Begin functions that obtain information from the users, and often *
141 * do something with that information (call other functions) *
143 *********************************************************************/
145 // Prompts user for partition number and returns the result. Returns "0"
146 // (the first partition) if none are currently defined.
147 uint32_t GPTDataTextUI::GetPartNum(void) {
150 ostringstream prompt;
152 if (GetPartRange(&low, &high) > 0) {
153 prompt << "Partition number (" << low + 1 << "-" << high + 1 << "): ";
154 partNum = GetNumber(low + 1, high + 1, low, prompt.str());
156 return (partNum - 1);
157 } // GPTDataTextUI::GetPartNum()
159 // What it says: Resize the partition table. (Default is 128 entries.)
160 void GPTDataTextUI::ResizePartitionTable(void) {
162 ostringstream prompt;
163 uint32_t curLow, curHigh;
165 cout << "Current partition table size is " << numParts << ".\n";
166 GetPartRange(&curLow, &curHigh);
167 curHigh++; // since GetPartRange() returns numbers starting from 0...
168 // There's no point in having fewer than four partitions....
169 if (curHigh < (blockSize / GPT_SIZE))
170 curHigh = blockSize / GPT_SIZE;
171 prompt << "Enter new size (" << curHigh << " up, default " << NUM_GPT_ENTRIES << "): ";
172 newSize = GetNumber(4, 65535, 128, prompt.str());
174 cout << "Caution: The partition table size should officially be 16KB or larger,\n"
175 << "which works out to 128 entries. In practice, smaller tables seem to\n"
176 << "work with most OSes, but this practice is risky. I'm proceeding with\n"
177 << "the resize, but you may want to reconsider this action and undo it.\n\n";
180 } // GPTDataTextUI::ResizePartitionTable()
182 // Interactively create a partition
183 void GPTDataTextUI::CreatePartition(void) {
184 uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector;
185 uint32_t firstFreePart = 0;
186 ostringstream prompt1, prompt2, prompt3;
189 // Find first free partition...
190 while (partitions[firstFreePart].GetFirstLBA() != 0) {
194 if (((firstBlock = FindFirstAvailable()) != 0) &&
195 (firstFreePart < numParts)) {
196 lastBlock = FindLastAvailable();
197 firstInLargest = FindFirstInLargest();
198 Align(&firstInLargest);
200 // Get partition number....
202 prompt1 << "Partition number (" << firstFreePart + 1 << "-" << numParts
203 << ", default " << firstFreePart + 1 << "): ";
204 partNum = GetNumber(firstFreePart + 1, numParts,
205 firstFreePart + 1, prompt1.str()) - 1;
206 if (partitions[partNum].GetFirstLBA() != 0)
207 cout << "partition " << partNum + 1 << " is in use.\n";
208 } while (partitions[partNum].GetFirstLBA() != 0);
210 // Get first block for new partition...
211 prompt2 << "First sector (" << firstBlock << "-" << lastBlock << ", default = "
212 << firstInLargest << ") or {+-}size{KMGTP}: ";
214 sector = GetSectorNum(firstBlock, lastBlock, firstInLargest, blockSize, prompt2.str());
215 } while (IsFree(sector) == 0);
217 if (Align(§or)) {
218 cout << "Information: Moved requested sector from " << origSector << " to "
219 << sector << " in\norder to align on " << sectorAlignment
220 << "-sector boundaries.\n";
222 cout << "Use 'l' on the experts' menu to adjust alignment\n";
224 // Align(§or); // Align sector to correct multiple
227 // Get last block for new partitions...
228 lastBlock = FindLastInFree(firstBlock);
229 prompt3 << "Last sector (" << firstBlock << "-" << lastBlock << ", default = "
230 << lastBlock << ") or {+-}size{KMGTP}: ";
232 sector = GetSectorNum(firstBlock, lastBlock, lastBlock, blockSize, prompt3.str());
233 } while (IsFree(sector) == 0);
236 firstFreePart = GPTData::CreatePartition(partNum, firstBlock, lastBlock);
237 partitions[partNum].ChangeType();
238 partitions[partNum].SetDefaultDescription();
240 if (firstFreePart >= numParts)
241 cout << "No table partition entries left\n";
243 cout << "No free sectors available\n";
245 } // GPTDataTextUI::CreatePartition()
247 // Interactively delete a partition (duh!)
248 void GPTDataTextUI::DeletePartition(void) {
251 ostringstream prompt;
253 if (GetPartRange(&low, &high) > 0) {
254 prompt << "Partition number (" << low + 1 << "-" << high + 1 << "): ";
255 partNum = GetNumber(low + 1, high + 1, low, prompt.str());
256 GPTData::DeletePartition(partNum - 1);
258 cout << "No partitions\n";
260 } // GPTDataTextUI::DeletePartition()
262 // Prompt user for a partition number, then change its type code
263 void GPTDataTextUI::ChangePartType(void) {
267 if (GetPartRange(&low, &high) > 0) {
268 partNum = GetPartNum();
269 partitions[partNum].ChangeType();
271 cout << "No partitions\n";
273 } // GPTDataTextUI::ChangePartType()
275 // Prompt user for a partition number, then change its unique
277 void GPTDataTextUI::ChangeUniqueGuid(void) {
282 if (GetPartRange(&low, &high) > 0) {
283 partNum = GetPartNum();
284 cout << "Enter the partition's new unique GUID ('R' to randomize): ";
285 guidStr = ReadString();
286 if ((guidStr.length() >= 32) || (guidStr[0] == 'R') || (guidStr[0] == 'r')) {
287 SetPartitionGUID(partNum, (GUIDData) guidStr);
288 cout << "New GUID is " << partitions[partNum].GetUniqueGUID() << "\n";
290 cout << "GUID is too short!\n";
293 cout << "No partitions\n";
294 } // GPTDataTextUI::ChangeUniqueGuid()
296 // Partition attributes seem to be rarely used, but I want a way to
297 // adjust them for completeness....
298 void GPTDataTextUI::SetAttributes(uint32_t partNum) {
299 partitions[partNum].SetAttributes();
300 } // GPTDataTextUI::SetAttributes()
302 // Prompts the user for a partition name and sets the partition's
303 // name. Returns 1 on success, 0 on failure (invalid partition
304 // number). (Note that the function skips prompting when an
305 // invalid partition number is detected.)
306 int GPTDataTextUI::SetName(uint32_t partNum) {
307 UnicodeString theName = "";
310 if (IsUsedPartNum(partNum)) {
311 cout << "Enter name: ";
312 theName = ReadUString();
313 partitions[partNum].SetName(theName);
315 cerr << "Invalid partition number (" << partNum << ")\n";
320 } // GPTDataTextUI::SetName()
322 // Ask user for two partition numbers and swap them in the table. Note that
323 // this just reorders table entries; it doesn't adjust partition layout on
325 // Returns 1 if successful, 0 if not. (If user enters identical numbers, it
326 // counts as successful.)
327 int GPTDataTextUI::SwapPartitions(void) {
328 int partNum1, partNum2, didIt = 0;
330 ostringstream prompt;
333 if (GetPartRange(&low, &high) > 0) {
334 partNum1 = GetPartNum();
335 if (high >= numParts - 1)
337 prompt << "New partition number (1-" << numParts
338 << ", default " << high + 2 << "): ";
339 partNum2 = GetNumber(1, numParts, high + 2, prompt.str()) - 1;
340 didIt = GPTData::SwapPartitions(partNum1, partNum2);
342 cout << "No partitions\n";
345 } // GPTDataTextUI::SwapPartitionNumbers()
347 // This function destroys the on-disk GPT structures. Returns 1 if the user
348 // confirms destruction, 0 if the user aborts or if there's a disk error.
349 int GPTDataTextUI::DestroyGPTwPrompt(void) {
352 if ((apmFound) || (bsdFound)) {
353 cout << "WARNING: APM or BSD disklabel structures detected! This operation could\n"
354 << "damage any APM or BSD partitions on this disk!\n";
356 cout << "\a\aAbout to wipe out GPT on " << device << ". Proceed? ";
357 if (GetYN() == 'Y') {
359 // Note on below: Touch the MBR only if the user wants it completely
360 // blanked out. Version 0.4.2 deleted the 0xEE partition and re-wrote
361 // the MBR, but this could wipe out a valid MBR that the program
362 // had subsequently discarded (say, if it conflicted with older GPT
364 cout << "Blank out MBR? ";
365 if (GetYN() == 'Y') {
368 cout << "MBR is unchanged. You may need to delete an EFI GPT (0xEE) partition\n"
369 << "with fdisk or another tool.\n";
371 } else allOK = 0; // if GPT structures destroyed
372 } else allOK = 0; // if user confirms destruction
374 } // GPTDataTextUI::DestroyGPTwPrompt()
376 // Get partition number from user and then call ShowPartDetails(partNum)
377 // to show its detailed information
378 void GPTDataTextUI::ShowDetails(void) {
382 if (GetPartRange(&low, &high) > 0) {
383 partNum = GetPartNum();
384 ShowPartDetails(partNum);
386 cout << "No partitions\n";
388 } // GPTDataTextUI::ShowDetails()
390 // Create a hybrid MBR -- an ugly, funky thing that helps GPT work with
391 // OSes that don't understand GPT.
392 void GPTDataTextUI::MakeHybrid(void) {
393 uint32_t partNums[3];
395 int numPartsToCvt, i, j, mbrNum = 0;
396 unsigned int hexCode = 0;
399 char eeFirst = 'Y'; // Whether EFI GPT (0xEE) partition comes first in table
401 cout << "\nWARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,\n"
402 << "just hit the Enter key at the below prompt and your MBR partition table will\n"
403 << "be untouched.\n\n\a";
405 // Use a local MBR structure, copying from protectiveMBR to keep its
406 // boot loader code intact....
407 hybridMBR = protectiveMBR;
408 hybridMBR.EmptyMBR(0);
410 // Now get the numbers of up to three partitions to add to the
412 cout << "Type from one to three GPT partition numbers, separated by spaces, to be\n"
413 << "added to the hybrid MBR, in sequence: ";
415 numPartsToCvt = sscanf(line.c_str(), "%d %d %d", &partNums[0], &partNums[1], &partNums[2]);
417 if (numPartsToCvt > 0) {
418 cout << "Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? ";
422 for (i = 0; i < numPartsToCvt; i++) {
424 if (partitions[j].IsUsed()) {
425 mbrNum = i + (eeFirst == 'Y');
426 cout << "\nCreating entry for GPT partition #" << j + 1
427 << " (MBR partition #" << mbrNum + 1 << ")\n";
428 hybridPart.SetType(GetMBRTypeCode(partitions[j].GetHexType() / 256));
429 hybridPart.SetLocation(partitions[j].GetFirstLBA(), partitions[j].GetLengthLBA());
430 hybridPart.SetInclusion(PRIMARY);
431 cout << "Set the bootable flag? ";
433 hybridPart.SetStatus(0x80);
435 hybridPart.SetStatus(0x00);
436 hybridPart.SetInclusion(PRIMARY);
438 cerr << "\nGPT partition #" << j + 1 << " does not exist; skipping.\n";
440 hybridMBR.AddPart(mbrNum, hybridPart);
443 if (numPartsToCvt > 0) { // User opted to create a hybrid MBR....
444 // Create EFI protective partition that covers the start of the disk.
445 // If this location (covering the main GPT data structures) is omitted,
446 // Linux won't find any partitions on the disk.
447 hybridPart.SetLocation(1, hybridMBR.FindLastInFree(1));
448 hybridPart.SetStatus(0);
449 hybridPart.SetType(0xEE);
450 hybridPart.SetInclusion(PRIMARY);
451 // newNote firstLBA and lastLBA are computed later...
452 if (eeFirst == 'Y') {
453 hybridMBR.AddPart(0, hybridPart);
455 hybridMBR.AddPart(3, hybridPart);
457 hybridMBR.SetHybrid();
459 // ... and for good measure, if there are any partition spaces left,
460 // optionally create another protective EFI partition to cover as much
461 // space as possible....
462 if (hybridMBR.CountParts() < 4) { // unused entry....
463 cout << "\nUnused partition space(s) found. Use one to protect more partitions? ";
464 if (GetYN() == 'Y') {
465 cout << "Note: Default is 0xEE, but this may confuse Mac OS X.\n";
466 // Comment on above: Mac OS treats disks with more than one
467 // 0xEE MBR partition as MBR disks, not as GPT disks.
468 hexCode = GetMBRTypeCode(0xEE);
469 hybridMBR.MakeBiggestPart(3, hexCode);
470 } // if (GetYN() == 'Y')
472 protectiveMBR = hybridMBR;
473 } // if (numPartsToCvt > 0)
474 } // GPTDataTextUI::MakeHybrid()
476 // Convert the GPT to MBR form, storing partitions in the protectiveMBR
477 // variable. This function is necessarily limited; it may not be able to
478 // convert all partitions, depending on the disk size and available space
479 // before each partition (one free sector is required to create a logical
480 // partition, which are necessary to convert more than four partitions).
481 // Returns the number of converted partitions; if this value
482 // is over 0, the calling function should call DestroyGPT() to destroy
483 // the GPT data, call SaveMBR() to save the MBR, and then exit.
484 int GPTDataTextUI::XFormToMBR(void) {
487 protectiveMBR.EmptyMBR(0);
488 for (i = 0; i < numParts; i++) {
489 if (partitions[i].IsUsed()) {
490 protectiveMBR.MakePart(i, partitions[i].GetFirstLBA(),
491 partitions[i].GetLengthLBA(),
492 partitions[i].GetHexType() / 0x0100, 0);
495 protectiveMBR.MakeItLegal();
496 return protectiveMBR.DoMenu();
497 } // GPTDataTextUI::XFormToMBR()
500 /*********************************************************************
502 * The following functions provide the main menus for the gdisk *
505 *********************************************************************/
507 // Accept a command and execute it. Returns only when the user
508 // wants to exit (such as after a 'w' or 'q' command).
509 void GPTDataTextUI::MainMenu(string filename) {
512 uint32_t temp1, temp2;
515 cout << "\nCommand (? for help): ";
516 switch (ReadString()[0]) {
521 cout << "Enter backup filename to save: ";
522 SaveGPTBackup(ReadString());
525 if (GetPartRange(&temp1, &temp2) > 0)
526 SetName(GetPartNum());
528 cout << "No partitions\n";
537 typeHelper.ShowAllTypes();
543 cout << "This option deletes all partitions and creates a new protective MBR.\n"
545 if (GetYN() == 'Y') {
557 RecoveryMenu(filename);
562 cout << "You may need to edit /etc/fstab and/or your boot loader configuration!\n";
571 if (SaveGPTData() == 1)
575 ExpertsMenu(filename);
583 } // GPTDataTextUI::MainMenu()
585 void GPTDataTextUI::ShowCommands(void) {
586 cout << "b\tback up GPT data to a file\n";
587 cout << "c\tchange a partition's name\n";
588 cout << "d\tdelete a partition\n";
589 cout << "i\tshow detailed information on a partition\n";
590 cout << "l\tlist known partition types\n";
591 cout << "n\tadd a new partition\n";
592 cout << "o\tcreate a new empty GUID partition table (GPT)\n";
593 cout << "p\tprint the partition table\n";
594 cout << "q\tquit without saving changes\n";
595 cout << "r\trecovery and transformation options (experts only)\n";
596 cout << "s\tsort partitions\n";
597 cout << "t\tchange a partition's type code\n";
598 cout << "v\tverify disk\n";
599 cout << "w\twrite table to disk and exit\n";
600 cout << "x\textra functionality (experts only)\n";
601 cout << "?\tprint this menu\n";
602 } // GPTDataTextUI::ShowCommands()
604 // Accept a recovery & transformation menu command. Returns only when the user
605 // issues an exit command, such as 'w' or 'q'.
606 void GPTDataTextUI::RecoveryMenu(string filename) {
611 cout << "\nRecovery/transformation command (? for help): ";
612 switch (ReadString()[0]) {
620 cout << "Warning! This will probably do weird things if you've converted an MBR to\n"
621 << "GPT form and haven't yet saved the GPT! Proceed? ";
623 LoadSecondTableAsMain();
626 RebuildSecondHeader();
629 cout << "Warning! This will probably do weird things if you've converted an MBR to\n"
630 << "GPT form and haven't yet saved the GPT! Proceed? ";
635 cout << "Warning! This will destroy the currently defined partitions! Proceed? ";
636 if (GetYN() == 'Y') {
637 if (LoadMBR(filename) == 1) { // successful load
640 cout << "Problem loading MBR! GPT is untouched; regenerating protective MBR!\n";
646 numParts = GetNumParts();
647 temp1 = XFormToMBR();
649 cout << "\nConverted " << temp1 << " partitions. Finalize and exit? ";
650 if ((temp1 > 0) && (GetYN() == 'Y')) {
651 if ((DestroyGPT() > 0) && (SaveMBR())) {
656 SetGPTSize(numParts, 0);
657 cout << "Note: New protective MBR created\n\n";
667 cout << "Enter backup filename to load: ";
668 LoadGPTBackup(ReadString());
690 if (SaveGPTData() == 1) {
695 ExpertsMenu(filename);
699 ShowRecoveryCommands();
703 } // GPTDataTextUI::RecoveryMenu()
705 void GPTDataTextUI::ShowRecoveryCommands(void) {
706 cout << "b\tuse backup GPT header (rebuilding main)\n";
707 cout << "c\tload backup partition table from disk (rebuilding main)\n";
708 cout << "d\tuse main GPT header (rebuilding backup)\n";
709 cout << "e\tload main partition table from disk (rebuilding backup)\n";
710 cout << "f\tload MBR and build fresh GPT from it\n";
711 cout << "g\tconvert GPT into MBR and exit\n";
712 cout << "h\tmake hybrid MBR\n";
713 cout << "i\tshow detailed information on a partition\n";
714 cout << "l\tload partition data from a backup file\n";
715 cout << "m\treturn to main menu\n";
716 cout << "o\tprint protective MBR data\n";
717 cout << "p\tprint the partition table\n";
718 cout << "q\tquit without saving changes\n";
719 cout << "t\ttransform BSD disklabel partition\n";
720 cout << "v\tverify disk\n";
721 cout << "w\twrite table to disk and exit\n";
722 cout << "x\textra functionality (experts only)\n";
723 cout << "?\tprint this menu\n";
724 } // GPTDataTextUI::ShowRecoveryCommands()
726 // Accept an experts' menu command. Returns only after the user
727 // selects an exit command, such as 'w' or 'q'.
728 void GPTDataTextUI::ExpertsMenu(string filename) {
729 GPTData secondDevice;
730 uint32_t temp1, temp2;
732 string guidStr, device;
734 ostringstream prompt;
737 cout << "\nExpert command (? for help): ";
738 switch (ReadString()[0]) {
743 if (GetPartRange(&temp1, &temp2) > 0)
744 SetAttributes(GetPartNum());
746 cout << "No partitions\n";
752 cout << "Partitions will begin on " << GetAlignment()
753 << "-sector boundaries.\n";
756 cout << "Relocating backup data structures to the end of the disk\n";
757 MoveSecondHeaderToEnd();
763 cout << "Enter the disk's unique GUID ('R' to randomize): ";
764 guidStr = ReadString();
765 if ((guidStr.length() >= 32) || (guidStr[0] == 'R') || (guidStr[0] == 'r')) {
766 SetDiskGUID((GUIDData) guidStr);
767 cout << "The new disk GUID is " << GetDiskGUID() << "\n";
769 cout << "GUID is too short!\n";
780 prompt << "Enter the sector alignment value (1-" << MAX_ALIGNMENT << ", default = "
781 << DEFAULT_ALIGNMENT << "): ";
782 temp1 = GetNumber(1, MAX_ALIGNMENT, DEFAULT_ALIGNMENT, prompt.str());
802 RecoveryMenu(filename);
806 ResizePartitionTable();
812 cout << "Type device filename, or press <Enter> to exit: ";
813 device = ReadString();
814 if (device.length() > 0) {
815 secondDevice = *this;
816 secondDevice.SetDisk(device);
817 secondDevice.SaveGPTData(0);
824 if (SaveGPTData() == 1) {
829 if (DestroyGPTwPrompt() == 1) {
834 ShowExpertCommands();
838 } // GPTDataTextUI::ExpertsMenu()
840 void GPTDataTextUI::ShowExpertCommands(void) {
841 cout << "a\tset attributes\n";
842 cout << "c\tchange partition GUID\n";
843 cout << "d\tdisplay the sector alignment value\n";
844 cout << "e\trelocate backup data structures to the end of the disk\n";
845 cout << "g\tchange disk GUID\n";
846 cout << "h\trecompute CHS values in protective/hybrid MBR\n";
847 cout << "i\tshow detailed information on a partition\n";
848 cout << "l\tset the sector alignment value\n";
849 cout << "m\treturn to main menu\n";
850 cout << "n\tcreate a new protective MBR\n";
851 cout << "o\tprint protective MBR data\n";
852 cout << "p\tprint the partition table\n";
853 cout << "q\tquit without saving changes\n";
854 cout << "r\trecovery and transformation options (experts only)\n";
855 cout << "s\tresize partition table\n";
856 cout << "t\ttranspose two partition table entries\n";
857 cout << "u\tReplicate partition table on new device\n";
858 cout << "v\tverify disk\n";
859 cout << "w\twrite table to disk and exit\n";
860 cout << "z\tzap (destroy) GPT data structures and exit\n";
861 cout << "?\tprint this menu\n";
862 } // GPTDataTextUI::ShowExpertCommands()
866 /********************************
868 * Non-class support functions. *
870 ********************************/
872 // GetMBRTypeCode() doesn't really belong in the class, since it's MBR-
873 // specific, but it's also user I/O-related, so I want to keep it in
876 // Get an MBR type code from the user and return it
877 int GetMBRTypeCode(int defType) {
881 cout.setf(ios::uppercase);
884 cout << "Enter an MBR hex code (default " << hex;
886 cout << defType << "): " << dec;
891 typeCode = StrToHex(line, 0);
892 } while ((typeCode <= 0) || (typeCode > 255));
897 // Note: ReadUString() is here rather than in support.cc so that the ICU
898 // libraries need not be linked to fixparts.
900 // Reads a Unicode string from stdin, returning it as an ICU-style string.
901 // Note that the returned string will NOT include the carriage return
902 // entered by the user. Relies on the ICU constructor from a string
903 // encoded in the current codepage to work.
904 UnicodeString ReadUString(void) {
905 return ReadString().c_str();