Hi all,
I called ZwCreateFile() and ZwWriteFile() to write data to remote file in my
FS filter driver
But the return value of ZwWriteFile() was not NT_SUCCESS.
Why?
My code:
case IRP_MJ_WRITE:
if((RtlCompareMemory(fullPathName,MirrFolder,10)==10)&&(strlen(fullPathName)
10))
{
DbgPrint((“We Should write here !\n”));
RtlInitUnicodeString(&myObjectName,L"\Device\Mup\Ren-test\CopyFile
\test.txt");
InitializeObjectAttributes(&myObjectAttr,
&myObjectName,OBJ_KERNEL_HANDLE,NULL,NULL);
ntStatus=ZwCreateFile(&myCopyFile,FILE_ANY_ACCESS,&myObjectAttr,&myIoStatus,
NULL,FILE_ATTRIBUTE_NORMAL,FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN_IF,FILE_NO_INTERMEDIATE_BUFFERING,NULL,0);
hookCompletion=NT_SUCCESS(ntStatus);
if(!hookCompletion)
DbgPrint((“Cannot create the target file object.\n”));
}
else
{
//
// Initialize the event
//
KeInitializeEvent(&event, SynchronizationEvent, FALSE);
ntStatus=ZwWriteFile(myCopyFile,&event,NULL,NULL,&IoStatusBlock,
Irp->UserBuffer,currentIrpStack->Parameters.Write.Length,
&(currentIrpStack->Parameters.Write.ByteOffset),NULL);
hookCompletion=NT_SUCCESS(ntStatus);
if(!hookCompletion){
DbgPrint((“Filemirr: Could not Write to remote file\n”));
}else// we get the pointer of the file object then we create IRP
{
//
// Wait for the I/O
//
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);
//to see if the write OK or not
hookCompletion=NT_SUCCESS( IoStatusBlock.Status );
if(hookCompletion)
{
DbgPrint((“Write to remote file OK!!\n”));
}
else
{
DbgPrint((“Write To Remote File Failed!!\n”));
}
ZwClose(myCopyFile);
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com