getting the path correctly now
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Thu, 2 Jan 2020 10:55:05 +0000 (12:55 +0200)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Thu, 2 Jan 2020 10:55:05 +0000 (12:55 +0200)
src/main.c

index 8f7b239..ab6d6ae 100644 (file)
@@ -9,9 +9,8 @@
 \r
 int main(int argc, char **argv)\r
 {\r
-       int devidx, ifidx;\r
+       int 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
@@ -22,49 +21,28 @@ int main(int argc, char **argv)
                return 1;\r
        }\r
 \r
-       devidx = 0;\r
+       ifidx = 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
+               memset(&devif, 0, sizeof devif);\r
+               devif.cbSize = sizeof devif;\r
+               if(!SetupDiEnumDeviceInterfaces(devset, 0, &GUID_DEVINTERFACE_DISK, ifidx, &devif)) {\r
+                       if(GetLastError() == ERROR_NO_MORE_ITEMS) break;\r
+                       ifidx++;\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
+               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
-               printf("found %d interfaces\n", ifidx);\r
-               devidx++;\r
-       }\r
+               devdetail->cbSize = sizeof *devdetail;\r
+               SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, detsz, 0, 0);\r
+               printf("device path: %s\n", devdetail->DevicePath);\r
+               free(devdetail);\r
 \r
-       printf("found %d devices\n", devidx);\r
+               ifidx++;\r
+       }\r
+       printf("found %d devices\n", ifidx);\r
        return 0;\r
 }\r