From bdf7ee4a54cb2d4dae492634d8b428a4aa553e2b Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 10 Jan 2026 19:46:43 +0200 Subject: [PATCH] Plain HDF with virtual RDB fix. --- hardfile.cpp | 29 +++++++++++-------------- od-win32/hardfile_win32.cpp | 42 ++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/hardfile.cpp b/hardfile.cpp index 9e15912e..172038af 100644 --- a/hardfile.cpp +++ b/hardfile.cpp @@ -1148,21 +1148,14 @@ static int hdf_read2(struct hardfiledata *hfd, void *buffer, uae_u64 offset, int static int hdf_write2(struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len, uae_u32 *error) { - if (len > INT_MAX) + if (len > INT_MAX) { return 0; - int ret = 0, extra = 0; - // writes to virtual RDB are ignored + } + int ret = 0; + // writes to virtual RDB return write protected if (offset < hfd->virtual_size) { - uae_s64 len2 = offset + len <= hfd->virtual_size ? len : hfd->virtual_size - offset; - if (len2 > INT_MAX) { - return 0; - } - len -= (int)len2; - if (len <= 0) - return (int)len2; - offset += len2; - buffer = (uae_u8*)buffer + len2; - extra = (int)len2; + *error = 28; + return 0; } offset -= hfd->virtual_size; @@ -1198,7 +1191,6 @@ static int hdf_write2(struct hardfiledata *hfd, void *buffer, uae_u64 offset, in if (ret <= 0) return ret; - ret += extra; return ret; } @@ -1282,8 +1274,9 @@ int hdf_read(struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len, ua v = hdf_cache_read(hfd, buffer, offset, len, error); adide_decode(buffer, len); } - if (hfd->byteswap) + if (hfd->byteswap) { hdf_byteswap(buffer, len); + } return v; } @@ -1302,8 +1295,9 @@ int hdf_write(struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len, u hf_log3(_T("cmd_write: %p %04x-%08x (%d) %08x (%d)\n"), buffer, (uae_u32)(offset >> 32), (uae_u32)offset, (uae_u32)(offset / hfd->ci.blocksize), (uae_u32)len, (uae_u32)(len / hfd->ci.blocksize)); - if (hfd->byteswap) + if (hfd->byteswap) { hdf_byteswap(buffer, len); + } if (!hfd->adide) { v = hdf_cache_write(hfd, buffer, offset, len, error); } else { @@ -1312,8 +1306,9 @@ int hdf_write(struct hardfiledata *hfd, void *buffer, uae_u64 offset, int len, u v = hdf_cache_write(hfd, buffer, offset, len, error); adide_decode(buffer, len); } - if (hfd->byteswap) + if (hfd->byteswap) { hdf_byteswap(buffer, len); + } return v; } diff --git a/od-win32/hardfile_win32.cpp b/od-win32/hardfile_win32.cpp index 323a4531..8d5d3884 100644 --- a/od-win32/hardfile_win32.cpp +++ b/od-win32/hardfile_win32.cpp @@ -2379,9 +2379,7 @@ static int hdf_seek (struct hardfiledata *hfd, uae_u64 offset, bool write) abort(); } if (hfd->physsize) { - if (offset >= hfd->physsize - hfd->virtual_size) { - if (hfd->virtual_rdb) - return -1; + if (offset >= hfd->physsize) { if (write) { gui_message (_T("hd: tried to seek out of bounds! (%I64X >= %I64X - %I64X)\n"), offset, hfd->physsize, hfd->virtual_size); abort (); @@ -2405,15 +2403,16 @@ static int hdf_seek (struct hardfiledata *hfd, uae_u64 offset, bool write) LARGE_INTEGER fppos; fppos.QuadPart = offset; ret = SetFilePointer(hfd->handle->h, fppos.LowPart, &fppos.HighPart, FILE_BEGIN); - if (ret == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) + if (ret == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) { return -1; + } } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { zfile_fseek (hfd->handle->zf, (long)offset, SEEK_SET); } return 0; } -static void poscheck (struct hardfiledata *hfd, int len) +static void poscheck(struct hardfiledata *hfd, int len) { DWORD err; uae_s64 pos = -1; @@ -2421,35 +2420,35 @@ static void poscheck (struct hardfiledata *hfd, int len) if (hfd->handle_valid == HDF_HANDLE_WIN32_NORMAL) { LARGE_INTEGER fppos; fppos.QuadPart = 0; - fppos.LowPart = SetFilePointer (hfd->handle->h, 0, &fppos.HighPart, FILE_CURRENT); + fppos.LowPart = SetFilePointer(hfd->handle->h, 0, &fppos.HighPart, FILE_CURRENT); if (fppos.LowPart == INVALID_SET_FILE_POINTER) { - err = GetLastError (); + err = GetLastError(); if (err != NO_ERROR) { - gui_message (_T("hd: poscheck failed. seek failure, error %d"), err); - abort (); + gui_message(_T("hd: poscheck failed. seek failure, error %d"), err); + abort(); } } pos = fppos.QuadPart; } else if (hfd->handle_valid == HDF_HANDLE_ZFILE) { - pos = zfile_ftell (hfd->handle->zf); + pos = zfile_ftell(hfd->handle->zf); } else if (hfd->handle_valid == HDF_HANDLE_WIN32_CHS) { pos = 0; } if (len < 0) { - gui_message (_T("hd: poscheck failed, negative length! (%d)"), len); - abort (); + gui_message(_T("hd: poscheck failed, negative length! (%d)"), len); + abort(); } if (pos < hfd->offset) { - gui_message (_T("hd: poscheck failed, offset out of bounds! (%I64d < %I64d)"), pos, hfd->offset); - abort (); + gui_message(_T("hd: poscheck failed, offset out of bounds! (%I64d < %I64d)"), pos, hfd->offset); + abort(); } - if (pos >= hfd->offset + hfd->physsize - hfd->virtual_size || pos >= hfd->offset + hfd->physsize + len - hfd->virtual_size) { - gui_message (_T("hd: poscheck failed, offset out of bounds! (%I64d >= %I64d, LEN=%d)"), pos, hfd->offset + hfd->physsize, len); - abort (); + if (pos >= hfd->offset + hfd->physsize) { + gui_message(_T("hd: poscheck failed, offset out of bounds! (%I64d >= %I64d, LEN=%d)"), pos, hfd->offset + hfd->physsize, len); + abort(); } if (pos & (hfd->ci.blocksize - 1)) { - gui_message (_T("hd: poscheck failed, offset not aligned to blocksize! (%I64X & %04X = %04X\n"), pos, hfd->ci.blocksize, pos & hfd->ci.blocksize); - abort (); + gui_message(_T("hd: poscheck failed, offset not aligned to blocksize! (%I64X & %04X = %04X\n"), pos, hfd->ci.blocksize, pos & hfd->ci.blocksize); + abort(); } } @@ -2585,8 +2584,9 @@ static int hdf_read_2(struct hardfiledata *hfd, void *buffer, uae_u64 offset, in return len; } hfd->cache_offset = offset; - if (offset + CACHE_SIZE > hfd->offset + (hfd->physsize - hfd->virtual_size)) - hfd->cache_offset = hfd->offset + (hfd->physsize - hfd->virtual_size) - CACHE_SIZE; + if (offset + CACHE_SIZE > hfd->offset + hfd->physsize) { + hfd->cache_offset = hfd->offset + hfd->physsize - CACHE_SIZE; + } if (hdf_seek(hfd, hfd->cache_offset, false)) { *error = 45; return 0; -- 2.47.3