From 133572908fa4dd286c36c5c15e459fdc5fcc903f Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sun, 28 Jun 2015 14:14:19 -0700 Subject: [PATCH] SCP: Add natural Windows support for RAW device names. Fixes issue raised in #67. Also avoid confusion when processing -F switch while also copying/creating a VHD --- sim_disk.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sim_disk.c b/sim_disk.c index 7b960a63..39ad1643 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -837,6 +837,7 @@ if (sim_switches & SWMASK ('F')) { /* format spec? */ return SCPE_2FARG; if (sim_disk_set_fmt (uptr, 0, gbuf, NULL) != SCPE_OK) return SCPE_ARG; + sim_switches = sim_switches & ~(SWMASK ('F')); /* Record Format specifier already processed */ } if (sim_switches & SWMASK ('D')) { /* create difference disk? */ char gbuf[CBUFSIZE]; @@ -1652,6 +1653,22 @@ if (strchr (openmode, 'r')) DesiredAccess |= GENERIC_READ; if (strchr (openmode, 'w') || strchr (openmode, '+')) DesiredAccess |= GENERIC_WRITE; +/* SCP Command Line parsing replaces \\ with \ presuming this is an + escape sequence. This only affecdts RAW device names and UNC paths. + We handle the RAW device name case here by prepending paths beginning + with \.\ with an extra \. */ +if (!memcmp ("\\.\\", rawdevicename, 3)) { + char *tmpname = malloc (2 + strlen (rawdevicename)); + + if (tmpname == NULL) + return NULL; + *tmpname = '\\'; + strcpy (tmpname + 1, rawdevicename); + Handle = CreateFileA (tmpname, DesiredAccess, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS|FILE_FLAG_WRITE_THROUGH, NULL); + free (tmpname); + if (Handle != INVALID_HANDLE_VALUE) + return (FILE *)Handle; + } Handle = CreateFileA (rawdevicename, DesiredAccess, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS|FILE_FLAG_WRITE_THROUGH, NULL); if (Handle == INVALID_HANDLE_VALUE) { _set_errno_from_status (GetLastError ());