mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 18:25:10 +00:00
This fixes a number of bugs, adds a bunch of commands, and essentially makes cgpt ready to use as a replacement for gpt. Still to do is to add commands and options that will let it generated intentionally bad partitions, for use in testing. Review URL: http://codereview.chromium.org/2719008
86 lines
1.9 KiB
C
86 lines
1.9 KiB
C
// Copyright (c) 2010 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 "cgpt.h"
|
|
|
|
#include <getopt.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "cgptlib_internal.h"
|
|
|
|
static void Usage(void)
|
|
{
|
|
printf("\nUsage: %s repair [OPTIONS] DRIVE\n\n"
|
|
"Repair damaged GPT headers and tables.\n\n"
|
|
"Options:\n"
|
|
" -v Verbose\n"
|
|
"\n", progname);
|
|
}
|
|
|
|
int cmd_repair(int argc, char *argv[]) {
|
|
struct drive drive;
|
|
int verbose = 0;
|
|
|
|
int c;
|
|
int errorcnt = 0;
|
|
|
|
opterr = 0; // quiet, you
|
|
while ((c=getopt(argc, argv, ":hv")) != -1)
|
|
{
|
|
switch (c)
|
|
{
|
|
case 'v':
|
|
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;
|
|
}
|
|
|
|
if (optind >= argc) {
|
|
Error("missing drive argument\n");
|
|
return CGPT_FAILED;
|
|
}
|
|
|
|
if (CGPT_OK != DriveOpen(argv[optind], &drive))
|
|
return CGPT_FAILED;
|
|
|
|
int gpt_retval = GptSanityCheck(&drive.gpt);
|
|
if (verbose)
|
|
printf("GptSanityCheck() returned %d: %s\n",
|
|
gpt_retval, GptError(gpt_retval));
|
|
|
|
GptRepair(&drive.gpt);
|
|
if (drive.gpt.modified & GPT_MODIFIED_HEADER1)
|
|
printf("Primary Header is updated.\n");
|
|
if (drive.gpt.modified & GPT_MODIFIED_ENTRIES1)
|
|
printf("Primary Entries is updated.\n");
|
|
if (drive.gpt.modified & GPT_MODIFIED_ENTRIES2)
|
|
printf("Secondary Entries is updated.\n");
|
|
if (drive.gpt.modified & GPT_MODIFIED_HEADER2)
|
|
printf("Secondary Header is updated.\n");
|
|
|
|
return DriveClose(&drive, 1);
|
|
}
|