srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 1 | // gdisk.cc |
2 | // Program modelled after Linux fdisk, but it manipulates GPT partitions | ||||
3 | // rather than MBR partitions. | ||||
4 | // | ||||
srs5694 | e4ac11e | 2009-08-31 10:13:04 -0400 | [diff] [blame] | 5 | // by Rod Smith, project began February 2009 |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 6 | |
srs5694 | 64cbd17 | 2011-03-01 22:03:54 -0500 | [diff] [blame] | 7 | /* This program is copyright (c) 2009-2011 by Roderick W. Smith. It is distributed |
srs5694 | 221e087 | 2009-08-29 15:00:31 -0400 | [diff] [blame] | 8 | under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ |
9 | |||||
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 10 | #include <string.h> |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 11 | #include <iostream> |
srs5694 | 08bb0da | 2010-02-19 17:19:55 -0500 | [diff] [blame] | 12 | #include "gpttext.h" |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 13 | |
14 | int main(int argc, char* argv[]) { | ||||
srs5694 | 08bb0da | 2010-02-19 17:19:55 -0500 | [diff] [blame] | 15 | GPTDataTextUI theGPT; |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 16 | string device = ""; |
17 | UnicodeString uString; | ||||
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 18 | |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 19 | cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n"; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 20 | |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 21 | if (!SizesOK()) |
22 | exit(1); | ||||
23 | |||||
24 | switch (argc) { | ||||
25 | case 1: | ||||
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 26 | cout << "Type device filename, or press <Enter> to exit: "; |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 27 | device = ReadString(); |
28 | if (device.length() == 0) | ||||
29 | exit(0); | ||||
30 | else if (theGPT.LoadPartitions(device)) { | ||||
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 31 | if (theGPT.GetState() != use_gpt) |
32 | WinWarning(); | ||||
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 33 | theGPT.MainMenu(device); |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 34 | } // if/elseif |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 35 | break; |
36 | case 2: // basic usage | ||||
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 37 | if (theGPT.LoadPartitions(argv[1])) { |
38 | if (theGPT.GetState() != use_gpt) | ||||
39 | WinWarning(); | ||||
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 40 | theGPT.MainMenu(argv[1]); |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 41 | } // if |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 42 | break; |
43 | case 3: // usage with "-l" option | ||||
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 44 | if (strcmp(argv[1], "-l") == 0) { |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 45 | device = (string) argv[2]; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 46 | } else if (strcmp(argv[2], "-l") == 0) { |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 47 | device = (string) argv[1]; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 48 | } else { // 3 arguments, but none is "-l" |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 49 | cerr << "Usage: " << argv[0] << " [-l] device_file\n"; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 50 | } // if/elseif/else |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 51 | if (device != "") { |
srs5694 | 5d58fe0 | 2010-01-03 20:57:08 -0500 | [diff] [blame] | 52 | theGPT.JustLooking(); |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 53 | if (theGPT.LoadPartitions(device)) |
srs5694 | 64cbd17 | 2011-03-01 22:03:54 -0500 | [diff] [blame] | 54 | theGPT.DisplayGPTData(); |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 55 | } // if |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 56 | break; |
57 | default: | ||||
58 | cerr << "Usage: " << argv[0] << " [-l] device_file\n"; | ||||
59 | break; | ||||
60 | } // switch | ||||
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 61 | } // main |