fdisk_free_parttype(org_t);
}
-static void
-list_disk_geometry(struct fdisk_context *cxt) {
+static void list_disk_geometry(struct fdisk_context *cxt)
+{
+ char *id = NULL;
unsigned long long bytes = cxt->total_sectors * cxt->sector_size;
long megabytes = bytes/1000000;
printf(_("Alignment offset: %lu bytes\n"), cxt->alignment_offset);
if (fdisk_dev_has_disklabel(cxt))
printf(_("Disk label type: %s\n"), cxt->label->name);
- if (fdisk_is_disklabel(cxt, DOS))
- dos_print_mbr_id(cxt);
+
+ if (fdisk_get_disklabel_id(cxt, &id) == 0 && id)
+ printf(_("Disk identifier: %s\n"), id);
printf("\n");
}
}
}
-void dos_print_mbr_id(struct fdisk_context *cxt)
+static int dos_get_disklabel_id(struct fdisk_context *cxt, char **id)
{
- fdisk_info(cxt, _("Disk identifier: 0x%08x"),
- mbr_get_id(cxt->firstsector));
+ unsigned int num;
+
+ assert(cxt);
+ assert(id);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, DOS));
+
+ num = mbr_get_id(cxt->firstsector);
+ if (asprintf(id, "0x%08x", num) > 0)
+ return 0;
+
+ return -ENOMEM;
}
static int dos_create_disklabel(struct fdisk_context *cxt)
.verify = dos_verify_disklabel,
.create = dos_create_disklabel,
.list = dos_list_disklabel,
+ .get_id = dos_get_disklabel_id,
.part_add = dos_add_partition,
.part_delete = dos_delete_partition,
int (*create)(struct fdisk_context *cxt);
/* list partition table */
int (*list)(struct fdisk_context *cxt);
+ /* get disk label ID */
+ int (*get_id)(struct fdisk_context *cxt, char **id);
/* new partition */
int (*part_add)(struct fdisk_context *cxt,
{
int rc = 0;
ssize_t esz = 0;
- struct gpt_guid *uid;
+ char str[37];
struct fdisk_gpt_label *gpt;
assert(cxt);
cxt->label->nparts_max = le32_to_cpu(gpt->pheader->npartition_entries);
cxt->label->nparts_cur = 0;
- uid = &gpt->pheader->disk_guid;
- fdisk_info(cxt, _("Building a new GPT disklabel "
- "(GUID: %08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X)\n"),
- uid->time_low, uid->time_mid,
- uid->time_hi_and_version,
- uid->clock_seq_hi,
- uid->clock_seq_low,
- uid->node[0], uid->node[1],
- uid->node[2], uid->node[3],
- uid->node[4], uid->node[5]);
+ guid_to_string(&gpt->pheader->disk_guid, str);
+ fdisk_info(cxt, _("Building a new GPT disklabel (GUID: %s)"), str);
fdisk_label_set_changed(cxt->label, 1);
done:
return rc;
}
+static int gpt_get_disklabel_id(struct fdisk_context *cxt, char **id)
+{
+ struct fdisk_gpt_label *gpt;
+ char str[37];
+
+ assert(cxt);
+ assert(id);
+ assert(cxt->label);
+ assert(fdisk_is_disklabel(cxt, GPT));
+
+ gpt = self_label(cxt);
+ guid_to_string(&gpt->pheader->disk_guid, str);
+
+ *id = strdup(str);
+ if (!*id)
+ return -ENOMEM;
+ return 0;
+}
+
static struct fdisk_parttype *gpt_get_partition_type(
struct fdisk_context *cxt,
size_t i)
.verify = gpt_verify_disklabel,
.create = gpt_create_disklabel,
.list = gpt_list_disklabel,
+ .get_id = gpt_get_disklabel_id,
+
.part_add = gpt_add_partition,
.part_delete = gpt_delete_partition,
.part_get_type = gpt_get_partition_type,
return cxt->label->op->create(cxt);
}
+/**
+ * fdisk_get_disklabel_id:
+ * @cxt: fdisk context
+ * @id: returns pointer to allocated string
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id)
+{
+ if (!cxt || !cxt->label)
+ return -EINVAL;
+ if (!cxt->label->op->get_id)
+ return -ENOSYS;
+
+ DBG(LABEL, dbgprint("asking for %s ID", cxt->label->name));
+ return cxt->label->op->get_id(cxt, id);
+}
+
/**
* fdisk_get_partition_type:
* @cxt: fdisk context
extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
extern int fdisk_list_disklabel(struct fdisk_context *cxt);
+extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
+
extern int fdisk_add_partition(struct fdisk_context *cxt, struct fdisk_parttype *t);
extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum);