[disk/pnp] Independence from WV_S_DISK_T
authorShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Mon, 10 Jan 2011 02:34:05 +0000 (21:34 -0500)
committerShao Miller <Shao.Miller@yrdsb.edu.on.ca>
Mon, 10 Jan 2011 02:34:05 +0000 (21:34 -0500)
At long last.  This involved tracking state in the disk
structure with WV_E_DISK_STATE, introducing WvDiskPnp()
for the IRP major function handling tables, and renaming
disk_pnp__dispatch() to WvlDiskPnp().

Oh, and an item on a to-do list was simultaneously
addressed: Don't do anything special on IRP_MJ_PNP:
IRP_MN_REMOVE_DEVICE except note the state.  PDOs should
not disappear unless detached by the user-land utility
or possibly other internal functions, but we should just
leave them intact from Device Manager / SetupAPI functions.

src/aoe/driver.c
src/include/disk.h
src/winvblock/disk/pnp.c
src/winvblock/driver.c

index cecc63f..b23d45c 100644 (file)
@@ -2006,7 +2006,7 @@ static NTSTATUS AoeIrpPnp_(
     if (aoe_disk->Dev->State == WvDevStateDeleted)
       return WvlIrpComplete(irp, 0, STATUS_NO_SUCH_DEVICE);
     /* Use the disk routine. */
-    return disk_pnp__dispatch(dev_obj, irp, aoe_disk->disk);
+    return WvlDiskPnp(dev_obj, irp, aoe_disk->disk);
   }
 
 static UCHAR STDCALL AoeDiskUnitNum_(IN WV_SP_DISK_T disk) {
index 3b2ff2a..5ebcff1 100644 (file)
@@ -34,6 +34,17 @@ typedef enum WVL_DISK_MEDIA_TYPE {
     WvlDiskMediaTypes
   } WVL_E_DISK_MEDIA_TYPE, * WVL_EP_DISK_MEDIA_TYPE;
 
+typedef enum WVL_DISK_STATE {
+    WvlDiskStateNotStarted,
+    WvlDiskStateStarted,
+    WvlDiskStateStopPending,
+    WvlDiskStateStopped,
+    WvlDiskStateRemovePending,
+    WvlDiskStateSurpriseRemovePending,
+    WvlDiskStateDeleted,
+    WvlDiskStates
+  } WVL_E_DISK_STATE, * WVL_EP_DISK_STATE;
+
 typedef char WVL_A_DISK_BOOT_SECT[512];
 typedef WVL_A_DISK_BOOT_SECT * WVL_AP_DISK_BOOT_SECT;
 
@@ -149,6 +160,8 @@ struct WV_DISK_T {
     PDEVICE_OBJECT ParentBus;
     PVOID ext;
     PDRIVER_OBJECT DriverObj;
+    WVL_E_DISK_STATE OldState;
+    WVL_E_DISK_STATE State;
   };
 
 /* Yield a pointer to the disk. */
@@ -220,7 +233,7 @@ extern WVL_M_LIB NTSTATUS STDCALL WvlDiskDevCtl(
 /* IRP_MJ_SCSI dispatcher from disk/scsi.c */
 extern WVL_M_LIB WVL_F_DISK_SCSI WvlDiskScsi;
 /* IRP_MJ_PNP dispatcher from disk/pnp.c */
-extern WVL_M_LIB WVL_F_DISK_PNP disk_pnp__dispatch;
+extern WVL_M_LIB WVL_F_DISK_PNP WvlDiskPnp;
 
 
 #endif  /* WV_M_DISK_H_ */
index 4ef9878..6fe5096 100644 (file)
@@ -43,7 +43,7 @@
 static WVL_F_DISK_PNP WvlDiskPnpQueryDevRelations_;
 static WVL_F_DISK_PNP WvlDiskPnpQueryBusInfo_;
 static WVL_F_DISK_PNP WvlDiskPnpQueryCapabilities_;
-static WVL_F_DISK_PNP disk_pnp__simple_;
+static WVL_F_DISK_PNP WvlDiskPnpSimple_;
 
 static NTSTATUS STDCALL WvlDiskPnpQueryDevRelations_(
     IN PDEVICE_OBJECT dev_obj,
@@ -191,12 +191,11 @@ static NTSTATUS STDCALL WvlDiskPnpQueryCapabilities_(
     return WvlIrpComplete(irp, irp->IoStatus.Information, status);
   }
 
-static NTSTATUS STDCALL disk_pnp__simple_(
+static NTSTATUS STDCALL WvlDiskPnpSimple_(
     IN PDEVICE_OBJECT dev_obj,
     IN PIRP irp,
     WV_SP_DISK_T disk
   ) {
-    WV_SP_DEV_T dev = disk->Dev;
     PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp);
     NTSTATUS status;
 
@@ -220,62 +219,55 @@ static NTSTATUS STDCALL disk_pnp__simple_(
 
         case IRP_MN_START_DEVICE:
           DBG("IRP_MN_START_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateStarted;
+          disk->OldState = disk->State;
+          disk->State = WvlDiskStateStarted;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_QUERY_STOP_DEVICE:
           DBG("IRP_MN_QUERY_STOP_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateStopPending;
+          disk->OldState = disk->State;
+          disk->State = WvlDiskStateStopPending;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_CANCEL_STOP_DEVICE:
           DBG("IRP_MN_CANCEL_STOP_DEVICE\n");
-          dev->State = dev->OldState;
+          disk->State = disk->OldState;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_STOP_DEVICE:
           DBG("IRP_MN_STOP_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateStopped;
+          disk->OldState = disk->State;
+          disk->State = WvlDiskStateStopped;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_QUERY_REMOVE_DEVICE:
           DBG("IRP_MN_QUERY_REMOVE_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateRemovePending;
+          disk->OldState = disk->State;
+          disk->State = WvlDiskStateRemovePending;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_REMOVE_DEVICE:
           DBG("IRP_MN_REMOVE_DEVICE\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateNotStarted;
-          if (!dev->BusNode.Linked) {
-              WvDevClose(dev);
-              WvDevFree(dev);
-              status = STATUS_NO_SUCH_DEVICE;
-            } else {
-              WvlBusRemoveNode(&dev->BusNode);
-              status = STATUS_SUCCESS;
-            }
+          disk->OldState = disk->State;
+          disk->State = WvlDiskStateNotStarted;
+          status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_CANCEL_REMOVE_DEVICE:
           DBG("IRP_MN_CANCEL_REMOVE_DEVICE\n");
-          dev->State = dev->OldState;
+          disk->State = disk->OldState;
           status = STATUS_SUCCESS;
           break;
 
         case IRP_MN_SURPRISE_REMOVAL:
           DBG("IRP_MN_SURPRISE_REMOVAL\n");
-          dev->OldState = dev->State;
-          dev->State = WvDevStateSurpriseRemovePending;
+          disk->OldState = disk->State;
+          disk->State = WvlDiskStateSurpriseRemovePending;
           status = STATUS_SUCCESS;
           break;
 
@@ -284,9 +276,7 @@ static NTSTATUS STDCALL disk_pnp__simple_(
           status = irp->IoStatus.Status;
       }
 
-    irp->IoStatus.Status = status;
-    IoCompleteRequest(irp, IO_NO_INCREMENT);
-    return status;
+    return WvlIrpComplete(irp, irp->IoStatus.Information, status);
   }
 
 /**
@@ -297,7 +287,7 @@ static NTSTATUS STDCALL disk_pnp__simple_(
  * @v Disk              The disk to process the IRP with.
  * @ret NTSTATUS        The status of the operation.
  */
-WVL_M_LIB NTSTATUS STDCALL disk_pnp__dispatch(
+WVL_M_LIB NTSTATUS STDCALL WvlDiskPnp(
     IN PDEVICE_OBJECT DevObj,
     IN PIRP Irp,
     WV_SP_DISK_T Disk
@@ -330,6 +320,6 @@ WVL_M_LIB NTSTATUS STDCALL disk_pnp__dispatch(
           return WvlDiskPnpQueryCapabilities_(DevObj, Irp, Disk);
 
         default:
-          return disk_pnp__simple_(DevObj, Irp, Disk);
+          return WvlDiskPnpSimple_(DevObj, Irp, Disk);
       }
   }
index 4395a8c..9207339 100644 (file)
@@ -461,7 +461,14 @@ NTSTATUS STDCALL WvDiskPnp(
     IN PIRP irp,
     IN UCHAR code
   ) {
-    return disk_pnp__dispatch(dev->Self, irp, disk__get_ptr(dev));
+    NTSTATUS status;
+    WV_SP_DISK_T disk = disk__get_ptr(dev);
+
+    status = WvlDiskPnp(dev->Self, irp, disk);
+    /* Note any state change. */
+    dev->OldState = disk->OldState;
+    dev->State = disk->State;
+    return status;
   }
 
 NTSTATUS STDCALL WvDiskPnpQueryDevText(