|
2 | 2 | #include "common/io.h" |
3 | 3 | #include "common/windows/unicode.h" |
4 | 4 | #include "common/mallocHelper.h" |
| 5 | +#include "common/debug.h" |
5 | 6 |
|
6 | 7 | #include <stdalign.h> |
7 | 8 | #include <windows.h> |
8 | 9 | #include <winioctl.h> |
9 | 10 | #include <cfgmgr32.h> |
10 | 11 |
|
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) { |
12 | 13 | FF_AUTO_CLOSE_FD HANDLE hDevice = CreateFileW(szDevice, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); |
13 | 14 | if (hDevice == INVALID_HANDLE_VALUE) { |
14 | | - return false; |
| 15 | + return "CreateFileW() failed"; |
15 | 16 | } |
16 | 17 |
|
17 | 18 | DWORD retSize; |
@@ -76,7 +77,7 @@ static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice |
76 | 77 | ffStrbufSetStatic(&name, "8-inch Floppy Disk"); |
77 | 78 | break; |
78 | 79 | default: |
79 | | - return true; // Unsupported |
| 80 | + return "Unsupported media type"; |
80 | 81 | } |
81 | 82 | interconnect = "Floppy Controller"; |
82 | 83 | type |= FF_PHYSICALDISK_TYPE_HDD | FF_PHYSICALDISK_TYPE_REMOVABLE; |
@@ -192,7 +193,7 @@ static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice |
192 | 193 | } |
193 | 194 |
|
194 | 195 | if (options->namePrefix.length && !ffStrbufStartsWith(&name, &options->namePrefix)) { |
195 | | - return true; |
| 196 | + return "Name prefix mismatch"; |
196 | 197 | } |
197 | 198 |
|
198 | 199 | FFPhysicalDiskResult* device = (FFPhysicalDiskResult*) ffListAdd(result); |
@@ -291,7 +292,7 @@ static bool detectPhysicalDisk(const char* physicalType, const wchar_t* szDevice |
291 | 292 | } |
292 | 293 | } |
293 | 294 |
|
294 | | - return true; |
| 295 | + return NULL; |
295 | 296 | } |
296 | 297 |
|
297 | 298 | 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 |
321 | 322 |
|
322 | 323 | // MULTI_SZ: "str1\0str2\0...\0\0" |
323 | 324 | 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 | + } |
325 | 332 | } |
326 | 333 | } |
327 | 334 |
|
|
0 commit comments