快速业务通道

读磁片磁区

作者 佚名技术 来源 程序设计 浏览 发布时间 2012-06-30

以前的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,&reg,&reg,&sreg);

那麽在windows 下转换为呼叫 deviceiocontrol 以便格式化、读取、写入该磁轨,dioc_registers 这struct 在套上 dos 下 int21对hdd或fdd 的各项参数如要格式化是int21也是有, 但windows下也另有提供。
#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, &reg, sizeof(dioc_registers), &reg,
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,
  &reg, sizeof(dioc_registers), &reg,
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,
  &reg, sizeof(dioc_registers), &reg,
sizeof(dioc_registers), &cb, 0);
if (!dwresult || (reg.reg_flags & 0x0001))
{
}

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号