如何读取RAW磁盘的东西,然后写在C + +进一步?

我想先写一些东西到磁盘设备上,然后读取相同的数据,然后再写一些。 我的代码如下所示:

std::string devicePath = "\\\\.\\PhysicalDrive0"; //'0' is only example here HANDLE source = CreateFile(disk.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, NULL, NULL); BOOST_TEST_REQUIRE(source, "Failed to create file handle."); std::unique_ptr<CHAR[]> primaryBuffer(new CHAR[DEFAULT_FILESIZE]); std::unique_ptr<CHAR[]> checkBuffer(new CHAR[DEFAULT_FILESIZE]); for (auto i = 0; i < DEFAULT_FILESIZE; ++i) { primaryBuffer[i] = 'x'; checkBuffer[i] = ' '; } WriteFile(source, primaryBuffer.get(), DEFAULT_FILESIZE, NULL, NULL); //Here I move the pointer to write data in new place. DWORD destination = SetFilePointer(source, DEFAULT_FILESIZE, NULL, FILE_BEGIN); WriteFile(&destination, source, DEFAULT_FILESIZE, NULL, NULL); ReadFile(source, primaryBuffer.get(), DEFAULT_FILESIZE, NULL, NULL); ReadFile(&destination, checkBuffer.get(), DEFAULT_FILESIZE, NULL, NULL); BOOST_TEST_MESSAGE(checkBuffer.get()); BOOST_TEST_MESSAGE(primaryBuffer.get()); 

不幸的是,这两种缓冲区都是不同的,我已经试过几乎所有的东西来检查什么是错 也许有人知道我在做什么错了?