[FASTFAT] Properly handle IRPs that can wait and these that cannot.
authorPierre Schweitzer <pierre@reactos.org>
Tue, 22 May 2018 19:29:10 +0000 (21:29 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Tue, 22 May 2018 19:30:08 +0000 (21:30 +0200)
CORE-14634

drivers/filesystems/fastfat/cleanup.c
drivers/filesystems/fastfat/create.c
drivers/filesystems/fastfat/misc.c

index f611a69..d19fa94 100644 (file)
@@ -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;
 }
index 84751c2..e2fbcca 100644 (file)
@@ -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);
index 0d29177..ad5f4bc 100644 (file)
@@ -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;