The Strategy Routine

MS-DOS calls the strategy routine (strat) for the device when the driver is first loaded and installed, and again whenever an application program issues an I/O request for the device. MS-DOS passes the strategy routine a double-word pointer to a data structure called a request header. This structure contains information about the type of operation to be performed. In current versions of MS-DOS, the strategy routine never actually performs any I/O operation but simply saves the pointer to the request header. The strat routine must not make any Int 21H function calls.

The first 13 bytes of the request header are the same for all device-driver functions and are therefore referred to as the static portion of the header. The number and contents of the subsequent bytes vary according to the type of function being requested (Figure 14-4). Both MS-DOS and the driver read and write information in the request header.

The request header's most important component is a command code, or function number, passed in its third byte to select a driver subfunction such as read, write, or status. Other information passed to the driver in the header includes unit numbers, transfer addresses, and sector or byte counts.

;

; MS-DOS request header structure definition

;

Request struc ; request header template structure

Rlength db ? ; 0 length of request header

Unit db ? ; 1 unit number for this request

Command db ? ; 2 request header's command code

Status dw ? ; 3 driver's return status word

Reserve db 8 dup (?) ; 5 reserved area

Media db ? ; 13 media descriptor byte

Address dd ? ; 14 memory address for transfer

Count dw ? ; 18 byte/sector count value

Sector dw ? ; 20 starting sector value

Request ends ; end of request header template

Figure 14-4. Format of request header. Only the first 13 bytes are common to all driver functions; the number and definition of the subsequent bytes vary, depending upon the function type. The structure shown here is the one used by the read and write subfunctions of the driver.