程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> 讀磁片磁區

讀磁片磁區

編輯:關於C++

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved