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 | 29 +++++++++++++++++++++++++++--
src/ldm.h | 10 ++++++++++
src/ldmtool.c | 4 ++++
test/ldmread.c | 9 ++++++---
4 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/src/ldm.c b/src/ldm.c
index 19a0663..5c570a5 100644
--- a/src/ldm.c
+++ b/src/ldm.c
@@ -469,6 +469,7 @@ struct _LDMVolumePrivate
{
guint32 id;
gchar *name;
+ uuid_t guid;
gchar *dgname;
guint64 size;
@@ -496,6 +497,7 @@ G_DEFINE_TYPE(LDMVolume, ldm_volume, G_TYPE_OBJECT)
enum {
PROP_LDM_VOLUME_PROP0,
PROP_LDM_VOLUME_NAME,
+ PROP_LDM_VOLUME_GUID,
PROP_LDM_VOLUME_TYPE,
PROP_LDM_VOLUME_SIZE,
PROP_LDM_VOLUME_PART_TYPE,
@@ -514,6 +516,14 @@ ldm_volume_get_property(GObject * const o, const guint property_id,
case PROP_LDM_VOLUME_NAME:
g_value_set_string(value, priv->name); break;
+ case PROP_LDM_VOLUME_GUID:
+ {
+ char guid_str[37];
+ uuid_unparse(priv->guid, guid_str);
+ g_value_set_string(value, guid_str);
+ }
+ break;
+
case PROP_LDM_VOLUME_TYPE:
g_value_set_enum(value, priv->type); break;
@@ -535,6 +545,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)
@@ -593,6 +604,20 @@ ldm_volume_class_init(LDMVolumeClass * const klass)
)
);
+ /**
+ * LDMVolume:guid:
+ *
+ * The GUID of the volume.
+ */
+ g_object_class_install_property(
+ object_class,
+ PROP_LDM_VOLUME_GUID,
+ g_param_spec_string(
+ "guid", "GUID", "The GUID of the volume",
+ NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
+ )
+ );
+
/**
* LDMVolume:type:
*
@@ -1514,8 +1539,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..9686778 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");
@@ -323,6 +326,7 @@ show_volume(LDM *const ldm, const gint argc, gchar ** const argv,
}
g_free(name);
+ g_free(guid);
g_free(hint);
if (found) break;
diff --git a/test/ldmread.c b/test/ldmread.c
index 85b539e..bc4d0c5 100644
--- a/test/ldmread.c
+++ b/test/ldmread.c
@@ -73,6 +73,7 @@ int main(int argc, const char *argv[])
{
gchar *name;
+ gchar *guid;
LDMVolumeType type;
guint64 size;
guint32 part_type;
@@ -80,15 +81,16 @@ int main(int argc, const char *argv[])
guint64 chunk_size;
g_object_get(vol, "name", &name, "type",
&type,
- "size", &size, "part-type",
&part_type,
- "hint", &hint, "chunk-size",
&chunk_size,
- NULL);
+ "guid", &guid, "size",
&size,
+ "part-type", &part_type,
"hint", &hint,
+ "chunk-size", &chunk_size, NULL);
GEnumValue * const type_v =
g_enum_get_value(g_type_class_peek(LDM_TYPE_VOLUME_TYPE),
type);
printf(" Volume: %s\n", name);
+ printf(" GUID: %s\n", guid);
printf(" Type: %s\n", type_v->value_nick);
printf(" Size: %lu\n", size);
printf(" Part Type: %hhu\n", part_type);
@@ -96,6 +98,7 @@ int main(int argc, const char *argv[])
printf(" Chunk Size: %lu\n", chunk_size);
g_free(name);
+ g_free(guid);
g_free(hint);
}
--
2.17.0