]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Fix directory harddrive uaehf.device status reporting.
authorToni Wilen <twilen@winuae.net>
Sat, 28 Apr 2018 12:23:19 +0000 (15:23 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 28 Apr 2018 12:23:19 +0000 (15:23 +0300)
filesys.cpp
hardfile.cpp

index 7165ae924b44ac9240eaad542068f5775c7d5a55..d9d66573c1e63b5533041f7302fd70018a4999ad 100644 (file)
@@ -595,7 +595,7 @@ void uci_set_defaults (struct uaedev_config_info *uci, bool rdb)
        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;
@@ -608,14 +608,18 @@ static void get_usedblocks(struct fs_usage *fsu, bool fs, int *pblocksize, uae_s
                        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)
@@ -628,7 +632,7 @@ static void get_usedblocks(struct fs_usage *fsu, bool fs, int *pblocksize, uae_s
                *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;
@@ -645,7 +649,7 @@ static bool get_blocks(const TCHAR *rootdir, int unit, int flags, int *pblocksiz
        }
        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;
@@ -749,7 +753,7 @@ static int set_filesys_unit_1 (int nr, struct uaedev_config_info *ci)
                _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;
@@ -3392,7 +3396,7 @@ static void       do_info(TrapContext *ctx, Unit *unit, dpacket *packet, uaecptr info,
                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 */
index 42791ca25fd7659a18d2899096c24e2555d0aeb3..45ac90716496d35049c366024f172bb50e7f2632 100644 (file)
@@ -144,6 +144,8 @@ static void getchs2 (struct hardfiledata *hfd, int *cyl, int *cylsec, int *head,
                *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.. */
@@ -158,6 +160,8 @@ static void getchs2 (struct hardfiledata *hfd, int *cyl, int *cylsec, int *head,
        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;
@@ -2251,6 +2255,8 @@ static int handle_scsi (TrapContext *ctx, uae_u8 *iobuf, uaecptr request, struct
        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;
@@ -2563,6 +2569,8 @@ static uae_u32 hardfile_do_io (TrapContext *ctx, struct hardfiledata *hfd, struc
        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) {
@@ -2573,24 +2581,14 @@ static uae_u32 hardfile_do_io (TrapContext *ctx, struct hardfiledata *hfd, struc
                        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
@@ -2731,6 +2729,8 @@ static uae_u32 hardfile_do_io (TrapContext *ctx, struct hardfiledata *hfd, struc
                        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);
@@ -2799,7 +2799,7 @@ static uae_u32 hardfile_do_io (TrapContext *ctx, struct hardfiledata *hfd, struc
 #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 */
@@ -3021,7 +3021,7 @@ void hardfile_install (void)
        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);