X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=rawdisktest;a=blobdiff_plain;f=src%2Fmain.c;h=c1da2d91c0ad7b96fbd451aeaa72ee56a4d4d23c;hp=8f7b239d0128d34070537d9b4fb6d5907c8b3729;hb=d6c8a8e10f6f00b22cf04b5c64f83cf36a3d8d32;hpb=87889506d908ae54b9b40a7e8095fff3583053a6 diff --git a/src/main.c b/src/main.c index 8f7b239..c1da2d9 100644 --- a/src/main.c +++ b/src/main.c @@ -11,10 +11,12 @@ int main(int argc, char **argv) { int devidx, ifidx; HDEVINFO devset; - SP_DEVINFO_DATA devinfo; + SP_DEVINFO_DATA devdata; SP_DEVICE_INTERFACE_DATA devif; SP_DEVICE_INTERFACE_DETAIL_DATA_A *devdetail; - DWORD detsz; + DWORD size; + DWORD regtype; + char devname[1024]; if((devset = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DISK, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)) == INVALID_HANDLE_VALUE) { @@ -24,47 +26,45 @@ int main(int argc, char **argv) devidx = 0; for(;;) { - memset(&devinfo, 0, sizeof devinfo); - devinfo.cbSize = sizeof devinfo; - if(!SetupDiEnumDeviceInfo(devset, devidx, &devinfo)) { - if(GetLastError() == ERROR_NO_MORE_ITEMS) { - printf("no such device: %d\n", devidx); - break; - } + memset(&devdata, 0, sizeof devdata); + devdata.cbSize = sizeof devdata; + if(!SetupDiEnumDeviceInfo(devset, devidx, &devdata)) { + if(GetLastError() == ERROR_NO_MORE_ITEMS) break; devidx++; continue; } - printf("device %d:\n", devidx); + regtype = SPDRP_PHYSICAL_DEVICE_OBJECT_NAME; + SetupDiGetDeviceRegistryProperty(devset, &devdata, SPDRP_FRIENDLYNAME, + ®type, (unsigned char*)devname, sizeof devname, &size); + + printf("Device %d: %s\n", devidx, devname); + ifidx = 0; for(;;) { memset(&devif, 0, sizeof devif); devif.cbSize = sizeof devif; - if(!SetupDiEnumDeviceInterfaces(devset, &devinfo, &GUID_DEVINTERFACE_DISK, ifidx, &devif)) { - if(GetLastError() == ERROR_NO_MORE_ITEMS) { - printf("no such interface: %d\n", ifidx); - break; - } + if(!SetupDiEnumDeviceInterfaces(devset, &devdata, &GUID_DEVINTERFACE_DISK, ifidx, &devif)) { + if(GetLastError() == ERROR_NO_MORE_ITEMS) break; ifidx++; continue; } - SetupDiGetDeviceInterfaceDetail(devset, &devif, 0, 0, &detsz, 0); - if(!(devdetail = malloc(detsz))) { - fprintf(stderr, "failed to allocate device interface detail buffer (size: %lu)\n", (unsigned long)detsz); + SetupDiGetDeviceInterfaceDetail(devset, &devif, 0, 0, &size, 0); + if(!(devdetail = malloc(size))) { + fprintf(stderr, "failed to allocate device interface detail buffer (size: %lu)\n", (unsigned long)size); return 1; } - devdetail->cbSize = detsz; - SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, detsz, 0, 0); - printf("device %d.%d path: %s\n", devidx, ifidx, devdetail->DevicePath); + devdetail->cbSize = sizeof *devdetail; + SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, size, 0, 0); + printf(" path: %s\n", devdetail->DevicePath); free(devdetail); ifidx++; } - printf("found %d interfaces\n", ifidx); + devidx++; + printf("found %d devices\n", devidx); } - - printf("found %d devices\n", devidx); return 0; }