Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: cgpt/cmd_repair.c

Issue 2719008: Nearly complete rewrite of cgpt tool. (Closed) Base URL: ssh://git@chromiumos-git//vboot_reference.git
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cgpt/cmd_create.c ('k') | cgpt/cmd_show.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #include "cgptlib_internal.h"
13
14 static void Usage(void)
15 {
16 printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n"
17 "Repair damaged GPT headers and tables.\n\n"
18 "Options:\n"
19 " -v Verbose\n"
20 "\n", progname);
21 }
22
23 int cmd_repair(int argc, char *argv[]) {
24 struct drive drive;
25 int verbose = 0;
26
27 int c;
28 int errorcnt = 0;
29
30 opterr = 0; // quiet, you
31 while ((c=getopt(argc, argv, ":hv")) != -1)
32 {
33 switch (c)
34 {
35 case 'v':
36 verbose++;
37 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 Error("missing drive argument\n");
63 return CGPT_FAILED;
64 }
65
66 if (CGPT_OK != DriveOpen(argv[optind], &drive))
67 return CGPT_FAILED;
68
69 int gpt_retval = GptSanityCheck(&drive.gpt);
70 if (verbose)
71 printf("GptSanityCheck() returned %d: %s\n",
72 gpt_retval, GptError(gpt_retval));
73
74 GptRepair(&drive.gpt);
75 if (drive.gpt.modified & GPT_MODIFIED_HEADER1)
76 printf("Primary Header is updated.\n");
77 if (drive.gpt.modified & GPT_MODIFIED_ENTRIES1)
78 printf("Primary Entries is updated.\n");
79 if (drive.gpt.modified & GPT_MODIFIED_ENTRIES2)
80 printf("Secondary Entries is updated.\n");
81 if (drive.gpt.modified & GPT_MODIFIED_HEADER2)
82 printf("Secondary Header is updated.\n");
83
84 return DriveClose(&drive, 1);
85 }
OLDNEW
« no previous file with comments | « cgpt/cmd_create.c ('k') | cgpt/cmd_show.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698