An app locks a byte range with key 1 and then writes to the file. In
Pre-Write, I try to write ourselves to that file using FltWriteFile with cached-write.
But as FltWriteFile does not take key of byte range lock, our FltWrite fails
with STATUS_FILE_LOCK_CONFLICT.
So I created callback data, set params appropriately
(set Iopb->Parameters.Write.Key = 1) and called it. But it also fails
with same error.
Debugging it, the callback data does the key is 1.But,the key in IRP is 0.So is that a bug with FltMgr?the FltMgr don’t copy the key to IRP?
There is FltWriteFileEx which takes key but available starting from windows 8.
the following is my implention for FltWriteFile with the Key:
NTSTATUS
MyWriteFile(
IN PFLT_INSTANCE Instance,
IN PFILE_OBJECT FileObject,
IN ULONG Key,
IN LARGE_INTEGER ByteOffset,
IN ULONG Length,
OUT PVOID Buffer,
IN FLT_IO_OPERATION_FLAGS Flags,
OUT PULONG BytesWritten
)
{
PFLT_CALLBACK_DATA data;
NTSTATUS status;
status = FltAllocateCallbackData( Instance, FileObject, &data );
if (!NT_SUCCESS( status )) return status;
data->Iopb->MajorFunction = IRP_MJ_WRITE;
data->Iopb->MinorFunction = 0;
data->Iopb->Parameters.Write.Length = Length;
data->Iopb->Parameters.Write.Key = Key;
data->Iopb->Parameters.Write.ByteOffset = ByteOffset;
data->Iopb->Parameters.Write.WriteBuffer = Buffer;
data->Iopb->Parameters.Write.MdlAddress = NULL;
data->Iopb->IrpFlags = Flags|IRP_SYNCHRONOUS_API;
FltPerformSynchronousIo( data );
status = data->IoStatus.Status;
*BytesWritten= data->IoStatus.Information;
FltFreeCallbackData( data );
return status;
}