Richard W.M. Jones
2011-Mar-23 16:02 UTC
[Libguestfs] [PATCH] New API: guestfs_inspect_get_product_variant
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -------------- next part -------------->From 3f1e3223c491aa057d02c1da418ed896d09fff7c Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Wed, 23 Mar 2011 16:00:48 +0000 Subject: [PATCH] New API: guestfs_inspect_get_product_variant This returns a product variant for inspected operating systems. In practice this is a useful way to distinguish between consumer and enterprise/server versions of Windows that otherwise have the same version number. --- generator/generator_actions.ml | 32 +++++++++++++++++++++++++++++++- images/guest-aux/windows-software | Bin 12288 -> 12288 bytes images/guest-aux/windows-software.reg | 1 + inspector/example-windows.xml | 2 ++ inspector/virt-inspector.c | 9 ++++++++- inspector/virt-inspector.pod | 3 ++- inspector/virt-inspector.rng | 1 + src/guestfs-internal.h | 1 + src/inspect.c | 25 +++++++++++++++++++++++++ 9 files changed, 71 insertions(+), 3 deletions(-) diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index e085fb6..11144e8 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -1,5 +1,5 @@ (* libguestfs - * Copyright (C) 2009-2010 Red Hat Inc. + * Copyright (C) 2009-2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1417,6 +1417,36 @@ L<guestfs(3)/ATTACHING TO RUNNING DAEMONS>. "\ Return the current attach method. See C<guestfs_set_attach_method>."); + ("inspect_get_product_variant", (RString "variant", [Device "root"], []), -1, [], + [], + "get product variant of inspected operating system", + "\ +This function should only be called with a root device string +as returned by C<guestfs_inspect_os>. + +This returns the product variant of the inspected operating +system. + +For Windows guests, this returns the contents of the Registry key +C<HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion> +C<InstallationType> which is usually a string such as +C<Client> or C<Server> (other values are possible). This +can be used to distinguish consumer and enterprise versions +of Windows that have the same version number (for example, +Windows 7 and Windows 2008 Server are both version 6.1, +but the former is C<Client> and the latter is C<Server>). + +For enterprise Linux guests, in future we intend this to return +the product variant such as C<Desktop>, C<Server> and so on. But +this is not implemented at present. + +If the product variant could not be determined, then the +string C<unknown> is returned. + +Please read L<guestfs(3)/INSPECTION> for more details. +See also C<guestfs_inspect_get_product_name>, +C<guestfs_inspect_get_major_version>."); + ] (* daemon_functions are any functions which cause some action diff --git a/images/guest-aux/windows-software b/images/guest-aux/windows-software index 1091c13e24f4548c6b87286907c1b1ac25b03fa3..e9358860b11053be0b52ce0222e9a14aa986afc8 100755 GIT binary patch delta 477 zcmZXQyGsK>5XNU$kcdQL9(Na#B6pX^1tbKESO{Sci=Z|Z7HOi15J at n`6N8UNQVD{J zFbLXN2CIOTV3E>7B#n<Mq|-kkoz5Lep$>dAu(R{~X17^v7TY4ip3sbZ2FC!vng(c6 z{idMeL<CKBo*P~~R`1L%HTJhWFh#Ar7l2W<wOHS4lxnq7qq<XHJ+jKqB&9F9zW_C; zLK*7N06<ksaN)xxEz2xC)pWNt#MmQke9&^Nk4z7_`*d#aWXAxLdXBB&t{$R%uFKr; zV at j3qQ4gm&K7iNdn+e-X_yJlZR{%heDx?o*=Sj#AsN%<7ERHi#!MeB|UFYclzC<qw zT8POUBnNsH3ui{qO9H$N;fh4RL+X<h*;(utTu21p<Shy7(KYUpi5$o0xQ7cFd-0Kp zqToqlHv8A$mVoa=qqG8WP3n at A;D4jM;=Cek2-d-ZF~<gYW#qUBV$axMhxcakVEhM^ Ci->{% delta 462 zcmZ{fyGz4R6vofJYG{!{wP{iu^rmTV<KWUEbg)oCsNe%fCk-wwy67UEO2;k+<Scb? zFHQv)r;<NFBo00n!Ocz`<!*YSElAN1J~-cb+#k2)wY*+MuokX~cZ~zU$s7)C1J|t* zC2U&Ptcw?7i7DDJv72?6gAZ9d;miXt+K*I6W>;e!>Rf%~n<#{yh{Dv*6nc1SSL3l1 zz>&Wg at 1iAA3sD;DbEFw+yrl?VTxrnwaq}`hppl~5(*XjqB8xP at 3-!;AXThZtf!nzn zZ|msGeLm1}C?&4u>whAqY5z8j{e00KBR1%{rx7Zox?})!$RRn>Z<I>oPEO*MtS}GH z<pB>2!ns at -C=33-#L&e1La{ta+%o~5N8|z3yBUBsIV4Y#lUR0Yypj3--JO$UJ$!Yl QTxC!$AM!xEVZ5(>0U4@}j{pDw diff --git a/images/guest-aux/windows-software.reg b/images/guest-aux/windows-software.reg index 984cbe4..e2efda6 100644 --- a/images/guest-aux/windows-software.reg +++ b/images/guest-aux/windows-software.reg @@ -5,6 +5,7 @@ [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion] "ProductName"=str(1):"Microsoft Windows 7 Phony Edition" "CurrentVersion"=str(1):"6.1" +"InstallationType"=str(1):"Client" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows] diff --git a/inspector/example-windows.xml b/inspector/example-windows.xml index 346b2ed..12c6956 100644 --- a/inspector/example-windows.xml +++ b/inspector/example-windows.xml @@ -6,9 +6,11 @@ <arch>i386</arch> <distro>windows</distro> <product_name>Microsoft Windows 7 Phony Edition</product_name> + <product_variant>Client</product_variant> <major_version>6</major_version> <minor_version>1</minor_version> <windows_systemroot>/Windows</windows_systemroot> + <format>installed</format> <mountpoints> <mountpoint dev="/dev/sda2">/</mountpoint> </mountpoints> diff --git a/inspector/virt-inspector.c b/inspector/virt-inspector.c index e7db5b9..4d8e3ad 100644 --- a/inspector/virt-inspector.c +++ b/inspector/virt-inspector.c @@ -1,5 +1,5 @@ /* virt-inspector - * Copyright (C) 2010 Red Hat Inc. + * Copyright (C) 2010-2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -373,6 +373,13 @@ output_root (xmlTextWriterPtr xo, char *root) xmlTextWriterWriteElement (xo, BAD_CAST "product_name", BAD_CAST str)); free (str); + str = guestfs_inspect_get_product_variant (g, root); + if (!str) exit (EXIT_FAILURE); + if (STRNEQ (str, "unknown")) + XMLERROR (-1, + xmlTextWriterWriteElement (xo, BAD_CAST "product_variant", BAD_CAST str)); + free (str); + i = guestfs_inspect_get_major_version (g, root); snprintf (buf, sizeof buf, "%d", i); XMLERROR (-1, diff --git a/inspector/virt-inspector.pod b/inspector/virt-inspector.pod index cd0e617..26c6126 100755 --- a/inspector/virt-inspector.pod +++ b/inspector/virt-inspector.pod @@ -165,6 +165,7 @@ describe the operating system, its architecture, the descriptive <arch>i386</arch> <distro>windows</distro> <product_name>Windows 7 Enterprise</product_name> + <product_variant>Client</product_variant> <major_version>6</major_version> <minor_version>1</minor_version> <windows_systemroot>/Windows</windows_systemroot> @@ -317,7 +318,7 @@ Matthew Booth L<mbooth at redhat.com> =head1 COPYRIGHT -Copyright (C) 2010 Red Hat Inc. +Copyright (C) 2010-2011 Red Hat Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/inspector/virt-inspector.rng b/inspector/virt-inspector.rng index 973bc3c..8d54fac 100644 --- a/inspector/virt-inspector.rng +++ b/inspector/virt-inspector.rng @@ -33,6 +33,7 @@ <optional><element name="arch"><text/></element></optional> <optional><element name="distro"><text/></element></optional> <optional><element name="product_name"><text/></element></optional> + <optional><element name="product_variant"><text/></element></optional> <element name="major_version"><text/></element> <element name="minor_version"><text/></element> <optional><element name="windows_systemroot"><text/></element></optional> diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index d0dcf23..155763d 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -244,6 +244,7 @@ struct inspect_fs { enum inspect_os_package_format package_format; enum inspect_os_package_management package_management; char *product_name; + char *product_variant; int major_version; int minor_version; char *arch; diff --git a/src/inspect.c b/src/inspect.c index 1129a53..b4acf17 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -1558,6 +1558,14 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) free (version); } + else if (STRCASEEQ (key, "InstallationType")) { + fs->product_variant = hivex_value_string (h, values[i]); + if (!fs->product_variant) { + perrorf (g, "hivex_value_string"); + free (key); + goto out; + } + } free (key); } @@ -1966,6 +1974,16 @@ guestfs__inspect_get_product_name (guestfs_h *g, const char *root) } char * +guestfs__inspect_get_product_variant (guestfs_h *g, const char *root) +{ + struct inspect_fs *fs = search_for_root (g, root); + if (!fs) + return NULL; + + return safe_strdup (g, fs->product_variant ? : "unknown"); +} + +char * guestfs__inspect_get_windows_systemroot (guestfs_h *g, const char *root) { struct inspect_fs *fs = search_for_root (g, root); @@ -2850,6 +2868,12 @@ guestfs__inspect_get_product_name (guestfs_h *g, const char *root) } char * +guestfs__inspect_get_product_variant (guestfs_h *g, const char *root) +{ + NOT_IMPL(NULL); +} + +char * guestfs__inspect_get_windows_systemroot (guestfs_h *g, const char *root) { NOT_IMPL(NULL); @@ -2924,6 +2948,7 @@ guestfs___free_inspect_info (guestfs_h *g) for (i = 0; i < g->nr_fses; ++i) { free (g->fses[i].device); free (g->fses[i].product_name); + free (g->fses[i].product_variant); free (g->fses[i].arch); free (g->fses[i].hostname); free (g->fses[i].windows_systemroot); -- 1.7.4.1