summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_repair.c
diff options
context:
space:
mode:
authorJay Srinivasan <jaysri@chromium.org>2012-01-26 21:50:05 -0800
committerGerrit <chrome-bot@google.com>2012-01-30 19:17:51 -0800
commita05814398202c4147a5e3f28474830ec0a9a0a90 (patch)
tree1273de56f9adbce9a2ab54bc1d74ac655e2f517b /cgpt/cgpt_repair.c
parentee2e590ff0db1f0a0c5f6a8122d7c090ea833924 (diff)
downloadvboot-release-R18-1660.B.tar.gz
Refactor of cgpt tool for 32->64 autoupdate work.release-R18-1660.B
This check-in splits the cgpt into two layers. The top layer (cmd_* files) does the command-line parsing and the bottom layer (cgpt_* files) does the actual cgpt work. This is done so that the bottom layer can be reused for the monolithic C++ post-installer code that will be done in subsequent checkins. BUG=chromium-os:25374 TEST=Tested with existing cgpt unit tests as well as running the cgpt commands manually. Change-Id: I69a31eb3e867a1430cac9a694581331368aa7bb4 Reviewed-on: https://gerrit.chromium.org/gerrit/14940 Reviewed-by: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
Diffstat (limited to 'cgpt/cgpt_repair.c')
-rw-r--r--cgpt/cgpt_repair.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/cgpt/cgpt_repair.c b/cgpt/cgpt_repair.c
new file mode 100644
index 00000000..3d7ca64c
--- /dev/null
+++ b/cgpt/cgpt_repair.c
@@ -0,0 +1,37 @@
+// 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 "cgpt.h"
+
+#include <string.h>
+
+#include "cgptlib_internal.h"
+#include "cgpt_params.h"
+
+int cgpt_repair(CgptRepairParams *params) {
+ struct drive drive;
+
+ if (params == NULL)
+ return CGPT_FAILED;
+
+ if (CGPT_OK != DriveOpen(params->driveName, &drive))
+ return CGPT_FAILED;
+
+ int gpt_retval = GptSanityCheck(&drive.gpt);
+ if (params->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);
+}