On Fri, Dec 14, 2012 at 12:07:22PM -0500, Skippy VonDrake wrote: > The error message: > hivex_close: do_hivex_close: you must call 'hivex-open' first to > initialize the hivex handle > > This is the process flow: > g = guestfs_create (); > guestfs_add_drive_opts (g, diskFile,GUESTFS_ADD_DRIVE_OPTS_FORMAT, > "raw",-1); > guestfs_launch (g) > char **roots = guestfs_inspect_os (g); > > guestfs_inspect_os returns NULL, guestfs_last_error(g) returns message above. > And guestfs_last_errno(g) returns 0. > > However this same code works fine with a Server2008 image and an XP image. > > I copied the verbose output to pastebin: http://pastebin.com/U9Jb6JwH > > Suggestions?
There is also a bug in the code ... The attached patch (not tested) may fix it. However it would still be extremely useful to see the trace output because (a) it would confirm if this is the bug or not, and (b) for some reason it seems as if the SOFTWARE or SYSTEM registry in the Win7 guest cannot be opened, and I don't understand why that would be. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
>From 96e729f83a4d212cc630a1e26396668c8ea89a65 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" <[email protected]> Date: Fri, 14 Dec 2012 21:54:13 +0000 Subject: [PATCH] inspection: Don't call guestfs_hivex_close if previous guestfs_hivex_open call failed. --- src/inspect-apps.c | 2 +- src/inspect-fs-windows.c | 42 ++++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/inspect-apps.c b/src/inspect-apps.c index ce8c438..61ab540 100644 --- a/src/inspect-apps.c +++ b/src/inspect-apps.c @@ -527,8 +527,8 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs) list_applications_windows_from_path (g, ret, hivepath2, sizeof hivepath2 / sizeof hivepath2[0]); - out: guestfs_hivex_close (g); + out: free (software_path); return ret; diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c index af4dcfd..4ef94e3 100644 --- a/src/inspect-fs-windows.c +++ b/src/inspect-fs-windows.c @@ -237,18 +237,18 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) if (guestfs_hivex_open (g, software_path, GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1) - goto out; + goto out0; node = guestfs_hivex_root (g); for (i = 0; node > 0 && i < sizeof hivepath / sizeof hivepath[0]; ++i) node = guestfs_hivex_node_get_child (g, node, hivepath[i]); if (node == -1) - goto out; + goto out1; if (node == 0) { perrorf (g, "hivex: cannot locate HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"); - goto out; + goto out1; } values = guestfs_hivex_node_values (g, node); @@ -308,8 +308,9 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) out2: guestfs_free_hivex_value_list (values); - out: + out1: guestfs_hivex_close (g); + out0: free (software_path); return ret; @@ -349,36 +350,36 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) if (guestfs_hivex_open (g, system_path, GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1) - goto out; + goto out0; root = guestfs_hivex_root (g); if (root == 0) - goto out; + goto out1; /* Get the CurrentControlSet. */ node = guestfs_hivex_node_get_child (g, root, "Select"); if (node == -1) - goto out; + goto out1; if (node == 0) { error (g, "hivex: could not locate HKLM\\SYSTEM\\Select"); - goto out; + goto out1; } value = guestfs_hivex_node_get_value (g, node, "Current"); if (value == -1) - goto out; + goto out1; if (value == 0) { error (g, "hivex: HKLM\\System\\Select Default entry not found"); - goto out; + goto out1; } /* XXX Should check the type. */ buf = guestfs_hivex_value_value (g, value, &buflen); if (buflen != 4) { error (g, "hivex: HKLM\\System\\Select\\Current expected to be DWORD"); - goto out; + goto out1; } dword = le32toh (*(int32_t *)buf); fs->windows_current_control_set = safe_asprintf (g, "ControlSet%03d", dword); @@ -389,7 +390,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) */ node = guestfs_hivex_node_get_child (g, root, "MountedDevices"); if (node == -1) - goto out; + goto out1; if (node == 0) /* Not found: skip getting drive letter mappings (RHBZ#803664). */ @@ -404,7 +405,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) for (i = count = 0; i < values->len; ++i) { char *key = guestfs_hivex_value_key (g, values->val[i].hivex_value_h); if (key == NULL) - goto out; + goto out1; if (STRCASEEQLEN (key, "\\DosDevices\\", 12) && c_isalpha (key[12]) && key[13] == ':') count++; @@ -417,7 +418,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) int64_t v = values->val[i].hivex_value_h; char *key = guestfs_hivex_value_key (g, v); if (key == NULL) - goto out; + goto out1; if (STRCASEEQLEN (key, "\\DosDevices\\", 12) && c_isalpha (key[12]) && key[13] == ':') { /* Get the binary value. Is it a fixed disk? */ @@ -450,30 +451,30 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) } if (node == -1) - goto out; + goto out1; if (node == 0) { perrorf (g, "hivex: cannot locate HKLM\\SYSTEM\\%s\\Services\\Tcpip\\Parameters", fs->windows_current_control_set); - goto out; + goto out1; } guestfs_free_hivex_value_list (values); values = guestfs_hivex_node_values (g, node); if (values == NULL) - goto out; + goto out1; for (i = 0; i < values->len; ++i) { int64_t v = values->val[i].hivex_value_h; char *key = guestfs_hivex_value_key (g, v); if (key == NULL) - goto out; + goto out1; if (STRCASEEQ (key, "Hostname")) { fs->hostname = guestfs_hivex_value_utf8 (g, v); if (!fs->hostname) { free (key); - goto out; + goto out1; } } /* many other interesting fields here ... */ @@ -483,8 +484,9 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) ret = 0; - out: + out1: guestfs_hivex_close (g); + out0: if (values) guestfs_free_hivex_value_list (values); free (system_path); free (buf); -- 1.8.0.1
_______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
