⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wipetest.cpp

📁 用于测试一个物理硬盘的数据速度
💻 CPP
字号:
// WipeTest.cpp: implementation of the WipeTest class.
//
//////////////////////////////////////////////////////////////////////

#include "WipeTest.h"
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <STRING.h>

using namespace std;

void PrintInform(LPBYTE pBuf, UINT uSize) {

	for(UINT i =1; i<=uSize; i++) {
		
		printf("%02X", pBuf[i-1]);
		if(i%16 == 0) {
			printf("\n");	//end of line  when word number more than 16
		}else if(i%8 == 0) {
			printf("   ");	//print " " between every word
		}else{
			printf(" ");
		}//end of if...else if..
		
	}//end of for

}//end of method PrintInform


BOOL readSectors( char pDiskPath[],BYTE bReadBuffer[],DWORD dwOffsetByte, DWORD dNumberOfBytesToRead) {

	HANDLE hFile = CreateFile(pDiskPath, GENERIC_READ, FILE_SHARE_READ , NULL, OPEN_EXISTING, 0, NULL );
	if(hFile == INVALID_HANDLE_VALUE){
		MessageBox(0, "can't open the disk!", 0, 0);
		return 0;
	}//end of if

	SetFilePointer(hFile, dwOffsetByte *512, 0, FILE_BEGIN);//

	DWORD dwReadByte;	//被读取的字节数

	BOOL bRead = ReadFile(hFile, bReadBuffer, dNumberOfBytesToRead, &dwReadByte, NULL);
	//cout << dwReadByte <<endl;	
	if(dwReadByte == 0){
		MessageBox(0, "read disk error!", 0, 0);
		return 0;
	} //end of if
	CloseHandle(hFile);
	return bRead;

}//end of method readSectors


BOOL writeSectors( char pDiskPath[], BYTE cWriteBuffer[],DWORD dwStartSector, DWORD dNumberOfBytesToWrite){
	
	HANDLE hFile = CreateFile(pDiskPath, GENERIC_WRITE, FILE_SHARE_READ , NULL, OPEN_EXISTING, 0, NULL );

	if(hFile == INVALID_HANDLE_VALUE){
		MessageBox(0, "can't open the disk!", 0, 0);
		return 0;
	}//end of if

	SetFilePointer(hFile, dwStartSector * 512, 0, FILE_BEGIN);
	
	DWORD dwWriteByte;	//被写入的字节数
	BOOL bWrite = WriteFile(hFile,cWriteBuffer,dNumberOfBytesToWrite, &dwWriteByte,NULL);
	//cout << "****************" << endl;
	if(dwWriteByte == 0){
		MessageBox(0, "Write disk error!", 0, 0);
		return 0;
	} //end of if

	CloseHandle(hFile);
	return bWrite;	

}//end of method writeSectors

int main(int argc,char *argv){
	char cFilePath[] = "\\\\.\\F:\\TTTT.txt" ;  //"\\\\.\\PhysicalDrive0";	//文件路径(一定要正确!)		
	char cPhisycalDiskPath[] = "\\\\.\\PhysicalDrive0";					//物理盘符路径
	DWORD readOffSetSector = 0;	 					//开始扇区
	DWORD uSectorNum = 1;						//预计读取的扇区总数	
	DWORD uReadSize = uSectorNum * 512;			//预计读取的扇区总数的总大小(Byte)
	DWORD uWriteSize = uSectorNum * 512;		//预计写入的扇区总数的总大小(Byte)
	BYTE bBuffer[512];							//数组存放DPT的内容
	
	
		
	if(readSectors(cPhisycalDiskPath,bBuffer, readOffSetSector, uReadSize)){
		PrintInform(bBuffer,uReadSize);	
		cout << "read appoint sector success!" <<endl;//读取任意指定扇区成功
		
	}//end of if
	
//	memset(bBuffer,5,512);
//	if(writeSectors(cFilePath,bBuffer, readOffSetSector, uReadSize)){
//		cout << "write oK!" <<endl;	//写入成功
//	}//*//*
	
	return 0;

}//end of method main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -