I have written a fairly simple minifilter that I’m using to track opens and
closes on files. When the file is closed, I want to know if the file was
modified. I didn’t see anything in the information provided in
IRP_MJ_CLEANUP that would tell me this (if it is there, could someone tell
me where to look?), so I decided to use a StreamContext to determine the
information.
So, basically, I’m doing the following:
-
During the post callback for an IRP_MJ_CREATE, I create and set a
StreamContext for the file. -
During the post callback for an IPR_MJ_WRITE, I acquire the context and
set my bool value to true, indicating that this file was modified during the
processing. -
During the pre callback for an IRP_MJ_CLEANUP, I acquire the context and
check the bool to see if this file was modified.
This seems to run OK, but after a while, the process in #2 calls an OS
crash. I finally have WinDbg running (although not optimally - I can’t seem
to get symbol loading working yet), and right before the crash, I do see a
bunch of instances where the Data->IoStatus.Status != STATUS_SUCCESS.
Here is the relevant code for the PostWriteCallback - anything obvious?
FLT_POSTOP_CALLBACK_STATUS
PostWriteCallback (
__inout PFLT_CALLBACK_DATA Data,
__in PCFLT_RELATED_OBJECTS FltObjects,
__in PVOID CompletionContext,
__in FLT_POST_OPERATION_FLAGS Flags
)
{
PT_STREAM_HANDLE_CONTEXT fileContext = NULL;
FLT_POSTOP_CALLBACK_STATUS returnStatus =
FLT_POSTOP_FINISHED_PROCESSING;
NTSTATUS status;
UNREFERENCED_PARAMETER( CompletionContext );
UNREFERENCED_PARAMETER( Flags );
if( FltObjects->FileObject == NULL )
{
DbgPrint( “PostWriteCallback:: NULL FileObject?\n” );
return returnStatus;
}
if ( Data->IoStatus.Status != STATUS_SUCCESS )
{
DbgPrint( “PostWriteCallback:: Data->IoStatus.Status !=
STATUS_SUCCESS\n” );
return returnStatus;
}
status = FltGetStreamHandleContext( FltObjects->Instance,
FltObjects->FileObject,
&fileContext );
if (NT_SUCCESS( status )) {
if( fileContext ) {
fileContext->FileModified = TRUE;
FltReleaseContext( fileContext );
}
}
return returnStatus;
}
–
Andrew Cheyne
Senior Software Developer
GridIron Software