From 9339a0fb4e734ca31cf64fdcc7ea0244f0d87fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 17 Dec 2023 13:43:52 +0800 Subject: [PATCH] DiskIO (Windows): detect serial number --- src/detection/diskio/diskio_windows.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/detection/diskio/diskio_windows.c b/src/detection/diskio/diskio_windows.c index 0fe06faf7..853c74266 100644 --- a/src/detection/diskio/diskio_windows.c +++ b/src/detection/diskio/diskio_windows.c @@ -64,8 +64,29 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) device->bytesWritten = (uint64_t) diskPerformance.BytesWritten.QuadPart; device->writeCount = (uint64_t) diskPerformance.WriteCount; - DEVICE_SEEK_PENALTY_DESCRIPTOR dspd = {}; DWORD retSize = 0; + + char sddBuffer[4096]; + if(DeviceIoControl( + hDevice, + IOCTL_STORAGE_QUERY_PROPERTY, + &(STORAGE_PROPERTY_QUERY) { + .PropertyId = StorageDeviceProperty, + .QueryType = PropertyStandardQuery, + }, + sizeof(STORAGE_PROPERTY_QUERY), + &sddBuffer, + sizeof(sddBuffer), + &retSize, + NULL + ) && retSize > 0) + { + STORAGE_DEVICE_DESCRIPTOR* sdd = (STORAGE_DEVICE_DESCRIPTOR*) sddBuffer; + if (sdd->SerialNumberOffset != 0) + ffStrbufSetS(&device->serial, (const char*) sddBuffer + sdd->SerialNumberOffset); + } + + DEVICE_SEEK_PENALTY_DESCRIPTOR dspd = {}; if(DeviceIoControl( hDevice, IOCTL_STORAGE_QUERY_PROPERTY,