Skip to content

Commit 5fe2cc6

Browse files
committed
PhysicalDisk (Windows): adds simple debug log
1 parent 50739ee commit 5fe2cc6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/detection/physicaldisk/physicaldisk_windows.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
#include "common/io.h"
33
#include "common/windows/unicode.h"
44
#include "common/mallocHelper.h"
5+
#include "common/debug.h"
56

67
#include <stdalign.h>
78
#include <windows.h>
89
#include <winioctl.h>
910
#include <cfgmgr32.h>
1011

11-
static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice, FFlist* result, FFPhysicalDiskOptions* options) {
12+
static const char* detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice, FFlist* result, FFPhysicalDiskOptions* options) {
1213
FF_AUTO_CLOSE_FD HANDLE hDevice = CreateFileW(szDevice, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1314
if (hDevice == INVALID_HANDLE_VALUE) {
14-
return false;
15+
return "CreateFileW() failed";
1516
}
1617

1718
DWORD retSize;
@@ -76,7 +77,7 @@ static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice
7677
ffStrbufSetStatic(&name, "8-inch Floppy Disk");
7778
break;
7879
default:
79-
return true; // Unsupported
80+
return "Unsupported media type";
8081
}
8182
interconnect = "Floppy Controller";
8283
type |= FF_PHYSICALDISK_TYPE_HDD | FF_PHYSICALDISK_TYPE_REMOVABLE;
@@ -192,7 +193,7 @@ static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice
192193
}
193194

194195
if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix)) {
195-
return true;
196+
return "Name prefix mismatch";
196197
}
197198

198199
FFPhysicalDiskResult* device = (FFPhysicalDiskResult*) ffListAdd(result);
@@ -291,7 +292,7 @@ static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice
291292
}
292293
}
293294

294-
return true;
295+
return NULL;
295296
}
296297

297298
static void detectPhysicalDisksByInterfaceClass(const char* type, const GUID* interfaceClassGuid, FFlist* result, FFPhysicalDiskOptions* options) {
@@ -321,7 +322,13 @@ static void detectPhysicalDisksByInterfaceClass(const char* type, const GUID* in
321322

322323
// MULTI_SZ: "str1\0str2\0...\0\0"
323324
for (const wchar_t* p = mszDeviceInterfaces; *p; p += wcslen(p) + 1) {
324-
detectPhysicalDisk(type, p, result, options);
325+
FF_DEBUG("Probing %s: %ls", type, p);
326+
FF_MAYBE_UNUSED const char* error = detectPhysicalDisk(type, p, result, options);
327+
if (error == NULL) {
328+
FF_DEBUG("Detected device \"%s\"", FF_LIST_LAST(FFPhysicalDiskResult, *result)->name.chars);
329+
} else {
330+
FF_DEBUG("Failed to detect device %s: %s", type, error);
331+
}
325332
}
326333
}
327334

0 commit comments

Comments
 (0)