~ubuntu-branches/ubuntu/trusty/vboot-utils/trusty

« back to all changes in this revision

Viewing changes to cgpt/cmd_repair.c

  • Committer: Package Import Robot
  • Author(s): Antonio Terceiro
  • Date: 2012-12-16 11:03:40 UTC
  • Revision ID: package-import@ubuntu.com-20121216110340-f7wcseecbc9jed5l
Tags: upstream-0~20121212
ImportĀ upstreamĀ versionĀ 0~20121212

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 
2
// 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>
 
8
#include <string.h>
 
9
 
 
10
#include "cgpt_params.h"
 
11
 
 
12
static void Usage(void)
 
13
{
 
14
  printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n"
 
15
         "Repair damaged GPT headers and tables.\n\n"
 
16
         "Options:\n"
 
17
         "  -v           Verbose\n"
 
18
         "\n", progname);
 
19
}
 
20
 
 
21
int cmd_repair(int argc, char *argv[]) {
 
22
  CgptRepairParams params;
 
23
  memset(&params, 0, sizeof(params));
 
24
 
 
25
  int c;
 
26
  int errorcnt = 0;
 
27
 
 
28
  opterr = 0;                     // quiet, you
 
29
  while ((c=getopt(argc, argv, ":hv")) != -1)
 
30
  {
 
31
    switch (c)
 
32
    {
 
33
    case 'v':
 
34
      params.verbose++;
 
35
      break;
 
36
 
 
37
    case 'h':
 
38
      Usage();
 
39
      return CGPT_OK;
 
40
    case '?':
 
41
      Error("unrecognized option: -%c\n", optopt);
 
42
      errorcnt++;
 
43
      break;
 
44
    case ':':
 
45
      Error("missing argument to -%c\n", optopt);
 
46
      errorcnt++;
 
47
      break;
 
48
    default:
 
49
      errorcnt++;
 
50
      break;
 
51
    }
 
52
  }
 
53
  if (errorcnt)
 
54
  {
 
55
    Usage();
 
56
    return CGPT_FAILED;
 
57
  }
 
58
 
 
59
  params.drive_name = argv[optind];
 
60
 
 
61
  return cgpt_repair(&params);
 
62
}