From 93347076a1e57405bac45bc55f338330b8e313da Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sun, 3 Sep 2023 18:35:51 -1000 Subject: [PATCH] DISK: Fix VHD to Ensure that the CHS capacity exceeds the disk length If the total sectors exceeds 127Gb this is not possible, but normal simh disks are smaller and the largest user settable size via RAUSER is just under 1Tb. The excessive size case (>127Gb) will have a CHS of 0xFFFF10FF. simh never cares about the CHS Disk Geometry value in the VHD footer data structure, but other applications which do care about the CHS value using the previously incorrect value as the capacity of the disk even though the Current Size indicated in the footer may have been larger. --- sim_disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim_disk.c b/sim_disk.c index b08f89d0..45dd24a7 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -6515,7 +6515,7 @@ if (1) { /* CHS Calculation */ cylinderTimesHeads = totalSectors / sectorsPerTrack; } } - cylinders = cylinderTimesHeads / heads; + cylinders = (totalSectors + sectorsPerTrack * heads - 1) / (sectorsPerTrack * heads); Footer.DiskGeometry = NtoHl ((cylinders<<16)|(heads<<8)|sectorsPerTrack); } Footer.Checksum = NtoHl (CalculateVhdFooterChecksum(&Footer, sizeof(Footer)));