[bus] Track state in WV_S_BUS_T
authorShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Wed, 29 Dec 2010 13:55:11 +0000 (08:55 -0500)
committerShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Wed, 29 Dec 2010 13:55:11 +0000 (08:55 -0500)
Instead of in the WV_S_DEV_T structure (for a bus only).

src/include/bus.h
src/winvblock/bus/pnp.c
src/winvblock/driver.c

index 612817d..1aba1c8 100644 (file)
 typedef void STDCALL WV_F_BUS_THREAD(IN WV_SP_BUS_T);
 typedef WV_F_BUS_THREAD * WV_FP_BUS_THREAD;
 
+/* Device state. */
+typedef enum WV_BUS_STATE {
+    WvBusStateNotStarted,
+    WvBusStateStarted,
+    WvBusStateStopPending,
+    WvBusStateStopped,
+    WvBusStateRemovePending,
+    WvBusStateSurpriseRemovePending,
+    WvBusStateDeleted,
+    WvBusStates
+  } WV_E_BUS_STATE, * WV_EP_BUS_STATE;
+
 /* The bus type. */
 typedef struct WV_BUS_T {
     WV_S_DEV_T Dev;
@@ -50,6 +62,8 @@ typedef struct WV_BUS_T {
     KEVENT ThreadSignal;
     winvblock__bool Stop;
     KEVENT ThreadStopped;
+    WV_E_BUS_STATE OldState;
+    WV_E_BUS_STATE State;
     struct {
         LIST_ENTRY Nodes;
         USHORT NodeCount;
index fed01c3..d91f414 100644 (file)
@@ -71,8 +71,8 @@ static NTSTATUS STDCALL WvBusPnpStartDev_(IN WV_SP_BUS_T bus, IN PIRP irp) {
         KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
       }
     if (NT_SUCCESS(status = irp->IoStatus.Status)) {
-        bus->Dev.OldState = bus->Dev.State;
-        bus->Dev.State = WvDevStateStarted;
+        bus->OldState = bus->State;
+        bus->State = WvBusStateStarted;
       }
     return driver__complete_irp(
         irp,
@@ -101,8 +101,8 @@ static NTSTATUS STDCALL WvBusPnpRemoveDev_(IN WV_SP_BUS_T bus, IN PIRP irp) {
     /* If we get here, we should be called by WvBusProcessWorkItems() */
     status = STATUS_SUCCESS;
     lower = bus->LowerDeviceObject;
-    dev->OldState = dev->State;
-    dev->State = WvDevStateDeleted;
+    bus->OldState = bus->State;
+    bus->State = WvBusStateDeleted;
     /* Pass the IRP on to any lower DEVICE_OBJECT */
     if (lower) {
         irp->IoStatus.Information = 0;
@@ -363,7 +363,6 @@ static NTSTATUS STDCALL WvBusPnpSimple_(
     IN UCHAR code
   ) {
     NTSTATUS status;
-    WV_SP_DEV_T dev = &bus->Dev;
     PDEVICE_OBJECT lower = bus->LowerDeviceObject;
 
     switch (code) {
@@ -375,41 +374,41 @@ static NTSTATUS STDCALL WvBusPnpSimple_(
 
         case IRP_MN_QUERY_STOP_DEVICE:
           DBG("bus_pnp: IRP_MN_QUERY_STOP_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateStopPending;
+          bus->OldState = bus->State;
+          bus->State = WvBusStateStopPending;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_CANCEL_STOP_DEVICE:
           DBG("bus_pnp: IRP_MN_CANCEL_STOP_DEVICE\n");
-          dev->State = dev->OldState;
+          bus->State = bus->OldState;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_STOP_DEVICE:
           DBG("bus_pnp: IRP_MN_STOP_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateStopped;
+          bus->OldState = bus->State;
+          bus->State = WvBusStateStopped;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_QUERY_REMOVE_DEVICE:
           DBG("bus_pnp: IRP_MN_QUERY_REMOVE_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateRemovePending;
+          bus->OldState = bus->State;
+          bus->State = WvBusStateRemovePending;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_CANCEL_REMOVE_DEVICE:
           DBG("bus_pnp: IRP_MN_CANCEL_REMOVE_DEVICE\n");
-          dev->State = dev->OldState;
+          bus->State = bus->OldState;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_SURPRISE_REMOVAL:
           DBG("bus_pnp: IRP_MN_SURPRISE_REMOVAL\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateSurpriseRemovePending;
+          bus->OldState = bus->State;
+          bus->State = WvBusStateSurpriseRemovePending;
           status = STATUS_SUCCESS;
           break;
 
index 38c9cbc..b871333 100644 (file)
@@ -517,6 +517,7 @@ static NTSTATUS driver__dispatch_pnp_(
     /* WvDevFromDevObj() checks for a NULL dev_obj */
     WV_SP_DEV_T dev = WvDevFromDevObj(dev_obj);
     PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp);
+    NTSTATUS status;
 
     #ifdef DEBUGIRPS
     Debug_IrpStart(dev_obj, irp);
@@ -526,11 +527,16 @@ static NTSTATUS driver__dispatch_pnp_(
       return driver__complete_irp(irp, 0, STATUS_NO_SUCH_DEVICE);
     /* Call the particular device's power handler. */
     if (dev->IrpMj && dev->IrpMj->Pnp) {
-        return dev->IrpMj->Pnp(
+        status = dev->IrpMj->Pnp(
             dev,
             irp,
             io_stack_loc->MinorFunction
           );
+        if (dev->IsBus) {
+            dev->OldState = WvDriverBus_.OldState;
+            dev->State = WvDriverBus_.State;
+          }
+        return status;
       }
     /* Otherwise, we don't support the IRP. */
     return driver__complete_irp(irp, 0, STATUS_NOT_SUPPORTED);