Hello,
I have to log file deletions in a NTFS file system using a minifilter.
I read that I have to catch file disposition on IRP_CREATE and
IRP_SET_INFORMATION, and this is easy, but my problem is when to log
the actual deletion. Suppose we have two files “test1” and “test2”
that are hard links to the same stream. Here there are some cases that
I tested, with some comments.
*** Case 1: two open handles ***
create(“test1”, handle1)
create(“test1”, handle2)
set_disposition_information(handle2)
close(handle2)
> Stream Handle Contex for handle2 deleted (handle2 closed) <<
close(handle1)
> All handles to “test1” closed <<
> Stream Context deleted (all handles to the stream closed) <<
> File “test1” deleted <<
Comment: file deletion happens when the last handle to the file name
has been released, so I cannot use the Stream Handle Context to track
it.
*** Case 2: hard links ***
create(“test1”, handle1)
create(“test2”, handle2)
set_disposition_information(handle2)
close(handle2)
> Stream Handle Contex for handle2 deleted (handle 2 closed) <<
> All handles to “test2” closed <<
> File “test2” deleted <<
close(handle1)
> Stream Context deleted (all handles to the stream closed) <<
Comment: I cannot use the Stream Context too, because it depends on
the stream (so every name of the stream) and not on the file name.
*** Case 3: mixed ***
create(“test1”, handle1)
create(“test1”, handle2)
create(“test2”, handle3)
set_disposition_information(handle2)
close(handle2)
> Stream Handle Context for handle2 deleted (handle2 closed) <<
close(handle1)
> All handles to “test1” closed <<
> File “test1” deleted <<
close(handle3)
> Stream Context deleted (all handles to the stream closed) <<
Comment: here it is clear that I can’t use any context to track when
“file1” deletion will actually happen. How can my minifilter be
notified about file deletion? Is there a way to get how many handles
are still opened on a file name (not on a stream)? With this
information, I could write a callback for cleanup or close IRPs and
see if the deletion is going to happen.
Thanks,
Paolo