Open mfranceschi opened 1 year ago
struct IoControl_GetBootSectorsInfo {
IoControl_GetBootSectorsInfo(const std::wstring& rootPath) {
const std::wstring name = LR"(\\.\)" + rootPath.substr(0, 2);
HANDLE handle = CreateFileW(
name.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, 0, nullptr);
MF::SystemErrors::Win32::throwCurrentSystemErrorIf(handle == INVALID_HANDLE_VALUE);
DWORD bytesReturned{0};
const bool success = DeviceIoControl(
(HANDLE)handle, // handle to volume
FSCTL_GET_BOOT_AREA_INFO, // dwIoControlCode
nullptr, // input buffer
0, // size of input buffer
&bootAreaInfo, // output buffer
sizeof(bootAreaInfo), // size of output buffer
&bytesReturned, nullptr) == TRUE;
CloseHandle(handle);
MF::SystemErrors::Win32::throwCurrentSystemErrorIf(!success);
}
uint16_t getBootSectorsCount() const {
std::cout << "BootSectorCount=" << bootAreaInfo.BootSectorCount
<< ", BootSector0=" << bootAreaInfo.BootSectors[0].Offset.QuadPart
<< ", BootSector1=" << bootAreaInfo.BootSectors[1].Offset.QuadPart;
return bootAreaInfo.BootSectorCount;
}
private:
BOOT_AREA_INFO bootAreaInfo{0};
};
But I suspect this API to be deprecated since it only proposes 2 mount points; it might have been created for a specific boot sector layout that has been superseded now.
std::uint16_t getBootSectorsCount()
bool isCompressed()
Misc notes: