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 | |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 7 | /* This program is copyright (c) 2009-2013 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; | ||||
Roderick W. Smith | a920398 | 2014-03-29 00:45:59 -0400 | [diff] [blame] | 18 | int isError = 0; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 19 | |
Roderick W. Smith | e62b527 | 2014-03-28 23:58:06 -0400 | [diff] [blame] | 20 | #ifndef EFI |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 21 | cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n"; |
Roderick W. Smith | e62b527 | 2014-03-28 23:58:06 -0400 | [diff] [blame] | 22 | #endif /*EFI*/ |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 23 | |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 24 | if (!SizesOK()) |
25 | exit(1); | ||||
26 | |||||
27 | switch (argc) { | ||||
28 | case 1: | ||||
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 29 | cout << "Type device filename, or press <Enter> to exit: "; |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 30 | device = ReadString(); |
31 | if (device.length() == 0) | ||||
32 | exit(0); | ||||
33 | else if (theGPT.LoadPartitions(device)) { | ||||
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 34 | if (theGPT.GetState() != use_gpt) |
35 | WinWarning(); | ||||
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 36 | theGPT.MainMenu(device); |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 37 | } // if/elseif |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 38 | break; |
39 | case 2: // basic usage | ||||
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 40 | if (theGPT.LoadPartitions(argv[1])) { |
41 | if (theGPT.GetState() != use_gpt) | ||||
42 | WinWarning(); | ||||
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 43 | theGPT.MainMenu(argv[1]); |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 44 | } // if |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 45 | break; |
46 | case 3: // usage with "-l" option | ||||
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 47 | if (strcmp(argv[1], "-l") == 0) { |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 48 | device = (string) argv[2]; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 49 | } else if (strcmp(argv[2], "-l") == 0) { |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 50 | device = (string) argv[1]; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 51 | } else { // 3 arguments, but none is "-l" |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 52 | cerr << "Usage: " << argv[0] << " [-l] device_file\n"; |
Roderick W. Smith | a920398 | 2014-03-29 00:45:59 -0400 | [diff] [blame] | 53 | isError = 1; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 54 | } // if/elseif/else |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 55 | if (device != "") { |
srs5694 | 5d58fe0 | 2010-01-03 20:57:08 -0500 | [diff] [blame] | 56 | theGPT.JustLooking(); |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 57 | if (theGPT.LoadPartitions(device)) |
srs5694 | 64cbd17 | 2011-03-01 22:03:54 -0500 | [diff] [blame] | 58 | theGPT.DisplayGPTData(); |
Roderick W. Smith | a920398 | 2014-03-29 00:45:59 -0400 | [diff] [blame] | 59 | else |
60 | isError = 1; | ||||
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 61 | } // if |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 62 | break; |
63 | default: | ||||
64 | cerr << "Usage: " << argv[0] << " [-l] device_file\n"; | ||||
Roderick W. Smith | a920398 | 2014-03-29 00:45:59 -0400 | [diff] [blame] | 65 | isError = 1; |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 66 | break; |
67 | } // switch | ||||
Roderick W. Smith | a920398 | 2014-03-29 00:45:59 -0400 | [diff] [blame] | 68 | return (isError); |
Roderick W. Smith | 84aaff6 | 2014-02-17 16:17:11 -0500 | [diff] [blame] | 69 | } // main |