| 站点地图 | 联系我
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | 书签 | ASP.Net书签 | 上善若水 厚德载物
 现在位置 :: 主页 >> 资料中心 >> ROOT / CODE / C/C++ /
 

读磁片磁区 (C++ Builder)

来源(怡园)

From: http://yynets.best.163.com/cbuilder.htm

读磁片磁区 (C++ Builder)

一、以前的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下也另有提供。

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,
&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)) {
}


Link: http://www.asm32.net/article_details.aspx?id=1900


浏览次数 373 发布时间 2006/8/25 5:52:48 从属分类 C/C++ 【评论】【 】【打印】【关闭
 
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | 书签 | ASP.Net书签 | 京ICP备09029108号-1