Index: drivers/filesystems/fastfat/dir.c =================================================================== --- drivers/filesystems/fastfat/dir.c (revision 72609) +++ drivers/filesystems/fastfat/dir.c (working copy) @@ -421,6 +421,12 @@ #endif Buffer = VfatGetUserBuffer(IrpContext->Irp, FALSE); + if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, + BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) + { + return STATUS_PENDING; + } + if (!ExAcquireResourceSharedLite(&pFcb->MainResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) { @@ -428,6 +434,7 @@ if (NT_SUCCESS(Status)) Status = STATUS_PENDING; + ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource); return Status; } @@ -461,6 +468,7 @@ if (!pCcb->SearchPattern.Buffer) { ExReleaseResourceLite(&pFcb->MainResource); + ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource); return STATUS_INSUFFICIENT_RESOURCES; } RtlCopyUnicodeString(&pCcb->SearchPattern, pSearchPattern); @@ -477,6 +485,7 @@ if (!pCcb->SearchPattern.Buffer) { ExReleaseResourceLite(&pFcb->MainResource); + ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource); return STATUS_INSUFFICIENT_RESOURCES; } pCcb->SearchPattern.Buffer[0] = L'*'; @@ -504,13 +513,6 @@ DirContext.ShortNameU.Buffer = ShortNameBuffer; DirContext.ShortNameU.MaximumLength = sizeof(ShortNameBuffer); - if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, - BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) - { - ExReleaseResourceLite(&pFcb->MainResource); - return STATUS_PENDING; - } - while ((Status == STATUS_SUCCESS) && (BufferLength > 0)) { Status = FindFile(IrpContext->DeviceExt, @@ -586,8 +588,8 @@ IrpContext->Irp->IoStatus.Information = Stack->Parameters.QueryDirectory.Length - BufferLength; } + ExReleaseResourceLite(&pFcb->MainResource); ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource); - ExReleaseResourceLite(&pFcb->MainResource); return Status; } Index: ntoskrnl/io/iomgr/file.c =================================================================== --- ntoskrnl/io/iomgr/file.c (revision 72609) +++ ntoskrnl/io/iomgr/file.c (working copy) @@ -1978,8 +1978,14 @@ /* Allocate an IRP */ Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); - if (!Irp) return; + if (!Irp) + { + /* Release the lock if we were holding it */ + if (FileObject->Flags & FO_SYNCHRONOUS_IO) IopUnlockFileObject(FileObject); + return; + } + /* Set it up */ Irp->UserEvent = &Event; Irp->UserIosb = &Irp->IoStatus;