A folder as a disk

You can use a folder on your computer as an SD card, a divMMC card or an IDE hard disk. The machine sees a FAT32 disk with your files on it, and its own DOS reads and writes them. Nothing is copied into an image. This page explains how that works and where its limits are. How to use it is described in A folder as a disk, and its settings are in the Folder as a disk group on the Emulation page.

A disk made up as it is read

When you open a folder, Xpeccy+ reads its tree once - names, sizes, dates - and lays out a FAT32 disk in memory around it. The disk has a partition table, a boot sector, two file tables, and one unbroken run of 4 KB clusters for every file. The file tables then follow from simple arithmetic, and only the directories are made up as the machine reads them. A file’s own bytes are read from the file on your computer at the moment the machine reads that part of the disk.

Every file has a long name, as on any FAT32 disk, and a short 8.3 name for an older DOS. In a short name, Russian letters are written in the cp866 code page, which ZX systems expect. Other letters become _. If a name loses something on the way - a long name, or one with spaces or a second dot - its short name ends in ~1, ~2 and so on, as Windows makes them: A long name.tap becomes ALONGN~1.TAP. The tree is read breadth first, so if a limit is reached, the deepest folders are left out, never the program at the top. A link to a folder is followed once. A link that leads back up the tree is left out, so the machine never sees one file under two names.

The disk is 512 MB, or twice that, and so on up to 32 GB - whatever size holds the files. If the folder can be written to, the disk gets as much free space again as its files take, plus 256 MB.

The folder is read again when the power goes off: at a Hard Reset or when you change the machine. It is like taking a real card out, copying files onto it and putting it back in. Apply in Options does not read the folder again, so the running program keeps the disk it knows.

Refresh

Refresh brings in the folder’s changes while the machine runs, without laying the disk out anew. First, what the machine wrote is carried to the folder. Then the folder is read and compared with the disk, and only the difference is written into the disk, the way a DOS would write it. A new file gets free clusters near the end of the disk and an entry in a free slot of its directory; a full directory grows by a cluster. A deleted file has its entries marked deleted and its clusters freed. A changed file gets its new size and as many clusters as that size needs. Everything else stays where it was.

This matters because a DOS keeps some of the disk in memory between calls: the cluster of the directory it is in, the clusters of a file it has open (a mounted disk image or tape too), and the free cluster count it read when it started. If the disk were laid out anew, other files would end up under all of these. Because everything stays in place, they read on as before. After a refresh, the free count that a DOS writes back from memory can be wrong. It is only a hint, and nothing is lost by it. If a DOS writes back a directory sector that it read before the refresh, the new entries in that sector are lost. esxDOS reads directories again each time.

A folder with many thousands of files takes seconds to read, and the window waits meanwhile. If a read takes more than a second, the status bar says Reading the folder …. The SD card slot of the ZX Evo, the Next and a Z-Controller, the hard disks and the divMMC’s cards are read only on a machine that has them. On another machine the card or disk stays in the settings, and its folder is read when you choose a machine with that drive, or give the machine a hard disk interface in Options.

Writing back

A DOS does not write a file all at once. It writes the data, then the file table, then the directory, and in between the disk is half done. So the machine’s writes are first kept in memory, and the machine always reads back what it wrote. Once the machine has written nothing for about half a second, Xpeccy+ reads back the file tables and directories as the machine left them and compares them with the tree it knows. Then it makes the same changes in the folder: new files, changed files, renames, moves and deletions.

The emulator is careful with your files:

  • a file is deleted only when all of its old clusters are free, and replaced only when its new content is complete;

  • anything that cannot be placed is kept in the top folder as name (recovered);

  • if a file was changed on the computer in the meantime, that version wins, and the machine’s version goes beside it as name (2);

  • if Windows refuses a name, the characters it refuses become _;

  • a deleted file goes to the system’s trash, unless Deleted files is set otherwise.

If the machine formats the disk, rewrites its partition table, or deletes nine tenths of a large tree at once, the folder stops following the disk. The disk lives on in memory until it is ejected, and a message says so once. If the folder is set to read only, it refuses every write, and the machine’s DOS reports an error, as it would with a protected card.

What a folder cannot do

A folder is just files on your computer, and your computer’s file system keeps less than a FAT disk does. Anything the machine puts on the disk other than a file’s name, size, last write time or content lives only in memory, and is gone once the folder is read again:

  • attributes - hidden, system, read only. The machine sees them while the disk is in, but the files on your computer do not get them;

  • other dates - a creation or access date the machine sets. After a reread, both are the last write time;

  • sectors outside files - what a DOS writes to sectors of its own: a boot sector, the reserved sectors, free space. A copy protection or a map of the disk kept there does not last;

  • where files lie - after a reread, every file is laid out anew, in one piece. A program that remembers where a file is on the disk, by sector or by cluster, finds something else there;

  • the volume label - it goes back to the disk’s own.

The folder also shows your computer’s files just as they are. A Windows shortcut (.lnk) is a file like any other and is not followed, and files that the system hides are not on the disk.

For full compatibility, use an image. An image file holds a disk sector for sector, so none of the above applies to it. A folder is for convenience, to share files between the machine and the computer.

Booting from a folder

The ZX Evolution boots from a hard disk without reading its file system. It runs an IS-DOS boot sector from a fixed place on the disk. A folder used as an IDE disk gets such a sector, taken from a ZXLDR file in its top level, so a system like NedoOS can start from a folder.