LDM volume GUID is a significant piece of information about LDM volume analogously to GPT disk/partition GUID. Windows use volume GUID to keeptrack of assigned drive letters, for example. We extract volume GUID while parsing volume VBLK in _parse_vblk_vol function. "show volume" ldmtool command returns extracted volume GUID alongside with other volume information. --- src/ldm.c | 6 ++++-- src/ldm.h | 10 ++++++++++ src/ldmtool.c | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ldm.c b/src/ldm.c index 19a0663..fe5a19b 100644 --- a/src/ldm.c +++ b/src/ldm.c @@ -467,6 +467,7 @@ typedef enum { struct _LDMVolumePrivate { + uuid_t guid; guint32 id; gchar *name; gchar *dgname; @@ -535,6 +536,7 @@ ldm_volume_get_property(GObject * const o, const guint property_id, } EXPORT_PROP_STRING(volume, LDMVolume, name) +EXPORT_PROP_GUID(volume, LDMVolume) EXPORT_PROP_SCALAR(volume, LDMVolume, size, guint64) EXPORT_PROP_SCALAR(volume, LDMVolume, part_type, guint8) EXPORT_PROP_STRING(volume, LDMVolume, hint) @@ -1514,8 +1516,8 @@ _parse_vblk_vol(const guint8 revision, const guint16 flags, vol->part_type = *((uint8_t *)vblk); vblk++; - /* Volume id */ - vblk += 16; + /* Volume GUID */ + memcpy(&vol->guid, vblk, 16); vblk += 16; if (flags & 0x08) vol->id1 = _parse_var_string(&vblk); if (flags & 0x20) vol->id2 = _parse_var_string(&vblk); diff --git a/src/ldm.h b/src/ldm.h index af0726e..280fbfb 100644 --- a/src/ldm.h +++ b/src/ldm.h @@ -369,6 +369,16 @@ GArray *ldm_volume_get_partitions(LDMVolume *o); */ gchar *ldm_volume_get_name(const LDMVolume *o); +/** + * ldm_volume_get_guid: + * @o: An #LDMVolume + * + * Get the Windows-assigned GUID of a volume. + * + * Returns: (transfer full): The string representation of the GUID + */ +gchar *ldm_volume_get_guid(const LDMVolume *o); + /** * ldm_volume_get_voltype: * @o: An #LDMVolume diff --git a/src/ldmtool.c b/src/ldmtool.c index 4899539..4a76126 100644 --- a/src/ldmtool.c +++ b/src/ldmtool.c @@ -279,6 +279,7 @@ show_volume(LDM *const ldm, const gint argc, gchar ** const argv, LDMVolume * const vol = g_array_index(volumes, LDMVolume *, i); gchar *name = ldm_volume_get_name(vol); + gchar* guid = ldm_volume_get_guid(vol); LDMVolumeType type = ldm_volume_get_voltype(vol); guint64 size = ldm_volume_get_size(vol); guint64 chunk_size = ldm_volume_get_chunk_size(vol); @@ -294,6 +295,8 @@ show_volume(LDM *const ldm, const gint argc, gchar ** const argv, json_builder_set_member_name(jb, "name"); json_builder_add_string_value(jb, name); + json_builder_set_member_name(jb, "guid"); + json_builder_add_string_value(jb, guid); json_builder_set_member_name(jb, "type"); json_builder_add_string_value(jb, type_v->value_nick); json_builder_set_member_name(jb, "size"); -- 2.17.0