Files
OpenCellular/cgpt/cmd_repair.c
Mike Frysinger c60eb7e735 cgpt: unify cli int parsing error checking
Most of the cmd funcs had the same logic copied & pasted multiple times
over.  Unify them into a common header.

BUG=chromium:644845
TEST=precq passes
TEST=passing invalid args to some funcs is caught
BRANCH=None

Change-Id: Ib7212bcbb17da1135b2508a52910aac37ee8e6cd
Reviewed-on: https://chromium-review.googlesource.com/382691
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2016-09-08 06:14:45 -07:00

72 lines
1.5 KiB
C

// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <getopt.h>
#include <string.h>
#include "cgpt.h"
#include "vboot_host.h"
extern const char* progname;
static void Usage(void)
{
printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n"
"Repair damaged GPT headers and tables.\n\n"
"Options:\n"
" -D NUM Size (in bytes) of the disk where partitions reside\n"
" default 0, meaning partitions and GPT structs are\n"
" both on DRIVE\n"
" -v Verbose\n"
"\n", progname);
}
int cmd_repair(int argc, char *argv[]) {
CgptRepairParams params;
memset(&params, 0, sizeof(params));
int c;
char* e = 0;
int errorcnt = 0;
opterr = 0; // quiet, you
while ((c=getopt(argc, argv, ":hvD:")) != -1)
{
switch (c)
{
case 'D':
params.drive_size = strtoull(optarg, &e, 0);
errorcnt += check_int_parse(c, e);
break;
case 'v':
params.verbose++;
break;
case 'h':
Usage();
return CGPT_OK;
case '?':
Error("unrecognized option: -%c\n", optopt);
errorcnt++;
break;
case ':':
Error("missing argument to -%c\n", optopt);
errorcnt++;
break;
default:
errorcnt++;
break;
}
}
if (errorcnt)
{
Usage();
return CGPT_FAILED;
}
params.drive_name = argv[optind];
return CgptRepair(&params);
}