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