Sharing violation when try to open file already opened for DELETE access

Hello
Scenario:

  1. Create and don’t close file with DELETE access requested and full sharing - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE.
  2. try to read this file with more utility (opens file with share FILE_SHARE_READ | FILE_SHARE_WRITE)
  3. more gets sharing violation error

I checked this on fastfat driver - sharing violation comes from IoCheckShareAccess.

If file created without requesting delete access more opens file successfully .
If I try to open file second time with FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE - open success.

Is this expected behavior ?
I thought that since I create file with full sharing anyone can open it in any sharing mode.

Actual code of file creation:
UNICODE_STRING file_path = RTL_CONSTANT_STRING(L"\SystemRoot\test_file_for_write");
OBJECT_ATTRIBUTES oba{};
InitializeObjectAttributes(&oba,
&file_path,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
NULL,
nullptr);

IO_STATUS_BLOCK iosb{};
NTSTATUS stat = IoCreateFileEx(&file,
    FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | DELETE | SYNCHRONIZE,
    &oba,
    &iosb,
    nullptr,
    FILE_ATTRIBUTE_NORMAL,
    FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
    FILE_CREATE,
    FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
    nullptr,
    0,
    CreateFileTypeNone,
    nullptr,
    0,
    nullptr);

Remember that it is the combination of access mode and share mode of the
first open that determines what combinations of access mode and share mode
are valid for subsequent opens.

Mark Roddy

Thank you Mark !

I have never encountered problems with sharing before and always assumed that sharing option is the only thing that defines sharing.
However now I checked ReactOS sources and indeed this is not the case.

Thank you very much again !