X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=instimg;a=blobdiff_plain;f=src%2Frawdisk.c;h=ba861dc601ada682099a8827296f5059ade80e7e;hp=b2576ba1feab85eed98f9c560b3226ad46dadd5f;hb=4f2abaf24d97f5d6fc253cca51ec87a8a95ab048;hpb=df3263076df0ad443dd9262b6250820c038fa7f2 diff --git a/src/rawdisk.c b/src/rawdisk.c index b2576ba..ba861dc 100644 --- a/src/rawdisk.c +++ b/src/rawdisk.c @@ -1,14 +1,21 @@ #include #include #include +#include #include #include #include #include #include "rawdisk.h" +#undef DBG_FAKE_DISKS + static GUID guid_iface_disk = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}}; +#ifndef IOCTL_DISK_UPDATE_PROPERTIES +#define IOCTL_DISK_UPDATE_PROPERTIES CTL_CODE(IOCTL_DISK_BASE,0x0050,METHOD_BUFFERED,FILE_ANY_ACCESS) +#endif + int rawdisk_detect(struct rawdisk_device *disks, int max_disks) { int devidx, ifidx, count; @@ -77,5 +84,45 @@ int rawdisk_detect(struct rawdisk_device *disks, int max_disks) devidx++; } +#ifdef DBG_FAKE_DISKS + { + int i; + for(i=0; i<3; i++) { + char buf[32]; + sprintf(buf, "\\\\?\\fake\\disk\\%d", i); + disks[count].path = strdup(buf); + sprintf(buf, "FAKE_DISK_%d", i); + disks[count].name = strdup(buf); + count++; + } + } +#endif + return count; } + +int rawdisk_eject(HANDLE hdev) +{ + DWORD sz; + return DeviceIoControl(hdev, IOCTL_STORAGE_EJECT_MEDIA, 0, 0, 0, 0, &sz, 0) == 0 ? -1 : 0; +} + +int rawdisk_load(HANDLE hdev) +{ + DWORD sz; + return DeviceIoControl(hdev, IOCTL_STORAGE_LOAD_MEDIA, 0, 0, 0, 0, &sz, 0) == 0 ? -1 : 0; +} + +void rawdisk_refresh(HANDLE hdev) +{ + DWORD sz; + char *buf; + + /* try to rock the boat so hopefully windows will re-read the disk and it'll show up */ + DeviceIoControl(hdev, IOCTL_DISK_UPDATE_PROPERTIES, 0, 0, 0, 0, &sz, 0); + + sz = sizeof(DRIVE_LAYOUT_INFORMATION) + sizeof(PARTITION_INFORMATION) * 32; + buf = alloca(sz); + + DeviceIoControl(hdev, IOCTL_DISK_GET_DRIVE_LAYOUT, 0, 0, buf, sz, &sz, 0); +} \ No newline at end of file