From df3263076df0ad443dd9262b6250820c038fa7f2 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Wed, 8 Jan 2020 10:19:06 +0200 Subject: [PATCH] rawdisk code added --- instimg.dsp | 11 +++++++- src/main.c | 21 +++++++++------ src/rawdisk.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rawdisk.h | 11 ++++++++ 4 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 src/rawdisk.c create mode 100644 src/rawdisk.h diff --git a/instimg.dsp b/instimg.dsp index 65018c2..85eb38f 100644 --- a/instimg.dsp +++ b/instimg.dsp @@ -65,6 +65,7 @@ LINK32=link.exe # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c @@ -77,7 +78,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib setupapi.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept !ENDIF @@ -94,6 +95,10 @@ SOURCE=.\src\main.c # End Source File # Begin Source File +SOURCE=.\src\rawdisk.c +# End Source File +# Begin Source File + SOURCE=.\src\widgets.c # End Source File # End Group @@ -102,6 +107,10 @@ SOURCE=.\src\widgets.c # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File +SOURCE=.\src\rawdisk.h +# End Source File +# Begin Source File + SOURCE=.\src\widgets.h # End Source File # End Group diff --git a/src/main.c b/src/main.c index 43a5b62..68b4c98 100644 --- a/src/main.c +++ b/src/main.c @@ -2,23 +2,28 @@ #include #include #include "widgets.h" +#include "rawdisk.h" static struct wgt_window *win; static struct wgt_widget *lb_instto, *bn_inst, *bn_cancel, *cb_devs, *ck_usbonly; +static struct rawdisk_device rawdev[64]; +static int num_rawdev; static void onclick(struct wgt_widget *w); static void onmodify(struct wgt_widget *w); int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, char *cmdline, int showcmd) { - int x, y; + int i, x, y; MSG msg; - static const char *items[] = { - "item one", - "item two", - "item three" - }; + static const char *items[64]; + if((num_rawdev = rawdisk_detect(rawdev, sizeof rawdev / sizeof *rawdev)) == -1) { + return 1; + } + for(i=0; i +#include +#include +#include +#include +#include +#include +#include "rawdisk.h" + +static GUID guid_iface_disk = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}}; + +int rawdisk_detect(struct rawdisk_device *disks, int max_disks) +{ + int devidx, ifidx, count; + HDEVINFO devset; + SP_DEVINFO_DATA devdata; + SP_DEVICE_INTERFACE_DATA devif; + SP_DEVICE_INTERFACE_DETAIL_DATA_A *devdetail; + DWORD size, regtype; + char devname[1024]; + + if((devset = SetupDiGetClassDevs(&guid_iface_disk, 0, 0, + DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)) == INVALID_HANDLE_VALUE) { + fprintf(stderr, "failed to enumerate devices\n"); + return -1; + } + + count = 0; + devidx = 0; + for(;;) { + memset(&devdata, 0, sizeof devdata); + devdata.cbSize = sizeof devdata; + if(!SetupDiEnumDeviceInfo(devset, devidx, &devdata)) { + if(GetLastError() == ERROR_NO_MORE_ITEMS) break; + devidx++; + continue; + } + + regtype = SPDRP_PHYSICAL_DEVICE_OBJECT_NAME; + SetupDiGetDeviceRegistryProperty(devset, &devdata, SPDRP_FRIENDLYNAME, + ®type, (unsigned char*)devname, sizeof devname, &size); + + count = 0; + ifidx = 0; + for(;;) { + memset(&devif, 0, sizeof devif); + devif.cbSize = sizeof devif; + if(!SetupDiEnumDeviceInterfaces(devset, &devdata, &guid_iface_disk, ifidx, &devif)) { + if(GetLastError() == ERROR_NO_MORE_ITEMS) break; + ifidx++; + continue; + } + + 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 = sizeof *devdetail; + SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, size, 0, 0); + + + if(count < max_disks) { + disks[count].path = strdup(devdetail->DevicePath); + disks[count].name = strdup(devname); + if(!disks[count].path || !disks[count].name) { + fprintf(stderr, "failed to allocate device strings\n"); + return -1; + } + count++; + } + + free(devdetail); + ifidx++; + } + + devidx++; + } + + return count; +} diff --git a/src/rawdisk.h b/src/rawdisk.h new file mode 100644 index 0000000..5c843b1 --- /dev/null +++ b/src/rawdisk.h @@ -0,0 +1,11 @@ +#ifndef RAWDISK_H_ +#define RAWDISK_H_ + +struct rawdisk_device { + char *name; + char *path; +}; + +int rawdisk_detect(struct rawdisk_device *disks, int max_disks); + +#endif /* RAWDISK_H_ */ \ No newline at end of file -- 1.7.10.4