19

I've recently unearthed an old book called MS-DOS 6 pour les nuls (More DOS for Dummies) by famed C programmer Dan Gookin. It was (still to me) a very interesting book in which he talks about MS-DOS in a very simplistic way. Obviously explaining what does SmartDrive do is out of the scope of such book, except that it is a disk caching program. So how do such programs work?

1
  • 2
    Guess it was a TSR program that installed its own handlers for interrupt vectors responsible for file access so that it could return a cached copy from RAM if it had one (and also invalidate the cache once the file has been modified). Not sure though if it worked at the file system level or at the disk sector level (the latter would be more reliable and I guess even simpler)
    – DmytroL
    Commented Dec 13, 2022 at 11:53

1 Answer 1

40

How SMARTDrive works depends on the version being considered.

The general idea of a disk cache like SMARTDrive is to intercept disk reads and, optionally, writes, and handle them from cache if possible. SMARTDrive sets aside an area of memory to use as the cache; the first time it intercepts a read request for a given area of a disk, it reads it from the disk, and the next time, it returns the data from cache instead. Whenever data is written to the disk, the cache is also updated, so that the next read from the cache returns the updated data.

Cache misses look like this (with version 4.0 or later, on a device handled by the BIOS):

                        Application reads data
                                  ↓
         MS-DOS translates file access to block device access
                                  ↓
                  SMARTDrive intercepts the request
                      but doesn’t have the data
                                  ↓
                     Block device calls the BIOS
                                  ↓
       The BIOS accesses the controller and retrieves the data

On the way back up, SMARTDrive saves the data to its cache before passing it on.

Then a cache hit looks like this instead:

                        Application reads data
                                  ↓
         MS-DOS translates file access to block device access
                                  ↓
                  SMARTDrive intercepts the request
                  and returns the corresponding data

Early versions of SMARTDrive were loaded as device drivers, and handled disk accesses at the interrupt 0x13 level (in the diagram above, just after “Block device calls the BIOS”); that meant they could only handle disks supported by that service (either through the built-in BIOS, or through an expansion card’s option ROM). Version 4.0 and later load as a terminate-and-stay-resident program, and handle disk accesses at the block driver level; this means that any drive supported by a DOS block driver can be cached (for example, CD-ROM drives, in version 5.0 and later). Version 4.0 also introduced write caches: writes could complete in the cache only, and SMARTDrive would propagate them to the underlying device later. (SMARTDrive 4.2 and later ensured that cached writes were sent to the device before the DOS prompt was shown, so users knew when they could safely switch of their computer.)

SMARTDrive hooks various other interrupts; for example, it hooks the reboot interrupt to ensure that data is written to disk before the system reboots.

An important feature of SMARTDrive (and other disk caches on PCs) is double-buffering. The disk cache uses expanded or extended memory, beyond the first megabyte of RAM; but that memory is often not mapped directly, so linear addresses don’t match physical addresses, and in some cases might not even be accessible to drive controllers. The cache therefore had to keep some conventional memory, and bounce data between buffers to get it to and from disks.

Several Microsoft knowledge base articles provide details of SmartDrive’s features: SMARTDrive Version History, SMARTDrive 4.0 Design Overview, and SMARTDrive and 32-Bit Disk Access (which goes into great detail about some of the interactions between Windows and the disk cache, and support for DOS programs running under Windows).

If you’re curious about disk caching on DOS PCs in general, you might find this PC Magazine article on their DCACHE utility interesting (note that this issue was scanned backwards, so you need to scroll up). One of the disk caches available in FreeDOS, LBAcache, includes a comparison of a number of DOS disk caches, and like all FreeDOS tools it includes full source code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .