DISK: Add support for reporting OS specific error messages when using RAW I/O

This commit is contained in:
Mark Pizzolato 2018-02-27 13:32:20 -08:00
parent 60db7e7239
commit 335b4ef210
3 changed files with 17 additions and 6 deletions

View file

@ -1984,8 +1984,12 @@ switch (DK_GET_FMT (uptr)) { /* case on format */
case DKUF_F_STD: /* SIMH format */
case DKUF_F_VHD: /* VHD format */
case DKUF_F_RAW: /* Raw Physical Disk Access */
#if defined(_WIN32)
saved_errno = GetLastError ();
#endif
perror (msg);
sim_printf ("%s %s: %s\n", sim_uname(uptr), msg, strerror(saved_errno));
sim_printf ("%s %s: %s\n", sim_uname(uptr), msg, sim_get_os_error_text (saved_errno));
break;
default:
;
}

View file

@ -375,8 +375,8 @@ return sim_fseeko (st, (t_offset)offset, whence);
}
#if defined(_WIN32)
static const char *
GetErrorText(DWORD dwError)
const char *
sim_get_os_error_text (int Error)
{
static char szMsgBuffer[2048];
DWORD dwStatus;
@ -384,13 +384,13 @@ DWORD dwStatus;
dwStatus = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM|
FORMAT_MESSAGE_IGNORE_INSERTS, // __in DWORD dwFlags,
NULL, // __in_opt LPCVOID lpSource,
dwError, // __in DWORD dwMessageId,
Error, // __in DWORD dwMessageId,
0, // __in DWORD dwLanguageId,
szMsgBuffer, // __out LPTSTR lpBuffer,
sizeof (szMsgBuffer) -1, // __in DWORD nSize,
NULL); // __in_opt va_list *Arguments
if (0 == dwStatus)
snprintf(szMsgBuffer, sizeof(szMsgBuffer) - 1, "Error Code: 0x%lX", dwError);
snprintf(szMsgBuffer, sizeof(szMsgBuffer) - 1, "Error Code: 0x%lX", Error);
while (sim_isspace (szMsgBuffer[strlen (szMsgBuffer)-1]))
szMsgBuffer[strlen (szMsgBuffer) - 1] = '\0';
return szMsgBuffer;
@ -400,7 +400,7 @@ t_stat sim_copyfile (const char *source_file, const char *dest_file, t_bool over
{
if (CopyFileA (source_file, dest_file, !overwrite_existing))
return SCPE_OK;
return sim_messagef (SCPE_ARG, "Error Copying '%s' to '%s': %s\n", source_file, dest_file, GetErrorText (GetLastError ()));
return sim_messagef (SCPE_ARG, "Error Copying '%s' to '%s': %s\n", source_file, dest_file, sim_get_os_error_text (GetLastError ()));
}
#include <io.h>
@ -471,6 +471,12 @@ return ftruncate(fileno(fptr), (off_t)size);
#include <utime.h>
#endif
const char *
sim_get_os_error_text (int Error)
{
return strerror (Error);
}
t_stat sim_copyfile (const char *source_file, const char *dest_file, t_bool overwrite_existing)
{
FILE *fIn = NULL, *fOut = NULL;

View file

@ -69,6 +69,7 @@ t_offset sim_fsize_name_ex (const char *fname);
t_stat sim_copyfile (const char *source_file, const char *dest_file, t_bool overwrite_existing);
void sim_buf_swap_data (void *bptr, size_t size, size_t count);
void sim_buf_copy_swapped (void *dptr, const void *bptr, size_t size, size_t count);
const char *sim_get_os_error_text (int error);
typedef struct SHMEM SHMEM;
t_stat sim_shmem_open (const char *name, size_t size, SHMEM **shmem, void **addr);
void sim_shmem_close (SHMEM *shmem);