summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_show.c
diff options
context:
space:
mode:
authorJay Srinivasan <jaysri@chromium.org>2012-02-16 17:40:45 -0800
committerGerrit <chrome-bot@google.com>2012-02-16 19:18:08 -0800
commit250549d3e742cddaf72b4f53d5739e54faf5db96 (patch)
tree646e9eee48897fc1d912a25443f1736191ac0354 /cgpt/cgpt_show.c
parent2ddd5f64515b4be9847a16de793c59b161221e1b (diff)
downloadvboot-250549d3e742cddaf72b4f53d5739e54faf5db96.tar.gz
Implementation of CgptManager C++ library and unit tests.
CgptManager exposes the cgpt commands via a C++ library so that the post-installer for 32- to 64-bit upgrade can link directly against a library and thus avoid any shell dependency. The default make target will not build libcgpt-cc.a since it requires some dependencies that are available only in chroot. A separate follow-up checkin to the vboot_reference ebuild will enable emerging the libcgpt-cc.a by default. BUG=chromium-os:25374 TEST=Tested with the new unit tests for CgptManager, ran existing cgpt unit tests, as well as running the cgpt commands manually. Built on both amd64 and x86. Tested that vboot_reference is also buildable outside of chroot. Tested that vboot_reference-firmware and vboot_reference-tests also build fine with these changes. CQ-DEPEND=I99f6c321e09c2425eaa8171d78685d2d731954c8 Change-Id: I59a896255b8ea2fc8b1b2150ae7c4ff9d0769699 Reviewed-on: https://gerrit.chromium.org/gerrit/15730 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Gaurav Shah <gauravsh@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org>
Diffstat (limited to 'cgpt/cgpt_show.c')
-rw-r--r--cgpt/cgpt_show.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 068895cb..d4170b1c 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -178,6 +178,42 @@ void EntriesDetails(GptData *gpt, const int secondary, int raw) {
}
}
+int cgpt_get_num_non_empty_partitions(CgptShowParams *params) {
+ struct drive drive;
+ int gpt_retval;
+ int retval;
+
+ if (params == NULL)
+ return CGPT_FAILED;
+
+ if (CGPT_OK != DriveOpen(params->drive_name, &drive))
+ return CGPT_FAILED;
+
+ if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
+ Error("GptSanityCheck() returned %d: %s\n",
+ gpt_retval, GptError(gpt_retval));
+ retval = CGPT_FAILED;
+ goto done;
+ }
+
+ params->num_partitions = 0;
+ int numEntries = GetNumberOfEntries(&drive.gpt);
+ int i;
+ for(i = 0; i < numEntries; i++) {
+ GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, i);
+ if (IsZero(&entry->type))
+ continue;
+
+ params->num_partitions++;
+ }
+
+ retval = CGPT_OK;
+
+done:
+ DriveClose(&drive, 0);
+ return retval;
+}
+
int cgpt_show(CgptShowParams *params) {
struct drive drive;
int gpt_retval;
@@ -185,7 +221,7 @@ int cgpt_show(CgptShowParams *params) {
if (params == NULL)
return CGPT_FAILED;
- if (CGPT_OK != DriveOpen(params->driveName, &drive))
+ if (CGPT_OK != DriveOpen(params->drive_name, &drive))
return CGPT_FAILED;
if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
@@ -339,8 +375,8 @@ int cgpt_show(CgptShowParams *params) {
}
}
- (void) CheckValid(&drive);
- (void) DriveClose(&drive, 0);
+ CheckValid(&drive);
+ DriveClose(&drive, 0);
return CGPT_OK;
}