Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


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

Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 264

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);

Comments

  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,374
    via Email
    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
  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 264

    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 !

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE