diff --git a/reactos/drivers/filesystems/ntfs/dirctl.c b/reactos/drivers/filesystems/ntfs/dirctl.c index 1c7e1967b1c..02b82e08393 100644 --- a/reactos/drivers/filesystems/ntfs/dirctl.c +++ b/reactos/drivers/filesystems/ntfs/dirctl.c @@ -477,10 +477,11 @@ CdfsGetBothDirectoryInformation(PFCB Fcb, } #endif -static NTSTATUS -NtfsQueryDirectory(PDEVICE_OBJECT DeviceObject, - PIRP Irp) +NTSTATUS +NtfsQueryDirectory(PNTFS_IRP_CONTEXT IrpContext) { + PIRP Irp; + PDEVICE_OBJECT DeviceObject; PDEVICE_EXTENSION DeviceExtension; LONG BufferLength = 0; PUNICODE_STRING SearchPattern = NULL; @@ -498,6 +499,10 @@ NtfsQueryDirectory(PDEVICE_OBJECT DeviceObject, DPRINT1("NtfsQueryDirectory() called\n"); + ASSERT(IrpContext); + Irp = IrpContext->Irp; + DeviceObject = IrpContext->DeviceObject; + DeviceExtension = DeviceObject->DeviceExtension; Stack = IoGetCurrentIrpStackLocation(Irp); FileObject = Stack->FileObject; @@ -672,37 +677,49 @@ NTSTATUS NTAPI NtfsFsdDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp) { - PIO_STACK_LOCATION Stack; - NTSTATUS Status; + PNTFS_IRP_CONTEXT IrpContext = NULL; + NTSTATUS Status = STATUS_UNSUCCESSFUL; DPRINT1("NtfsDirectoryControl() called\n"); - Stack = IoGetCurrentIrpStackLocation(Irp); + FsRtlEnterFileSystem(); + ASSERT(DeviceObject); + ASSERT(Irp); - switch (Stack->MinorFunction) + NtfsIsIrpTopLevel(Irp); + + IrpContext = NtfsAllocateIrpContext(DeviceObject, Irp); + if (IrpContext) { - case IRP_MN_QUERY_DIRECTORY: - Status = NtfsQueryDirectory(DeviceObject, - Irp); - break; - - case IRP_MN_NOTIFY_CHANGE_DIRECTORY: - DPRINT1("IRP_MN_NOTIFY_CHANGE_DIRECTORY\n"); - Status = STATUS_NOT_IMPLEMENTED; - break; - - default: - DPRINT1("NTFS: MinorFunction %d\n", Stack->MinorFunction); - Status = STATUS_INVALID_DEVICE_REQUEST; - break; + switch (IrpContext->MinorFunction) + { + case IRP_MN_QUERY_DIRECTORY: + Status = NtfsQueryDirectory(IrpContext); + break; + + case IRP_MN_NOTIFY_CHANGE_DIRECTORY: + DPRINT1("IRP_MN_NOTIFY_CHANGE_DIRECTORY\n"); + Status = STATUS_NOT_IMPLEMENTED; + break; + + default: + Status = STATUS_INVALID_DEVICE_REQUEST; + break; + } } - + else + Status = STATUS_INSUFFICIENT_RESOURCES; + Irp->IoStatus.Status = Status; Irp->IoStatus.Information = 0; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - - return(Status); + + if (IrpContext) + ExFreePoolWithTag(IrpContext, TAG('N', 'I', 'R', 'P')); + + IoSetTopLevelIrp(NULL); + FsRtlExitFileSystem(); + return Status; } /* EOF */ diff --git a/reactos/drivers/filesystems/ntfs/misc.c b/reactos/drivers/filesystems/ntfs/misc.c index 4e1d76d8f07..f35bb1b7ea7 100644 --- a/reactos/drivers/filesystems/ntfs/misc.c +++ b/reactos/drivers/filesystems/ntfs/misc.c @@ -74,20 +74,24 @@ NtfsAllocateIrpContext(PDEVICE_OBJECT DeviceObject, TRACE_(NTFS, "NtfsAllocateIrpContext()\n"); - IoStackLocation = IoGetCurrentIrpStackLocation(Irp); - IrpContext = (PNTFS_IRP_CONTEXT)ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_IRP_CONTEXT), TAG('N', 'I', 'R', 'P')); if (IrpContext == NULL) return NULL; - RtlZeroMemory(IrpContext, sizeof(NTFS_IRP_CONTEXT)); + IrpContext->Identifier.Type = NTFS_TYPE_IRP_CONTEST; IrpContext->Identifier.Size = sizeof(NTFS_IRP_CONTEXT); IrpContext->Irp = Irp; - IrpContext->MajorFunction = IoStackLocation->MajorFunction; - IrpContext->MinorFunction = IoStackLocation->MinorFunction; IrpContext->DeviceObject = DeviceObject; - IrpContext->IsTopLevel = (IoGetTopLevelIrp() == Irp); + if (Irp) + { + IoStackLocation = IoGetCurrentIrpStackLocation(Irp); + ASSERT(IoStackLocation); + + IrpContext->MajorFunction = IoStackLocation->MajorFunction; + IrpContext->MinorFunction = IoStackLocation->MinorFunction; + IrpContext->IsTopLevel = (IoGetTopLevelIrp() == Irp); + } return IrpContext; }