一、以前的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))
{
}
本文地址:http://com.8s8s.com/it/it30482.htm