win9x_win2k下对物理磁盘的操作

简介: <br>void CReadSectorDlg::OnReadButton() <br>{<br><span style="white-space:pre"> </span>UpdateData (TRUE) ;<br><span style="white-space:pre"> </span>CFile m_Sector_file ;<br><span style="white-space:

void CReadSectorDlg::OnReadButton() 
{
UpdateData (TRUE) ;
CFile m_Sector_file ;
char * buffer ;

if ( m_FileName_str == "") 
{
MessageBox ("Please enter a file to which the read sector contents are to be stored !!");
return ;
}

m_Sector_file.Open (m_FileName_str, CFile::modeCreate | CFile::modeWrite  , NULL ) ;
buffer = (char*) malloc (512 * m_NumSec_int) ;

buffer = ReadSectors (m_Head_int, m_Track_int, m_Sector_int, m_NumSec_int);
if ( buffer == NULL ) 
{
MessageBox ("Operation Failed -- !!");
return ;
}
m_Sector_file.Write (buffer, 512*m_NumSec_int) ;
m_Sector_file.Close ();

MessageBox ("Operation Complete !","ReadSectors",  MB_ICONINFORMATION );

}


char * CReadSectorDlg::ReadSectors(int head, int track, int sector, int numsec)
{                                                                                   //磁道,扇区
// getting logical sector from absolut head/track/sector ...
int LogicalSector = (sector-1) + (head*SECTORSPERTRACK) + (track*SECTORSPERTRACK*NUMOFHEADS) ;

typedef struct _DIOC_REGISTERS {
    DWORD reg_EBX;
    DWORD reg_EDX;
    DWORD reg_ECX;
    DWORD reg_EAX;
    DWORD reg_EDI;
    DWORD reg_ESI;
    DWORD reg_Flags;
} DIOC_REGISTERS ;

// char *buffer , errah[10], erral[10] ; 
 char *buffer ; 
 HANDLE hDevice ;
 DIOC_REGISTERS reg ;
 BOOL  fResult ;
 DWORD cb ;

 // Creating handle to vwin32.vxd  ...win 95 / 98 !
 hDevice = CreateFile ( "\\\\.\\vwin32", 0, 0, NULL, 0, FILE_FLAG_DELETE_ON_CLOSE, NULL );

 if ( hDevice == INVALID_HANDLE_VALUE ) 
 {
   //MessageBox ( "Error doing CreateFile () !" ) ;
 /* 
    ...this means that a handle to vwin32.vxd was not able to be opened ...
    ....so the operating system is not win 95/98 ...but NT , win2k ...or what (?) ..
    .....reading sectors is  more easy now .....
  */
HANDLE hDevice; 
char* buffer = (char*)malloc (512*numsec);
strset ( buffer , ' ');
DWORD bytesread ;
// Creating a handle to drive a: using CreateFile () function ..

hDevice = CreateFile("\\\\.\\c:", 
        GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 
        NULL, OPEN_EXISTING, 0, NULL); 
 
    if (hDevice == INVALID_HANDLE_VALUE) 
{
MessageBox ("Failed !");
        return NULL;
}
// Setting the pointer to point to the start of the sector we want to read ..

SetFilePointer (hDevice, (LogicalSector*512), NULL, FILE_BEGIN); 
if (!ReadFile (hDevice, buffer, 512*numsec, &bytesread, NULL) )
{
/*
int err;
char error[10];
err=GetLastError ();
itoa (err, error, 10);
MessageBox (error, "Reading sectors ...Failed  ");
*/
return NULL ;
}

    CloseHandle(hDevice); 
return buffer ;
 }

SS

http://download.csdn.net/detail/mao0514/7825687

相关文章
|
Windows
Windows 动态磁盘详解
Windows 动态磁盘详解
317 0
Windows 动态磁盘详解
|
Linux
Linux:磁盘情况查询+磁盘情况的工作使用指令(内含使用实例)
Linux:磁盘情况查询+磁盘情况的工作使用指令(内含使用实例)
156 0
Linux:磁盘情况查询+磁盘情况的工作使用指令(内含使用实例)
硬盘安装win8
官网下载win8.1单语言版 https://www.microsoft.com/zh-cn/software-download/windows8ISO Win8.1_SingleLang_Chinese_Simplified_x64.iso 引导 找一个空的硬盘,MBR分区,60G(C:) + 60G(D:); 把iso解压到D:盘; 使用BOOTICEx64_v1.3.3.2.exe,C:盘安装主引导记录为NT6.x,D:盘分区引导记录为BOOTMGR; BIOS中选这个新硬盘启动,就会进入安装界面。
1633 0