Write sucess but return length is Zero?

Hi,

I’m trying to roll my own write IRP in IRP_MJ_WRITE, I just copy the
original Irp->Flags to
the new Irp->Flags, put in a dummy buffer, then send this new Irp to another
fileobject
(the backup file created by me), in case the
Irp->Flags = IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO
the IoCallDriver() returned SUCCESS, but the returned
ioStatusBlock.Information = 0.
How come the returned length is always zero but I didn’t get any error
returned? If I assume the
write is success and bypass here, after done, the data won’t be saved in the
backup file.
Can anyone figure out the problem here?

thanks,

AFei

I think the hint is your comment that you “put in a dummy buffer”. What
does this mean? I suspect that this means you change Irp->UserBuffer
(but not Irp->MdlAddress). For IRP_MJ_WRITE with IRP_PAGING_IO and
IRP_NOCACHE set the FSD is going to expect an MDL. That it works at all
is interesting, but there are lots of invalid things one can do from
kernel mode drivers.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of AFei
Sent: Wednesday, July 28, 2004 3:10 PM
To: ntfsd redirect
Subject: [ntfsd] Write sucess but return length is Zero?

Hi,

I’m trying to roll my own write IRP in IRP_MJ_WRITE, I just copy the
original Irp->Flags to the new Irp->Flags, put in a dummy buffer, then
send this new Irp to another fileobject (the backup file created by me),
in case the
Irp->Flags = IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO
the IoCallDriver() returned SUCCESS, but the returned
ioStatusBlock.Information = 0.
How come the returned length is always zero but I didn’t get any error
returned? If I assume the write is success and bypass here, after done,
the data won’t be saved in the backup file.
Can anyone figure out the problem here?

thanks,

AFei


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com To unsubscribe
send a blank email to xxxxx@lists.osr.com

Hi Tony,

I do use the MDL, please take a look at the following code pieces, just call
the function like this:
SendWriteIRP( …, IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO,
“abcde”, 5, … outLen );
It will return 0 with outLen = 0 every time. Any problems here?

STATUS SendWriteIRP( … IN ULONG flags, IN PVOID buff, IN ULONG buffLen,
…, OUT ULONG & ulLen )
{

ulLen = 0;
ioStatusBlock.Status = STATUS_SUCCESS;

ioStatusBlock.Information = 0;

myIrp = IoAllocateIrp( Dev->StackSize, FALSE );

if( !myIrp ) return STATUS_INSUFFICIENT_RESOURCES;

myIrpSp = IoGetNextIrpStackLocation( myIrp );

myIrp->Tail.Overlay.OriginalFileObject = fileObj;

myIrp->Tail.Overlay.Thread = PsGetCurrentThread();

myIrp->AssociatedIrp.SystemBuffer = buff;

myMdl = IoAllocateMdl( (PVOID)buff, buffLen, FALSE, FALSE, myIrp );

if( !myMdl ) return STATUS_INSUFFICIENT_RESOURCES;

MmBuildMdlForNonPagedPool( myMdl );

myIrp->MdlAddress = myMdl;

myIrp->UserBuffer = MmGetMdlVirtualAddress( myMdl );

myIrp->Flags = flags;

myIrp->RequestorMode = KernelMode;

myIrp->UserIosb = &ioStatusBlock;

myIrp->UserEvent = NULL;

myIrpSp->MajorFunction = IRP_MJ_WRITE;

myIrpSp->MinorFunction = 0;

myIrpSp->Parameters.Write.ByteOffset = *offset;

myIrpSp->Parameters.Write.Length = buffLen;

myIrpSp->FileObject = fileObj;

myIrpSp->DeviceObject = Dev;

KeInitializeEvent( &event, NotificationEvent, FALSE );

IoSetCompletionRoutine( myIrp,
(PIO_COMPLETION_ROUTINE)SAFF_ReadWriteCompletion, &event, TRUE, TRUE,
TRUE );

status = IoCallDriver( Dev, myIrp );

if( STATUS_PENDING == status )

{

(VOID)KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );

status = ioStatusBlock.Status;

}

if( NT_SUCCESS( status ) ) ulLen = ioStatusBlock.Information;

}

“Tony Mason” wrote in message news:xxxxx@ntfsd…
I think the hint is your comment that you “put in a dummy buffer”. What
does this mean? I suspect that this means you change Irp->UserBuffer
(but not Irp->MdlAddress). For IRP_MJ_WRITE with IRP_PAGING_IO and
IRP_NOCACHE set the FSD is going to expect an MDL. That it works at all
is interesting, but there are lots of invalid things one can do from
kernel mode drivers.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of AFei
Sent: Wednesday, July 28, 2004 3:10 PM
To: ntfsd redirect
Subject: [ntfsd] Write sucess but return length is Zero?

Hi,

I’m trying to roll my own write IRP in IRP_MJ_WRITE, I just copy the
original Irp->Flags to the new Irp->Flags, put in a dummy buffer, then
send this new Irp to another fileobject (the backup file created by me),
in case the
Irp->Flags = IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO
the IoCallDriver() returned SUCCESS, but the returned
ioStatusBlock.Information = 0.
How come the returned length is always zero but I didn’t get any error
returned? If I assume the write is success and bypass here, after done,
the data won’t be saved in the backup file.
Can anyone figure out the problem here?

thanks,

AFei


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com To unsubscribe
send a blank email to xxxxx@lists.osr.com

You need to be carefull if you trying to set the IRP_PAGING_IO flag.
Paging IO never extends EOF and sometimes it doesn’t write beyond
ValidDataLength.
You need to make sure that the data were written to the file into this range
via regular IO before you can expect that Paging IO actually write data.

Alexei.

-----Original Message-----
From: AFei [mailto:xxxxx@hotmail.com]
Sent: Wednesday, July 28, 2004 2:24 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] Write sucess but return length is Zero?

Hi Tony,

I do use the MDL, please take a look at the following code pieces, just call
the function like this:
SendWriteIRP( …, IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO,
“abcde”, 5, … outLen );
It will return 0 with outLen = 0 every time. Any problems here?

STATUS SendWriteIRP( … IN ULONG flags, IN PVOID buff, IN ULONG buffLen,
…, OUT ULONG & ulLen )
{

ulLen = 0;
ioStatusBlock.Status = STATUS_SUCCESS;

ioStatusBlock.Information = 0;

myIrp = IoAllocateIrp( Dev->StackSize, FALSE );

if( !myIrp ) return STATUS_INSUFFICIENT_RESOURCES;

myIrpSp = IoGetNextIrpStackLocation( myIrp );

myIrp->Tail.Overlay.OriginalFileObject = fileObj;

myIrp->Tail.Overlay.Thread = PsGetCurrentThread();

myIrp->AssociatedIrp.SystemBuffer = buff;

myMdl = IoAllocateMdl( (PVOID)buff, buffLen, FALSE, FALSE, myIrp );

if( !myMdl ) return STATUS_INSUFFICIENT_RESOURCES;

MmBuildMdlForNonPagedPool( myMdl );

myIrp->MdlAddress = myMdl;

myIrp->UserBuffer = MmGetMdlVirtualAddress( myMdl );

myIrp->Flags = flags;

myIrp->RequestorMode = KernelMode;

myIrp->UserIosb = &ioStatusBlock;

myIrp->UserEvent = NULL;

myIrpSp->MajorFunction = IRP_MJ_WRITE;

myIrpSp->MinorFunction = 0;

myIrpSp->Parameters.Write.ByteOffset = *offset;

myIrpSp->Parameters.Write.Length = buffLen;

myIrpSp->FileObject = fileObj;

myIrpSp->DeviceObject = Dev;

KeInitializeEvent( &event, NotificationEvent, FALSE );

IoSetCompletionRoutine( myIrp,
(PIO_COMPLETION_ROUTINE)SAFF_ReadWriteCompletion, &event, TRUE, TRUE,
TRUE );

status = IoCallDriver( Dev, myIrp );

if( STATUS_PENDING == status )

{

(VOID)KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, NULL );

status = ioStatusBlock.Status;

}

if( NT_SUCCESS( status ) ) ulLen = ioStatusBlock.Information;

}

“Tony Mason” wrote in message news:xxxxx@ntfsd…
I think the hint is your comment that you “put in a dummy buffer”. What
does this mean? I suspect that this means you change Irp->UserBuffer
(but not Irp->MdlAddress). For IRP_MJ_WRITE with IRP_PAGING_IO and
IRP_NOCACHE set the FSD is going to expect an MDL. That it works at all
is interesting, but there are lots of invalid things one can do from
kernel mode drivers.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of AFei
Sent: Wednesday, July 28, 2004 3:10 PM
To: ntfsd redirect
Subject: [ntfsd] Write sucess but return length is Zero?

Hi,

I’m trying to roll my own write IRP in IRP_MJ_WRITE, I just copy the
original Irp->Flags to the new Irp->Flags, put in a dummy buffer, then
send this new Irp to another fileobject (the backup file created by me),
in case the
Irp->Flags = IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO
the IoCallDriver() returned SUCCESS, but the returned
ioStatusBlock.Information = 0.
How come the returned length is always zero but I didn’t get any error
returned? If I assume the write is success and bypass here, after done,
the data won’t be saved in the backup file.
Can anyone figure out the problem here?

thanks,

AFei


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com To unsubscribe
send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@vmware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Yes, that is the problem! In IRP_MJ_WRITE, originally I only do the backup
when
Irp->Flags & ( IRP_NOCACHE | IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO ),
this normally happens after the file was closed, so the backup file won’t be
able to extend EOF
with this paging flag as you said, if I just backup the file despite of the
paging flag, it works great!

thanks a lot,

AFei

“Alexei Jelvis” wrote in message news:xxxxx@ntfsd…
You need to be carefull if you trying to set the IRP_PAGING_IO flag.
Paging IO never extends EOF and sometimes it doesn’t write beyond
ValidDataLength.
You need to make sure that the data were written to the file into this range
via regular IO before you can expect that Paging IO actually write data.

Alexei.