Hi Scott,
My previous comment went missing, so please forgive me if this is a duplicate post.
Your second request would have failed because it requests GENERIC_READ | GENERIC_WRITE but no sharing was allowed by the first and second open.
I have tried the flags used in your sample and was able to reproduce the sharing violation behavior you are seeing, then added FILE_SHARE_READ and FILE_SHARE_WRITE in both open requests and it gave STATUS_SUCCESS in both requests.
Also, if I remove FILE_OPEN_REQUIRING_OPLOCK and FILE_COMPLETE_IF_OPLOCKED it doesn’t change the behavior.
Here is relevant code snippet which I had originally used:
status = ZwCreateFile(&hFile1,
FILE_WRITE_DATA | SYNCHRONIZE,
&oa,
&ioStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS | FILE_OPEN_REQUIRING_OPLOCK,
NULL,
0);
if (status != 0)
{
return status;
}
status = ZwCreateFile(&hFile2,
FILE_WRITE_DATA | SYNCHRONIZE | DELETE,
&oa,
&ioStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE | FILE_COMPLETE_IF_OPLOCKED,
NULL,
0);
if (status != 0)
{
…
}
Also attached the source file here (since it won’t let me attach a .cpp file, added .txt extension to it)
Thanks,
Arun