Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18681367
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: C/C++

2008-05-31 14:14:13

一、以前的dos版要读、写、格式化第0轨的第1个磁区,程式大致如下:

char buffer[512];

reg.x.dx=0 ;   /* for drive a *
reg.x.cx=0x0001  /* for boot sector */
reg.x.bx=fp_off(buffer);
sreg.es=fp_seg(buffer);
resg.x.ax=0x0201;   /*  02 for read, 03 for write ,05 for format */
int86x(0x13,®,®,&sreg);

    那麽在windows 下转换为呼叫 deviceiocontrol 以便格式化、读取、写入该磁轨,dioc_registers 这struct 在套上 dos 下 int21对hdd或fdd 的各项参数如要格式化是int21也是有, 但windows下也另有提供。

l#pragma pack(push, 1)
struct dioc_registers {
    dword reg_ebx;
    dword reg_edx;
    dword reg_ecx;
    dword reg_eax;
    dword reg_edi;
    dword reg_esi;
    dword reg_flags;
};
#pragma pack(pop)

sdiskimageinfo->hdevice = ::createfile(\"\\\\\\\\.\\\\vwin32\", 0, 0, null, 0, file_flag_delete_on_close, null);
if( sdiskimageinfo->hdevice == invalid_handle_value)
  brunnext = false;

// reset floppy disk
  reg.reg_ebx = 0;
  reg.reg_eax = 0x0000;       // ioctl for block devices
  reg.reg_edx = sdiskimageinfo->driver;
  reg.reg_edi = 0; reg.reg_esi= 0;
  reg.reg_flags = 0x0001;     // assume error (carry flag is set)
  dwresult = ::deviceiocontrol( sdiskimageinfo->hdevice, vwin32_dioc_dos_int13, ®, sizeof(dioc_registers), ®,
sizeof(dioc_registers), &cb, 0);

// seek floppy
      reg.reg_ebx = 0;
      reg.reg_eax = 0x0c00;       // ioctl for block devices
      reg.reg_ecx = ( sdiskimageinfo->nc << 8) | sdiskimageinfo->ns;
      reg.reg_edx = ( sdiskimageinfo->nh << 8) | sdiskimageinfo->driver;
      reg.reg_edi = 0;
reg.reg_esi= 0;
      reg.reg_flags = 0x0001;     // assume error (carry flag is set)
      dwresult = ::deviceiocontrol( sdiskimageinfo->hdevice,
vwin32_dioc_dos_int13,
                                   ®, sizeof(dioc_registers), ®,
sizeof(dioc_registers), &cb, 0);

// read floppy
r_creatediskimagefile:
      reg.reg_ebx = 0;
      reg.reg_eax = 0x0200 | 0x01;       // ioctl for block devices
      reg.reg_ecx = ( sdiskimageinfo->nc << 8) | sdiskimageinfo->ns;
      reg.reg_edx = ( sdiskimageinfo->nh << 8) | sdiskimageinfo->driver;
      reg.reg_ebx = (dword) &m_buf;
      reg.reg_edi = 0;
reg.reg_esi= 0;
      reg.reg_flags = 0x0001;     // assume error (carry flag is set)
      dwresult = ::deviceiocontrol( hdevice, vwin32_dioc_dos_int13,
                                   ®, sizeof(dioc_registers), ®,
sizeof(dioc_registers), &cb, 0);
      if (!dwresult || (reg.reg_flags & 0x0001))
      {
}
阅读(244) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~