qga/commands-win32: Style cleanups before adding Windows Server 2025
v3 cover qga/commands-win32: Style cleanups before adding Windows Server 2025
Respin of Dehan's v2 since I had the changes stashed.
Supersedes: <[email protected]>
Dehan Meng (1):
qga-win: Add support of Windows Server 2025 in get-osinfo command
Philippe Mathieu-Daudé (2):
qga/commands-win32: Declare const qualifier before type qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
qga/commands-win32.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
Signature · 1 line
2.41.0
PATCH v3 1/3 qga/commands-win32: Declare const qualifier before type
Most of the code base use the 'const' qualifier *before* the type being qualified. Use the same style to unify.
--- qga/commands-win32.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
qga/commands-win32.c +11 -11
@@ -2120,11 +2120,11 @@ GuestUserList *qmp_guest_get_users(Error **errp)typedef struct _ga_matrix_lookup_t {int major;int minor; -char const *version; -char const *version_id; +const char *version; +const char *version_id; }ga_matrix_lookup_t ; -static ga_matrix_lookup_t const WIN_VERSION_MATRIX [2 ][7 ] = { +static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][7 ] = { {/* Desktop editions */ {5 ,0 ,"Microsoft Windows 2000" ,"2000" },
@@ -2148,18 +2148,18 @@ static ga_matrix_lookup_t const WIN_VERSION_MATRIX[2][7] = {typedef struct _ga_win_10_0_t {int first_build; -char const *version; -char const *version_id; +const char *version; +const char *version_id; }ga_win_10_0_t ; -static ga_win_10_0_t const WIN_10_0_SERVER_VERSION_MATRIX [4 ] = { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX [4 ] = { {14393 ,"Microsoft Windows Server 2016" ,"2016" }, {17763 ,"Microsoft Windows Server 2019" ,"2019" }, {20344 ,"Microsoft Windows Server 2022" ,"2022" }, {0 ,0 } }; -static ga_win_10_0_t const WIN_10_0_CLIENT_VERSION_MATRIX [3 ] = { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX [3 ] = { {10240 ,"Microsoft Windows 10" ,"10" }, {22000 ,"Microsoft Windows 11" ,"11" }, {0 ,0 }
@@ -2185,16 +2185,16 @@ static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp)return ; } -static char *ga_get_win_name (OSVERSIONINFOEXW const *os_version,bool id) +static char *ga_get_win_name (const OSVERSIONINFOEXW *os_version,bool id) {DWORD major = os_version->dwMajorVersion;DWORD minor = os_version->dwMinorVersion;DWORD build = os_version->dwBuildNumber;int tbl_idx = (os_version->wProductType !=VER_NT_WORKSTATION ); -ga_matrix_lookup_t const *table =WIN_VERSION_MATRIX [tbl_idx]; -ga_win_10_0_t const *win_10_0_table = tbl_idx ? +const ga_matrix_lookup_t *table =WIN_VERSION_MATRIX [tbl_idx]; +const ga_win_10_0_t *win_10_0_table = tbl_idx ?WIN_10_0_SERVER_VERSION_MATRIX :WIN_10_0_CLIENT_VERSION_MATRIX ; -ga_win_10_0_t const *win_10_0_version =NULL ; +const ga_win_10_0_t *win_10_0_version =NULL ;while (table->version !=NULL ) {if (major ==10 && minor ==0 ) {while (win_10_0_table->version !=NULL ) {
Signature · 1 line
2.41.0
Re: [PATCH v3 1/3] qga/commands-win32: Declare const qualifier before type
Quoted 77 lines · Philippe Mathieu-Daudé
Most of the code base use the 'const' qualifier *before* the type being qualified. Use the same style to unify.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/commands-win32.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)qga/commands-win32.c +7
-7@@ -2120,11 +2120,11 @@ GuestUserList *qmp_guest_get_users(Error **errp)typedef struct _ga_matrix_lookup_t {int major;int minor; -char const *version; -char const *version_id; +const char *version; +const char *version_id; }ga_matrix_lookup_t ; -static ga_matrix_lookup_t const WIN_VERSION_MATRIX [2 ][7 ] = { +static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][7 ] = { {/* Desktop editions */ {5 ,0 ,"Microsoft Windows 2000" ,"2000" },@@ -2148,18 +2148,18 @@ static ga_matrix_lookup_t const WIN_VERSION_MATRIX[2][7] = {typedef struct _ga_win_10_0_t {int first_build; -char const *version; -char const *version_id; +const char *version; +const char *version_id; }ga_win_10_0_t ; -static ga_win_10_0_t const WIN_10_0_SERVER_VERSION_MATRIX [4 ] = { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX [4 ] = { {14393 ,"Microsoft Windows Server 2016" ,"2016" }, {17763 ,"Microsoft Windows Server 2019" ,"2019" }, {20344 ,"Microsoft Windows Server 2022" ,"2022" }, {0 ,0 } }; -static ga_win_10_0_t const WIN_10_0_CLIENT_VERSION_MATRIX [3 ] = { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX [3 ] = { {10240 ,"Microsoft Windows 10" ,"10" }, {22000 ,"Microsoft Windows 11" ,"11" },{0, 0}qga/commands-win32.c +4
-4@@ -2185,16 +2185,16 @@ static voidga_get_win_version (RTL_OSVERSIONINFOEXW *info, Error **errp) return; } -static char *ga_get_win_name (OSVERSIONINFOEXW const *os_version,bool id) +static char *ga_get_win_name (const OSVERSIONINFOEXW *os_version,bool id) {DWORD major = os_version->dwMajorVersion;DWORD minor = os_version->dwMinorVersion;DWORD build = os_version->dwBuildNumber;int tbl_idx = (os_version->wProductType !=VER_NT_WORKSTATION ); -ga_matrix_lookup_t const *table =WIN_VERSION_MATRIX [tbl_idx]; -ga_win_10_0_t const *win_10_0_table = tbl_idx ? +const ga_matrix_lookup_t *table =WIN_VERSION_MATRIX [tbl_idx]; +const ga_win_10_0_t *win_10_0_table = tbl_idx ?WIN_10_0_SERVER_VERSION_MATRIX :WIN_10_0_CLIENT_VERSION_MATRIX ; -ga_win_10_0_t const *win_10_0_version =NULL ; +const ga_win_10_0_t *win_10_0_version =NULL ;while (table->version !=NULL ) {if (major ==10 && minor ==0 ) {while (win_10_0_table->version != NULL) {--
2.41.0
PATCH v3 2/3 qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
In reply to Philippe Mathieu-Daudéga_get_win_name() iterates over all elements in the arrays by checking the 'version' field is non-NULL. Since the arrays are guarded by a NULL terminating element, we don't need to specify their size:
static char *ga_get_win_name(...)
{
...
const ga_matrix_lookup_t *table = WIN_VERSION_MATRIX[tbl_idx];
const ga_win_10_0_t *win_10_0_table = ...
...
while (table->version != NULL) {
^^^^^^^^^^^^^^^
while (win_10_0_table->version != NULL) {
^^^^^^^^^^^^^^^This will simplify maintenance when adding new entries to these arrays.
--- qga/commands-win32.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
qga/commands-win32.c +9 -10
@@ -2124,7 +2124,7 @@ typedef struct _ga_matrix_lookup_t {const char *version_id; } ga_matrix_lookup_t; -static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][7 ] = { +static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][] = { {/* Desktop editions */ {5 ,0 ,"Microsoft Windows 2000" ,"2000" },
@@ -2133,7 +2133,7 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { { 6, 1, "Microsoft Windows 7" "7"}, { 6, 2, "Microsoft Windows 8", "8"}, { 6, 3, "Microsoft Windows 8.1", "8.1"}, - { 0, 0, 0} + { } },{ /* Server editions */ { 5, 2, "Microsoft Windows Server 2003", "2003"},
@@ -2141,28 +2141,27 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, { 6, 2, "Microsoft Windows Server 2012", "2012"}, { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, - { 0, 0, 0}, - { 0, 0, 0} + { }, } };typedef struct _ga_win_10_0_t {int first_build; -const char *version; -const char *version_id; +char const *version; +char const *version_id; }ga_win_10_0_t ; -static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX [4 ] = { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX [] = { {14393 ,"Microsoft Windows Server 2016" ,"2016" }, {17763 ,"Microsoft Windows Server 2019" ,"2019" }, {20344 ,"Microsoft Windows Server 2022" ,"2022" }, - {0 ,0 } + { } }; -static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX [3 ] = { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX [] = { {10240 ,"Microsoft Windows 10" ,"10" }, {22000 ,"Microsoft Windows 11" ,"11" }, - {0 ,0 } + { } };static void ga_get_win_version (RTL_OSVERSIONINFOEXW *info,Error **errp)
Signature · 1 line
2.41.0
Re: [PATCH v3 2/3] qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
Quoted 88 lines · Philippe Mathieu-Daudé
ga_get_win_name()iterates over all elements in the arrays by checking the 'version' field is non-NULL. Since the arrays are guarded by a NULL terminating element, we don't need to specify their size:static char *ga_get_win_name(...) { ... const ga_matrix_lookup_t *table = WIN_VERSION_MATRIX[tbl_idx]; const ga_win_10_0_t *win_10_0_table = ... ... while (table->version != NULL) { ^^^^^^^^^^^^^^^ while (win_10_0_table->version != NULL) { ^^^^^^^^^^^^^^^This will simplify maintenance when adding new entries to these arrays.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/commands-win32.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)qga/commands-win32.c +2
-2@@ -2124,7 +2124,7 @@ typedef struct _ga_matrix_lookup_t {const char *version_id; } ga_matrix_lookup_t; -static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][7 ] = { +static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][] = { {/* Desktop editions */ {5 ,0 ,"Microsoft Windows 2000" ,"2000" },@@ -2133,7 +2133,7 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { { 6, 1, "Microsoft Windows 7" "7"}, { 6, 2, "Microsoft Windows 8", "8"}, { 6, 3, "Microsoft Windows 8.1", "8.1"}, - { 0, 0, 0} + { } },{/* Server editions */ { 5, 2, "Microsoft Windows Server 2003", "2003"},qga/commands-win32.c +7
-8@@ -2141,28 +2141,27 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, { 6, 2, "Microsoft Windows Server 2012", "2012"}, { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, - { 0, 0, 0}, - { 0, 0, 0} + { }, } }; typedef struct _ga_win_10_0_t { int first_build; - const char *version; - const char *version_id; + char const *version; + char const *version_id; } ga_win_10_0_t; -static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[4] = { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[] = { {14393, "Microsoft Windows Server 2016", "2016"}, {17763, "Microsoft Windows Server 2019", "2019"}, {20344, "Microsoft Windows Server 2022", "2022"}, - {0, 0} + { } }; -static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[3] = { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[] = { {10240, "Microsoft Windows 10", "10"}, {22000, "Microsoft Windows 11", "11"}, - {0, 0} + { } };static void
ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp)
--
2.41.0
Re: [PATCH v3 2/3] qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
In reply to Philippe Mathieu-DaudéQuoted 29 lines · Philippe Mathieu-Daudé
ga_get_win_name()iterates over all elements in the arrays by checking the 'version' field is non-NULL. Since the arrays are guarded by a NULL terminating element, we don't need to specify their size:static char *ga_get_win_name(...) { ... const ga_matrix_lookup_t *table = WIN_VERSION_MATRIX[tbl_idx]; const ga_win_10_0_t *win_10_0_table = ... ... while (table->version != NULL) { ^^^^^^^^^^^^^^^ while (win_10_0_table->version != NULL) { ^^^^^^^^^^^^^^^This will simplify maintenance when adding new entries to these arrays.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/commands-win32.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)qga/commands-win32.c +0
-0
qga/commands-win32.c typedef struct _ga_matrix_lookup_t { · line 2128
Quoted 6 lines
qga/commands-win32.c +1
-1@@ -2124,7 +2124,7 @@ typedef struct _ga_matrix_lookup_t {const char *version_id; } ga_matrix_lookup_t; -static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][7 ] = { +static const ga_matrix_lookup_t WIN_VERSION_MATRIX [2 ][] = {
I love this idea but mingw-gcc - no.
../qga/commands-win32.c:2125:33: error: array type has incomplete element type ‘ga_matrix_lookup_t[]’ {aka ‘struct _ga_matrix_lookup_t[]’}
2125 | static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][] = {
| ^~~~~~~~~~~~~~~~~~../qga/commands-win32.c:2125:33: note: declaration of ‘WIN_VERSION_MATRIX’ as multidimensional array must have bounds for all dimensions except the first
I think we can do the same as with Win10 and create 2 variables:
WIN_SERVER_VERSION_MATRIX and WIN_CLIENT_VERSION_MATRIX
If you want I can fix this by myself.
Best Regards,
Konstantin Kostiuk.
{Quoted 53 lines
qga/commands-win32.c +1
-1/* Desktop editions */ { 5, 0, "Microsoft Windows 2000", "2000"},@@ -2133,7 +2133,7 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { { 6, 1, "Microsoft Windows 7" "7"}, { 6, 2, "Microsoft Windows 8", "8"}, { 6, 3, "Microsoft Windows 8.1", "8.1"}, - { 0, 0, 0} + { } },{/* Server editions */ { 5, 2, "Microsoft Windows Server 2003", "2003"},qga/commands-win32.c +7
-8@@ -2141,28 +2141,27 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, { 6, 2, "Microsoft Windows Server 2012", "2012"}, { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, - { 0, 0, 0}, - { 0, 0, 0} + { }, } }; typedef struct _ga_win_10_0_t { int first_build; - const char *version; - const char *version_id; + char const *version; + char const *version_id; } ga_win_10_0_t; -static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[4] = { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[] = { {14393, "Microsoft Windows Server 2016", "2016"}, {17763, "Microsoft Windows Server 2019", "2019"}, {20344, "Microsoft Windows Server 2022", "2022"}, - {0, 0} + { } }; -static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[3] = { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[] = { {10240, "Microsoft Windows 10", "10"}, {22000, "Microsoft Windows 11", "11"}, - {0, 0} + { } };static void
ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp)
--
2.41.0
Re: [PATCH v3 2/3] qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
In reply to Philippe Mathieu-DaudéQuoted 27 lines · Philippe Mathieu-Daudé
ga_get_win_name()iterates over all elements in the arrays by checking the 'version' field is non-NULL. Since the arrays are guarded by a NULL terminating element, we don't need to specify their size:static char *ga_get_win_name(...) { ... const ga_matrix_lookup_t *table = WIN_VERSION_MATRIX[tbl_idx]; const ga_win_10_0_t *win_10_0_table = ... ... while (table->version != NULL) { ^^^^^^^^^^^^^^^ while (win_10_0_table->version != NULL) { ^^^^^^^^^^^^^^^This will simplify maintenance when adding new entries to these arrays.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/commands-win32.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)typedef struct _ga_win_10_0_t { int first_build;
qga/commands-win32.c static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = { · line 2151
Quoted 4 lines
qga/commands-win32.c +2
-2-const char *version; -const char *version_id; +char const *version; +char const *version_id;
Oops, missed rebase.
Quoted 1 line
} ga_win_10_0_t;
PATCH v3 3/3 qga-win: Add support of Windows Server 2025 in get-osinfo command
In reply to Philippe Mathieu-DaudéFrom: Dehan Meng <[email protected]>
Add support of Windows Server 2025 in get-osinfo command
Message-ID: <[email protected]>
--- qga/commands-win32.c | 1 + 1 file changed, 1 insertion(+)
qga/commands-win32.c +1 -0
@@ -2155,6 +2155,7 @@ static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[] = { {14393, "Microsoft Windows Server 2016", "2016"}, {17763, "Microsoft Windows Server 2019", "2019"}, {20344, "Microsoft Windows Server 2022", "2022"}, + {26040, "MIcrosoft Windows Server 2025", "2025"}, { } };
Signature · 1 line
2.41.0
Re: [PATCH v3 3/3] qga-win: Add support of Windows Server 2025 in get-osinfo command
Quoted 28 lines · Philippe Mathieu-Daudé
From: Dehan Meng <[email protected]>
Add support of Windows Server 2025 in get-osinfo command
Signed-off-by Dehan Meng <[email protected]>Message-ID: <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- qga/commands-win32.c | 1 + 1 file changed, 1 insertion(+)qga/commands-win32.c +1
-1@@ -2155,6 +2155,7 @@ static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[] = { {14393 ,"Microsoft Windows Server 2016" ,"2016" }, {17763 ,"Microsoft Windows Server 2019" ,"2019" }, {20344 ,"Microsoft Windows Server 2022" ,"2022" }, + {26040 ,"MIcrosoft Windows Server 2025" ,"2025" }, { } }; --2.41.0