800KB raw images may be mis-detected as MGT
Closed this issue · 2 comments
From a user report:
They are trying to write a 80x2x5x1024 (= 800KB) RAW image for a CP/M machine to floppy under Windows, and override sector size and count (-s5 -z3), however image is detected as MGT and these options are ignored. I suppose that MGT detection could be improved by checking magic numbers at a different offset?
Unfortunately, 800KiB files fall back on MGT for backwards compatibility, to ensure quirky SAM Coupé disks are still recognised. It's also partly to allow zero-filled files to be treated as MGT, where there's no disk content to match against signatures.
It's supposed to be possible to override the format, to change some values from the detected defaults. In your case I hoped using -s 5 (5 sectors per track) or -z 3 (1024 bytes per sector) would be enough to get it correctly recognised, but it doesn't seem to be working. Either it's broken or I never got around to finishing that -- I'll check!
It'd also be worth me changing the MGT reader to only accept file extensions known to be used for MGT disks: .dsk, .img, .mgt. Unfortunately, the first two are quite common disk image extensions. It could perhaps also treat completely blank images as a special case.
Raw formats (including MGT) should only be tried when signature recognition has failed on other types. Perhaps another format is needed to recognise them? The CP/M support in SAMdisk is also fairly tied to SAM Coupé Pro-DOS, so it's unlikely to recognise other CP/M formats without some help.
I've pushed a couple of commits that should hopefully resolve this.
The MGT file reader is now stricter, and requires either directory signature matches or a .mgt file extension. Blank files and quirky SAM disks without a .mgt extension will fall back to the RAW file handler, which will use the same format, but with a warning.
If the raw file handler guesses the wrong format, you can override parts of it to correct it. The default for an 800K file is still the MGT format:
$ samdisk info 800.img
[800.img]
Warning: input format guessed from file size -- please check
Type: RAW
Format: 250Kbps MFM, 80 cyls, 2 heads, 10 sectors, 512 bytes/sector
However, you can override parts of the geometry:
$ samdisk info 800.img -s5
[800.img]
Type: RAW
Format: 250Kbps MFM, 80 cyls, 2 heads, 5 sectors, 1024 bytes/sector
In that case the sector size has been adjusted to match the change in sector count. You can do it with cyls/heads and it works changing either value too:
$ samdisk info 800.img -z3
[800.img]
Type: RAW
Format: 250Kbps MFM, 80 cyls, 2 heads, 5 sectors, 1024 bytes/sector
Similarly, a completely unrecognised file format such as an empty 810K image will normally be rejected:
$ samdisk info 810.img
[810.img]
Error: unrecognised disk image format
However, providing sufficient details from the 80/2/0/512 default allows it to be recognised:
$ samdisk info 810.img -c81 -s10
[810.img]
Type: RAW
Format: 250Kbps MFM, 81 cyls, 2 heads, 10 sectors, 512 bytes/sector