简体   繁体   中英

Extended Read Sectors From Drive (INT 13h AH=42h)

I am trying to read 1 block of first hard drive into the memory. I tried with different LBAs but it loads spaces in to the buffer. In following code, i added for loop so that i can see if it loads anything else than just spaces. Do you guys know why it's only loading spaces into the buffer?

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>

struct DAP
{
    unsigned char size;
    unsigned char reserved1;
    unsigned char blocks;
    unsigned char reserved2;
    unsigned char far *buffer;
    unsigned long int lbalod;
    unsigned long int lbahid;
} dap;

char st[80];
unsigned char buf[512];
FILE *fptr;
unsigned long int itrations = 16450559; //10gb
unsigned long int i = 0;

void main(void)
{
    clrscr();
    for(; i<itrations; i++)
    {
        dap.size = sizeof(dap);
        dap.reserved1 = 0;
        dap.blocks = 1;
        dap.reserved2 = 0;
        dap.buffer = (unsigned char far *)MK_FP(_DS, buf);
        dap.lbalod = i;
        dap.lbahid = 0;
        _AH = 0x42;
        _DL = 0x80;
        _SI = (unsigned int)&dap;
        geninterrupt(0x13);
        printf("%lu: %s\n", i, buf);
    }
}

It's using Borland Turbo C over VMWare virtual machine that is setup with WinXP. I have also tried the same on DOSBOX on Windows 7. Any help would be much appreciated.

These are only my suggestions in the hope that they help your debugging.

  1. Print sizeof(dap) to ensure that it is indeed 16

  2. Insert memset(buf, 'A', sizeof(buf)); before you issue INT 13h so that you can check buf is modified or not

  3. Try printf("%lu: [%s]\\n", i, buf); instead, because when buf contains \\0 around its head printf stops there. The braces should work as marks.

  4. Print _AH and _CF which should contain return codes of INT 13h

#include <dos.h>
#include <bios.h>

struct DAP
{
    unsigned char size;
    unsigned char reserved1;
    unsigned char blocks;
    unsigned char reserved2;
    unsigned char far *buffer;
    unsigned long int lbalod;
    unsigned long int lbahid;
} dap;
char st[50];
unsigned char buff[256];
FILE *fptr;

main(void)
{
puts ("enter the lba low double word: ");
gets (st);
dap.lbalod=atol(st);
puts ("enter the lba high double word: ");
gets (st);
dap.lbahid=atol(st);
dap.size=16;
dap.reserved1=0;
dap.blocks1;
dap.reserved2=0
dap.buffer = (unsigned char far *)MK FP(DS.buf);
_AH = 0x42;
_DL = 0x80;
_SI = (unsigned int)%dap;

geninterrupt(0x13);
puts ("enter the path: ");
gets(st);
fptr = fopen(st, "wb");
fwrite(buf,256,1,fptr);
fclose(fptr);
}

 i am getting statement missing error on this line dap.buffer = (unsigned char far *)MK_FP(_DS, buf);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM