9.3.1 Device-Driver Header

The device-driver header, which must be at the beginning of the device driver, identifies the device driver, specifies the driver's strategy and interrupt routines, and defines the attributes of the device the driver supports. The form of the device-driver header corresponds to a DEVICEHEADER structure:

DEVICEHEADER STRUC

dhLink dd ? ;link to next driver

dhAttributes dw ? ;device attributes

dhStrategy dw ? ;strategy-routine offset

dhInterrupt dw ? ;interrupt-routine offset

dhNameOrUnits db '????????' ;logical-device name

;(character device only)

;or number of units

;(block device only)

DEVICEHEADER ENDS

The dhLink field must be 0FFFFh if there are no other device-driver headers in the file. Otherwise, the low 16 bits must contain the offset (from the beginning of the load image) to the next device-driver header, and the high 16 bits must contain zero. When loading the driver, MS-DOS sets this field to point to the next driver in the driver chain.

The dhAttributes field specifies the device type and provides additional information that MS-DOS uses when creating requests. The bits in this field must be set as follows:

Bit Meaning

0 For a character-device driver. Specifies that the device is the standard input device. This bit must be set to 1 if the driver replaces the resident device driver that supports the standard input device.
1 For a character-device driver. Specifies that the device is the standard output device. This bit must be set to 1 if the driver replaces the resident device driver that supports the standard output device.
  For a block-device driver. Specifies whether the driver can process 32-bit sector addresses. This bit must be set to 1 if the driver supports 32-bit sector addressing. MS-DOS checks this bit to determine whether it should use the rwrHugeSector field at the end of the READWRITEREQUEST structure used with Read (Device-Driver Function 04h), Write (Device-Driver Function 08h), and Write with Verify (Device-Driver Function 09h).
  This bit must be zero if the device supports only 16-bit sector addressing.
2 For a character-device driver. Specifies that the device is the NUL device. The resident NUL device driver cannot be replaced. This bit must be zero for all other device drivers.
3 For a character-device driver. Specifies that the device is the clock device. This bit must be set to 1 if the driver replaces the resident device driver that supports the clock device.
4 For a character-device driver. Specifies that the driver supports fast character output. If this bit is set, MS-DOS issues Interrupt 29h (with the character value in the AL register) when a program writes to the device—for example, when using Direct Console I/O (Interrupt 21h Function 06h). During its initialization, the device driver must install a handler (for Interrupt 29h) that carries out the fast output.
6 Specifies whether the device supports logical-drive mapping or generic IOCTL functions, or both. This bit must be set to 1 if the device driver implements Get Logical Drive and Set Logical Drive (Device-Driver Functions 17h and 18h) or Generic IOCTL (Device-Driver Function 13h).
7 Specifies whether the device supports IOCTL queries. This bit must be set to 1 if the device driver implements IOCTL Query (Device-Driver Function 19h).
11 Specifies whether the driver supports Open Device, Close Device, and Removable Media (Device-Driver Functions 0Dh, 0Eh, and 0Fh). This bit must be set to 1 if the driver implements these functions. Only block-device drivers support Removable Media.
13 For a character-device driver. Specifies whether the driver supports Output Until Busy (Device-Driver Function 10h). This bit must be set to 1 if the driver implements this function.
  For a block-device driver. Specifies whether the driver requires MS-DOS to supply the first sector of the first file allocation table (FAT) when it calls Build BPB (Device-Driver Function 02h). Drivers that have no other means of determining the current medium type use the media descriptor in the first byte of the FAT. This bit must be set to 1 if the driver requires the FAT.
14 Specifies whether the driver supports IOCTL Read and IOCTL Write (Device-Driver Functions 03h and 0Ch). This bit must be set to 1 if the driver implements these functions.
15 Specifies whether the driver supports a character device or a block device. This bit must be set to 1 if the driver supports a character device.

Any bits in the dhAttributes field that are not used for a given device type must be zero.

The dhStrategy and dhInterrupt fields contain the offsets to the entry points of the strategy and interrupt routines. Since these fields are 16-bit values, the entry points must be in the same segment as the device-driver file header. For a device driver in a binary image file, the offsets are in bytes from the beginning of the file; for a driver in an .EXE-format file, the offsets are in bytes from the beginning of the file's load image.

The dhNameOrUnits field is an 8-byte field that contains either a logical-device name or a 1-byte value specifying the number of units supported. A character-device driver must supply a logical-device name of no more than eight characters. If it has fewer than eight characters, the name must be left-aligned and any remaining bytes in the field must be filled with space characters (ASCII 20h). The device name must not contain a colon (:). A block-device driver does not supply a name; instead, it can supply the number of units it supports. This is optional, however, since MS-DOS fills in this field with the value the driver returns by using Init (Device-Driver Function 00h).

For a full description of the DEVICEHEADER structure, see Section 9.9, “Structures.”