_bios_disk

Description

Calls BIOS disk services, using INT 0x13.

#include <bios.h>

unsigned _bios_disk( unsigned service, struct _diskinfo_t *diskinfo );

service Disk function desired  
diskinfo Disk parameters  

Remarks

The _bios_disk routine uses INT 0x13 to provide several disk-access functions. The service parameter selects the function desired, while the diskinfo structure provides the necessary parameters. Note that the low-level disk operations allowed by the _bios_disk routine are very dangerous to use because they perform direct manipulation of the disk.

The diskinfo structure provides the following parameters:

Element Description

unsigned drive Drive number
unsigned head Head number
unsigned track Track number
unsigned sector Starting sector number
unsigned nsectors Number of sectors to read, write, or compare
void far *buffer Memory location to write to, read from, or compare

The service argument can be set to one of the following manifest constants:

Constant Function

_DISK_FORMAT Formats the track specified by diskinfo. The head and track fields indicate the track to format. Only one track can be formatted in a single call. The buffer field points to a set of sector markers. The format of the markers depends on the type of disk drive; see a technical reference to the PC BIOS to determine the marker format. The high-order byte (AH) of the return value contains the status of the call; 0 equals success. If there is an error, the high-order byte will contain a set of status flags, as defined below under Return Value.
_DISK_READ Reads one or more disk sectors into memory. This service uses all fields of the structure pointed to by diskinfo, as defined earlier in this section. If no error occurs, the function returns 0 in the high-order byte and the number of sectors read in the low-order byte. If there is an error, the high-order byte (AH) will contain a set of status flags, as defined below under Return Value.
_DISK_RESET Forces the disk controller to do a hard reset, preparing for floppy-disk I/O. This is useful after an error occurs in another operation, such as a read. If this service is specified, the diskinfo argument is ignored. Status is returned in the 8 high-order bits (AH) of the return value. If there is an error, the high-order byte will contain a set of status flags, as defined below under Return Value.
_DISK_STATUS Obtains the status of the last disk operation. If this service is specified, the diskinfo argument is ignored. Status is returned in the 8 low-order bits (AL) of the return value. If there is an error, the low-order byte (AL) will contain a set of status flags, as defined below under Return Value.
_DISK_VERIFY Checks the disk to be sure the specified sectors exist and can be read. It also runs a CRC (cyclic redundancy check) test. This service uses all fields (except buffer) of the structure pointed to by diskinfo, as defined earlier in this section. If no error occurs, the function returns 0 in the high-order byte (AH) and the number of sectors compared in the low-order byte (AL). The error status flags are listed below under Return Value.
_DISK_WRITE Writes data from memory to one or more disk sectors. This service uses all fields of the structure pointed to by diskinfo, as defined earlier in this section. If no error occurs, the function returns 0 in the high-order byte (AH) and the number of sectors written in the low-order byte (AL). If there is an error, the high-order byte will contain a set of status flags, as defined below under Return Value.

Return Value

The _bios_disk function returns the value in the AX register after the BIOS interrupt.

Bits Meaning

0x00 No error
0x01 Invalid request or a bad command
0x02 Address mark not found
0x03 Disk write protected
0x04 Sector not found
0x05 Reset failed
0x06 Floppy disk removed
0x07 Drive parameter activity failed
0x08 Direct Memory Access (DMA) overrun
0x09 DMA crossed 64K boundary
0x0A Bad sector flag detected
0x0B Bad track flag detected
0x0C Media type not found
0x0D Invalid number of sectors on format
0x0E Control data access mark detected
0x0F DMA arbitration level out of range
0x10 Data read (CRC or ECC) error
0x11 Corrected data read (ECC) error
0x20 Controller failure
0x40 Seek error
0x80 Disk timed out or failed to respond
0xAA Drive not ready
0xBB Undefined error
0xCC Write fault on drive
0xE0 Status error
0xFF Sense operation failed

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

Example

/* BDISK.C: This program first attempts to verify a disk by using an

* invalid disk head number. After printing the return value error code,

* the program verifies the disk by using a valid disk head code.

*/

#include <conio.h>

#include <stdio.h>

#include <bios.h>

void main( void )

{

unsigned status = 0;

struct _diskinfo_t disk_info;

disk_info.drive = 0;

disk_info.head = 10; /* Invalid head number */

disk_info.track = 1;

disk_info.sector = 2;

disk_info.nsectors = 8;

printf( "Insert disk in drive A: and press any key\n" );

_getch();

status = _bios_disk( _DISK_VERIFY, &disk_info );

printf( "Return value: 0x%.4x\n", status );

if( status & 0xff00 ) /* Error if high byte is 0 */

printf( "Seek error\n" );

else

printf( "No seek error\n" );

printf( "Press any key\n" );

_getch();

disk_info.head = 0; /* Valid head number */

status = _bios_disk( _DISK_VERIFY, &disk_info );

printf( "Return value: 0x%.4x\n", status );

if( status & 0xff00 ) /* Error if high byte is 0 */

printf( "Seek error\n" );

else

printf( "No seek error\n" );

}

Output

Insert disk in drive A: and press any key

Return value: 0x0400

Seek error

Press any key

Return value: 0x0008

No seek error