SetInfo hanging at cleanup/close

I have to resize the file in some situations when closing the file, but
the Set Info IRP I build and send lower hangs and I cannot figure why. I
perform also some reads and writes and Query Info for the name and all
work fine. The same function for Set Info works fine in other situations.
Is there a restriction for using it at MJ_CLEANUP or MJ_CLOSE ? How can
I resize the file? ZwSetInformationFile does not work either.
This is the function:

NTSTATUS
MakeIrpFileInformationRequest( UCHAR MajorFunction,
ULONG IrpFlags,
PDEVICE_OBJECT next_device,
PFILE_OBJECT FileObject,
FILE_INFORMATION_CLASS infoclass,
PVOID buffer_unsafe,
int bufsize)
{
PIRP pirp = NULL;
PRKEVENT ev = NULL;
PIO_STACK_LOCATION nextstack = NULL;
IO_STATUS_BLOCK *iostat = NULL;
NTSTATUS status;
BYTE *buffer_safe;

ev = GetEventFromPool();
if(!ev)
return STATUS_INSUFFICIENT_RESOURCES;
pirp = IoAllocateIrp(next_device->StackSize, FALSE);
if(!pirp)
{
ReleaseEventFromPool(ev);
return STATUS_INSUFFICIENT_RESOURCES;
}

nextstack = IoGetNextIrpStackLocation(pirp);
nextstack->MajorFunction = MajorFunction;
nextstack->DeviceObject = next_device;
nextstack->FileObject = FileObject;
nextstack->Parameters.SetFile.FileInformationClass = infoclass;
nextstack->Parameters.SetFile.Length = bufsize;
buffer_safe = ExAllocatePool(NonPagedPool, bufsize);
memcpy(buffer_safe, buffer_unsafe, bufsize);
pirp->AssociatedIrp.SystemBuffer = buffer_safe;
iostat = ExAllocatePool(NonPagedPool, sizeof(IO_STATUS_BLOCK));
pirp->UserIosb = iostat;
// pirp->Flags |= IrpFlags;// | IRP_NOCACHE;

IoSetCompletionRoutine( pirp, CloseCompletion, ev, TRUE, TRUE, TRUE );
IoCallDriver(next_device, pirp);
KeWaitForSingleObject(ev, Executive, KernelMode, FALSE, 0);
ReleaseEventFromPool(ev);
memcpy(buffer_unsafe, buffer_safe, bufsize);
ExFreePool(buffer_safe);

status = iostat->Status;
ExFreePool(iostat);
return status;
}

Between IRP_MJ_CLEANUP and IRP_MJ_CLOSE, only operations associated with
paging I/O may be sent to the file system. Note that while you can set the
IRP_PAGING_IO bit in your IRP, the rules for paging IRPs are different than
they are for normal IRPs.

Regards,

Tony

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

-----Original Message-----
From: Daniel Turcanu [mailto:xxxxx@ipdevel.ro]
Sent: Thursday, June 19, 2003 12:07 PM
To: File Systems Developers
Subject: [ntfsd] SetInfo hanging at cleanup/close

I have to resize the file in some situations when closing the file, but
the Set Info IRP I build and send lower hangs and I cannot figure why. I
perform also some reads and writes and Query Info for the name and all
work fine. The same function for Set Info works fine in other situations.
Is there a restriction for using it at MJ_CLEANUP or MJ_CLOSE ? How can
I resize the file? ZwSetInformationFile does not work either.
This is the function:

NTSTATUS
MakeIrpFileInformationRequest( UCHAR MajorFunction,
ULONG IrpFlags,
PDEVICE_OBJECT next_device,
PFILE_OBJECT FileObject,
FILE_INFORMATION_CLASS infoclass,
PVOID buffer_unsafe,
int bufsize)
{
PIRP pirp = NULL;
PRKEVENT ev = NULL;
PIO_STACK_LOCATION nextstack = NULL;
IO_STATUS_BLOCK *iostat = NULL;
NTSTATUS status;
BYTE *buffer_safe;

ev = GetEventFromPool();
if(!ev)
return STATUS_INSUFFICIENT_RESOURCES;
pirp = IoAllocateIrp(next_device->StackSize, FALSE);
if(!pirp)
{
ReleaseEventFromPool(ev);
return STATUS_INSUFFICIENT_RESOURCES;
}

nextstack = IoGetNextIrpStackLocation(pirp);
nextstack->MajorFunction = MajorFunction;
nextstack->DeviceObject = next_device;
nextstack->FileObject = FileObject;
nextstack->Parameters.SetFile.FileInformationClass = infoclass;
nextstack->Parameters.SetFile.Length = bufsize;
buffer_safe = ExAllocatePool(NonPagedPool, bufsize);
memcpy(buffer_safe, buffer_unsafe, bufsize);
pirp->AssociatedIrp.SystemBuffer = buffer_safe;
iostat = ExAllocatePool(NonPagedPool, sizeof(IO_STATUS_BLOCK));
pirp->UserIosb = iostat;
// pirp->Flags |= IrpFlags;// | IRP_NOCACHE;

IoSetCompletionRoutine( pirp, CloseCompletion, ev, TRUE, TRUE, TRUE );
IoCallDriver(next_device, pirp);
KeWaitForSingleObject(ev, Executive, KernelMode, FALSE, 0);
ReleaseEventFromPool(ev);
memcpy(buffer_unsafe, buffer_safe, bufsize);
ExFreePool(buffer_safe);

status = iostat->Status;
ExFreePool(iostat);
return status;
}


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

I tried processing right before the MJ_CLEANUP but it is the same. I
tried also to use the system thread, but in that case the write
operation didn’t work either. I don’t know, is there a restriction for
sending MJ_WRITE from the system thread ? Or a special combination of
flags needed? As far as I see the thread hangs everytime almost in the
same place because of a KiUnexpectedInterrupt (this is the last function
I see on the stack). I tried a lot of combinations of flags for the
write and set info operations and for the re-opening, but it is the
same. Is this, what I am trying to do, really impossible?

Daniel

Tony Mason wrote:

Between IRP_MJ_CLEANUP and IRP_MJ_CLOSE, only operations associated with
paging I/O may be sent to the file system. Note that while you can set the
IRP_PAGING_IO bit in your IRP, the rules for paging IRPs are different than
they are for normal IRPs.

Regards,

Tony

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

-----Original Message-----
From: Daniel Turcanu [mailto:xxxxx@ipdevel.ro]
Sent: Thursday, June 19, 2003 12:07 PM
To: File Systems Developers
Subject: [ntfsd] SetInfo hanging at cleanup/close

I have to resize the file in some situations when closing the file, but
the Set Info IRP I build and send lower hangs and I cannot figure why. I
perform also some reads and writes and Query Info for the name and all
work fine. The same function for Set Info works fine in other situations.
Is there a restriction for using it at MJ_CLEANUP or MJ_CLOSE ? How can
I resize the file? ZwSetInformationFile does not work either.
This is the function:

NTSTATUS
MakeIrpFileInformationRequest( UCHAR MajorFunction,
ULONG IrpFlags,
PDEVICE_OBJECT next_device,
PFILE_OBJECT FileObject,
FILE_INFORMATION_CLASS infoclass,
PVOID buffer_unsafe,
int bufsize)
{
PIRP pirp = NULL;
PRKEVENT ev = NULL;
PIO_STACK_LOCATION nextstack = NULL;
IO_STATUS_BLOCK *iostat = NULL;
NTSTATUS status;
BYTE *buffer_safe;

ev = GetEventFromPool();
if(!ev)
return STATUS_INSUFFICIENT_RESOURCES;
pirp = IoAllocateIrp(next_device->StackSize, FALSE);
if(!pirp)
{
ReleaseEventFromPool(ev);
return STATUS_INSUFFICIENT_RESOURCES;
}

nextstack = IoGetNextIrpStackLocation(pirp);
nextstack->MajorFunction = MajorFunction;
nextstack->DeviceObject = next_device;
nextstack->FileObject = FileObject;
nextstack->Parameters.SetFile.FileInformationClass = infoclass;
nextstack->Parameters.SetFile.Length = bufsize;
buffer_safe = ExAllocatePool(NonPagedPool, bufsize);
memcpy(buffer_safe, buffer_unsafe, bufsize);
pirp->AssociatedIrp.SystemBuffer = buffer_safe;
iostat = ExAllocatePool(NonPagedPool, sizeof(IO_STATUS_BLOCK));
pirp->UserIosb = iostat;
// pirp->Flags |= IrpFlags;// | IRP_NOCACHE;

IoSetCompletionRoutine( pirp, CloseCompletion, ev, TRUE, TRUE, TRUE );
IoCallDriver(next_device, pirp);
KeWaitForSingleObject(ev, Executive, KernelMode, FALSE, 0);
ReleaseEventFromPool(ev);
memcpy(buffer_unsafe, buffer_safe, bufsize);
ExFreePool(buffer_safe);

status = iostat->Status;
ExFreePool(iostat);
return status;
}


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


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

No, what you are trying to do (write to a file prior to the IRP_MJ_CLEANUP)
is certainly quite possible. There is something wrong with the specific
implementation you have, but from what you have described I have no idea as
to what it might be.

Regards,

Tony

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

-----Original Message-----
From: Daniel Turcanu [mailto:xxxxx@ipdevel.ro]
Sent: Friday, June 20, 2003 1:26 PM
To: File Systems Developers
Subject: [ntfsd] RE: SetInfo hanging at cleanup/close

I tried processing right before the MJ_CLEANUP but it is the same. I
tried also to use the system thread, but in that case the write
operation didn’t work either. I don’t know, is there a restriction for
sending MJ_WRITE from the system thread ? Or a special combination of
flags needed? As far as I see the thread hangs everytime almost in the
same place because of a KiUnexpectedInterrupt (this is the last function
I see on the stack). I tried a lot of combinations of flags for the
write and set info operations and for the re-opening, but it is the
same. Is this, what I am trying to do, really impossible?

Daniel

Tony Mason wrote:

Between IRP_MJ_CLEANUP and IRP_MJ_CLOSE, only operations associated with
paging I/O may be sent to the file system. Note that while you can set the
IRP_PAGING_IO bit in your IRP, the rules for paging IRPs are different than
they are for normal IRPs.

Regards,

Tony

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

-----Original Message-----
From: Daniel Turcanu [mailto:xxxxx@ipdevel.ro]
Sent: Thursday, June 19, 2003 12:07 PM
To: File Systems Developers
Subject: [ntfsd] SetInfo hanging at cleanup/close

I have to resize the file in some situations when closing the file, but
the Set Info IRP I build and send lower hangs and I cannot figure why. I
perform also some reads and writes and Query Info for the name and all
work fine. The same function for Set Info works fine in other situations.
Is there a restriction for using it at MJ_CLEANUP or MJ_CLOSE ? How can
I resize the file? ZwSetInformationFile does not work either.
This is the function:

NTSTATUS
MakeIrpFileInformationRequest( UCHAR MajorFunction,
ULONG IrpFlags,
PDEVICE_OBJECT next_device,
PFILE_OBJECT FileObject,
FILE_INFORMATION_CLASS infoclass,
PVOID buffer_unsafe,
int bufsize)
{
PIRP pirp = NULL;
PRKEVENT ev = NULL;
PIO_STACK_LOCATION nextstack = NULL;
IO_STATUS_BLOCK *iostat = NULL;
NTSTATUS status;
BYTE *buffer_safe;

ev = GetEventFromPool();
if(!ev)
return STATUS_INSUFFICIENT_RESOURCES;
pirp = IoAllocateIrp(next_device->StackSize, FALSE);
if(!pirp)
{
ReleaseEventFromPool(ev);
return STATUS_INSUFFICIENT_RESOURCES;
}

nextstack = IoGetNextIrpStackLocation(pirp);
nextstack->MajorFunction = MajorFunction;
nextstack->DeviceObject = next_device;
nextstack->FileObject = FileObject;
nextstack->Parameters.SetFile.FileInformationClass = infoclass;
nextstack->Parameters.SetFile.Length = bufsize;
buffer_safe = ExAllocatePool(NonPagedPool, bufsize);
memcpy(buffer_safe, buffer_unsafe, bufsize);
pirp->AssociatedIrp.SystemBuffer = buffer_safe;
iostat = ExAllocatePool(NonPagedPool, sizeof(IO_STATUS_BLOCK));
pirp->UserIosb = iostat;
// pirp->Flags |= IrpFlags;// | IRP_NOCACHE;

IoSetCompletionRoutine( pirp, CloseCompletion, ev, TRUE, TRUE, TRUE );
IoCallDriver(next_device, pirp);
KeWaitForSingleObject(ev, Executive, KernelMode, FALSE, 0);
ReleaseEventFromPool(ev);
memcpy(buffer_unsafe, buffer_safe, bufsize);
ExFreePool(buffer_safe);

status = iostat->Status;
ExFreePool(iostat);
return status;
}


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


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


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

Looking at your code below:

#1. You should also set pIrp->Tail.Overlay.Thread and
pIrp->Tail.Overlay.OriginalFileObject.
#2. You should set pIrp->RequestorMode to KernelMode.
#3. If you’re just going to sit on the event after sending down the IRP,
you should set pIrp->Flags to IRP_SYNCHRONOUS_API as an optimization (so
that the filesystem won’t bother posting the request).
#4. Make the IoStatus block a local variable and save yourself the pool
allocation; the stack will not be paged out because you’re waiting as
KernelMode.

If the code continues to fail, give us more information about the
failure (WinDbg !analyze -v on bugcheck, status code on simple failure).

  • Nick Ryan

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Daniel Turcanu
Sent: Friday, June 20, 2003 10:26 AM
To: File Systems Developers
Subject: [ntfsd] RE: SetInfo hanging at cleanup/close

I tried processing right before the MJ_CLEANUP but it is the same. I
tried also to use the system thread, but in that case the write
operation didn’t work either. I don’t know, is there a
restriction for
sending MJ_WRITE from the system thread ? Or a special combination of
flags needed? As far as I see the thread hangs everytime
almost in the
same place because of a KiUnexpectedInterrupt (this is the
last function
I see on the stack). I tried a lot of combinations of flags for the
write and set info operations and for the re-opening, but it is the
same. Is this, what I am trying to do, really impossible?

Daniel

Tony Mason wrote:

>Between IRP_MJ_CLEANUP and IRP_MJ_CLOSE, only operations associated
>with paging I/O may be sent to the file system. Note that while you
>can set the IRP_PAGING_IO bit in your IRP, the rules for paging IRPs
>are different than they are for normal IRPs.
>
>Regards,
>
>Tony
>
>Tony Mason
>Consulting Partner
>OSR Open Systems Resources, Inc.
>http://www.osr.com
>
>
>-----Original Message-----
>From: Daniel Turcanu [mailto:xxxxx@ipdevel.ro]
>Sent: Thursday, June 19, 2003 12:07 PM
>To: File Systems Developers
>Subject: [ntfsd] SetInfo hanging at cleanup/close
>
>I have to resize the file in some situations when closing
the file, but
>the Set Info IRP I build and send lower hangs and I cannot
figure why. I
>perform also some reads and writes and Query Info for the
name and all
>work fine. The same function for Set Info works fine in
other situations.
>Is there a restriction for using it at MJ_CLEANUP or
MJ_CLOSE ? How can
>I resize the file? ZwSetInformationFile does not work either.
>This is the function:
>
>NTSTATUS
>MakeIrpFileInformationRequest( UCHAR MajorFunction,
> ULONG IrpFlags,
> PDEVICE_OBJECT next_device,
> PFILE_OBJECT FileObject,
> FILE_INFORMATION_CLASS infoclass,
> PVOID buffer_unsafe,
> int bufsize)
>{
> PIRP pirp = NULL;
> PRKEVENT ev = NULL;
> PIO_STACK_LOCATION nextstack = NULL;
> IO_STATUS_BLOCK *iostat = NULL;
> NTSTATUS status;
> BYTE *buffer_safe;
>
>
> ev = GetEventFromPool();
> if(!ev)
> return STATUS_INSUFFICIENT_RESOURCES;
> pirp = IoAllocateIrp(next_device->StackSize, FALSE);
> if(!pirp)
> {
> ReleaseEventFromPool(ev);
> return STATUS_INSUFFICIENT_RESOURCES;
> }
>
> nextstack = IoGetNextIrpStackLocation(pirp);
> nextstack->MajorFunction = MajorFunction;
> nextstack->DeviceObject = next_device;
> nextstack->FileObject = FileObject;
> nextstack->Parameters.SetFile.FileInformationClass = infoclass;
> nextstack->Parameters.SetFile.Length = bufsize;
> buffer_safe = ExAllocatePool(NonPagedPool, bufsize);
> memcpy(buffer_safe, buffer_unsafe, bufsize);
> pirp->AssociatedIrp.SystemBuffer = buffer_safe;
> iostat = ExAllocatePool(NonPagedPool, sizeof(IO_STATUS_BLOCK));
> pirp->UserIosb = iostat;
>// pirp->Flags |= IrpFlags;// | IRP_NOCACHE;
>
> IoSetCompletionRoutine( pirp, CloseCompletion, ev, TRUE,
TRUE, TRUE );
> IoCallDriver(next_device, pirp);
> KeWaitForSingleObject(ev, Executive, KernelMode, FALSE, 0);
> ReleaseEventFromPool(ev);
> memcpy(buffer_unsafe, buffer_safe, bufsize);
> ExFreePool(buffer_safe);
>
> status = iostat->Status;
> ExFreePool(iostat);
> return status;
>}
>
>
>
>
>
>
>—
>You are currently subscribed to ntfsd as: xxxxx@osr.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>—
>You are currently subscribed to ntfsd as: xxxxx@ipdevel.ro To
>unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
>


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