Exact file sizes in CP/M Plus
DOS Plus, CP/M 3 and some CP/M 2 clones (specifically, DOS+2.5) support
exact file sizes. The following system calls support them:
BDOS function 15 - open a file
Entered with DE=address of File Control Block, C=15 (0Fh)
If the byte at FCB+32 (FCB+20h) is 255 (0FFh) then on return from this
function the byte will contain the Last Record Byte Count.
Remember to reset this byte to zero before attempting sequential I/O.
BDOS function 17 - search for first
Entered with DE=address of File Control Block, C=17 (11h)
Returns a pointer to the file's directory entry. The byte at ENTRY+13
(ENTRY+0Dh) contains the Last Record Byte Count.
BDOS function 18 - search for next
Entered with C=18 (12h)
Returns a pointer to the file's directory entry. The byte at ENTRY+13
(ENTRY+0Dh) contains the Last Record Byte Count.
BDOS function 30 - set file attributes
Entered with DE=address of File Control Block, C=30 (1Eh)
To set the Last Record Byte Count, store the required
value at FCB+32 (FCB+20h), and set bit 7 of FCB+6.
From CP/M's point of view, it's just a number from 0-255 associated with
the file which programs can use for any purpose whatever. The documentation
defines no interpretation for it.
If we want programs to be able to share files with exact lengths, then
there had better be some sort of agreement on what the numbers mean. They must
satisfy:
- If the number is zero, the file uses every byte in its disc image (for
compatibility with earlier versions).
- It must be possible to find the number of bytes in the last record exactly.
Unfortunately, this still leaves two plausible systems:
- The number is the number of unused bytes in the last record.
- The number is the number of bytes used in the last record; since this
ranges from 1-128, 0 is not a valid value and we know it means 128.
The only programs I have seen using the system are Tilmann Reh's MSDOS, my
MSODBALL and PIP under DOS Plus; all of these adopt the second interpretation.