Thursday, February 19, 2015

Learning C Functions : biosdisk ( Dos Only )

C Programming :
Function
:
biosdisk

Syntax

#include <bios.h>
int biosdisk(int cmd, int drive, int head, int track, int sector, int nsects, void *buffer);

Description

biosdisk uses interrupt 0x13 to issue disk operations directly to the BIOS.
drive is a number that specifies which disk drive is to be used: 0 for the first floppy disk drive, 1 for the second floppy disk drive, 2 for the third, and
so on. For hard disk drives, a drive value of 0x80 specifies the first drive, 0x81 specifies the second, 0x82 the third, and so forth.
For hard disks, the physical drive is specified, not the disk partition. If necessary, the application program must interpret the partition table
information itself.
cmd indicates the operation to perform. Depending on the value of cmd, the other parameters may or may not be needed.
Here are the possible values for cmd for the IBM PC, XT, AT, or PS/2, or any compatible system:

0    Resets disk system, forcing the drive controller to do a hard reset. All other parameters are ignored.
1    Returns the status of the last disk operation. All other parameters are ignored.
2    Reads one or more disk sectors into memory. The starting sector to read is given by head, track, and sector. The number of sectors is given
by nsects. The data is read, 512 bytes per sector, into buffer.
3    Writes one or more disk sectors from memory. The starting sector to write is given by head, track, and sector. The number of sectors is given
by nsects. The data is written, 512 bytes per sector, from buffer.
4    Verifies one or more sectors. The starting sector is given by head, track, and sector. The number of sectors is given by nsects.
5    Formats a track. The track is specified by head and track. buffer points to a table of sector headers to be written on the named track. See the
Technical Reference Manual for the IBM PC for a description of this table and the format operation.

The following cmd values are allowed only for the XT, AT, PS/2, and compatibles:

6    Formats a track and sets bad sector flags.
7    Formats the drive beginning at a specific track.
8    Returns the current drive parameters. The drive information is returned in buffer in the first 4 bytes.
9    Initializes drive-pair characteristics.
10    Does a long read, which reads 512 plus 4 extra bytes per sector.
11    Does a long write, which writes 512 plus 4 extra bytes per sector.
12    Does a disk seek.
13    Alternates disk reset.
14    Reads sector buffer.
15    Writes sector buffer.
16    Tests whether the named drive is ready.
17    Recalibrates the drive.
18    Controller RAM diagnostic.
19    Drive diagnostic.
20    Controller internal diagnostic.

biosdisk operates below the level of files on raw sectors. It can destroy file contents and directories on a hard disk.

Return Value
biosdisk returns a status byte composed of the following bits:

0x00    Operation successful.
0x01    Bad command.
0x02    Address mark not found.
0x03    Attempt to write to write-protected disk.
0x04    Sector not found.
0x05    Reset failed (hard disk).
0x06    Disk changed since last operation.
0x07    Drive parameter activity failed.
0x08    Direct memory access (DMA) overrun.
0x09    Attempt to perform DMA across 64K boundary.
0x0A    Bad sector detected.
0x0B    Bad track detected.
0x0C    Unsupported track.
0x10    Bad CRC/ECC on disk read.
0x11    CRC/ECC corrected data error.
0x20    Controller has failed.
0x40    Seek operation failed.
0x80    Attachment failed to respond.
0xAA    Drive not ready (hard disk only).
0xBB    Undefined error occurred (hard disk only).
0xCC    Write fault occurred.
0xE0    Status error.
0xFF    Sense operation failed.
0x11    is not an error because the data is correct. The value is returned to give the application an opportunity to decide for itself.

Example :
/*  biosdisk example  */

#include <bios.h>
#include <stdio.h>

int main(void)
{
   #define CMD    2    /*  read sector command */
   #define DRIVE  0    /*  drive number for A: */
   #define HEAD   0    /*  disk head number */
   #define TRACK  1    /*  track number */
   #define SECT   1    /*  sector number */
   #define NSECT  1    /*  sector count */

   int result;
   char buffer[512];
   printf("Attempting to read from drive A:\n");
   result = biosdisk(CMD, DRIVE, HEAD, TRACK, SECT, NSECT, buffer);
   if (result == 0)
      printf("Disk read from A: successful.\n");
   else
      printf("Attempt to read from drive A: failed.\n");
   return 0;
}

No comments:

Post a Comment