10 /*#define DBG_FAKE_DISKS*/
12 static GUID guid_iface_disk = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
14 int rawdisk_detect(struct rawdisk_device *disks, int max_disks)
16 int devidx, ifidx, count;
18 SP_DEVINFO_DATA devdata;
19 SP_DEVICE_INTERFACE_DATA devif;
20 SP_DEVICE_INTERFACE_DETAIL_DATA_A *devdetail;
24 if((devset = SetupDiGetClassDevs(&guid_iface_disk, 0, 0,
25 DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)) == INVALID_HANDLE_VALUE) {
26 fprintf(stderr, "failed to enumerate devices\n");
33 memset(&devdata, 0, sizeof devdata);
34 devdata.cbSize = sizeof devdata;
35 if(!SetupDiEnumDeviceInfo(devset, devidx, &devdata)) {
36 if(GetLastError() == ERROR_NO_MORE_ITEMS) break;
41 regtype = SPDRP_PHYSICAL_DEVICE_OBJECT_NAME;
42 SetupDiGetDeviceRegistryProperty(devset, &devdata, SPDRP_FRIENDLYNAME,
43 ®type, (unsigned char*)devname, sizeof devname, &size);
48 memset(&devif, 0, sizeof devif);
49 devif.cbSize = sizeof devif;
50 if(!SetupDiEnumDeviceInterfaces(devset, &devdata, &guid_iface_disk, ifidx, &devif)) {
51 if(GetLastError() == ERROR_NO_MORE_ITEMS) break;
56 SetupDiGetDeviceInterfaceDetail(devset, &devif, 0, 0, &size, 0);
57 if(!(devdetail = malloc(size))) {
58 fprintf(stderr, "failed to allocate device interface detail buffer (size: %lu)\n", (unsigned long)size);
61 devdetail->cbSize = sizeof *devdetail;
62 SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, size, 0, 0);
65 if(count < max_disks) {
66 disks[count].path = strdup(devdetail->DevicePath);
67 disks[count].name = strdup(devname);
68 if(!disks[count].path || !disks[count].name) {
69 fprintf(stderr, "failed to allocate device strings\n");
87 sprintf(buf, "\\\\?\\fake\\disk\\%d", i);
88 disks[count].path = strdup(buf);
89 sprintf(buf, "FAKE_DISK_%d", i);
90 disks[count].name = strdup(buf);