wbemprox: Get the disk drive serial number from mountmgr.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49160
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2020-05-26 10:18:43 +02:00 committed by Alexandre Julliard
parent 4ed26b63ca
commit 84857d2706
2 changed files with 65 additions and 2 deletions

View File

@ -44,6 +44,7 @@
#include "ntsecapi.h" #include "ntsecapi.h"
#include "winspool.h" #include "winspool.h"
#include "setupapi.h" #include "setupapi.h"
#include "ntddstor.h"
#include "wine/asm.h" #include "wine/asm.h"
#include "wine/debug.h" #include "wine/debug.h"
@ -140,7 +141,7 @@ static const struct column col_diskdrive[] =
{ L"MediaType", CIM_STRING }, { L"MediaType", CIM_STRING },
{ L"Model", CIM_STRING }, { L"Model", CIM_STRING },
{ L"PNPDeviceID", CIM_STRING }, { L"PNPDeviceID", CIM_STRING },
{ L"SerialNumber", CIM_STRING }, { L"SerialNumber", CIM_STRING|COL_FLAG_DYNAMIC },
{ L"Size", CIM_UINT64 }, { L"Size", CIM_UINT64 },
}; };
static const struct column col_diskdrivetodiskpartition[] = static const struct column col_diskdrivetodiskpartition[] =
@ -2081,6 +2082,42 @@ static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
} }
return free.QuadPart; return free.QuadPart;
} }
static WCHAR *get_diskdrive_serialnumber( WCHAR letter )
{
WCHAR *ret = NULL;
STORAGE_DEVICE_DESCRIPTOR *desc;
HANDLE handle = INVALID_HANDLE_VALUE;
STORAGE_PROPERTY_QUERY query = {0};
WCHAR drive[7];
DWORD size;
swprintf( drive, ARRAY_SIZE(drive), L"\\\\.\\%c:", letter );
handle = CreateFileW( drive, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
if (handle == INVALID_HANDLE_VALUE) goto done;
query.PropertyId = StorageDeviceProperty;
query.QueryType = PropertyStandardQuery;
size = sizeof(*desc) + 256;
for (;;)
{
if (!(desc = heap_alloc( size ))) break;
if (DeviceIoControl( handle, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), desc, size, NULL, NULL ))
{
if (desc->SerialNumberOffset) ret = heap_strdupAW( (const char *)desc + desc->SerialNumberOffset );
heap_free( desc );
break;
}
heap_free( desc );
if (GetLastError() == ERROR_MORE_DATA) size = desc->Size;
else break;
}
done:
if (handle != INVALID_HANDLE_VALUE) CloseHandle( handle );
if (!ret) ret = heap_strdupW( L"WINEHDISK" );
return ret;
}
static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond ) static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
{ {
@ -2114,7 +2151,7 @@ static enum fill_status fill_diskdrive( struct table *table, const struct expr *
rec->mediatype = (type == DRIVE_FIXED) ? L"Fixed hard disk" : L"Removable media"; rec->mediatype = (type == DRIVE_FIXED) ? L"Fixed hard disk" : L"Removable media";
rec->model = L"Wine Disk Drive"; rec->model = L"Wine Disk Drive";
rec->pnpdevice_id = L"IDE\\Disk\\VEN_WINE"; rec->pnpdevice_id = L"IDE\\Disk\\VEN_WINE";
rec->serialnumber = L"WINEHDISK"; rec->serialnumber = get_diskdrive_serialnumber( root[0] );
get_freespace( root, &size ); get_freespace( root, &size );
rec->size = size; rec->size = size;
if (!match_row( table, row, cond, &status )) if (!match_row( table, row, cond, &status ))

View File

@ -1456,6 +1456,31 @@ static void test_Win32_DesktopMonitor( IWbemServices *services )
SysFreeString( wql ); SysFreeString( wql );
} }
static void test_Win32_DiskDrive( IWbemServices *services )
{
BSTR wql = SysAllocString( L"wql" ), query = SysAllocString( L"SELECT * FROM Win32_DiskDrive" );
IEnumWbemClassObject *result;
IWbemClassObject *obj;
HRESULT hr;
DWORD count;
hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
ok( hr == S_OK, "got %08x\n", hr );
for (;;)
{
hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
if (hr != S_OK) break;
check_property( obj, L"DeviceID", VT_BSTR, CIM_STRING );
IWbemClassObject_Release( obj );
}
IEnumWbemClassObject_Release( result );
SysFreeString( query );
SysFreeString( wql );
}
static void test_Win32_DisplayControllerConfiguration( IWbemServices *services ) static void test_Win32_DisplayControllerConfiguration( IWbemServices *services )
{ {
BSTR wql = SysAllocString( L"wql" ); BSTR wql = SysAllocString( L"wql" );
@ -1561,6 +1586,7 @@ START_TEST(query)
test_Win32_ComputerSystemProduct( services ); test_Win32_ComputerSystemProduct( services );
test_Win32_Bios( services ); test_Win32_Bios( services );
test_Win32_DesktopMonitor( services ); test_Win32_DesktopMonitor( services );
test_Win32_DiskDrive( services );
test_Win32_DisplayControllerConfiguration( services ); test_Win32_DisplayControllerConfiguration( services );
test_Win32_IP4RouteTable( services ); test_Win32_IP4RouteTable( services );
test_Win32_OperatingSystem( services ); test_Win32_OperatingSystem( services );