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

用bcb 读磁片磁区

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 19:42:46
                   读磁片磁区

一、以前的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 .
页面执行时间:5,062.50000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号