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
30
#include "attributes.h"
36
/********************************************
38
* GPTDataText class and related structures *
40
********************************************/
42
GPTDataTextUI::GPTDataTextUI(void) : GPTData() {
43
} // default constructor
45
GPTDataTextUI::GPTDataTextUI(string filename) : GPTData(filename) {
46
} // constructor passing filename
48
GPTDataTextUI::~GPTDataTextUI(void) {
49
} // default destructor
51
/*********************************************************************
53
* The following functions are extended (interactive) versions of *
54
* simpler functions in the base class.... *
56
*********************************************************************/
58
// Overridden function; calls base-class function and then makes
59
// additional queries of the user, if the base-class function can't
61
WhichToUse GPTDataTextUI::UseWhichPartitions(void) {
66
which = GPTData::UseWhichPartitions();
67
if ((which != use_abort) || beQuiet)
70
// If we get past here, it means that the non-interactive tests were
71
// inconclusive, so we must ask the user which table to use....
72
mbrState = protectiveMBR.GetValidity();
74
if ((state == gpt_valid) && (mbrState == mbr)) {
75
cout << "Found valid MBR and GPT. Which do you want to use?\n";
76
answer = GetNumber(1, 3, 2, " 1 - MBR\n 2 - GPT\n 3 - Create blank GPT\n\nYour answer: ");
79
} else if (answer == 2) {
81
cout << "Using GPT and creating fresh protective MBR.\n";
82
} else which = use_new;
85
// Nasty decisions here -- GPT is present, but corrupt (bad CRCs or other
87
if (state == gpt_corrupt) {
88
if ((mbrState == mbr) || (mbrState == hybrid)) {
89
cout << "Found valid MBR and corrupt GPT. Which do you want to use? (Using the\n"
90
<< "GPT MAY permit recovery of GPT data.)\n";
91
answer = GetNumber(1, 3, 2, " 1 - MBR\n 2 - GPT\n 3 - Create blank GPT\n\nYour answer: ");
94
} else if (answer == 2) {
96
} else which = use_new;
97
} else if (mbrState == invalid) {
98
cout << "Found invalid MBR and corrupt GPT. What do you want to do? (Using the\n"
99
<< "GPT MAY permit recovery of GPT data.)\n";
100
answer = GetNumber(1, 2, 1, " 1 - Use current GPT\n 2 - Create blank GPT\n\nYour answer: ");
103
} else which = use_new;
105
} // if (corrupt GPT)
108
} // UseWhichPartitions()
110
// Ask the user for a partition number; and prompt for verification
111
// if the requested partition isn't of a known BSD type.
112
// Lets the base-class function do the work, and returns its value (the
113
// number of converted partitions).
114
int GPTDataTextUI::XFormDisklabel(void) {
117
int goOn = 1, numDone = 0;
120
partNum = GetPartNum();
122
// Now see if the specified partition has a BSD type code....
123
hexCode = partitions[partNum].GetHexType();
124
if ((hexCode != 0xa500) && (hexCode != 0xa900)) {
125
cout << "Specified partition doesn't have a disklabel partition type "
126
<< "code.\nContinue anyway? ";
127
goOn = (GetYN() == 'Y');
131
numDone = GPTData::XFormDisklabel(partNum);
134
} // GPTData::XFormDisklabel(int i)
137
/*********************************************************************
139
* Begin functions that obtain information from the users, and often *
140
* do something with that information (call other functions) *
142
*********************************************************************/
144
// Prompts user for partition number and returns the result. Returns "0"
145
// (the first partition) if none are currently defined.
146
uint32_t GPTDataTextUI::GetPartNum(void) {
149
ostringstream prompt;
151
if (GetPartRange(&low, &high) > 0) {
152
prompt << "Partition number (" << low + 1 << "-" << high + 1 << "): ";
153
partNum = GetNumber(low + 1, high + 1, low, prompt.str());
155
return (partNum - 1);
156
} // GPTDataTextUI::GetPartNum()
158
// What it says: Resize the partition table. (Default is 128 entries.)
159
void GPTDataTextUI::ResizePartitionTable(void) {
161
ostringstream prompt;
162
uint32_t curLow, curHigh;
164
cout << "Current partition table size is " << numParts << ".\n";
165
GetPartRange(&curLow, &curHigh);
166
curHigh++; // since GetPartRange() returns numbers starting from 0...
167
// There's no point in having fewer than four partitions....
168
if (curHigh < (blockSize / GPT_SIZE))
169
curHigh = blockSize / GPT_SIZE;
170
prompt << "Enter new size (" << curHigh << " up, default " << NUM_GPT_ENTRIES << "): ";
171
newSize = GetNumber(4, 65535, 128, prompt.str());
173
cout << "Caution: The partition table size should officially be 16KB or larger,\n"
174
<< "which works out to 128 entries. In practice, smaller tables seem to\n"
175
<< "work with most OSes, but this practice is risky. I'm proceeding with\n"
176
<< "the resize, but you may want to reconsider this action and undo it.\n\n";
179
} // GPTDataTextUI::ResizePartitionTable()
181
// Interactively create a partition
182
void GPTDataTextUI::CreatePartition(void) {
183
uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector;
184
uint32_t firstFreePart = 0;
185
ostringstream prompt1, prompt2, prompt3;
188
// Find first free partition...
189
while (partitions[firstFreePart].GetFirstLBA() != 0) {
193
if (((firstBlock = FindFirstAvailable()) != 0) &&
194
(firstFreePart < numParts)) {
195
lastBlock = FindLastAvailable();
196
firstInLargest = FindFirstInLargest();
197
Align(&firstInLargest);
199
// Get partition number....
201
prompt1 << "Partition number (" << firstFreePart + 1 << "-" << numParts
202
<< ", default " << firstFreePart + 1 << "): ";
203
partNum = GetNumber(firstFreePart + 1, numParts,
204
firstFreePart + 1, prompt1.str()) - 1;
205
if (partitions[partNum].GetFirstLBA() != 0)
206
cout << "partition " << partNum + 1 << " is in use.\n";
207
} while (partitions[partNum].GetFirstLBA() != 0);
209
// Get first block for new partition...
210
prompt2 << "First sector (" << firstBlock << "-" << lastBlock << ", default = "
211
<< firstInLargest << ") or {+-}size{KMGTP}: ";
213
sector = GetSectorNum(firstBlock, lastBlock, firstInLargest, blockSize, prompt2.str());
214
} while (IsFree(sector) == 0);
216
if (Align(§or)) {
217
cout << "Information: Moved requested sector from " << origSector << " to "
218
<< sector << " in\norder to align on " << sectorAlignment
219
<< "-sector boundaries.\n";
221
cout << "Use 'l' on the experts' menu to adjust alignment\n";
223
// Align(§or); // Align sector to correct multiple
226
// Get last block for new partitions...
227
lastBlock = FindLastInFree(firstBlock);
228
prompt3 << "Last sector (" << firstBlock << "-" << lastBlock << ", default = "
229
<< lastBlock << ") or {+-}size{KMGTP}: ";
231
sector = GetSectorNum(firstBlock, lastBlock, lastBlock, blockSize, prompt3.str());
232
} while (IsFree(sector) == 0);
235
firstFreePart = GPTData::CreatePartition(partNum, firstBlock, lastBlock);
236
partitions[partNum].ChangeType();
237
partitions[partNum].SetDefaultDescription();
239
if (firstFreePart >= numParts)
240
cout << "No table partition entries left\n";
242
cout << "No free sectors available\n";
244
} // GPTDataTextUI::CreatePartition()
246
// Interactively delete a partition (duh!)
247
void GPTDataTextUI::DeletePartition(void) {
250
ostringstream prompt;
252
if (GetPartRange(&low, &high) > 0) {
253
prompt << "Partition number (" << low + 1 << "-" << high + 1 << "): ";
254
partNum = GetNumber(low + 1, high + 1, low, prompt.str());
255
GPTData::DeletePartition(partNum - 1);
257
cout << "No partitions\n";
259
} // GPTDataTextUI::DeletePartition()
261
// Prompt user for a partition number, then change its type code
262
void GPTDataTextUI::ChangePartType(void) {
266
if (GetPartRange(&low, &high) > 0) {
267
partNum = GetPartNum();
268
partitions[partNum].ChangeType();
270
cout << "No partitions\n";
272
} // GPTDataTextUI::ChangePartType()
274
// Prompt user for a partition number, then change its unique
276
void GPTDataTextUI::ChangeUniqueGuid(void) {
281
if (GetPartRange(&low, &high) > 0) {
282
partNum = GetPartNum();
283
cout << "Enter the partition's new unique GUID ('R' to randomize): ";
284
guidStr = ReadString();
285
if ((guidStr.length() >= 32) || (guidStr[0] == 'R') || (guidStr[0] == 'r')) {
286
SetPartitionGUID(partNum, (GUIDData) guidStr);
287
cout << "New GUID is " << partitions[partNum].GetUniqueGUID() << "\n";
289
cout << "GUID is too short!\n";
292
cout << "No partitions\n";
293
} // GPTDataTextUI::ChangeUniqueGuid()
295
// Partition attributes seem to be rarely used, but I want a way to
296
// adjust them for completeness....
297
void GPTDataTextUI::SetAttributes(uint32_t partNum) {
298
partitions[partNum].SetAttributes();
299
} // GPTDataTextUI::SetAttributes()
301
// Prompts the user for a partition name and sets the partition's
302
// name. Returns 1 on success, 0 on failure (invalid partition
303
// number). (Note that the function skips prompting when an
304
// invalid partition number is detected.)
305
int GPTDataTextUI::SetName(uint32_t partNum) {
306
UnicodeString theName = "";
309
if (IsUsedPartNum(partNum)) {
310
cout << "Enter name: ";
311
theName = ReadUString();
312
partitions[partNum].SetName(theName);
314
cerr << "Invalid partition number (" << partNum << ")\n";
319
} // GPTDataTextUI::SetName()
321
// Ask user for two partition numbers and swap them in the table. Note that
322
// this just reorders table entries; it doesn't adjust partition layout on
324
// Returns 1 if successful, 0 if not. (If user enters identical numbers, it
325
// counts as successful.)
326
int GPTDataTextUI::SwapPartitions(void) {
327
int partNum1, partNum2, didIt = 0;
329
ostringstream prompt;
332
if (GetPartRange(&low, &high) > 0) {
333
partNum1 = GetPartNum();
334
if (high >= numParts - 1)
336
prompt << "New partition number (1-" << numParts
337
<< ", default " << high + 2 << "): ";
338
partNum2 = GetNumber(1, numParts, high + 2, prompt.str()) - 1;
339
didIt = GPTData::SwapPartitions(partNum1, partNum2);
341
cout << "No partitions\n";
344
} // GPTDataTextUI::SwapPartitionNumbers()
346
// This function destroys the on-disk GPT structures. Returns 1 if the user
347
// confirms destruction, 0 if the user aborts or if there's a disk error.
348
int GPTDataTextUI::DestroyGPTwPrompt(void) {
351
if ((apmFound) || (bsdFound)) {
352
cout << "WARNING: APM or BSD disklabel structures detected! This operation could\n"
353
<< "damage any APM or BSD partitions on this disk!\n";
355
cout << "\a\aAbout to wipe out GPT on " << device << ". Proceed? ";
356
if (GetYN() == 'Y') {
358
// Note on below: Touch the MBR only if the user wants it completely
359
// blanked out. Version 0.4.2 deleted the 0xEE partition and re-wrote
360
// the MBR, but this could wipe out a valid MBR that the program
361
// had subsequently discarded (say, if it conflicted with older GPT
363
cout << "Blank out MBR? ";
364
if (GetYN() == 'Y') {
367
cout << "MBR is unchanged. You may need to delete an EFI GPT (0xEE) partition\n"
368
<< "with fdisk or another tool.\n";
370
} else allOK = 0; // if GPT structures destroyed
371
} else allOK = 0; // if user confirms destruction
373
} // GPTDataTextUI::DestroyGPTwPrompt()
375
// Get partition number from user and then call ShowPartDetails(partNum)
376
// to show its detailed information
377
void GPTDataTextUI::ShowDetails(void) {
381
if (GetPartRange(&low, &high) > 0) {
382
partNum = GetPartNum();
383
ShowPartDetails(partNum);
385
cout << "No partitions\n";
387
} // GPTDataTextUI::ShowDetails()
389
// Create a hybrid MBR -- an ugly, funky thing that helps GPT work with
390
// OSes that don't understand GPT.
391
void GPTDataTextUI::MakeHybrid(void) {
392
uint32_t partNums[3];
394
int numPartsToCvt, i, j, mbrNum = 0;
395
unsigned int hexCode = 0;
398
char eeFirst = 'Y'; // Whether EFI GPT (0xEE) partition comes first in table
400
cout << "\nWARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,\n"
401
<< "just hit the Enter key at the below prompt and your MBR partition table will\n"
402
<< "be untouched.\n\n\a";
404
// Use a local MBR structure, copying from protectiveMBR to keep its
405
// boot loader code intact....
406
hybridMBR = protectiveMBR;
407
hybridMBR.EmptyMBR(0);
409
// Now get the numbers of up to three partitions to add to the
411
cout << "Type from one to three GPT partition numbers, separated by spaces, to be\n"
412
<< "added to the hybrid MBR, in sequence: ";
414
numPartsToCvt = sscanf(line.c_str(), "%d %d %d", &partNums[0], &partNums[1], &partNums[2]);
416
if (numPartsToCvt > 0) {
417
cout << "Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? ";
421
for (i = 0; i < numPartsToCvt; i++) {
423
if (partitions[j].IsUsed()) {
424
mbrNum = i + (eeFirst == 'Y');
425
cout << "\nCreating entry for GPT partition #" << j + 1
426
<< " (MBR partition #" << mbrNum + 1 << ")\n";
427
hybridPart.SetType(GetMBRTypeCode(partitions[j].GetHexType() / 256));
428
hybridPart.SetLocation(partitions[j].GetFirstLBA(), partitions[j].GetLengthLBA());
429
hybridPart.SetInclusion(PRIMARY);
430
cout << "Set the bootable flag? ";
432
hybridPart.SetStatus(0x80);
434
hybridPart.SetStatus(0x00);
435
hybridPart.SetInclusion(PRIMARY);
437
cerr << "\nGPT partition #" << j + 1 << " does not exist; skipping.\n";
439
hybridMBR.AddPart(mbrNum, hybridPart);
442
if (numPartsToCvt > 0) { // User opted to create a hybrid MBR....
443
// Create EFI protective partition that covers the start of the disk.
444
// If this location (covering the main GPT data structures) is omitted,
445
// Linux won't find any partitions on the disk.
446
hybridPart.SetLocation(1, hybridMBR.FindLastInFree(1));
447
hybridPart.SetStatus(0);
448
hybridPart.SetType(0xEE);
449
hybridPart.SetInclusion(PRIMARY);
450
// newNote firstLBA and lastLBA are computed later...
451
if (eeFirst == 'Y') {
452
hybridMBR.AddPart(0, hybridPart);
454
hybridMBR.AddPart(3, hybridPart);
456
hybridMBR.SetHybrid();
458
// ... and for good measure, if there are any partition spaces left,
459
// optionally create another protective EFI partition to cover as much
460
// space as possible....
461
if (hybridMBR.CountParts() < 4) { // unused entry....
462
cout << "\nUnused partition space(s) found. Use one to protect more partitions? ";
463
if (GetYN() == 'Y') {
464
cout << "Note: Default is 0xEE, but this may confuse Mac OS X.\n";
465
// Comment on above: Mac OS treats disks with more than one
466
// 0xEE MBR partition as MBR disks, not as GPT disks.
467
hexCode = GetMBRTypeCode(0xEE);
468
hybridMBR.MakeBiggestPart(3, hexCode);
469
} // if (GetYN() == 'Y')
471
protectiveMBR = hybridMBR;
472
} // if (numPartsToCvt > 0)
473
} // GPTDataTextUI::MakeHybrid()
475
// Convert the GPT to MBR form, storing partitions in the protectiveMBR
476
// variable. This function is necessarily limited; it may not be able to
477
// convert all partitions, depending on the disk size and available space
478
// before each partition (one free sector is required to create a logical
479
// partition, which are necessary to convert more than four partitions).
480
// Returns the number of converted partitions; if this value
481
// is over 0, the calling function should call DestroyGPT() to destroy
482
// the GPT data, call SaveMBR() to save the MBR, and then exit.
483
int GPTDataTextUI::XFormToMBR(void) {
486
protectiveMBR.EmptyMBR(0);
487
for (i = 0; i < numParts; i++) {
488
if (partitions[i].IsUsed()) {
489
protectiveMBR.MakePart(i, partitions[i].GetFirstLBA(),
490
partitions[i].GetLengthLBA(),
491
partitions[i].GetHexType() / 0x0100, 0);
494
protectiveMBR.MakeItLegal();
495
return protectiveMBR.DoMenu();
496
} // GPTDataTextUI::XFormToMBR()
499
/*********************************************************************
501
* The following functions provide the main menus for the gdisk *
504
*********************************************************************/
506
// Accept a command and execute it. Returns only when the user
507
// wants to exit (such as after a 'w' or 'q' command).
508
void GPTDataTextUI::MainMenu(string filename) {
511
uint32_t temp1, temp2;
514
cout << "\nCommand (? for help): ";
515
switch (ReadString()[0]) {
519
cout << "Enter backup filename to save: ";
520
SaveGPTBackup(ReadString());
523
if (GetPartRange(&temp1, &temp2) > 0)
524
SetName(GetPartNum());
526
cout << "No partitions\n";
535
typeHelper.ShowAllTypes();
541
cout << "This option deletes all partitions and creates a new protective MBR.\n"
543
if (GetYN() == 'Y') {
555
RecoveryMenu(filename);
560
cout << "You may need to edit /etc/fstab and/or your boot loader configuration!\n";
569
if (SaveGPTData() == 1)
573
ExpertsMenu(filename);
581
} // GPTDataTextUI::MainMenu()
583
void GPTDataTextUI::ShowCommands(void) {
584
cout << "b\tback up GPT data to a file\n";
585
cout << "c\tchange a partition's name\n";
586
cout << "d\tdelete a partition\n";
587
cout << "i\tshow detailed information on a partition\n";
588
cout << "l\tlist known partition types\n";
589
cout << "n\tadd a new partition\n";
590
cout << "o\tcreate a new empty GUID partition table (GPT)\n";
591
cout << "p\tprint the partition table\n";
592
cout << "q\tquit without saving changes\n";
593
cout << "r\trecovery and transformation options (experts only)\n";
594
cout << "s\tsort partitions\n";
595
cout << "t\tchange a partition's type code\n";
596
cout << "v\tverify disk\n";
597
cout << "w\twrite table to disk and exit\n";
598
cout << "x\textra functionality (experts only)\n";
599
cout << "?\tprint this menu\n";
600
} // GPTDataTextUI::ShowCommands()
602
// Accept a recovery & transformation menu command. Returns only when the user
603
// issues an exit command, such as 'w' or 'q'.
604
void GPTDataTextUI::RecoveryMenu(string filename) {
609
cout << "\nRecovery/transformation command (? for help): ";
610
switch (ReadString()[0]) {
617
cout << "Warning! This will probably do weird things if you've converted an MBR to\n"
618
<< "GPT form and haven't yet saved the GPT! Proceed? ";
620
LoadSecondTableAsMain();
623
RebuildSecondHeader();
626
cout << "Warning! This will probably do weird things if you've converted an MBR to\n"
627
<< "GPT form and haven't yet saved the GPT! Proceed? ";
632
cout << "Warning! This will destroy the currently defined partitions! Proceed? ";
633
if (GetYN() == 'Y') {
634
if (LoadMBR(filename) == 1) { // successful load
637
cout << "Problem loading MBR! GPT is untouched; regenerating protective MBR!\n";
643
numParts = GetNumParts();
644
temp1 = XFormToMBR();
646
cout << "\nConverted " << temp1 << " partitions. Finalize and exit? ";
647
if ((temp1 > 0) && (GetYN() == 'Y')) {
648
if ((DestroyGPT() > 0) && (SaveMBR())) {
653
SetGPTSize(numParts, 0);
654
cout << "Note: New protective MBR created\n\n";
664
cout << "Enter backup filename to load: ";
665
LoadGPTBackup(ReadString());
687
if (SaveGPTData() == 1) {
692
ExpertsMenu(filename);
696
ShowRecoveryCommands();
700
} // GPTDataTextUI::RecoveryMenu()
702
void GPTDataTextUI::ShowRecoveryCommands(void) {
703
cout << "b\tuse backup GPT header (rebuilding main)\n";
704
cout << "c\tload backup partition table from disk (rebuilding main)\n";
705
cout << "d\tuse main GPT header (rebuilding backup)\n";
706
cout << "e\tload main partition table from disk (rebuilding backup)\n";
707
cout << "f\tload MBR and build fresh GPT from it\n";
708
cout << "g\tconvert GPT into MBR and exit\n";
709
cout << "h\tmake hybrid MBR\n";
710
cout << "i\tshow detailed information on a partition\n";
711
cout << "l\tload partition data from a backup file\n";
712
cout << "m\treturn to main menu\n";
713
cout << "o\tprint protective MBR data\n";
714
cout << "p\tprint the partition table\n";
715
cout << "q\tquit without saving changes\n";
716
cout << "t\ttransform BSD disklabel partition\n";
717
cout << "v\tverify disk\n";
718
cout << "w\twrite table to disk and exit\n";
719
cout << "x\textra functionality (experts only)\n";
720
cout << "?\tprint this menu\n";
721
} // GPTDataTextUI::ShowRecoveryCommands()
723
// Accept an experts' menu command. Returns only after the user
724
// selects an exit command, such as 'w' or 'q'.
725
void GPTDataTextUI::ExpertsMenu(string filename) {
726
GPTData secondDevice;
727
uint32_t temp1, temp2;
729
string guidStr, device;
731
ostringstream prompt;
734
cout << "\nExpert command (? for help): ";
735
switch (ReadString()[0]) {
739
if (GetPartRange(&temp1, &temp2) > 0)
740
SetAttributes(GetPartNum());
742
cout << "No partitions\n";
748
cout << "Partitions will begin on " << GetAlignment()
749
<< "-sector boundaries.\n";
752
cout << "Relocating backup data structures to the end of the disk\n";
753
MoveSecondHeaderToEnd();
759
cout << "Enter the disk's unique GUID ('R' to randomize): ";
760
guidStr = ReadString();
761
if ((guidStr.length() >= 32) || (guidStr[0] == 'R') || (guidStr[0] == 'r')) {
762
SetDiskGUID((GUIDData) guidStr);
763
cout << "The new disk GUID is " << GetDiskGUID() << "\n";
765
cout << "GUID is too short!\n";
776
prompt << "Enter the sector alignment value (1-" << MAX_ALIGNMENT << ", default = "
777
<< DEFAULT_ALIGNMENT << "): ";
778
temp1 = GetNumber(1, MAX_ALIGNMENT, DEFAULT_ALIGNMENT, prompt.str());
798
RecoveryMenu(filename);
802
ResizePartitionTable();
808
cout << "Type device filename, or press <Enter> to exit: ";
809
device = ReadString();
810
if (device.length() > 0) {
811
secondDevice = *this;
812
secondDevice.SetDisk(device);
813
secondDevice.SaveGPTData(0);
820
if (SaveGPTData() == 1) {
825
if (DestroyGPTwPrompt() == 1) {
830
ShowExpertCommands();
834
} // GPTDataTextUI::ExpertsMenu()
836
void GPTDataTextUI::ShowExpertCommands(void) {
837
cout << "a\tset attributes\n";
838
cout << "c\tchange partition GUID\n";
839
cout << "d\tdisplay the sector alignment value\n";
840
cout << "e\trelocate backup data structures to the end of the disk\n";
841
cout << "g\tchange disk GUID\n";
842
cout << "h\trecompute CHS values in protective/hybrid MBR\n";
843
cout << "i\tshow detailed information on a partition\n";
844
cout << "l\tset the sector alignment value\n";
845
cout << "m\treturn to main menu\n";
846
cout << "n\tcreate a new protective MBR\n";
847
cout << "o\tprint protective MBR data\n";
848
cout << "p\tprint the partition table\n";
849
cout << "q\tquit without saving changes\n";
850
cout << "r\trecovery and transformation options (experts only)\n";
851
cout << "s\tresize partition table\n";
852
cout << "t\ttranspose two partition table entries\n";
853
cout << "u\tReplicate partition table on new device\n";
854
cout << "v\tverify disk\n";
855
cout << "w\twrite table to disk and exit\n";
856
cout << "z\tzap (destroy) GPT data structures and exit\n";
857
cout << "?\tprint this menu\n";
858
} // GPTDataTextUI::ShowExpertCommands()
862
/********************************
864
* Non-class support functions. *
866
********************************/
868
// GetMBRTypeCode() doesn't really belong in the class, since it's MBR-
869
// specific, but it's also user I/O-related, so I want to keep it in
872
// Get an MBR type code from the user and return it
873
int GetMBRTypeCode(int defType) {
877
cout.setf(ios::uppercase);
880
cout << "Enter an MBR hex code (default " << hex;
882
cout << defType << "): " << dec;
887
typeCode = StrToHex(line, 0);
888
} while ((typeCode <= 0) || (typeCode > 255));
893
// Note: ReadUString() is here rather than in support.cc so that the ICU
894
// libraries need not be linked to fixparts.
896
// Reads a Unicode string from stdin, returning it as an ICU-style string.
897
// Note that the returned string will NOT include the carriage return
898
// entered by the user. Relies on the ICU constructor from a string
899
// encoded in the current codepage to work.
900
UnicodeString ReadUString(void) {
901
return ReadString().c_str();