initial commit
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Thu, 2 Jan 2020 10:50:11 +0000 (12:50 +0200)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Thu, 2 Jan 2020 10:50:11 +0000 (12:50 +0200)
Makefile [new file with mode: 0644]
src/main.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..a2c4f4b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+src = $(wildcard src/*.c)\r
+obj = $(src:.c=.o)\r
+bin = rawdisktest\r
+\r
+CFLAGS = -pedantic -Wall -g\r
+LDFLAGS = -lsetupapi -luuid\r
+\r
+$(bin): $(obj)\r
+       $(CC) -o $(bin) $(obj) $(LDFLAGS)\r
+\r
+.PHONY: clean\r
+clean:\r
+       rm -f $(obj) $(bin)\r
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..8f7b239
--- /dev/null
@@ -0,0 +1,70 @@
+#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