Raw Disk FILE_FLAG_OVERLAPPED

CreateFileW fails:

    HANDLE hVol = CreateFileW(
        L"\\\\?\\C:",
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_FLAG_OVERLAPPED,
        NULL, OPEN_EXISTING, NULL, NULL
    );

Is this simply unsupported? I wish to use IOCPs with DeviceIoControl on a raw drive to obtain volume information. My other option is parsing the NTFS headers directly.
Apologies if this is offtopic, but I suspect I can get a conclusive answer quickly here. I’m able to use FSCTL_QUERY_USN_JOURNAL etc. just fine if I remove FILE_FLAG_OVERLAPPED.

I cannot help you with an answer but my suggestion would be to diagnose this using FileTest use NtCreateFile to check the parameterization. Win32 will be interpreting what you need. In particular I’d make sure that SYNCHRONIZE (access) and FILE_SYNCRHONOUS_ALERT and FILE_SYNCRHONOUS_NONALERT were not being set.

It turns out I was putting the flag in the wrong argument position despite staring at the function arguments in IntelliSense.
However, it was worth coming here for the mention of FileTest, so thank you.

1 Like

HA! That’s a good one! Thanks for posting back the root-cause of the problem. Looking at your OP now that we know the problem, the cause is very obvious.

The CreateFile APIs and their vast array of bitmasks is hideous to deal with. Sure, it should be “obvious” that FILE_FLAG_OVERLAPPED doesn’t belong on the ShareAccess argument, but does belong on the Flags argument. But the Flags argument takes FILE_ATTRIBUTE_xxx bits as well as FILE_FLAG_xxx bits… and if that’s not enough, it now also takes SECURITY_xxx bits – and all these bits only in specific combinations.

Again, thanks for following-up with the solution.

Peter