用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧C++ Builder

读磁片磁区

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:39:49


一、以前的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))
      {
}

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:46,375.00000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号