[Libguestfs] [PATCHv2] inspect: get windows drive letters for GPT disks.
Richard W.M. Jones
rjones at redhat.com
Sat Feb 6 10:05:46 UTC 2016
I got it to work by adding the attached patches. If you agree
with these changes, please fold them into your patch v3.
Thanks,
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
-------------- next part --------------
>From 96b13f7f064d4044038487b4a5c1f50038d9c91f Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Sat, 6 Feb 2016 09:51:42 +0000
Subject: [PATCH 1/4] inspection: Only convert registry blob to GUID once.
Updates commit d3b1387bdd118762606d6b589b9e2e67ae582d3b.
---
src/inspect-fs-windows.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 1698e81..9aa9847 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -623,6 +623,7 @@ static char *
map_registry_disk_blob_gpt (guestfs_h *g, const void *blob)
{
CLEANUP_FREE_STRING_LIST char **parts = NULL;
+ CLEANUP_FREE char *blob_guid = extract_guid_from_registry_blob (g, blob);
size_t i;
parts = guestfs_list_partitions (g);
@@ -632,7 +633,6 @@ map_registry_disk_blob_gpt (guestfs_h *g, const void *blob)
for (i = 0; parts[i] != NULL; i += 2) {
CLEANUP_FREE char *fs_guid = NULL;
- CLEANUP_FREE char *blob_guid = NULL;
int partnum;
CLEANUP_FREE char *device = NULL;
CLEANUP_FREE char *type = NULL;
@@ -661,9 +661,6 @@ map_registry_disk_blob_gpt (guestfs_h *g, const void *blob)
if (fs_guid == NULL)
continue;
- /* extract the GUID from the Windows registry blob */
- blob_guid = extract_guid_from_registry_blob (g, blob);
-
/* if both GUIDs match, we have found mapping for out device */
if (STRCASEEQ (fs_guid, blob_guid))
return safe_strdup (g, parts[i]);
--
2.5.0
-------------- next part --------------
>From cbb7a7612e900a2df245083807fc961b49ad43c7 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Sat, 6 Feb 2016 09:53:02 +0000
Subject: [PATCH 2/4] inspection: Check every partition, not every other
partition.
Fixes commit d3b1387bdd118762606d6b589b9e2e67ae582d3b.
---
src/inspect-fs-windows.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 9aa9847..4ae1f79 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -631,7 +631,7 @@ map_registry_disk_blob_gpt (guestfs_h *g, const void *blob)
if (parts == NULL)
return NULL;
- for (i = 0; parts[i] != NULL; i += 2) {
+ for (i = 0; parts[i] != NULL; ++i) {
CLEANUP_FREE char *fs_guid = NULL;
int partnum;
CLEANUP_FREE char *device = NULL;
--
2.5.0
-------------- next part --------------
>From 92291a3a67bd18dacca99b3fd5b3768c76f6c63d Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Sat, 6 Feb 2016 09:54:06 +0000
Subject: [PATCH 3/4] inspection: Stylistic updates.
---
src/inspect-fs-windows.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 4ae1f79..343ade9 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -627,7 +627,6 @@ map_registry_disk_blob_gpt (guestfs_h *g, const void *blob)
size_t i;
parts = guestfs_list_partitions (g);
-
if (parts == NULL)
return NULL;
@@ -638,32 +637,28 @@ map_registry_disk_blob_gpt (guestfs_h *g, const void *blob)
CLEANUP_FREE char *type = NULL;
partnum = guestfs_part_to_partnum (g, parts[i]);
-
if (partnum == -1)
- continue;
+ continue;
device = guestfs_part_to_dev (g, parts[i]);
-
if (device == NULL)
- continue;
+ continue;
type = guestfs_part_get_parttype (g, device);
-
if (type == NULL)
- continue;
+ continue;
if (STRCASENEQ (type, "gpt"))
- continue;
+ continue;
/* get the GPT parition GUID from the partition block device */
fs_guid = guestfs_part_get_gpt_guid (g, device, partnum);
-
if (fs_guid == NULL)
continue;
- /* if both GUIDs match, we have found mapping for out device */
+ /* if both GUIDs match, we have found the mapping for our device */
if (STRCASEEQ (fs_guid, blob_guid))
- return safe_strdup (g, parts[i]);
+ return safe_strdup (g, parts[i]);
}
return NULL;
@@ -699,7 +694,7 @@ extract_guid_from_registry_blob (guestfs_h *g, const void *blob)
return safe_asprintf (g,
"%08" PRIX32 "-%04" PRIX16 "-%04" PRIX16 "-%04" PRIX64 "-%06" PRIX64,
- data1, data2, data3, (data4 >> 48), (data4 << 16));
+ data1, data2, data3, data4 >> 48, data4 << 16);
}
/* NB: This function DOES NOT test for the existence of the file. It
--
2.5.0
-------------- next part --------------
>From a1ae967025c63e9e8557c2f72818ee3cd3202e72 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Sat, 6 Feb 2016 10:02:50 +0000
Subject: [PATCH 4/4] inspection: Convert the GUID from binary to text
correctly.
Fixes commit d3b1387bdd118762606d6b589b9e2e67ae582d3b.
---
src/inspect-fs-windows.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 343ade9..ba72727 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -693,8 +693,8 @@ extract_guid_from_registry_blob (guestfs_h *g, const void *blob)
data4 = be64toh (data4);
return safe_asprintf (g,
- "%08" PRIX32 "-%04" PRIX16 "-%04" PRIX16 "-%04" PRIX64 "-%06" PRIX64,
- data1, data2, data3, data4 >> 48, data4 << 16);
+ "%08" PRIX32 "-%04" PRIX16 "-%04" PRIX16 "-%04" PRIX64 "-%012" PRIX64,
+ data1, data2, data3, data4 >> 48, data4 & 0xffffffffffff);
}
/* NB: This function DOES NOT test for the existence of the file. It
--
2.5.0
More information about the Libguestfs
mailing list