首页 > 编程 > Java > 正文

读磁片磁区

2019-09-06 23:33:50
字体:
来源:转载
供稿:网友

                   
一、以前的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,
/t/t/t/t   ®, 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,
/t/t/t/t   ®, sizeof(dioc_registers), ®,
sizeof(dioc_registers), &cb, 0);
     if (!dwresult || (reg.reg_flags & 0x0001))
     {
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选