- Move the code from my previous commit before signalling the user event
[reactos.git] / reactos / ntoskrnl / io / iomgr / irp.c
index 6eafbd0..21870d5 100644 (file)
@@ -393,6 +393,29 @@ IopCompleteRequest(IN PKAPC Apc,
             }
         }
 
+        /* Update transfer count for everything but create operation */
+        if (!(Irp->Flags & IRP_CREATE_OPERATION))
+        {
+            if (Irp->Flags & IRP_WRITE_OPERATION)
+            {
+                /* Update write transfer count */
+                IopUpdateTransferCount(IopWriteTransfer,
+                                       (ULONG)Irp->IoStatus.Information);
+            }
+            else if (Irp->Flags & IRP_READ_OPERATION)
+            {
+                /* Update read transfer count */
+                IopUpdateTransferCount(IopReadTransfer,
+                                       (ULONG)Irp->IoStatus.Information);
+            }
+            else
+            {
+                /* Update other transfer count */
+                IopUpdateTransferCount(IopOtherTransfer,
+                                       (ULONG)Irp->IoStatus.Information);
+            }
+        }
+
         /* Now that we've signaled the events, de-associate the IRP */
         IopUnQueueIrpFromThread(Irp);
 
@@ -437,6 +460,22 @@ IopCompleteRequest(IN PKAPC Apc,
     }
     else
     {
+        /* Check if we have an associated user IOSB */
+        if (Irp->UserIosb)
+        {
+            /* We do, so let's give them the final status */
+            _SEH2_TRY
+            {
+               /*  Save the IOSB Information */
+               *Irp->UserIosb = Irp->IoStatus;
+            }
+            _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+            {
+               /* Ignore any error */
+            }
+            _SEH2_END;
+        }
+
         /*
          * Either we didn't return from the request, or we did return but this
          * request was synchronous.
@@ -446,9 +485,6 @@ IopCompleteRequest(IN PKAPC Apc,
             /* So we did return with a synch operation, was it the IRP? */
             if (Irp->Flags & IRP_SYNCHRONOUS_API)
             {
-                /* Yes, this IRP was synchronous, so return the I/O Status */
-                *Irp->UserIosb = Irp->IoStatus;
-
                 /* Now check if the user gave an event */
                 if (Irp->UserEvent)
                 {
@@ -689,12 +725,11 @@ IoBuildAsynchronousFsdRequest(IN ULONG MajorFunction,
                                /* Free the IRP and its MDL */
                                IoFreeMdl(Irp->MdlAddress);
                                IoFreeIrp(Irp);
-                               Irp = NULL;
+
+                /* Fail */
+                               _SEH2_YIELD(return NULL);
                        }
                        _SEH2_END;
-               
-            /* This is how we know if we failed during the probe */
-            if (!Irp) return NULL;
         }
         else
         {
@@ -885,12 +920,11 @@ IoBuildDeviceIoControlRequest(IN ULONG IoControlCode,
                     /* Free the input buffer and IRP */
                     if (InputBuffer) ExFreePool(Irp->AssociatedIrp.SystemBuffer);
                     IoFreeIrp(Irp);
-                    Irp = NULL;
+
+                    /* Fail */
+                    _SEH2_YIELD(return NULL);
                 }
                 _SEH2_END;
-
-                /* This is how we know if probing failed */
-                if (!Irp) return NULL;
             }
             break;
 
@@ -1113,6 +1147,9 @@ IofCallDriver(IN PDEVICE_OBJECT DeviceObject,
     PDRIVER_OBJECT DriverObject;
     PIO_STACK_LOCATION StackPtr;
 
+    /* Make sure this is a valid IRP */
+    ASSERT(Irp->Type == IO_TYPE_IRP);
+
     /* Get the Driver Object */
     DriverObject = DeviceObject->DriverObject;
 
@@ -1193,13 +1230,15 @@ IofCompleteRequest(IN PIRP Irp,
         ErrorCode = PtrToUlong(LastStackPtr->Parameters.Others.Argument4);
     }
 
-    /* Get the Current Stack and skip it */
+    /* Get the Current Stack */
     StackPtr = IoGetCurrentIrpStackLocation(Irp);
-    IoSkipCurrentIrpStackLocation(Irp);
 
     /* Loop the Stacks and complete the IRPs */
     do
     {
+        /* Skip current stack location */
+        IoSkipCurrentIrpStackLocation(Irp);
+
         /* Set Pending Returned */
         Irp->PendingReturned = StackPtr->Control & SL_PENDING_RETURNED;
 
@@ -1262,10 +1301,9 @@ IofCompleteRequest(IN PIRP Irp,
             IopClearStackLocation(StackPtr);
         }
 
-        /* Move to next stack location and pointer */
-        IoSkipCurrentIrpStackLocation(Irp);
+        /* Move pointer to next stack location */
         StackPtr++;
-    } while (Irp->CurrentLocation <= (Irp->StackCount + 1));
+    } while (Irp->CurrentLocation <= Irp->StackCount);
 
     /* Check if the IRP is an associated IRP */
     if (Irp->Flags & IRP_ASSOCIATED_IRP)