从驱动器扩展读取扇区(INT 13h AH = 42h)

时间:2014-01-26 15:04:02

标签: c turbo-c

我正在尝试将1块第一块硬盘读入内存。我尝试使用不同的LBA,但它会在缓冲区中加载空格。在下面的代码中,我添加了for循环,以便我可以看到它是否加载除了空格之外的任何内容。你们知道为什么它只是在缓冲区中加载空间吗?

#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);
    }
}

它使用Borland Turbo C而不是使用WinXP设置的VMWare虚拟机。我也在Windows 7上的DOSBOX上尝试过相同的操作。任何帮助都会非常感激。

2 个答案:

答案 0 :(得分:1)

这些只是我的建议,希望它们可以帮助您进行调试。

  1. 打印sizeof(dap)以确保确实16

  2. 在发出memset(buf, 'A', sizeof(buf));之前插入INT 13h,以便检查buf是否已修改

  3. 请尝试使用printf("%lu: [%s]\n", i, buf);,因为buf在其\0周围包含printf时会停在那里。大括号应该作为标记。

  4. 打印_AH_CF,其中应包含INT 13h

  5. 的返回代码

答案 1 :(得分:0)

#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);