Int 21H [3.2] Function 44H Subfunction 0DH (13) IOCTL: generic I/O control for block devices

Provides a general-purpose mechanism for communication between application programs and block-device drivers. Allows a program to inspect or change device parameters for a logical drive and to read, write, format, and verify disk tracks in a hardware-independent manner.

Call with:

AH = 44H

AL = 0DH

BL = drive code (0 = default, 1 = A, 2 = B, etc.)

CH = category (major) code:

08H = disk drive

CL = function (minor) code:

40H = Set Device Parameters

41H = Write Track

42H = Format and Verify Track

47H = Set Access Flag (4.0)

60H = Get Device Parameters

61H = Read Track

62H = Verify Track

67H = Get Access Flag (4.0)

DS:DX = segment:offset of parameter block

Returns:

If function successful

Carry flag = clear

and, if called with CL = 60H or 61H

DS:DX = segment:offset of parameter block

If function unsuccessful

Carry flag = set

AX = error code

Notes:

The minor code 40H (Set Device Parameters) function must be used before an attempt to write, read, format, or verify a track on a logical drive. In general, the following sequence applies to any of these operations:

Get the current parameters (minor code 60H). Examine and save them.

Set the new parameters (minor code 40H).

Perform the task.

Retrieve the original parameters and restore them with minor code 40H.

For minor codes 40H (Set Device Parameters) and 60H (Get Device Parameters), the parameter block is formatted as follows:

Special-functions field: offset 00H, length = 1 byte

Bit(s) Value Meaning 0 0 device BPB field contains a new default BPB 1 use current BPB 1 0 use all fields in parameter block 1 use track layout field only 2 0 sectors in track may be different sizes (should always be avoided) 1 sectors in track are all same size; sector numbers range from 1 to the total number of sectors in the track (should always be used) 3—7 0 reserved

Device type field: offset 01H, length 1 byte

Value Meaning 0 320/360 KB, 5.25-inch disk 1 1.2 MB, 5.25-inch disk 2 720 KB, 3.5-inch disk 3 single-density, 8-inch disk 4 double-density, 8-inch disk 5 fixed disk 6 tape drive 7 other type of block device

Device attributes field: offset 02H, length 1 word

Bit(s) Value Meaning 0 0 removable storage medium 1 nonremovable storage medium 1 0 door lock not supported 1 door lock supported 2—15 0 reserved Number of cylinders field: offset 04H, length 1 word Maximum number of cylinders supported on the block device

Media type field: offset 06H, length 1 byte

Value Meaning 0 1.2 MB, 5.25-inch disk 1 320/360 KB, 5.25-inch disk

Device BPB field: offset 07H, length 31 bytes For format of the device BPB, see separate Note below. If bit 0 = 0 in special-functions field, this field contains the new default BPB for the device. If bit 0 = 1 in special-functions field, the BPB in this field is returned by the device driver in response to subsequent Build BPB requests.

Track layout field: offset 26H, variable-length table

Length Meaning Word number of sectors in track Word number of first sector in track Word size of first sector in track . . . Word number of last sector in track Word size of last sector in track

The device BPB field is a 31-byte data structure that describes the current disk and its control areas. The field is formatted as follows:

Byte(s) Meaning 00H—01H bytes per sector 02H sectors per cluster (allocation unit) 03—04H reserved sectors, beginning at sector 0 05H number of file allocation tables (FATs) 06H—07H maximum number of root-directory entries 08H—09H number of sectors 0AH media descriptor 0BH—0CH sectors per FAT 0DH—0EH sectors per track 0FH—10H number of heads 11H—14H number of hidden sectors 15H—18H large number of sectors (if bytes 08H—09H=0) 19H—1EH reserved

When minor code 40H (Set Device Parameters) is used, the number of cylinders should not be altered, or some or all of the volume may become inaccessible.

For minor codes 41H (Write Track) and 61H (Read Track), the parameter block is formatted as follows:

Byte(s) Meaning 00H special-functions field (must be 0) 01H—02H head 03H—04H cylinder 05H—06H starting sector 07H—08H sectors to transfer 09H—0CH transfer buffer address

For minor codes 42H (Format and Verify Track) and 62H (Verify Track), the parameter block is formatted as follows:

Byte(s) Meaning 00H special-functions field

Bit(s) Significance 0 0 = Format/Verify track 1 = Format status call (MS-DOS 4.0 only) 1—7 reserved (0) 01H—02H head 03H—04H cylinder

In MS-DOS 4.0, this function may be called with bit 0 of the special-functions field set after a minor code 40H call (Set Device Parameters) to determine whether the driver supports the specified number of tracks and sectors per track. A status is returned in the special-functions field which is interpreted as follows:

Value Meaning 0 specified number of tracks and sectors per track supported 1 this function not supported by the ROM BIOS 2 specified number of tracks and sectors per track not supported 3 no disk in drive

For minor codes 47H (Set Access Flag) and 67H (Get Access Flag), the parameter block is formatted as follows:

Byte Meaning 00H special-functions field (must be 0) 01H disk access flag

When the disk access flag is zero, access to the medium is blocked by the driver. The flag is set to zero when the driver detects an unformatted medium or a medium with an invalid boot record. When the access flag is nonzero, read/write operations to the medium are allowed by the driver. A formatting program must clear the disk access flag with minor code 47H before it requests minor code 42H (Format and Verify Track).

Example:

Get the device parameter block for disk drive C.

dbpb db 128 dup (0) ; device parameter block

.

.

.

mov ax,440dh ; function & subfunction

mov bl,3 ; drive C = 3

mov ch,8 ; disk category

mov cl,60h ; get device parameters

mov dx,seg dbpb ; buffer address

mov ds,dx

mov dx,offset dbpb

int 21h ; transfer to MS-DOS

jc error ; jump if function failed

.

.

.