Strange File Resizing on DOS
os2museum.com
os2museum.com
CP/M had a submit-command, which would read a text-file containing a list of commands and write out a file named $$$.SUB to the A:.
Later when the CP/M booted (via a cold start, or a warm start which was triggered by pressing Ctrl-C) it would be processed.
The $$$.SUB file was processed in reverse, and it would be assumed to contain N entries of 128 bytes each. The last record would be read, the command be executed, and the file would be resized down by 128 bytes.
So given input like:
FOO
BAR
BAZ
The CP/M command-processor (i.e. shell) would run "BAZ", truncate the $$$.SUB file by 128 bytes. Then it would do the same, executing "BAR", truncating down, and then running "FOO", truncating down to zero, and erasing.How do I know this? I wrote a CP/M emulator and had a devil of a time working out the behaviour, but the CP/M "Close File" call will truncate a file is some values of the FCB tell it to. Since CP/M itself used this I can only assume that user-programs did too.
The "last record" field of the FCB / direntry will be decremented for each line, so that the shell can keep track of where in the file it should continue (this can't be stored in memory, because programs are explicitly allowed to overwrite the command processor). But the space on disk won't be freed until it's done executing all commands in the file.
For an emulator it makes sense to actually truncate the file, because on other systems there is likely no way to store a "logical" file size that is shorter than the actual one.
On Windows, the resulting file is guaranteed to have any intervening bytes zero-initialized, but for DOS, that wasn't always the case, and any thus-created file could recycle previously deleted data, especially on redirected filesystems (e.g. LAN Manager or Novell NetWare volumes).
It definitely is a problem if a network server extends files that way!
NTFS has a "zero fill" flag that the OS sets for newly allocated blocks, so it doesn't actually have to fill them on disk - it can just return zeroes when an application tries to read from a part of the file that hasn't been written yet. I believe ext4 and all other modern filesystems have this optimization as well.
That depends: if the operation was on a floppy you got from someone else, that data might very well be theirs.
> NTFS has a "zero fill" flag
True, but irrelevant: the Windows API guarantees the "seeking to an offset greater than the file length and then writing anything, including nothing, will fill the intervening bytes with zeroes" behavior. How this translates to the underlying file system (which may very well not be NTFS) is an implementation detail.