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;
}