blob: 8cd47a847d1edbd0613694801ae4ba733dbec7dd [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
srs5694fed16d02010-01-27 23:03:40 -050019 cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n";
srs5694e7b4ff92009-08-18 13:16:10 -040020
srs569455d92612010-03-07 22:16:07 -050021 if (!SizesOK())
22 exit(1);
23
24 switch (argc) {
25 case 1:
srs569455d92612010-03-07 22:16:07 -050026 cout << "Type device filename, or press <Enter> to exit: ";
srs56945a608532011-03-17 13:53:01 -040027 device = ReadString();
28 if (device.length() == 0)
29 exit(0);
30 else if (theGPT.LoadPartitions(device)) {
srs569400b6d7a2011-06-26 22:40:06 -040031 if (theGPT.GetState() != use_gpt)
32 WinWarning();
srs5694a17fe692011-09-10 20:30:20 -040033 theGPT.MainMenu(device);
srs56945a608532011-03-17 13:53:01 -040034 } // if/elseif
srs569455d92612010-03-07 22:16:07 -050035 break;
36 case 2: // basic usage
srs569400b6d7a2011-06-26 22:40:06 -040037 if (theGPT.LoadPartitions(argv[1])) {
38 if (theGPT.GetState() != use_gpt)
39 WinWarning();
srs5694a17fe692011-09-10 20:30:20 -040040 theGPT.MainMenu(argv[1]);
srs569400b6d7a2011-06-26 22:40:06 -040041 } // if
srs569455d92612010-03-07 22:16:07 -050042 break;
43 case 3: // usage with "-l" option
srs5694e7b4ff92009-08-18 13:16:10 -040044 if (strcmp(argv[1], "-l") == 0) {
srs56945a608532011-03-17 13:53:01 -040045 device = (string) argv[2];
srs5694e7b4ff92009-08-18 13:16:10 -040046 } else if (strcmp(argv[2], "-l") == 0) {
srs56945a608532011-03-17 13:53:01 -040047 device = (string) argv[1];
srs5694e7b4ff92009-08-18 13:16:10 -040048 } else { // 3 arguments, but none is "-l"
srs5694fed16d02010-01-27 23:03:40 -050049 cerr << "Usage: " << argv[0] << " [-l] device_file\n";
srs5694e7b4ff92009-08-18 13:16:10 -040050 } // if/elseif/else
srs56945a608532011-03-17 13:53:01 -040051 if (device != "") {
srs56945d58fe02010-01-03 20:57:08 -050052 theGPT.JustLooking();
srs56945a608532011-03-17 13:53:01 -040053 if (theGPT.LoadPartitions(device))
srs569464cbd172011-03-01 22:03:54 -050054 theGPT.DisplayGPTData();
srs5694e7b4ff92009-08-18 13:16:10 -040055 } // if
srs569455d92612010-03-07 22:16:07 -050056 break;
57 default:
58 cerr << "Usage: " << argv[0] << " [-l] device_file\n";
59 break;
60 } // switch
srs5694a17fe692011-09-10 20:30:20 -040061} // main