1*57696d54SAkhilesh Sanikop // gdisk.cc 2*57696d54SAkhilesh Sanikop // Program modelled after Linux fdisk, but it manipulates GPT partitions 3*57696d54SAkhilesh Sanikop // rather than MBR partitions. 4*57696d54SAkhilesh Sanikop // 5*57696d54SAkhilesh Sanikop // by Rod Smith, project began February 2009 6*57696d54SAkhilesh Sanikop 7*57696d54SAkhilesh Sanikop /* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed 8*57696d54SAkhilesh Sanikop under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ 9*57696d54SAkhilesh Sanikop 10*57696d54SAkhilesh Sanikop #include <string.h> 11*57696d54SAkhilesh Sanikop #include <iostream> 12*57696d54SAkhilesh Sanikop #include "gpttext.h" 13*57696d54SAkhilesh Sanikop 14*57696d54SAkhilesh Sanikop using namespace std; 15*57696d54SAkhilesh Sanikop main(int argc,char * argv[])16*57696d54SAkhilesh Sanikopint main(int argc, char* argv[]) { 17*57696d54SAkhilesh Sanikop GPTDataTextUI theGPT; 18*57696d54SAkhilesh Sanikop string device = ""; 19*57696d54SAkhilesh Sanikop UnicodeString uString; 20*57696d54SAkhilesh Sanikop int isError = 0; 21*57696d54SAkhilesh Sanikop 22*57696d54SAkhilesh Sanikop #ifndef EFI 23*57696d54SAkhilesh Sanikop cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n"; 24*57696d54SAkhilesh Sanikop #endif /*EFI*/ 25*57696d54SAkhilesh Sanikop 26*57696d54SAkhilesh Sanikop if (!SizesOK()) 27*57696d54SAkhilesh Sanikop exit(1); 28*57696d54SAkhilesh Sanikop 29*57696d54SAkhilesh Sanikop switch (argc) { 30*57696d54SAkhilesh Sanikop case 1: 31*57696d54SAkhilesh Sanikop cout << "Type device filename, or press <Enter> to exit: "; 32*57696d54SAkhilesh Sanikop device = ReadString(); 33*57696d54SAkhilesh Sanikop if (device.length() == 0) 34*57696d54SAkhilesh Sanikop exit(0); 35*57696d54SAkhilesh Sanikop else if (theGPT.LoadPartitions(device)) { 36*57696d54SAkhilesh Sanikop if (theGPT.GetState() != use_gpt) 37*57696d54SAkhilesh Sanikop WinWarning(); 38*57696d54SAkhilesh Sanikop theGPT.MainMenu(device); 39*57696d54SAkhilesh Sanikop } // if/elseif 40*57696d54SAkhilesh Sanikop break; 41*57696d54SAkhilesh Sanikop case 2: // basic usage 42*57696d54SAkhilesh Sanikop if (theGPT.LoadPartitions(argv[1])) { 43*57696d54SAkhilesh Sanikop if (theGPT.GetState() != use_gpt) 44*57696d54SAkhilesh Sanikop WinWarning(); 45*57696d54SAkhilesh Sanikop theGPT.MainMenu(argv[1]); 46*57696d54SAkhilesh Sanikop } // if 47*57696d54SAkhilesh Sanikop break; 48*57696d54SAkhilesh Sanikop case 3: // usage with "-l" option 49*57696d54SAkhilesh Sanikop if (strcmp(argv[1], "-l") == 0) { 50*57696d54SAkhilesh Sanikop device = (string) argv[2]; 51*57696d54SAkhilesh Sanikop } else if (strcmp(argv[2], "-l") == 0) { 52*57696d54SAkhilesh Sanikop device = (string) argv[1]; 53*57696d54SAkhilesh Sanikop } else { // 3 arguments, but none is "-l" 54*57696d54SAkhilesh Sanikop cerr << "Usage: " << argv[0] << " [-l] device_file\n"; 55*57696d54SAkhilesh Sanikop isError = 1; 56*57696d54SAkhilesh Sanikop } // if/elseif/else 57*57696d54SAkhilesh Sanikop if (device != "") { 58*57696d54SAkhilesh Sanikop theGPT.JustLooking(); 59*57696d54SAkhilesh Sanikop if (theGPT.LoadPartitions(device)) 60*57696d54SAkhilesh Sanikop theGPT.DisplayGPTData(); 61*57696d54SAkhilesh Sanikop else 62*57696d54SAkhilesh Sanikop isError = 1; 63*57696d54SAkhilesh Sanikop } // if 64*57696d54SAkhilesh Sanikop break; 65*57696d54SAkhilesh Sanikop default: 66*57696d54SAkhilesh Sanikop cerr << "Usage: " << argv[0] << " [-l] device_file\n"; 67*57696d54SAkhilesh Sanikop isError = 1; 68*57696d54SAkhilesh Sanikop break; 69*57696d54SAkhilesh Sanikop } // switch 70*57696d54SAkhilesh Sanikop return (isError); 71*57696d54SAkhilesh Sanikop } // main 72