blob: a6ea2e9d105822c81657b756487d24e08615ba5f [file] [log] [blame]
srs5694e7b4ff92009-08-18 13:16:10 -04001// gdisk.cc
2// Program modelled after Linux fdisk, but it manipulates GPT partitions
3// rather than MBR partitions.
4//
srs5694e4ac11e2009-08-31 10:13:04 -04005// by Rod Smith, project began February 2009
srs5694e7b4ff92009-08-18 13:16:10 -04006
Roderick W. Smithe3ee7332013-09-24 12:56:11 -04007/* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed
srs5694221e0872009-08-29 15:00:31 -04008 under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
9
srs5694fed16d02010-01-27 23:03:40 -050010#include <string.h>
srs5694fed16d02010-01-27 23:03:40 -050011#include <iostream>
srs569408bb0da2010-02-19 17:19:55 -050012#include "gpttext.h"
srs5694e7b4ff92009-08-18 13:16:10 -040013
14int main(int argc, char* argv[]) {
srs569408bb0da2010-02-19 17:19:55 -050015 GPTDataTextUI theGPT;
srs56945a608532011-03-17 13:53:01 -040016 string device = "";
17 UnicodeString uString;
srs5694e7b4ff92009-08-18 13:16:10 -040018
Roderick W. Smithe62b5272014-03-28 23:58:06 -040019#ifndef EFI
srs5694fed16d02010-01-27 23:03:40 -050020 cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n";
Roderick W. Smithe62b5272014-03-28 23:58:06 -040021#endif /*EFI*/
srs5694e7b4ff92009-08-18 13:16:10 -040022
srs569455d92612010-03-07 22:16:07 -050023 if (!SizesOK())
24 exit(1);
25
26 switch (argc) {
27 case 1:
srs569455d92612010-03-07 22:16:07 -050028 cout << "Type device filename, or press <Enter> to exit: ";
srs56945a608532011-03-17 13:53:01 -040029 device = ReadString();
30 if (device.length() == 0)
31 exit(0);
32 else if (theGPT.LoadPartitions(device)) {
srs569400b6d7a2011-06-26 22:40:06 -040033 if (theGPT.GetState() != use_gpt)
34 WinWarning();
srs5694a17fe692011-09-10 20:30:20 -040035 theGPT.MainMenu(device);
srs56945a608532011-03-17 13:53:01 -040036 } // if/elseif
srs569455d92612010-03-07 22:16:07 -050037 break;
38 case 2: // basic usage
srs569400b6d7a2011-06-26 22:40:06 -040039 if (theGPT.LoadPartitions(argv[1])) {
40 if (theGPT.GetState() != use_gpt)
41 WinWarning();
srs5694a17fe692011-09-10 20:30:20 -040042 theGPT.MainMenu(argv[1]);
srs569400b6d7a2011-06-26 22:40:06 -040043 } // if
srs569455d92612010-03-07 22:16:07 -050044 break;
45 case 3: // usage with "-l" option
srs5694e7b4ff92009-08-18 13:16:10 -040046 if (strcmp(argv[1], "-l") == 0) {
srs56945a608532011-03-17 13:53:01 -040047 device = (string) argv[2];
srs5694e7b4ff92009-08-18 13:16:10 -040048 } else if (strcmp(argv[2], "-l") == 0) {
srs56945a608532011-03-17 13:53:01 -040049 device = (string) argv[1];
srs5694e7b4ff92009-08-18 13:16:10 -040050 } else { // 3 arguments, but none is "-l"
srs5694fed16d02010-01-27 23:03:40 -050051 cerr << "Usage: " << argv[0] << " [-l] device_file\n";
srs5694e7b4ff92009-08-18 13:16:10 -040052 } // if/elseif/else
srs56945a608532011-03-17 13:53:01 -040053 if (device != "") {
srs56945d58fe02010-01-03 20:57:08 -050054 theGPT.JustLooking();
srs56945a608532011-03-17 13:53:01 -040055 if (theGPT.LoadPartitions(device))
srs569464cbd172011-03-01 22:03:54 -050056 theGPT.DisplayGPTData();
srs5694e7b4ff92009-08-18 13:16:10 -040057 } // if
srs569455d92612010-03-07 22:16:07 -050058 break;
59 default:
60 cerr << "Usage: " << argv[0] << " [-l] device_file\n";
61 break;
62 } // switch
Roderick W. Smith84aaff62014-02-17 16:17:11 -050063 return 1 ;
64} // main