ITPub博客

首页 > 应用开发 > IT综合 > 用bcb 读磁片磁区 (转)

用bcb 读磁片磁区 (转)

原创 IT综合 作者:worldblog 时间:2007-12-05 11:22:25 0 删除 编辑
用bcb 读磁片磁区 (转)[@more@]  读磁片磁区

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


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-988690/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    6241
  • 访问量
    2404265