Linux Disk Commands
Device Concept
Linux generally makes heavy use of its filesystem, and access to hardware devices is no exception. For floppy disks, the raw content of the disk (i.e. without interpreting the disk as folders and files) is accessed through a device file. Traditionally, the first floppy drive is called /dev/fd0 and the second is /dev/fd1. Reading data from these devices translates into accesses to the raw data on the floppy disk. The data is read in logical sector order, so the image will conform to the '.ST' format used by some emulators. The commands that manipulate the disk directly (e.g. setting the disk size) are from the fdutils package, and those that manipulate files within the image are from the mtools package.
Reading the Image
The following command will create a disk image "image.st" for the disk in the first floppy drive:
cp /dev/fd0 image.st
The drivers for the disk drive usually sense the disk format correctly, detecting extra tracks and sectors. If this doesn't happen, you can set the format manually. This example sets 10 sectors, 83 tracks, double-sided:
setfdprm /dev/fd0 dd ds sect=10 cyl=82
Note that sectors count from 1, but cylinders count from 0.
Fast Format
Some disks formatted with Fastcopy III or Fastcopy Pro on the Atari ST are known to be unreadable on some PCs, even when accessing the disk controller directly. The skewing of the disk is beyond the capabilities of the hardware. If you encounter this problem, you will have to copy the disk contents using an Atari ST or other hardware that does not suffer the same problem.
Writing the Image
To write the image to a disk, first make sure that the disk has the right format, then copy the image back to the appropriate floppy device.
You can find out some information about the image with the following handy script. It reads details from the bootsector to identify the sides, sectors and tracks on the disk:
#!/bin/sh od -v -Ad -t u1 -w1 $1 | awk 'NR==20 {sl=$2} NR==21 {sh=$2} NR==25 {spt=$2} NR==27 {s=$2; print "Sides: " s " Sectors: " spt " Tracks: " (sh * 256 + sl) / spt / s; exit}'
Paste the script into a file 'imgstats', then use the following command to make the file executable:
chmod 700 imgstats
You can then use the script to analyse a floppy disk image in .ST format:
./imgstats image.st Sides: 2 Sectors: 9 Tracks: 80
The disk can be formatted with superformat. You specify the disk and the size in the same way as for setfdprm:
superformat /dev/fd0 dd ds sect=10 cyl=80
Linux will generally trust whatever the disk boot sector says the size of the disk is, rather than looking around the disk. You can probe the disk for its size with various low-level floppy disk controller commands if need be - there's a tutorial in the fdutils documentation. If you know how many sectors and tracks the disk has had formatted on it, regardless of what disk image was written to it, you can set the parameters directly (they should last until you take the disk out):
setfdprm /dev/fd0 dd ds sect=10 cyl=82
Generally, you should only do this when you're sure that the number of sectors is the same and the number of tracks is sufficient. If in doubt, reformat the disk to the right size before writing the image.
To write the image:
cp image.st /dev/fd0
Using the Disk Directly
Linux has a suite of programs, mtools, that are designed to work with floppy disks and disk images. The commands mirror the old MS-DOS commands for working with disks. For example:
mdir a:
Will give a DOS-style directory listing for the disk in the first floppy drive.
mkdir files mcopy -s a:/ files
This command will copy the entire content of the disk, recursively, to the directory 'files'.
Using a Disk Image
Newer versions of mtools allow access to disk images as well as real floppy disks. Add the option '-i image.st' for whatever image you want to use, and use the drive letter ':' instead of a real drive letter. For example:
mdir -i image.st ::/
mkdir files mcopy -i image.st -s ::/ files
There are some other disk image formats, such as MSA and DIM.
MSA is the format created by the Magic Shadow Archiver, it's very popular for use with emulators. Thomas Huth has created a Linux program to convert between the '.ST' format and the '.MSA' format.
The DIM format is created using FastCopy. It is the same as the '.ST' format, but with some additional information in a 32-byte header. You can convert this with the following command, which simply strips off the first 32 bytes:
dd if=image.dim of=image.st bs=32 skip=1