• 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 
main(int argc,char * argv[])14 int main(int argc, char* argv[]) {
15    GPTDataTextUI theGPT;
16    string device = "";
17    UnicodeString uString;
18    int isError = 0;
19 
20 #ifndef EFI
21    cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n";
22 #endif /*EFI*/
23 
24    if (!SizesOK())
25       exit(1);
26 
27    switch (argc) {
28       case 1:
29          cout << "Type device filename, or press <Enter> to exit: ";
30          device = ReadString();
31          if (device.length() == 0)
32             exit(0);
33          else if (theGPT.LoadPartitions(device)) {
34             if (theGPT.GetState() != use_gpt)
35                WinWarning();
36             theGPT.MainMenu(device);
37          } // if/elseif
38          break;
39       case 2: // basic usage
40          if (theGPT.LoadPartitions(argv[1])) {
41             if (theGPT.GetState() != use_gpt)
42                WinWarning();
43             theGPT.MainMenu(argv[1]);
44          } // if
45          break;
46       case 3: // usage with "-l" option
47          if (strcmp(argv[1], "-l") == 0) {
48             device = (string) argv[2];
49          } else if (strcmp(argv[2], "-l") == 0) {
50             device = (string) argv[1];
51          } else { // 3 arguments, but none is "-l"
52             cerr << "Usage: " << argv[0] << " [-l] device_file\n";
53             isError = 1;
54          } // if/elseif/else
55          if (device != "") {
56             theGPT.JustLooking();
57             if (theGPT.LoadPartitions(device))
58                theGPT.DisplayGPTData();
59             else
60                isError = 1;
61          } // if
62          break;
63       default:
64          cerr << "Usage: " << argv[0] << " [-l] device_file\n";
65          isError = 1;
66          break;
67    } // switch
68    return (isError);
69 } // main
70