Absread() : Read absolute disk sectors in C [dos.h function]
Declaration : absread()
int absread(int drive,int nsects,long lsect,void *buffer);
Remarks:
- absread uses DOS interrupt 0×25 to read specific disk sectors.
- absread reads absolute disk sectors
- It ignores the logical structure of a disk and pay no attention to files, FATs, or directories.
- The number of sectors to read is limited to 64K or the size of the buffer, whichever is smaller.
Parameters
[table style="1"]
Parameter | What It Is/Does ? |
---|---|
drive | Drive number to read (or write): 0 = A, 1 = B, etc. |
nsects | Number of sectors to read (or write) |
lsect | Beginning logical sector number |
buffer | Memory address where the data is to be read (or written) |
[/table]
Return Value:
- On success, return 0.
- On error, return -1 and set errno to the value of the AX register returned by the system call.
Live Example :
#include <stdio.h> #include <conio.h> #include <process.h> #include <dos.h> int main(void) { int i, strt, ch_out, sector; char buf[512]; printf("Insert a diskette into drive A and press any key\n"); getch(); sector = 0; if (absread(0, 1, sector, &buf) != 0) { perror("Disk problem"); exit(1); } printf("Read OK\n"); strt = 3; for (i=0; i<80; i++) { ch_out = buf[strt+i]; putchar(ch_out); } printf("\n"); return(0); }
Output :
Insert a diskette into drive A and press any key
*It will show this output in newer versions of PC those do not have Floppy Disk Drives.