@node _bios_disk, bios @findex _bios_disk @tindex diskinfo_t@r{ structure} @subheading Syntax @example #include unsigned _bios_disk(unsigned cmd, struct diskinfo_t *di) @end example @subheading Description This function interfaces with the BIOS disk service (interrupt 0x13). The parameter @var{cmd} select the corresponding disk service and the structure @var{di} holds the disk parameters. @example struct diskinfo_t @{ unsigned drive; /* Drive number. */ unsigned head; /* Head number. */ unsigned track; /* Track number. */ unsigned sector; /* Sector number. (1-63) */ unsigned nsectors; /* Number of sectors to read/write/verify. */ void *buffer; /* Buffer for reading/writing/verifying. */ @} @end example The following services are available based on value of @var{cmd}: @table @code @item _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 @var{di} 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. @item _DISK_STATUS Obtains the status of the last disk operation. If this service is specified, the 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. @item _DISK_READ Reads one or more disk sectors into memory. This service uses all fields of the structure pointed to by @var{diskinfo}. 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. @item _DISK_WRITE Writes data from memory to one or more disk sectors. This service uses all fields of the structure pointed to by . 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. @item _DISK_FORMAT Formats the track specified by @var{diskinfo}. The @var{head} and @var{track} fields indicate the track to format. Only one track can be formatted in a single call. The @var{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. @item _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 @var{buffer}) of the structure pointed to by @var{diskinfo}. 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), as defined below under Return Value. @end table @subheading Return Value Return value of AX register. The meaning of high-order byte (AH): @example 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 @end example @subheading Portability @portability !ansi, !posix @subheading Example @example char record_buffer[512]; struct diskinfo_t di; di.drive = 0x80; di.head = 0; di.track = 0; di.sector = 1; di.nsectors = 1; di.buffer = &record_buffer; if ( _bios_disk(_DISK_READ, &di) ) puts("Disk error."); @end example