Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52977

Unable to use QFile to write to the boot sector in Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.6.0
    • Core: I/O
    • 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            laknoll Lars Knoll
            robbie Robert Escott
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes