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

Home NTFSD

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/


How to cancel pre-write operation without prompt?

CalCal Member Posts: 17

I have tried the following method to cancel in pre-write, but dialog boxes prompt to save as a different file:

Data->IoStatus.Status = STATUS_CANCELLED;
Data->IoStatus.Information = 0;
return FLT_PREOP_COMPLETE;

However I don't want any dialog boxes to show, I changed above with:
Data->IoStatus.Status = STATUS_SUCCESS;

then the file become empty afterward, even though no prompt of dialog boxes.

How can I abort write to existing files without changing their content?

Any advice would be appreciated.

Comments

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 525
    via Email
    Save is not atomic. Each app has different ideas what a Save is.
  • CalCal Member Posts: 17

    So what is the best way of blocking write to a file?

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 525
    via Email
    "Writw to a file" can be done in several ways.
    Best is to deny Open/Create/Overwrite (IRP MJ CREATE) if write access is
    requested.

    Dejan.
  • CalCal Member Posts: 17
    edited January 30

    Thank you Dejan, but maybe I should provide more details to be clear about what I want to achieve.
    Let's say a text file was opened with write access (https://community.osr.com/discussion/77714/irp-mj-create-with-write-access) by WordPad, users can view the content, but I want the file filter to conditionally block the changes made by the users when they are trying to save the file. I should still do that in Pre-Create rather than Pre-Write?

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 525
    via Email
    App should not request write until they need to save a file. So view is
    still possible.

    Yes, in PreCreate.
  • CalCal Member Posts: 17
    edited January 30

    As the link (I posted earlier) described, we can find the file was opened with write access in IRP_MJ_CREATE, but how can we tell if the user is actually trying to save the file? Using Irp->IoStatus.Information?

    And how should I abort write in Pre-Create, like below?
    Data->IoStatus.Status = STATUS_CANCELLED;
    Data->IoStatus.Information = 0;
    return FLT_PREOP_COMPLETE;

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 525
    via Email
    You don't. If it asks for Write access, presume it does.
  • CalCal Member Posts: 17
    edited January 30

    Following previous post, I can differentiate when user is trying to save the file by checking write access. However, the dialogs for "save as" still prompt after I return FLT_PREOP_COMPLETE with status = STATUS_CANCELLED or STATUS_ACCESS_DENIED in pre-create.
    Should I do something in post-cteate or CLEANUP / CLOSE in order to get rid of the prompt?

  • Dejan_MaksimovicDejan_Maksimovic Member - All Emails Posts: 525
    via Email
    No, just PreCreate.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

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!
Kernel Debugging 30 January 2023 Live, Online
Developing Minifilters 20 March 2023 Live, Online
Internals & Software Drivers 17 April 2023 Live, Online
Writing WDF Drivers 22 May 2023 Live, Online