blob: 1e081f8ce5d059701d702daef0b1e922446dddd9 [file] [log] [blame]
Jay Srinivasana0581432012-01-26 21:50:05 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Bill Richardsonf1372d92010-06-11 09:15:55 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "cgpt.h"
6
7#include <getopt.h>
Bill Richardsonf1372d92010-06-11 09:15:55 -07008#include <string.h>
Bill Richardsonf1372d92010-06-11 09:15:55 -07009
Jay Srinivasana0581432012-01-26 21:50:05 -080010#include "cgpt_params.h"
Bill Richardsonf1372d92010-06-11 09:15:55 -070011
12static void Usage(void)
13{
14 printf("\nUsage: %s create [OPTIONS] DRIVE\n\n"
15 "Create or reset an empty GPT.\n\n"
16 "Options:\n"
17 " -z Zero the sectors of the GPT table and entries\n"
18 "\n", progname);
19}
20
21int cmd_create(int argc, char *argv[]) {
22 struct drive drive;
Jay Srinivasana0581432012-01-26 21:50:05 -080023
24 CgptCreateParams params;
25 memset(&params, 0, sizeof(params));
Bill Richardsonc4e92af2010-10-12 07:33:15 -070026
Bill Richardsonf1372d92010-06-11 09:15:55 -070027 int c;
28 int errorcnt = 0;
29
30 opterr = 0; // quiet, you
31 while ((c=getopt(argc, argv, ":hz")) != -1)
32 {
33 switch (c)
34 {
35 case 'z':
Jay Srinivasana0581432012-01-26 21:50:05 -080036 params.zap = 1;
Bill Richardsonf1372d92010-06-11 09:15:55 -070037 break;
38
39 case 'h':
40 Usage();
41 return CGPT_OK;
42 case '?':
43 Error("unrecognized option: -%c\n", optopt);
44 errorcnt++;
45 break;
46 case ':':
47 Error("missing argument to -%c\n", optopt);
48 errorcnt++;
49 break;
50 default:
51 errorcnt++;
52 break;
53 }
54 }
55 if (errorcnt)
56 {
57 Usage();
58 return CGPT_FAILED;
59 }
60
61 if (optind >= argc) {
62 Usage();
63 return CGPT_FAILED;
64 }
65
Jay Srinivasana0581432012-01-26 21:50:05 -080066 params.driveName = argv[optind];
Bill Richardsonf1372d92010-06-11 09:15:55 -070067
Jay Srinivasana0581432012-01-26 21:50:05 -080068 return cgpt_create(&params);
Bill Richardsonf1372d92010-06-11 09:15:55 -070069}