Pino Toscano
2019-Feb-25 12:36 UTC
[Libguestfs] [PATCH] inspect: return osinfo short IDs for recent Windows versions
Return the right osinfo short IDs for the majority of Windows versions
since Windows XP.
---
lib/inspect-osinfo.c | 60 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/lib/inspect-osinfo.c b/lib/inspect-osinfo.c
index 816d317f1..f93f7ac52 100644
--- a/lib/inspect-osinfo.c
+++ b/lib/inspect-osinfo.c
@@ -69,6 +69,66 @@ guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char
*root)
if (STREQ (distro, "msdos"))
return safe_strdup (g, "msdos6.22");
}
+ else if (STREQ (type, "windows")) {
+ CLEANUP_FREE char *product_name = NULL;
+ CLEANUP_FREE char *product_variant = NULL;
+
+ product_name = guestfs_inspect_get_product_name (g, root);
+ if (!product_name)
+ return NULL;
+ product_variant = guestfs_inspect_get_product_variant (g, root);
+ if (!product_variant)
+ return NULL;
+
+ switch (major) {
+ case 5:
+ switch (minor) {
+ case 1:
+ return safe_strdup (g, "winxp");
+ case 2:
+ if (strstr (product_name, "XP"))
+ return safe_strdup (g, "winxp");
+ else if (strstr (product_name, "R2"))
+ return safe_strdup (g, "win2k3r2");
+ else
+ return safe_strdup (g, "win2k3");
+ }
+ break;
+ case 6:
+ switch (minor) {
+ case 0:
+ if (strstr (product_variant, "Server"))
+ return safe_strdup (g, "win2k8");
+ else
+ return safe_strdup (g, "winvista");
+ case 1:
+ if (strstr (product_variant, "Server"))
+ return safe_strdup (g, "win2k8r2");
+ else
+ return safe_strdup (g, "win7");
+ case 2:
+ if (strstr (product_variant, "Server"))
+ return safe_strdup (g, "win2k12");
+ else
+ return safe_strdup (g, "win8");
+ case 3:
+ if (strstr (product_variant, "Server"))
+ return safe_strdup (g, "win2k12r2");
+ else
+ return safe_strdup (g, "win8.1");
+ }
+ break;
+ case 10:
+ switch (minor) {
+ case 0:
+ if (strstr (product_variant, "Server"))
+ return safe_strdup (g, "win2k16");
+ else
+ return safe_strdup (g, "win10");
+ }
+ break;
+ }
+ }
/* No ID could be guessed, return "unknown". */
return safe_strdup (g, "unknown");
--
2.20.1
Richard W.M. Jones
2019-Mar-25 14:34 UTC
Re: [Libguestfs] [PATCH] inspect: return osinfo short IDs for recent Windows versions
On Mon, Feb 25, 2019 at 01:36:40PM +0100, Pino Toscano wrote:> Return the right osinfo short IDs for the majority of Windows versions > since Windows XP. > --- > lib/inspect-osinfo.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 60 insertions(+) > > diff --git a/lib/inspect-osinfo.c b/lib/inspect-osinfo.c > index 816d317f1..f93f7ac52 100644 > --- a/lib/inspect-osinfo.c > +++ b/lib/inspect-osinfo.c > @@ -69,6 +69,66 @@ guestfs_impl_inspect_get_osinfo (guestfs_h *g, const char *root) > if (STREQ (distro, "msdos")) > return safe_strdup (g, "msdos6.22"); > } > + else if (STREQ (type, "windows")) { > + CLEANUP_FREE char *product_name = NULL; > + CLEANUP_FREE char *product_variant = NULL; > + > + product_name = guestfs_inspect_get_product_name (g, root); > + if (!product_name) > + return NULL; > + product_variant = guestfs_inspect_get_product_variant (g, root); > + if (!product_variant) > + return NULL; > + > + switch (major) { > + case 5: > + switch (minor) { > + case 1: > + return safe_strdup (g, "winxp"); > + case 2: > + if (strstr (product_name, "XP")) > + return safe_strdup (g, "winxp"); > + else if (strstr (product_name, "R2")) > + return safe_strdup (g, "win2k3r2"); > + else > + return safe_strdup (g, "win2k3"); > + } > + break; > + case 6: > + switch (minor) { > + case 0: > + if (strstr (product_variant, "Server")) > + return safe_strdup (g, "win2k8"); > + else > + return safe_strdup (g, "winvista"); > + case 1: > + if (strstr (product_variant, "Server")) > + return safe_strdup (g, "win2k8r2"); > + else > + return safe_strdup (g, "win7"); > + case 2: > + if (strstr (product_variant, "Server")) > + return safe_strdup (g, "win2k12"); > + else > + return safe_strdup (g, "win8"); > + case 3: > + if (strstr (product_variant, "Server")) > + return safe_strdup (g, "win2k12r2"); > + else > + return safe_strdup (g, "win8.1"); > + } > + break; > + case 10: > + switch (minor) { > + case 0: > + if (strstr (product_variant, "Server")) > + return safe_strdup (g, "win2k16"); > + else > + return safe_strdup (g, "win10"); > + } > + break; > + } > + }Looks fine, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Reasonably Related Threads
- [PATCH v2] inspect: return osinfo short IDs for recent Windows versions
- [PATCH v12 00/11] Reimplement inspection in the daemon.
- [PATCH v10 00/10] Reimplement inspection in the daemon.
- [PATCH v9 00/11] Reimplement inspection in the daemon.
- [PATCH v11 00/10] Reimplement inspection in the daemon.