Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
5.6.0
-
None
-
Windows 10, Visual Studio 2015
Description
In Windows, it is possible to write the that disk by using ::CreateFile and passing in the drive name in the format "\\.\A:" (eg. for the A: drive). You should then be able to write to any part of the drive (including the boot sector) by seeking to that position.
Unfortunately, when I try to use QFile, I get a system error message "The parameter is incorrect".
I've traced through the Qt code and found that the problem appears to be with the following line in QFSEnginePrivate::nativeOpen()
// WriteOnly can create files, ReadOnly cannot.
DWORD creationDisp = (openMode & QIODevice::WriteOnly) ? OPEN_ALWAYS : OPEN_EXISTING;
If I have my QFile object open for writing, then creationDisp will hold the value of OPEN_ALWAYS, and this causes the call to ::CreateFile to return an invalid file handle.
If I put a breakpoint on this line and use the variable watch window of Visual Studio and change the value to OPEN_EXISTING, then ::CreateFile returns a valid file handle and I can successfully continue writing to the disk sectors as expected.