DiskDump should now automatically shrink a disk image whose logical format is smaller than its physical format

This commit is contained in:
Jeff Parsons 2017-07-04 15:25:54 -07:00 committed by Jeff Parsons
commit 3ba2f569b9
6 changed files with 33 additions and 39 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -7,7 +7,7 @@
<category>Productivity</category>
<author>Lotus</author>
<releaseDate/>
<disk id="disk01" size="368640" chs="40:2:9" img="archive/123-DISK1-SYSTEM-PATCHED.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK1-SYSTEM-PATCHED.json" md5="02b4711a30c8100415026c38e542ddc3" md5json="a6440e2e7c766cca184708a969213d00">
<disk id="disk01" size="327680" chs="40:2:8" img="archive/123-DISK1-SYSTEM-PATCHED.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK1-SYSTEM-PATCHED.json" md5="02b4711a30c8100415026c38e542ddc3" md5json="67bd239caae3fe973447efd7d11fef70">
<name>Lotus 1-2-3 1.0a (1-System)</name>
<file size="256" time="1983-07-01 02:23:00" attr="0x20">123.CNF</file>
<file size="89984" time="1984-08-17 16:59:30" attr="0x20">123.EXE</file>
@ -21,7 +21,7 @@
<file size="329" time="1983-07-01 02:23:00" attr="0x20">PR.DRV</file>
<file size="5294" time="1983-07-01 02:23:00" attr="0x20">TD.DRV</file>
</disk>
<disk id="disk02" size="368640" chs="40:2:9" img="archive/123-DISK2-UTILITY.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK2-UTILITY.json" md5="3f76942627e958a5495656f0332c88a4" md5json="7bc7de246155e26a41f844bf0d993067">
<disk id="disk02" size="327680" chs="40:2:8" img="archive/123-DISK2-UTILITY.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK2-UTILITY.json" md5="3f76942627e958a5495656f0332c88a4" md5json="b8c3ff0aab7450550937012b992b5ba5">
<name>Lotus 1-2-3 1.0a (2-Utility)</name>
<file size="1036" time="1983-07-01 01:23:00" attr="0x20">B&amp;W.BAT</file>
<file size="1036" time="1983-07-01 01:23:00" attr="0x20">BOTH.BAT</file>
@ -57,7 +57,7 @@
<file size="16128" time="1983-07-01 01:23:00" attr="0x20">WKSDBF.EXE</file>
<file size="14336" time="1983-07-01 01:23:00" attr="0x20">WKSDIF.EXE</file>
</disk>
<disk id="disk03" size="368640" chs="40:2:9" img="archive/123-DISK3-GRAPH.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK3-GRAPH.json" md5="f7169659ec0f1f7666390fe2bc9c6f46" md5json="844c406a7534242cdaf2898bfa43b40a">
<disk id="disk03" size="327680" chs="40:2:8" img="archive/123-DISK3-GRAPH.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK3-GRAPH.json" md5="f7169659ec0f1f7666390fe2bc9c6f46" md5json="64bd8a111a8d7551acb5e06ddea75e80">
<name>Lotus 1-2-3 1.0a (3-Graph)</name>
<file size="3597" time="1983-07-01 01:23:00" attr="0x20">BLOCK1.FON</file>
<file size="6593" time="1983-07-01 01:23:00" attr="0x20">BLOCK2.FON</file>
@ -80,7 +80,7 @@
<file size="7726" time="1983-07-01 01:23:00" attr="0x20">SCRIPT2.FON</file>
<file size="5294" time="1983-07-01 01:23:00" attr="0x20">TD.DRV</file>
</disk>
<disk id="disk04" size="368640" chs="40:2:9" img="archive/123-DISK4-TUTORIAL.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK4-TUTORIAL.json" md5="532be253f5efd4c43b1c72551eb005dd" md5json="bc32e9675734b2986f1bd25559163fe4">
<disk id="disk04" size="327680" chs="40:2:8" img="archive/123-DISK4-TUTORIAL.img" href="/disks/pcx86/apps/lotus/123/1.0a/123-DISK4-TUTORIAL.json" md5="532be253f5efd4c43b1c72551eb005dd" md5json="33aefdb820476048491cacb8041df388">
<name>Lotus 1-2-3 1.0a (4-Tutorial)</name>
<file size="2139" time="1983-07-01 01:23:00" attr="0x20">GD.DRV</file>
<file size="352" time="1983-07-01 01:23:00" attr="0x20">KB.DRV</file>

View file

@ -2768,26 +2768,32 @@ DiskDump.prototype.convertToJSON = function()
}
}
}
var nLogicalSectorsPerTrack = nSectorsPerTrack;
if (iBPB >= 0) {
/*
* Sometimes we come across a physical 360Kb disk image that contains a logical 320Kb image (and similarly,
* a physical 180Kb disk image that contains a logical 160Kb disk image), presumably because it was possible
* for someone to take a diskette formatted with 9 sectors/track and then use FORMAT or DISKCOPY to create
* a smaller file system on it (ie, using only 8 sectors/track).
*/
if (!bMediaIDBPB) bMediaIDBPB = this.bufDisk.readUInt8(offBootSector + 512);
if (iBPB >= 2 && bMediaIDBPB == DiskAPI.FAT.MEDIA_320KB && bMediaID == DiskAPI.FAT.MEDIA_360KB || bMediaIDBPB == DiskAPI.FAT.MEDIA_160KB && bMediaID == DiskAPI.FAT.MEDIA_180KB) {
iBPB -= 2;
bMediaID = DiskDump.aDefaultBPBs[iBPB][DiskAPI.BPB.MEDIA_ID];
nLogicalSectorsPerTrack = DiskDump.aDefaultBPBs[iBPB][DiskAPI.BPB.TRACK_SECS];
DiskDump.logWarning("shrinking track size to " + nLogicalSectorsPerTrack + " sectors/track");
}
if (fBPBExists) {
/*
* In deference to the PC-DOS 2.0 BPB behavior discussed above, we stop our BPB verification
* after the first word of HIDDEN_SECS.
*
* Also, we permit a physical 360Kb disk image to contain a logical 320Kb image (and similarly, a physical
* 180Kb disk image to contain a logical 160Kb disk image), because it was entirely possible for someone to
* take a diskette formatted with 9 sectors/track and "DISKCOPY" another disk with only 8 sectors/track onto it.
* When we imaged the physical disk, we likely read all readable sectors, regardless of whether the file system
* contained within used them all or not.
*/
if ((bMediaIDBPB != DiskAPI.FAT.MEDIA_320KB || bMediaID != DiskAPI.FAT.MEDIA_360KB) && (bMediaIDBPB != DiskAPI.FAT.MEDIA_160KB || bMediaID != DiskAPI.FAT.MEDIA_180KB)) {
for (i = DiskAPI.BPB.SECTOR_BYTES; i < DiskAPI.BPB.HIDDEN_SECS + 2; i++) {
var bDefault = DiskDump.aDefaultBPBs[iBPB][i];
var bActual = this.bufDisk.readUInt8(offBootSector + i);
if (bDefault != bActual) {
DiskDump.logWarning("BPB byte " + str.toHexByte(i) + " default (" + str.toHexByte(bDefault) + ") does not match actual byte: " + str.toHexByte(bActual));
fBPBExists = false;
}
for (i = DiskAPI.BPB.SECTOR_BYTES; i < DiskAPI.BPB.HIDDEN_SECS + 2; i++) {
var bDefault = DiskDump.aDefaultBPBs[iBPB][i];
var bActual = this.bufDisk.readUInt8(offBootSector + i);
if (bDefault != bActual) {
DiskDump.logWarning("BPB byte " + str.toHexByte(i) + " default (" + str.toHexByte(bDefault) + ") does not match actual byte: " + str.toHexByte(bActual));
fBPBExists = false;
}
}
}
@ -2806,19 +2812,7 @@ DiskDump.prototype.convertToJSON = function()
*
* However, if --forceBPB is specified, all those concerns go out the window: the goal is assumed to
* be a mountable disk, not a bootable disk. So the BPB copy starts at offset 0 instead of SECTOR_BYTES.
*
* And again, we must also deal with a physical 360Kb disk image containing a logical 320Kb image (and
* similarly, a physical 180Kb disk image containing a logical 160Kb disk image). So we check the FAT ID
* byte to make sure we're using a BPB that matches the logical disk image.
*/
bMediaIDBPB = this.bufDisk.readUInt8(offBootSector + 512);
if (bMediaIDBPB == DiskAPI.FAT.MEDIA_320KB && bMediaID == DiskAPI.FAT.MEDIA_360KB) {
if (iBPB == 3) iBPB = 1;
}
else if (bMediaIDBPB == DiskAPI.FAT.MEDIA_160KB && bMediaID == DiskAPI.FAT.MEDIA_180KB) {
if (iBPB == 2) iBPB = 0;
}
bMediaID = DiskDump.aDefaultBPBs[iBPB][DiskAPI.BPB.MEDIA_ID];
for (i = this.forceBPB? 0 : DiskAPI.BPB.SECTOR_BYTES; i < DiskAPI.BPB.LARGE_SECS+4; i++) {
this.bufDisk.writeUInt8(DiskDump.aDefaultBPBs[iBPB][i] || 0, offBootSector + i);
}
@ -2878,13 +2872,13 @@ DiskDump.prototype.convertToJSON = function()
cbSector = cbSectorDSK;
nHeads = this.bufDisk.readUInt8(offBootSector + 0x01);
nCylinders = this.bufDisk.readUInt16LE(offBootSector + 0x02);
nSectorsPerTrack= this.bufDisk.readUInt16LE(offBootSector + 0x04);
nLogicalSectorsPerTrack = nSectorsPerTrack = this.bufDisk.readUInt16LE(offBootSector + 0x04);
var nTracks = nHeads * nCylinders;
cbTrack = nSectorsPerTrack * cbSector;
offTrack = 0x08;
if (!cbTrack) {
for (iTrack = 0; iTrack < nTracks; iTrack++) {
nSectorsPerTrack = this.bufDisk.readUInt16LE(offTrack);
nLogicalSectorsPerTrack = nSectorsPerTrack = this.bufDisk.readUInt16LE(offTrack);
cbSectorDSK = this.bufDisk.readUInt16LE(offTrack+2);
cbTrack = nSectorsPerTrack * cbSectorDSK;
offSector = this.bufDisk.readUInt32LE(offTrack+4);
@ -2923,7 +2917,7 @@ DiskDump.prototype.convertToJSON = function()
if (aTracks.length) {
var aTrack = aTracks[iTrack++];
nSectorsPerTrack = aTrack[0];
nLogicalSectorsPerTrack = nSectorsPerTrack = aTrack[0];
cbSector = aTrack[1];
bufTrack = aTrack[2];
cbTrack = nSectorsPerTrack * cbSector;
@ -2933,7 +2927,7 @@ DiskDump.prototype.convertToJSON = function()
var aSectors;
if (this.fJSONNative) {
aSectors = new Array(nSectorsPerTrack);
aSectors = new Array(nLogicalSectorsPerTrack);
aHeads[iHead] = aSectors;
} else {
json += this.dumpLine(2, "[", "head:" + this.sJSONWhitespace + iHead + ", track:" + this.sJSONWhitespace + iCylinder);
@ -2947,7 +2941,7 @@ DiskDump.prototype.convertToJSON = function()
* be unnecessary.
*/
var cbSectorThisTrack = cbSector;
var nSectorsThisTrack = nSectorsPerTrack;
var nSectorsThisTrack = nLogicalSectorsPerTrack;
/*
* Notes regarding XDF track layouts, from http://forum.kryoflux.com/viewtopic.php?f=3&t=234: