494
494
return protectiveMBR.DoMenu();
495
495
} // GPTDataTextUI::XFormToMBR()
498
/*********************************************************************
500
* The following functions provide the main menus for the gdisk *
503
*********************************************************************/
505
// Accept a command and execute it. Returns only when the user
506
// wants to exit (such as after a 'w' or 'q' command).
507
void GPTDataTextUI::MainMenu(string filename) {
510
uint32_t temp1, temp2;
513
cout << "\nCommand (? for help): ";
514
switch (ReadString()[0]) {
518
cout << "Enter backup filename to save: ";
519
SaveGPTBackup(ReadString());
522
if (GetPartRange(&temp1, &temp2) > 0)
523
SetName(GetPartNum());
525
cout << "No partitions\n";
534
typeHelper.ShowAllTypes();
540
cout << "This option deletes all partitions and creates a new protective MBR.\n"
542
if (GetYN() == 'Y') {
554
RecoveryMenu(filename);
559
cout << "You may need to edit /etc/fstab and/or your boot loader configuration!\n";
568
if (SaveGPTData() == 1)
572
ExpertsMenu(filename);
580
} // GPTDataTextUI::MainMenu()
582
void GPTDataTextUI::ShowCommands(void) {
583
cout << "b\tback up GPT data to a file\n";
584
cout << "c\tchange a partition's name\n";
585
cout << "d\tdelete a partition\n";
586
cout << "i\tshow detailed information on a partition\n";
587
cout << "l\tlist known partition types\n";
588
cout << "n\tadd a new partition\n";
589
cout << "o\tcreate a new empty GUID partition table (GPT)\n";
590
cout << "p\tprint the partition table\n";
591
cout << "q\tquit without saving changes\n";
592
cout << "r\trecovery and transformation options (experts only)\n";
593
cout << "s\tsort partitions\n";
594
cout << "t\tchange a partition's type code\n";
595
cout << "v\tverify disk\n";
596
cout << "w\twrite table to disk and exit\n";
597
cout << "x\textra functionality (experts only)\n";
598
cout << "?\tprint this menu\n";
599
} // GPTDataTextUI::ShowCommands()
601
// Accept a recovery & transformation menu command. Returns only when the user
602
// issues an exit command, such as 'w' or 'q'.
603
void GPTDataTextUI::RecoveryMenu(string filename) {
608
cout << "\nRecovery/transformation command (? for help): ";
609
switch (ReadString()[0]) {
616
cout << "Warning! This will probably do weird things if you've converted an MBR to\n"
617
<< "GPT form and haven't yet saved the GPT! Proceed? ";
619
LoadSecondTableAsMain();
622
RebuildSecondHeader();
625
cout << "Warning! This will probably do weird things if you've converted an MBR to\n"
626
<< "GPT form and haven't yet saved the GPT! Proceed? ";
631
cout << "Warning! This will destroy the currently defined partitions! Proceed? ";
632
if (GetYN() == 'Y') {
633
if (LoadMBR(filename) == 1) { // successful load
636
cout << "Problem loading MBR! GPT is untouched; regenerating protective MBR!\n";
642
numParts = GetNumParts();
643
temp1 = XFormToMBR();
645
cout << "\nConverted " << temp1 << " partitions. Finalize and exit? ";
646
if ((temp1 > 0) && (GetYN() == 'Y')) {
647
if ((DestroyGPT() > 0) && (SaveMBR())) {
652
SetGPTSize(numParts);
653
cout << "Note: New protective MBR created\n\n";
663
cout << "Enter backup filename to load: ";
664
LoadGPTBackup(ReadString());
686
if (SaveGPTData() == 1) {
691
ExpertsMenu(filename);
695
ShowRecoveryCommands();
699
} // GPTDataTextUI::RecoveryMenu()
701
void GPTDataTextUI::ShowRecoveryCommands(void) {
702
cout << "b\tuse backup GPT header (rebuilding main)\n";
703
cout << "c\tload backup partition table from disk (rebuilding main)\n";
704
cout << "d\tuse main GPT header (rebuilding backup)\n";
705
cout << "e\tload main partition table from disk (rebuilding backup)\n";
706
cout << "f\tload MBR and build fresh GPT from it\n";
707
cout << "g\tconvert GPT into MBR and exit\n";
708
cout << "h\tmake hybrid MBR\n";
709
cout << "i\tshow detailed information on a partition\n";
710
cout << "l\tload partition data from a backup file\n";
711
cout << "m\treturn to main menu\n";
712
cout << "o\tprint protective MBR data\n";
713
cout << "p\tprint the partition table\n";
714
cout << "q\tquit without saving changes\n";
715
cout << "t\ttransform BSD disklabel partition\n";
716
cout << "v\tverify disk\n";
717
cout << "w\twrite table to disk and exit\n";
718
cout << "x\textra functionality (experts only)\n";
719
cout << "?\tprint this menu\n";
720
} // GPTDataTextUI::ShowRecoveryCommands()
722
// Accept an experts' menu command. Returns only after the user
723
// selects an exit command, such as 'w' or 'q'.
724
void GPTDataTextUI::ExpertsMenu(string filename) {
725
GPTData secondDevice;
726
uint32_t temp1, temp2;
728
string guidStr, device;
730
ostringstream prompt;
733
cout << "\nExpert command (? for help): ";
734
switch (ReadString()[0]) {
738
if (GetPartRange(&temp1, &temp2) > 0)
739
SetAttributes(GetPartNum());
741
cout << "No partitions\n";
747
cout << "Partitions will begin on " << GetAlignment()
748
<< "-sector boundaries.\n";
751
cout << "Relocating backup data structures to the end of the disk\n";
752
MoveSecondHeaderToEnd();
758
cout << "Enter the disk's unique GUID ('R' to randomize): ";
759
guidStr = ReadString();
760
if ((guidStr.length() >= 32) || (guidStr[0] == 'R') || (guidStr[0] == 'r')) {
761
SetDiskGUID((GUIDData) guidStr);
762
cout << "The new disk GUID is " << GetDiskGUID() << "\n";
764
cout << "GUID is too short!\n";
775
prompt << "Enter the sector alignment value (1-" << MAX_ALIGNMENT << ", default = "
776
<< DEFAULT_ALIGNMENT << "): ";
777
temp1 = GetNumber(1, MAX_ALIGNMENT, DEFAULT_ALIGNMENT, prompt.str());
797
RecoveryMenu(filename);
801
ResizePartitionTable();
807
cout << "Type device filename, or press <Enter> to exit: ";
808
device = ReadString();
809
if (device.length() > 0) {
810
secondDevice = *this;
811
secondDevice.SetDisk(device);
812
secondDevice.SaveGPTData(0);
819
if (SaveGPTData() == 1) {
824
if (DestroyGPTwPrompt() == 1) {
829
ShowExpertCommands();
833
} // GPTDataTextUI::ExpertsMenu()
835
void GPTDataTextUI::ShowExpertCommands(void) {
836
cout << "a\tset attributes\n";
837
cout << "c\tchange partition GUID\n";
838
cout << "d\tdisplay the sector alignment value\n";
839
cout << "e\trelocate backup data structures to the end of the disk\n";
840
cout << "g\tchange disk GUID\n";
841
cout << "h\trecompute CHS values in protective/hybrid MBR\n";
842
cout << "i\tshow detailed information on a partition\n";
843
cout << "l\tset the sector alignment value\n";
844
cout << "m\treturn to main menu\n";
845
cout << "n\tcreate a new protective MBR\n";
846
cout << "o\tprint protective MBR data\n";
847
cout << "p\tprint the partition table\n";
848
cout << "q\tquit without saving changes\n";
849
cout << "r\trecovery and transformation options (experts only)\n";
850
cout << "s\tresize partition table\n";
851
cout << "t\ttranspose two partition table entries\n";
852
cout << "u\tReplicate partition table on new device\n";
853
cout << "v\tverify disk\n";
854
cout << "w\twrite table to disk and exit\n";
855
cout << "z\tzap (destroy) GPT data structures and exit\n";
856
cout << "?\tprint this menu\n";
857
} // GPTDataTextUI::ShowExpertCommands()
497
861
/********************************
499
863
* Non-class support functions. *