阅读:4364回复:4
FltCreateFile 参数不正确 及 STATUS_FILE_LOCK_CONFLICT 文件锁冲突错误 请教
改写minifilter SwappBuffer例程
将写文件的BUFFER拷贝出来 在FltDoCompletionProcessingWhenSafe设置WriteSafePostCallback函数准备将内容写入另外备份文件, 但是FltCreateFile 显示STATUS 为C0000369 为STATUS_INVALID_DEVICE_OBJECT_PARAMETER 使用ZwCreateFile代替FltCreateFile 写入文件时出现STATUS_FILE_LOCK_CONFLICT 文件锁冲突错误 请问 1、FltCreateFile 有何错误? 2、写入文件时出现STATUS_FILE_LOCK_CONFLICT 文件锁冲突错误 代码如下 WriteSafePostCallback( __inout PFLT_CALLBACK_DATA Data, __in PCFLT_RELATED_OBJECTS FltObjects, __in_opt PVOID CompletionContext, __in FLT_POST_OPERATION_FLAGS Flags ) { PPRE_2_POST_CONTEXT p2pCtx; int i; FLT_POSTOP_CALLBACK_STATUS RetPostOperationStatus; NTSTATUS status; PVOID newBuf = NULL; LARGE_INTEGER WriOffset; ULONG WriLen; UNICODE_STRING BackFile; OBJECT_ATTRIBUTES ObjAttrib; HANDLE BackHandle = NULL; IO_STATUS_BLOCK IoStatusBlock={0}; LARGE_INTEGER Interval; PFILE_OBJECT FileObject; ULONG WriteBytes; Interval.QuadPart = -2000000; FltLockUserBuffer(Data); p2pCtx = CompletionContext; newBuf = p2pCtx->SwappedBuffer; WriLen = p2pCtx->WriLen; WriOffset = p2pCtx->WriOffset; //DbgPrint("DoSafe Buffer%s\n",p2pCtx->SwappedBuffer); DbgPrint("DoSafe WriLen%d\n",p2pCtx->WriLen); DbgPrint("DoSafeWriOffset%d\n",p2pCtx->WriOffset); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RtlInitUnicodeString(&BackFile,ReplacePath); InitializeObjectAttributes(&ObjAttrib,&BackFile, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL,NULL); /*尝试用FLTCREATEFILE status = ZwCreateFile(&BackHandle, GENERIC_WRITE, &ObjAttrib, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); if (!NT_SUCCESS(status)) { DbgPrint(" CreateBackFile Failed\n"); goto PostWriEnd; } */ status = FltCreateFile(FileProData.Filter, FltObjects->Instance, &BackHandle, FILE_ALL_ACCESS, &ObjAttrib, &IoStatusBlock, (PLARGE_INTEGER)NULL, FILE_ATTRIBUTE_NORMAL,FILE_SHARE_READ, FILE_OPEN , 0l, NULL, 0L, IO_IGNORE_SHARE_ACCESS_CHECK); if(!NT_SUCCESS(status)) { DbgPrint("FltCreateFile Failed\:%x\n",status); goto PostWriEnd; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //创建句柄完成 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// for(i = 0 ;i<50;i++) { status = ZwWriteFile(BackHandle, NULL, NULL, NULL, &IoStatusBlock, newBuf, WriLen, &WriOffset, NULL); if(NT_SUCCESS(status)) { DbgPrint("Write BackFile Success\n"); goto PostWriEnd; } status = ObReferenceObjectByHandle(BackHandle,NULL,NULL,KernelMode,&FileObject,NULL); if(!NT_SUCCESS(status)) { DbgPrint("ReferenceObject Success\n"); goto PostWriEnd; } status = FltWriteFile(Data->Iopb->TargetInstance,FileObject,&WriOffset,WriLen,newBuf, FLTFL_IO_OPERATION_NON_CACHED,&WriteBytes,NULL,NULL); ObfDereferenceObject(FileObject); if(NT_SUCCESS(status)) { DbgPrint("FltWrite BackFile Success\n"); goto PostWriEnd; } KeDelayExecutionThread(0, 0, &Interval); }//for(i = 0 ;i<50;i++) PostWriEnd: if(BackHandle) ZwClose(BackHandle); return FLT_POSTOP_FINISHED_PROCESSING; } |
|
禁止发言
|
沙发#
发布于:2010-10-28 11:13
用户被禁言,该主题自动屏蔽! |
板凳#
发布于:2010-10-28 14:15
谢谢回复
基础不牢靠 就是图省事才用MINIFILTER啊 谁知道在某个文件写操作中写备份文件会出现文件错问题 我在CREATE进行写操作就没问题 |
|
禁止发言
|
地板#
发布于:2010-10-28 16:02
用户被禁言,该主题自动屏蔽! |
地下室#
发布于:2010-10-28 16:31
OK 我试试先
|
|