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;
if (ret <= 0)
return ret;
- ret += extra;
return ret;
}
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;
}
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 {
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;
}
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 ();
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;
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();
}
}
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;