]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Plain HDF with virtual RDB fix.
authorToni Wilen <twilen@winuae.net>
Sat, 10 Jan 2026 17:46:43 +0000 (19:46 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 10 Jan 2026 17:46:43 +0000 (19:46 +0200)
hardfile.cpp
od-win32/hardfile_win32.cpp

index 9e15912e334bd93ed4211d72eba8d3266d1312fb..172038af12c49fe53affdf4001dc6fdaf150c86e 100644 (file)
@@ -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;
 }
 
index 323a453187553fb7a8fe34a532801aa44ee296b7..8d5d388450ffe8fb7c7990c515163bbaf67e478f 100644 (file)
@@ -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;