From b4363068d10d05e39581874a5aa10fe0183b4948 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Tue, 22 May 2018 21:29:10 +0200 Subject: [PATCH] [FASTFAT] Properly handle IRPs that can wait and these that cannot. CORE-14634 --- drivers/filesystems/fastfat/cleanup.c | 26 +++----------------- drivers/filesystems/fastfat/create.c | 5 ---- drivers/filesystems/fastfat/misc.c | 35 +++++++++++++++++++++------ 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/drivers/filesystems/fastfat/cleanup.c b/drivers/filesystems/fastfat/cleanup.c index f611a69def1..d19fa94703e 100644 --- a/drivers/filesystems/fastfat/cleanup.c +++ b/drivers/filesystems/fastfat/cleanup.c @@ -50,17 +50,8 @@ VfatCleanupFile( } else { - if(!ExAcquireResourceExclusiveLite(&pFcb->MainResource, - BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) - { - return STATUS_PENDING; - } - if(!ExAcquireResourceExclusiveLite(&pFcb->PagingIoResource, - BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) - { - ExReleaseResourceLite(&pFcb->MainResource); - return STATUS_PENDING; - } + ExAcquireResourceExclusiveLite(&pFcb->MainResource, TRUE); + ExAcquireResourceExclusiveLite(&pFcb->PagingIoResource, TRUE); pCcb = FileObject->FsContext2; if (BooleanFlagOn(pCcb->Flags, CCB_DELETE_ON_CLOSE)) @@ -173,21 +164,10 @@ VfatCleanup( return STATUS_SUCCESS; } - if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, - BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) - { - return VfatMarkIrpContextForQueue(IrpContext); - } - + ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE); Status = VfatCleanupFile(IrpContext); - ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource); - if (Status == STATUS_PENDING) - { - return VfatMarkIrpContextForQueue(IrpContext); - } - IrpContext->Irp->IoStatus.Information = 0; return Status; } diff --git a/drivers/filesystems/fastfat/create.c b/drivers/filesystems/fastfat/create.c index 84751c25958..e2fbccaf9c8 100644 --- a/drivers/filesystems/fastfat/create.c +++ b/drivers/filesystems/fastfat/create.c @@ -1059,11 +1059,6 @@ VfatCreate( return STATUS_SUCCESS; } - if (!BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)) - { - return VfatMarkIrpContextForQueue(IrpContext); - } - IrpContext->Irp->IoStatus.Information = 0; ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE); Status = VfatCreateFile(IrpContext->DeviceObject, IrpContext->Irp); diff --git a/drivers/filesystems/fastfat/misc.c b/drivers/filesystems/fastfat/misc.c index 0d291776b57..ad5f4bcec3e 100644 --- a/drivers/filesystems/fastfat/misc.c +++ b/drivers/filesystems/fastfat/misc.c @@ -287,18 +287,39 @@ VfatAllocateIrpContext( IrpContext->MinorFunction = IrpContext->Stack->MinorFunction; IrpContext->FileObject = IrpContext->Stack->FileObject; IrpContext->Flags = IRPCONTEXT_COMPLETE; - if (MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL || - MajorFunction == IRP_MJ_DEVICE_CONTROL || - MajorFunction == IRP_MJ_SHUTDOWN) + + /* Easy cases that can wait */ + if (MajorFunction == IRP_MJ_CLEANUP || + MajorFunction == IRP_MJ_CREATE || + MajorFunction == IRP_MJ_SHUTDOWN || + MajorFunction == IRP_MJ_CLOSE /* likely to be fixed */) { - IrpContext->Flags |= IRPCONTEXT_CANWAIT; + SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT); } - else if (MajorFunction != IRP_MJ_CLEANUP && - MajorFunction != IRP_MJ_CLOSE && + /* Cases that can wait if synchronous IRP */ + else if ((MajorFunction == IRP_MJ_DEVICE_CONTROL || + MajorFunction == IRP_MJ_QUERY_INFORMATION || + MajorFunction == IRP_MJ_SET_INFORMATION || + MajorFunction == IRP_MJ_FLUSH_BUFFERS || + MajorFunction == IRP_MJ_LOCK_CONTROL || + MajorFunction == IRP_MJ_QUERY_VOLUME_INFORMATION || + MajorFunction == IRP_MJ_SET_VOLUME_INFORMATION || + MajorFunction == IRP_MJ_DIRECTORY_CONTROL || + MajorFunction == IRP_MJ_WRITE || + MajorFunction == IRP_MJ_READ) && IoIsOperationSynchronous(Irp)) { - IrpContext->Flags |= IRPCONTEXT_CANWAIT; + SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT); } + /* Cases that can wait if synchronous or if no FO */ + else if ((MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL || + MajorFunction == IRP_MJ_PNP) && + (IoGetCurrentIrpStackLocation(Irp)->FileObject == NULL || + IoIsOperationSynchronous(Irp))) + { + SetFlag(IrpContext->Flags, IRPCONTEXT_CANWAIT); + } + KeInitializeEvent(&IrpContext->Event, NotificationEvent, FALSE); IrpContext->RefCount = 0; IrpContext->PriorityBoost = IO_NO_INCREMENT;