Mykola Ivanets
2018-May-10 20:15 UTC
[Libguestfs] [PATCH libldm v3 0/2] Make libldm to parse and return volume GUID.
v2: wrap commit message, "PATCH libldm" prefix. v3: correctly initialize and free GLib resources. The result of this patch might be used by libguestfs to return drive mappings for LDM volumes. Note, that "show volume" ldmtool command already returns hint which is a drive letter assigned by Windows to corresponding volume. But it is not reliable source of information. More over, in multiboot environment it will be unclear which drive letter belongs to which operating system. Volume GUID allows to overcome this shortcoming. Mykola Ivanets (2): Make libldm to parse and return volume GUID. Make git to ignore all test output files. src/ldm.c | 29 +++++++++++++++++++++++++++-- src/ldm.h | 10 ++++++++++ src/ldmtool.c | 4 ++++ test/.gitignore | 39 ++++++++++++++++++++------------------- test/ldmread.c | 9 ++++++--- 5 files changed, 67 insertions(+), 24 deletions(-) -- 2.17.0
Mykola Ivanets
2018-May-10 20:15 UTC
[Libguestfs] [PATCH libldm v3 1/2] Make libldm to parse and return volume GUID.
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
Mykola Ivanets
2018-May-10 20:15 UTC
[Libguestfs] [PATCH libldm v3 2/2] Make git to ignore all test output files.
All files generted after running "make check" are added into .gitignore. --- test/.gitignore | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/test/.gitignore b/test/.gitignore index 8ee133a..7e62d30 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,19 +1,20 @@ -2003R2_MIRRORED -2003R2_MIRRORED_partial_1 -2003R2_MIRRORED_partial_2 -2003R2_RAID5 -2003R2_RAID5_partial_1 -2003R2_RAID5_partial_2 -2003R2_RAID5_partial_3 -2003R2_SIMPLE -2003R2_SPANNED -2003R2_STRIPED -2008R2_MIRRORED -2008R2_MIRRORED_partial_1 -2008R2_MIRRORED_partial_2 -2008R2_RAID5 -2008R2_RAID5_partial_1 -2008R2_RAID5_partial_2 -2008R2_RAID5_partial_3 -2008R2_SPANNED -2008R2_STRIPED +2003R2_MIRRORED* +2003R2_MIRRORED_partial_1* +2003R2_MIRRORED_partial_2* +2003R2_RAID5* +2003R2_RAID5_partial_1* +2003R2_RAID5_partial_2* +2003R2_RAID5_partial_3* +2003R2_SIMPLE* +2003R2_SPANNED* +2003R2_STRIPED* +2008R2_MIRRORED* +2008R2_MIRRORED_partial_1* +2008R2_MIRRORED_partial_2* +2008R2_RAID5* +2008R2_RAID5_partial_1* +2008R2_RAID5_partial_2* +2008R2_RAID5_partial_3* +2008R2_SPANNED* +2008R2_STRIPED* +test-suite.log -- 2.17.0
Possibly Parallel Threads
- [PATCH libldm v4 0/3] Make libldm to parse and return volume GUID.
- [PATCH 0/1] libldm: Make libldm to parse and return volume GUID.
- [PATCH libldm v2 0/1] Make libldm to parse and return volume GUID.
- [PATCH libldm 00/12] New API: an ability to retrieve created device-mapper devices back after they have been created.
- [PATCH 0/2] Two build fixes for libldm