Function 27h Random Block Read

mov cx, cRecords ;number of records to read

mov dx, seg FileFCB

mov ds, dx

mov dx, offset FileFCB ;ds:dx points to FCB

mov ah, 27h ;Random Block Read

int 21h

cmp al, 0 ;zero means success

jne error_handler

Random Block Read (Function 27h) reads one or more records from the file identified by the file control block (FCB). Data read from the file is written to the memory at the current disk transfer address (DTA).

This function has been superseded by Read File or Device (Function 3Fh) and Move File Pointer (Function 42h).

Parameters

cRecords

Specifies the number of records to read.

FileFCB

Points to an FCB structure that identifies an open file. The structure must have been previously filled by using Open File with FCB (Function 0Fh) or Create File with FCB (Function 16h). Also, the fcbRandomRecNo field must specify the first record to read. The FCB structure has the following form:

FCB STRUC

fcbDriveID db ? ;drive no. (0=default, 1=A, etc.)

fcbFileName db '????????' ;filename

fcbExtent db '???' ;file extension

fcbCurBlockNo dw ? ;current block number

fcbRecSize dw ? ;record size

fcbFileSize db 4 dup (?) ;size of file in bytes

fcbFileDate dw ? ;date file last modified

fcbFileTime dw ? ;time file last modified

fcbReserved db 8 dup (?) ;reserved

fcbCurRecNo db ? ;current record number

fcbRandomRecNo db 4 dup (?) ;random record number

FCB ENDS

For a full description of the FCB structure, see Chapter 3, “File System.”

Return Value

If the function is successful, the AL register contains 00h, the memory at the DTA contains the records read from the file, and the CX register contains a count of the number of records read. Otherwise, the AL register contains an error value, which may be one of the following:

Value Meaning

01h End of file encountered, no data in record
02h Segment boundary overlapped by DTA, read canceled
03h End of file encountered, partial record at DTA (rest of record filled with zeros)

Comments

A program using this function must ensure that the buffer at the DTA is large enough to hold all the data read from the file.

MS-DOS updates the fcbCurBlockNo and fcbCurRecNo fields in the FCB structure to agree with the fcbRandomRecNo field before it attempts to read the record from the disk. The block and record fields are incremented after a successful read operation; successive calls to this function read sequential groups of records from the file until MS-DOS reaches the end of the file.

This function can be used to read files on a network drive but only if the network has granted read (or similar) access to the given file or drive.

See Also

Function 0Fh Open File with FCB
Function 16h Create File with FCB
Function 21h Random Read
Function 28h Random Block Write
Function 3Fh Read File or Device
Function 42h Move File Pointer