The media-check function applies only to block devices, and in character-device drivers it should do nothing except set the done flag. This function is called when a drive-access call other than a simple file read or write is pending. MS-DOS passes to the function the media descriptor byte for the disk that it assumes is in the drive (Figure 14-8). If feasible, the media-check routine returns a code indicating whether the disk has been changed since the last transfer. If the media-check routine can assert that the disk has not been changed, MS-DOS can bypass rereading the FAT before a directory access, which improves overall performance.
Code Meaning
0F0H 3.5", 2-sided, 18-sector
0F8H fixed disk
0F9H 3.5", 2-sided, 9-sector
0F9H 5.25", 2-sided, 15-sector
0FCH 5.25", 1-sided, 9-sector
0FDH 5.25", 2-sided, 9-sector
0FEH 5.25", 1-sided, 8-sector
0FFH 5.25", 2-sided, 8-sector
Figure 14-8. Current valid MS-DOS codes for the media descriptor byte of the request header, assuming bit 13 in the attribute word of the driver header is zero.
MS-DOS responds to the results of the media-check function in the following ways:
If the disk has not been changed, MS-DOS proceeds with the disk access.
If the disk has been changed, MS-DOS invalidates all buffers associated with this unit, including buffers containing data waiting to be written (this data is simply lost), performs a BUILD BPB call, and then reads the disk's FAT and directory.
If the disk-change status is unknown, the action taken by MS-DOS depends upon the state of its internal buffers. If data that needs to be written out is present in the buffers, MS-DOS assumes no disk change has occurred and writes the data (taking the risk that, if the disk really was changed, the file structure on the new disk may be damaged). If the buffers are empty or have all been previously flushed to the disk, MS-DOS assumes that the disk was changed, and then proceeds as described above for the disk-changed return code.
If bit 11 of the device-header attribute word is set (that is, the driver supports the optional open/close/removable-media functions), the host system is MS-DOS version 3.0 or later, and the function returns the disk-changed code (-1), the function must also return the segment and offset of the ASCIIZ volume label for the previous disk in the drive. (If the driver does not have the volume label, it can return a pointer to the ASCIIZ string NO NAME.) If MS-DOS determines that the disk was changed with unwritten data still present in its buffers, it issues a critical-error 0FH (invalid disk change). Application programs can trap this critical error and prompt the user to replace the original disk.
The media-check function is called with
RH + 1 BYTE Unit code
RH + 2 BYTE Command code = 1
RH + 13 BYTE Media descriptor byte
It returns
RH + 3 WORD Status
RH + 14 BYTE Media-change code:
-1 if disk changed
0 if don't know whether disk changed
1 if disk not changed
RH + 15 DWORD Pointer to previous volume label, if
device attribute bit 11 = 1 and disk
has been changed (MS-DOS versions 3.0
and later)