Wednesday, 9 November 2022

CP/M File System Checker (fsck)

CP/M 2.2 is a very interesting historic operating system. Though very small (approximately 3.6 KB), it manages to achieve quite a lot in this space. Most of the benefits come from its filing system, which though extremely primitive by modern standards is still quite an advance on a "bare metal" machine. The disk format is relatively simple, but still offers file sizes of up to 8 MB - an almost unthinkable size for a machine with  a 64 KB addressing space! As I usually find with such things, there are complexities in the details. It did take me a while to get my head around "logical" versus "physical" extents, for example. Descriptions exist elsewhere on the internet, such as https://www.seasip.info/Cpm/format22.html

fsck

There are a number of ways in which the system could potentially become "confused", though I have not experienced this myself. It is possible for a block to become allocated to more than one file, for example. Some sort of file system checker seems desirable, broadly similar to "fsck" or "chkdsk". A search didn't reveal a suitable one, at least not for generic systems. Writing the CP/M BIOS for ZARC left me with a reasonable understanding of the disk format, so I had a go myself. The results are here: https://github.com/rundel-tech/ZARC/tree/main/software/cpm/cpm_dev/fsck

fsck checks each directory entry for the following errors:

  • User number out of range (>15)
  • Illegal (unprintable) characters in the file name or file type (any character <0x20 or >=0x7f)
  • Extent count out of range (low byte >=32)
  • S1 out of range (not zero)
  • A file contains a duplicated physical extent
  • Block number is out of range

Other errors detected are:

  • "Sparse" files, i.e. ones with gaps in their allocations (warning)
  • Physical extents with no allocations at all (warning)
  • Record count should be 0x80 for all but the last extent.
  • A block is allocated more than once

Note that sparse files are not actually illegal in CP/M, but they are somewhat unusual and so worth warning about.

A disk usage map is displayed, and an optional surface scan is performed to check that all blocks are readable.

Example Run

The following shows fsck being used to check drive E: for errors.

A>fsck e:
*** CP/M File System Checker V1.1 ***

Directory checks complete
Errors and warnings: 0
Files found: 60
Unused directory entries: 446
Blocks used: 212

Block map ('D': directory, 'F': file and '-': unused).
DDDDDDDDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
F-------------------------------------------------------------------------------
---------FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF--------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------
Surface scan skipped
Returning to CP/M.

A>

The optional surface scan was not invoked in this case.  "fsck e: /s" would enable this.

 

No comments:

Post a Comment

Popular Posts