diff --git a/modules/diskdump/lib/diskdump.js b/modules/diskdump/lib/diskdump.js index a8698f30f..e10079266 100644 --- a/modules/diskdump/lib/diskdump.js +++ b/modules/diskdump/lib/diskdump.js @@ -2142,14 +2142,18 @@ DiskDump.prototype.convertToJSON = function() var cbDiskData = this.bufDisk.length; if (cbDiskData >= 3000000) { // arbitrary threshold between diskette image sizes and hard disk image sizes - /* - * In this case, the first sector should be an MBR; find the active partition entry, - * then read the LBA of the first partition sector to calculate the boot sector offset. - */ - for (var offEntry = 0x1BE; offEntry <= 0x1EE; offEntry += 0x10) { - if (this.bufDisk.readUInt8(offEntry) >= 0x80) { - offBootSector = this.bufDisk.readUInt16LE(offEntry + 0x08) * cbSector; - break; + var wSig = this.bufDisk.readUInt16LE(0x1FE); + if (wSig == 0xAA55) { + /* + * In this case, the first sector should be an MBR; find the active partition entry, + * then read the LBA of the first partition sector to calculate the boot sector offset. + */ + for (var offEntry = 0x1BE; offEntry <= 0x1EE; offEntry += 0x10) { + if (this.bufDisk.readUInt8(offEntry) >= 0x80) { + offBootSector = this.bufDisk.readUInt32LE(offEntry + 0x08) * cbSector; + cbDiskData = this.bufDisk.readUInt32LE(offEntry + 0x0C) * cbSector; + break; + } } } /* diff --git a/modules/shared/lib/diskapi.js b/modules/shared/lib/diskapi.js index 809513046..81b38ab15 100644 --- a/modules/shared/lib/diskapi.js +++ b/modules/shared/lib/diskapi.js @@ -83,7 +83,11 @@ DiskAPI.DISKETTE_FORMATS = { 737280: [80,2,9], // media type 0xF9: 80 cylinders, 2 heads (double-sided), 9 sectors/track, (1440 total sectors x 512 bytes/sector == 737280) 1228800: [80,2,15], // media type 0xF9: 80 cylinders, 2 heads (double-sided), 15 sectors/track, (2400 total sectors x 512 bytes/sector == 1228800) 1474560: [80,2,18], // media type 0xF0: 80 cylinders, 2 heads (double-sided), 18 sectors/track, (2880 total sectors x 512 bytes/sector == 1474560) - 2949120: [80,2,36] // media type 0xF0: 80 cylinders, 2 heads (double-sided), 36 sectors/track, (5760 total sectors x 512 bytes/sector == 2949120) + 2949120: [80,2,36], // media type 0xF0: 80 cylinders, 2 heads (double-sided), 36 sectors/track, (5760 total sectors x 512 bytes/sector == 2949120) + /* + * The following are common early hard disk sizes, which we explicitly map to CHS values, since the BPB can mislead us when attempting to calculate total cylinders + */ + 21368320:[615,4,17] // PC AT 20Mb hard disk (type 2) }; DiskAPI.MBR = {