--- /dev/null
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <windows.h>\r
+#include <setupapi.h>\r
+#include <devguid.h>\r
+#include <ntddstor.h>\r
+#include <winioctl.h>\r
+\r
+int main(int argc, char **argv)\r
+{\r
+ int devidx, ifidx;\r
+ HDEVINFO devset;\r
+ SP_DEVINFO_DATA devinfo;\r
+ SP_DEVICE_INTERFACE_DATA devif;\r
+ SP_DEVICE_INTERFACE_DETAIL_DATA_A *devdetail;\r
+ DWORD detsz;\r
+\r
+ if((devset = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0,\r
+ DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)) == INVALID_HANDLE_VALUE) {\r
+ fprintf(stderr, "failed to enumerate devices\n");\r
+ return 1;\r
+ }\r
+\r
+ devidx = 0;\r
+ for(;;) {\r
+ memset(&devinfo, 0, sizeof devinfo);\r
+ devinfo.cbSize = sizeof devinfo;\r
+ if(!SetupDiEnumDeviceInfo(devset, devidx, &devinfo)) {\r
+ if(GetLastError() == ERROR_NO_MORE_ITEMS) {\r
+ printf("no such device: %d\n", devidx);\r
+ break;\r
+ }\r
+ devidx++;\r
+ continue;\r
+ }\r
+\r
+ printf("device %d:\n", devidx);\r
+ ifidx = 0;\r
+ for(;;) {\r
+ memset(&devif, 0, sizeof devif);\r
+ devif.cbSize = sizeof devif;\r
+ if(!SetupDiEnumDeviceInterfaces(devset, &devinfo, &GUID_DEVINTERFACE_DISK, ifidx, &devif)) {\r
+ if(GetLastError() == ERROR_NO_MORE_ITEMS) {\r
+ printf("no such interface: %d\n", ifidx);\r
+ break;\r
+ }\r
+ ifidx++;\r
+ continue;\r
+ }\r
+\r
+ SetupDiGetDeviceInterfaceDetail(devset, &devif, 0, 0, &detsz, 0);\r
+ if(!(devdetail = malloc(detsz))) {\r
+ fprintf(stderr, "failed to allocate device interface detail buffer (size: %lu)\n", (unsigned long)detsz);\r
+ return 1;\r
+ }\r
+ devdetail->cbSize = detsz;\r
+ SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, detsz, 0, 0);\r
+ printf("device %d.%d path: %s\n", devidx, ifidx, devdetail->DevicePath);\r
+ free(devdetail);\r
+\r
+ ifidx++;\r
+ }\r
+ printf("found %d interfaces\n", ifidx);\r
+ devidx++;\r
+ }\r
+\r
+ printf("found %d devices\n", devidx);\r
+ return 0;\r
+}\r