uci->device_emu_unit = -1;
}
-static void get_usedblocks(struct fs_usage *fsu, bool fs, int *pblocksize, uae_s64 *pnumblocks, uae_s64 *pinuse)
+static void get_usedblocks(struct fs_usage *fsu, bool fs, int *pblocksize, uae_s64 *pnumblocks, uae_s64 *pinuse, bool reduce)
{
uae_s64 numblocks = 0, inuse;
int blocksize = *pblocksize;
fsu->avail *= 1024;
}
}
- while (blocksize < 32768 || numblocks == 0) {
+ if (reduce) {
+ while (blocksize < 32768 || numblocks == 0) {
+ numblocks = fsu->total / blocksize;
+ if (numblocks <= 10)
+ numblocks = 10;
+ // Value that does not overflow when multiplied by 100 (uses 128 to keep it simple)
+ if (numblocks < 0x02000000)
+ break;
+ blocksize *= 2;
+ }
+ } else {
numblocks = fsu->total / blocksize;
- if (numblocks <= 10)
- numblocks = 10;
- // Value that does not overflow when multiplied by 100 (uses 128 to keep it simple)
- if (numblocks < 0x02000000)
- break;
- blocksize *= 2;
}
inuse = (numblocks * blocksize - fsu->avail) / blocksize;
if (inuse > numblocks)
*pblocksize = blocksize;
}
-static bool get_blocks(const TCHAR *rootdir, int unit, int flags, int *pblocksize, uae_s64 *pnumblocks, uae_s64 *pinuse)
+static bool get_blocks(const TCHAR *rootdir, int unit, int flags, int *pblocksize, uae_s64 *pnumblocks, uae_s64 *pinuse, bool reduce)
{
struct fs_usage fsu;
int ret;
}
if (ret)
return false;
- get_usedblocks(&fsu, fs, &blocksize, pnumblocks, pinuse);
+ get_usedblocks(&fsu, fs, &blocksize, pnumblocks, pinuse, reduce);
if (pblocksize)
*pblocksize = blocksize;
return ret == 0;
_tcscpy(ui->hf.product_rev, vsp);
xfree(vs);
ui->hf.ci.unit_feature_level = HD_LEVEL_SCSI_2;
- if (get_blocks(c.rootdir, nr, flags, &ui->hf.ci.blocksize, &numblocks, NULL))
+ if (get_blocks(c.rootdir, nr, flags, &ui->hf.ci.blocksize, &numblocks, NULL, false))
ui->hf.ci.max_lba = numblocks > 0xffffffff ? 0xffffffff : numblocks;
else
ui->hf.ci.max_lba = 0x00ffffff;
put_long_host(buf + 28, 0);
} else {
uae_s64 numblocks, inuse;
- get_usedblocks(&fsu, fs, &blocksize, &numblocks, &inuse);
+ get_usedblocks(&fsu, fs, &blocksize, &numblocks, &inuse, true);
//write_log(_T("total %lld avail %lld Blocks %lld Inuse %lld blocksize %d\n"), fsu.total, fsu.avail, numblocks, inuse, blocksize);
put_long_host(buf + 12, (uae_u32)numblocks); /* numblocks */
put_long_host(buf + 16, (uae_u32)inuse); /* inuse */
*tracksec = hfd->ci.sectors;
*cylsec = (*head) * (*tracksec);
*cyl = (unsigned int)(hfd->virtsize / hfd->ci.blocksize) / ((*tracksec) * (*head));
+ if (*cyl == 0)
+ *cyl = (unsigned int)hfd->ci.max_lba / ((*tracksec) * (*head));
return;
}
/* no, lets guess something.. */
else
heads = 255;
*cyl = (unsigned int)(hfd->virtsize / hfd->ci.blocksize) / (sectors * heads);
+ if (*cyl == 0)
+ *cyl = (unsigned int)hfd->ci.max_lba / (sectors * heads);
*cylsec = sectors * heads;
*tracksec = sectors;
*head = heads;
scsi_log (_T("\n"));
if (safeonly && !scsi_cmd_is_safe(sd->cmd[0])) {
+ sd->reply_len = 0;
+ sd->data_len = 0;
sd->status = 2;
sd->sense_len = 18;
sd->sense[0] = 0x70;
case CMD_READ:
if (nodisk (hfd))
goto no_disk;
+ if (vdisk(hfpd))
+ goto v_disk;
offset = get_long_host(iobuf + 44);
len = get_long_host(iobuf + 36); /* io_Length */
if (offset & bmask) {
unaligned (cmd, offset, len, hfd->ci.blocksize);
goto bad_len;
}
- if (vdisk(hfpd)) {
- for (int i = 0; i < len; i++) {
- put_byte(dataptr + i, 0);
- }
- if (offset == 0) {
- put_long(dataptr, 0x444f5301);
- }
- actual = len;
- } else {
- if (len + offset > hfd->virtsize) {
- outofbounds(cmd, offset, len, hfd->virtsize);
- goto bad_len;
- }
- if (isbadblock(hfd, offset, len)) {
- goto bad_block;
- }
- actual = (uae_u32)cmd_read(ctx, hfd, dataptr, offset, len);
+ if (len + offset > hfd->virtsize) {
+ outofbounds(cmd, offset, len, hfd->virtsize);
+ goto bad_len;
}
+ if (isbadblock(hfd, offset, len)) {
+ goto bad_block;
+ }
+ actual = (uae_u32)cmd_read(ctx, hfd, dataptr, offset, len);
break;
#if HDF_SUPPORT_TD64
getchsx (hfd, &cyl, &cylsec, &head, &tracksec);
trap_put_long(ctx, dataptr + 0, hfd->ci.blocksize);
size = hfd->virtsize / hfd->ci.blocksize;
+ if (!size)
+ size = hfd->ci.max_lba;
if (size > 0x00ffffffff)
size = 0xffffffff;
trap_put_long(ctx, dataptr + 4, (uae_u32)size);
#if HDF_SUPPORT_DS
case HD_SCSICMD: /* SCSI */
if (vdisk(hfpd)) {
- error = handle_scsi(ctx, iobuf, request, hfd, hfpd->sd, false);
+ error = handle_scsi(ctx, iobuf, request, hfd, hfpd->sd, true);
} else if (HDF_SUPPORT_DS_PARTITION || enable_ds_partition_hdf || (!hfd->ci.sectors && !hfd->ci.surfaces && !hfd->ci.reserved)) {
error = handle_scsi(ctx, iobuf, request, hfd, hfpd->sd, false);
} else { /* we don't want users trashing their "partition" hardfiles with hdtoolbox */
uae_sem_init (&change_sem, 0, 1);
ROM_hardfile_resname = ds (currprefs.uaescsidevmode == 1 ? _T("scsi.device") : _T("uaehf.device"));
- ROM_hardfile_resid = ds (_T("UAE hardfile.device 0.4"));
+ ROM_hardfile_resid = ds (_T("UAE hardfile.device 0.6"));
nscmd_cmd = here ();
dw (NSCMD_DEVICEQUERY);