DISK: Add support for reporting OS specific error messages when using RAW I/O
This commit is contained in:
parent
60db7e7239
commit
335b4ef210
3 changed files with 17 additions and 6 deletions
|
@ -1984,8 +1984,12 @@ switch (DK_GET_FMT (uptr)) { /* case on format */
|
||||||
case DKUF_F_STD: /* SIMH format */
|
case DKUF_F_STD: /* SIMH format */
|
||||||
case DKUF_F_VHD: /* VHD format */
|
case DKUF_F_VHD: /* VHD format */
|
||||||
case DKUF_F_RAW: /* Raw Physical Disk Access */
|
case DKUF_F_RAW: /* Raw Physical Disk Access */
|
||||||
|
#if defined(_WIN32)
|
||||||
|
saved_errno = GetLastError ();
|
||||||
|
#endif
|
||||||
perror (msg);
|
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:
|
default:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
16
sim_fio.c
16
sim_fio.c
|
@ -375,8 +375,8 @@ return sim_fseeko (st, (t_offset)offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static const char *
|
const char *
|
||||||
GetErrorText(DWORD dwError)
|
sim_get_os_error_text (int Error)
|
||||||
{
|
{
|
||||||
static char szMsgBuffer[2048];
|
static char szMsgBuffer[2048];
|
||||||
DWORD dwStatus;
|
DWORD dwStatus;
|
||||||
|
@ -384,13 +384,13 @@ DWORD dwStatus;
|
||||||
dwStatus = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM|
|
dwStatus = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM|
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS, // __in DWORD dwFlags,
|
FORMAT_MESSAGE_IGNORE_INSERTS, // __in DWORD dwFlags,
|
||||||
NULL, // __in_opt LPCVOID lpSource,
|
NULL, // __in_opt LPCVOID lpSource,
|
||||||
dwError, // __in DWORD dwMessageId,
|
Error, // __in DWORD dwMessageId,
|
||||||
0, // __in DWORD dwLanguageId,
|
0, // __in DWORD dwLanguageId,
|
||||||
szMsgBuffer, // __out LPTSTR lpBuffer,
|
szMsgBuffer, // __out LPTSTR lpBuffer,
|
||||||
sizeof (szMsgBuffer) -1, // __in DWORD nSize,
|
sizeof (szMsgBuffer) -1, // __in DWORD nSize,
|
||||||
NULL); // __in_opt va_list *Arguments
|
NULL); // __in_opt va_list *Arguments
|
||||||
if (0 == dwStatus)
|
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]))
|
while (sim_isspace (szMsgBuffer[strlen (szMsgBuffer)-1]))
|
||||||
szMsgBuffer[strlen (szMsgBuffer) - 1] = '\0';
|
szMsgBuffer[strlen (szMsgBuffer) - 1] = '\0';
|
||||||
return szMsgBuffer;
|
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))
|
if (CopyFileA (source_file, dest_file, !overwrite_existing))
|
||||||
return SCPE_OK;
|
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>
|
#include <io.h>
|
||||||
|
@ -471,6 +471,12 @@ return ftruncate(fileno(fptr), (off_t)size);
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
#endif
|
#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)
|
t_stat sim_copyfile (const char *source_file, const char *dest_file, t_bool overwrite_existing)
|
||||||
{
|
{
|
||||||
FILE *fIn = NULL, *fOut = NULL;
|
FILE *fIn = NULL, *fOut = NULL;
|
||||||
|
|
|
@ -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);
|
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_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);
|
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;
|
typedef struct SHMEM SHMEM;
|
||||||
t_stat sim_shmem_open (const char *name, size_t size, SHMEM **shmem, void **addr);
|
t_stat sim_shmem_open (const char *name, size_t size, SHMEM **shmem, void **addr);
|
||||||
void sim_shmem_close (SHMEM *shmem);
|
void sim_shmem_close (SHMEM *shmem);
|
||||||
|
|
Loading…
Add table
Reference in a new issue