blob: 5f85498298182a7109878fb025a40582c4d35827 [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;
Roderick W. Smitha9203982014-03-29 00:45:59 -040018 int isError = 0;
srs5694e7b4ff92009-08-18 13:16:10 -040019
Roderick W. Smithe62b5272014-03-28 23:58:06 -040020#ifndef EFI
srs5694fed16d02010-01-27 23:03:40 -050021 cout << "GPT fdisk (gdisk) version " << GPTFDISK_VERSION << "\n\n";
Roderick W. Smithe62b5272014-03-28 23:58:06 -040022#endif /*EFI*/
srs5694e7b4ff92009-08-18 13:16:10 -040023
srs569455d92612010-03-07 22:16:07 -050024 if (!SizesOK())
25 exit(1);
26
27 switch (argc) {
28 case 1:
srs569455d92612010-03-07 22:16:07 -050029 cout << "Type device filename, or press <Enter> to exit: ";
srs56945a608532011-03-17 13:53:01 -040030 device = ReadString();
31 if (device.length() == 0)
32 exit(0);
33 else if (theGPT.LoadPartitions(device)) {
srs569400b6d7a2011-06-26 22:40:06 -040034 if (theGPT.GetState() != use_gpt)
35 WinWarning();
srs5694a17fe692011-09-10 20:30:20 -040036 theGPT.MainMenu(device);
srs56945a608532011-03-17 13:53:01 -040037 } // if/elseif
srs569455d92612010-03-07 22:16:07 -050038 break;
39 case 2: // basic usage
srs569400b6d7a2011-06-26 22:40:06 -040040 if (theGPT.LoadPartitions(argv[1])) {
41 if (theGPT.GetState() != use_gpt)
42 WinWarning();
srs5694a17fe692011-09-10 20:30:20 -040043 theGPT.MainMenu(argv[1]);
srs569400b6d7a2011-06-26 22:40:06 -040044 } // if
srs569455d92612010-03-07 22:16:07 -050045 break;
46 case 3: // usage with "-l" option
srs5694e7b4ff92009-08-18 13:16:10 -040047 if (strcmp(argv[1], "-l") == 0) {
srs56945a608532011-03-17 13:53:01 -040048 device = (string) argv[2];
srs5694e7b4ff92009-08-18 13:16:10 -040049 } else if (strcmp(argv[2], "-l") == 0) {
srs56945a608532011-03-17 13:53:01 -040050 device = (string) argv[1];
srs5694e7b4ff92009-08-18 13:16:10 -040051 } else { // 3 arguments, but none is "-l"
srs5694fed16d02010-01-27 23:03:40 -050052 cerr << "Usage: " << argv[0] << " [-l] device_file\n";
Roderick W. Smitha9203982014-03-29 00:45:59 -040053 isError = 1;
srs5694e7b4ff92009-08-18 13:16:10 -040054 } // if/elseif/else
srs56945a608532011-03-17 13:53:01 -040055 if (device != "") {
srs56945d58fe02010-01-03 20:57:08 -050056 theGPT.JustLooking();
srs56945a608532011-03-17 13:53:01 -040057 if (theGPT.LoadPartitions(device))
srs569464cbd172011-03-01 22:03:54 -050058 theGPT.DisplayGPTData();
Roderick W. Smitha9203982014-03-29 00:45:59 -040059 else
60 isError = 1;
srs5694e7b4ff92009-08-18 13:16:10 -040061 } // if
srs569455d92612010-03-07 22:16:07 -050062 break;
63 default:
64 cerr << "Usage: " << argv[0] << " [-l] device_file\n";
Roderick W. Smitha9203982014-03-29 00:45:59 -040065 isError = 1;
srs569455d92612010-03-07 22:16:07 -050066 break;
67 } // switch
Roderick W. Smitha9203982014-03-29 00:45:59 -040068 return (isError);
Roderick W. Smith84aaff62014-02-17 16:17:11 -050069} // main