summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_show.c
diff options
context:
space:
mode:
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;
}