win-pvdrivers

changeset 35:2e1d570b69e9 0.4.0

Final commit before 0.4.0
author James Harper <james.harper@bendigoit.com.au>
date Wed Dec 05 19:56:11 2007 +1100 (2007-12-05)
parents 7fc983eddda8
children f5a275d63b7d
files target/xenhide.inf target/xenpci.inf target/xenvbd.inf xenpci/xenbus.c xenpci/xenpci.c xenpci/xenpci.h xenvbd/xenvbd.c
line diff
     1.1 --- a/target/xenhide.inf	Sun Dec 02 23:13:20 2007 +1100
     1.2 +++ b/target/xenhide.inf	Wed Dec 05 19:56:11 2007 +1100
     1.3 @@ -3,7 +3,7 @@ Signature="$WINDOWS NT$"
     1.4  Class=System
     1.5  ClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318}
     1.6  Provider=%JAMESHARPER%
     1.7 -DriverVer=11/20/2007,0.3.0.1
     1.8 +DriverVer=11/20/2007,0.4.0.0
     1.9  
    1.10  [ControlFlags]
    1.11  ExcludeFromSelect = *
     2.1 --- a/target/xenpci.inf	Sun Dec 02 23:13:20 2007 +1100
     2.2 +++ b/target/xenpci.inf	Wed Dec 05 19:56:11 2007 +1100
     2.3 @@ -3,7 +3,7 @@ Signature="$WINDOWS NT$"
     2.4  Class=System
     2.5  ClassGuid={4D36E97D-E325-11CE-BFC1-08002BE10318}
     2.6  Provider=%JAMESHARPER%
     2.7 -DriverVer=11/20/2007,0.3.0.2
     2.8 +DriverVer=12/05/2007,0.4.0.0
     2.9  
    2.10  [DestinationDirs]
    2.11  DefaultDestDir = 12
     3.1 --- a/target/xenvbd.inf	Sun Dec 02 23:13:20 2007 +1100
     3.2 +++ b/target/xenvbd.inf	Wed Dec 05 19:56:11 2007 +1100
     3.3 @@ -3,7 +3,7 @@ Signature="$WINDOWS NT$"
     3.4  Class=SCSIAdapter
     3.5  ClassGuid={4D36E97B-E325-11CE-BFC1-08002BE10318}
     3.6  Provider=%JAMESHARPER%
     3.7 -DriverVer=12/02/2007,0.3.0.52
     3.8 +DriverVer=12/05/2007,0.4.0.0
     3.9  
    3.10  [DestinationDirs]
    3.11  DefaultDestDir = 12
     4.1 --- a/xenpci/xenbus.c	Sun Dec 02 23:13:20 2007 +1100
     4.2 +++ b/xenpci/xenbus.c	Wed Dec 05 19:56:11 2007 +1100
     4.3 @@ -73,6 +73,8 @@ static KEVENT XenBus_ReadThreadEvent;
     4.4  static HANDLE XenBus_WatchThreadHandle;
     4.5  static KEVENT XenBus_WatchThreadEvent;
     4.6  
     4.7 +static BOOLEAN XenBus_ShuttingDown;
     4.8 +
     4.9  static void
    4.10  XenBus_ReadThreadProc(PVOID StartContext);
    4.11  static void
    4.12 @@ -266,7 +268,7 @@ xenbus_msg_reply(int type, xenbus_transa
    4.13  //  DEFINE_WAIT(w);
    4.14    struct xsd_sockmsg *rep;
    4.15  
    4.16 -  KdPrint((__DRIVER_NAME " --> xenbus_msg_reply\n"));
    4.17 +//  KdPrint((__DRIVER_NAME " --> xenbus_msg_reply\n"));
    4.18  
    4.19    id = allocate_xenbus_id();
    4.20  //  add_waiter(w, req_info[id].waitq);
    4.21 @@ -277,7 +279,7 @@ xenbus_msg_reply(int type, xenbus_transa
    4.22  //  remove_waiter(w);
    4.23  //  wake(current);
    4.24  //
    4.25 -  KdPrint((__DRIVER_NAME "     starting wait\n"));
    4.26 +//  KdPrint((__DRIVER_NAME "     starting wait\n"));
    4.27  
    4.28    KeWaitForSingleObject(&req_info[id].WaitEvent, Executive, KernelMode, FALSE, NULL);
    4.29  
    4.30 @@ -286,7 +288,7 @@ xenbus_msg_reply(int type, xenbus_transa
    4.31    rep = req_info[id].Reply;
    4.32  //  BUG_ON(rep->req_id != id);
    4.33    release_xenbus_id(id);
    4.34 -  KdPrint((__DRIVER_NAME " <-- xenbus_msg_reply\n"));
    4.35 +//  KdPrint((__DRIVER_NAME " <-- xenbus_msg_reply\n"));
    4.36    return rep;
    4.37  }
    4.38  
    4.39 @@ -356,18 +358,31 @@ char* xenbus_wait_for_value(const char* 
    4.40  NTSTATUS
    4.41  XenBus_Init()
    4.42  {
    4.43 -  //KdPrint((__DRIVER_NAME " --> XenBus_Init\n"));
    4.44 +  NTSTATUS Status;
    4.45 +  OBJECT_ATTRIBUTES oa;
    4.46 +  int i;
    4.47 +
    4.48 +  KdPrint((__DRIVER_NAME " --> XenBus_Init\n"));
    4.49  
    4.50    xen_store_evtchn = EvtChn_GetXenStorePort();
    4.51    xen_store_interface = EvtChn_GetXenStoreRingAddr();
    4.52  
    4.53 -  //KdPrint((__DRIVER_NAME "     xen_store_evtchn = %08x\n", xen_store_evtchn));
    4.54 -  //KdPrint((__DRIVER_NAME "     xen_store_interface = %08x\n", xen_store_interface));
    4.55 +  for (i = 0; i < MAX_WATCH_ENTRIES; i++)
    4.56 +    XenBus_WatchEntries[i].Active = 0;
    4.57  
    4.58    KeInitializeEvent(&XenBus_ReadThreadEvent, SynchronizationEvent, FALSE);
    4.59    KeInitializeEvent(&XenBus_WatchThreadEvent, SynchronizationEvent, FALSE);
    4.60 +  XenBus_ShuttingDown = FALSE;
    4.61  
    4.62 -  //KdPrint((__DRIVER_NAME " <-- XenBus_Init\n"));
    4.63 +  //InitializeObjectAttributes(&oa, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
    4.64 +  //Status = PsCreateSystemThread(&XenBus_ReadThreadHandle, THREAD_ALL_ACCESS, &oa, NULL, NULL, XenBus_ReadThreadProc, NULL);
    4.65 +  Status = PsCreateSystemThread(&XenBus_ReadThreadHandle, THREAD_ALL_ACCESS, NULL, NULL, NULL, XenBus_ReadThreadProc, NULL);
    4.66 +
    4.67 +  //InitializeObjectAttributes(&oa, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
    4.68 +  //Status = PsCreateSystemThread(&XenBus_WatchThreadHandle, THREAD_ALL_ACCESS, &oa, NULL, NULL, XenBus_WatchThreadProc, NULL);
    4.69 +  Status = PsCreateSystemThread(&XenBus_WatchThreadHandle, THREAD_ALL_ACCESS, NULL, NULL, NULL, XenBus_WatchThreadProc, NULL);
    4.70 +
    4.71 +  KdPrint((__DRIVER_NAME " <-- XenBus_Init\n"));
    4.72  
    4.73    return STATUS_SUCCESS;
    4.74  }
    4.75 @@ -375,23 +390,8 @@ XenBus_Init()
    4.76  NTSTATUS
    4.77  XenBus_Start()
    4.78  {
    4.79 -  OBJECT_ATTRIBUTES oa;
    4.80 -  NTSTATUS status;
    4.81 -  int i;
    4.82 -
    4.83    KdPrint((__DRIVER_NAME " --> XenBus_Start\n"));
    4.84  
    4.85 -  InitializeObjectAttributes(&oa, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
    4.86 -  status = PsCreateSystemThread(&XenBus_ReadThreadHandle, THREAD_ALL_ACCESS, &oa, NULL, NULL, XenBus_ReadThreadProc, NULL);
    4.87 -
    4.88 -  // remove all existing watches already in Xen too...
    4.89 -
    4.90 -  for (i = 0; i < MAX_WATCH_ENTRIES; i++)
    4.91 -    XenBus_WatchEntries[i].Active = 0;
    4.92 -
    4.93 -  InitializeObjectAttributes(&oa, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
    4.94 -  status = PsCreateSystemThread(&XenBus_WatchThreadHandle, THREAD_ALL_ACCESS, &oa, NULL, NULL, XenBus_WatchThreadProc, NULL);
    4.95 -
    4.96    EvtChn_Bind(xen_store_evtchn, XenBus_Interrupt, NULL);
    4.97  
    4.98    KdPrint((__DRIVER_NAME " <-- XenBus_Start\n"));
    4.99 @@ -404,19 +404,48 @@ XenBus_Stop()
   4.100  {
   4.101    int i;
   4.102  
   4.103 +  KdPrint((__DRIVER_NAME " --> XenBus_Stop\n"));
   4.104 +
   4.105    for (i = 0; i < MAX_WATCH_ENTRIES; i++)
   4.106    {
   4.107 -    if (!XenBus_WatchEntries[i].Active)
   4.108 -      continue;
   4.109 -    XenBus_RemWatch(XBT_NIL, XenBus_WatchEntries[i].Path, XenBus_WatchEntries[i].ServiceRoutine, XenBus_WatchEntries[i].ServiceContext);
   4.110 +    if (XenBus_WatchEntries[i].Active)
   4.111 +      XenBus_RemWatch(XBT_NIL, XenBus_WatchEntries[i].Path, XenBus_WatchEntries[i].ServiceRoutine, XenBus_WatchEntries[i].ServiceContext);
   4.112    }
   4.113  
   4.114    EvtChn_Unbind(xen_store_evtchn);
   4.115  
   4.116 -  // Does this actually stop the threads???
   4.117 +  KdPrint((__DRIVER_NAME " <-- XenBus_Stop\n"));
   4.118 +
   4.119 +  return STATUS_SUCCESS;
   4.120 +}
   4.121 +
   4.122 +NTSTATUS
   4.123 +XenBus_Close()
   4.124 +{
   4.125 +  PKWAIT_BLOCK WaitBlockArray[2];
   4.126 +  PVOID WaitArray[2];
   4.127 +
   4.128 +  XenBus_ShuttingDown = TRUE;
   4.129 +
   4.130 +  KdPrint((__DRIVER_NAME "     Signalling Threads\n"));
   4.131 +  KeSetEvent(&XenBus_ReadThreadEvent, 1, FALSE);
   4.132 +  KeSetEvent(&XenBus_WatchThreadEvent, 1, FALSE);
   4.133 +  KdPrint((__DRIVER_NAME "     Waiting for threads to die\n"));
   4.134 +  ObReferenceObjectByHandle(XenBus_ReadThreadHandle, THREAD_ALL_ACCESS, NULL, KernelMode, &WaitArray[0], NULL);
   4.135 +  ObReferenceObjectByHandle(XenBus_WatchThreadHandle, THREAD_ALL_ACCESS, NULL, KernelMode, &WaitArray[1], NULL);
   4.136 +  KeWaitForMultipleObjects(2, WaitArray, WaitAll, Executive, KernelMode, FALSE, NULL, WaitBlockArray);
   4.137 +  KdPrint((__DRIVER_NAME "     Threads are dead\n"));
   4.138 +
   4.139 +  XenBus_ShuttingDown = FALSE;
   4.140 +
   4.141 +  ObDereferenceObject(WaitArray[0]);
   4.142 +  ObDereferenceObject(WaitArray[1]);
   4.143 +
   4.144    ZwClose(XenBus_WatchThreadHandle);
   4.145    ZwClose(XenBus_ReadThreadHandle);
   4.146  
   4.147 +  KdPrint((__DRIVER_NAME " <-- XenBus_Close\n"));
   4.148 +
   4.149    return STATUS_SUCCESS;
   4.150  }
   4.151  
   4.152 @@ -480,9 +509,6 @@ do_ls_test(const char *pre)
   4.153    //KdPrint((__DRIVER_NAME " --> do_ls_test\n"));
   4.154  }
   4.155  
   4.156 -int ReadThreadSetCount;
   4.157 -int ReadThreadWaitCount;
   4.158 -
   4.159  static void
   4.160  XenBus_ReadThreadProc(PVOID StartContext) {
   4.161    int NewWriteIndex;
   4.162 @@ -495,6 +521,11 @@ XenBus_ReadThreadProc(PVOID StartContext
   4.163    for(;;)
   4.164    {
   4.165      KeWaitForSingleObject(&XenBus_ReadThreadEvent, Executive, KernelMode, FALSE, NULL);
   4.166 +    if (XenBus_ShuttingDown)
   4.167 +    {
   4.168 +      KdPrint((__DRIVER_NAME "     Shutdown detected in ReadThreadProc\n"));
   4.169 +      PsTerminateSystemThread(0);
   4.170 +    }
   4.171      //KdPrint((__DRIVER_NAME "     ReadThread Woken (Count = %d)\n", ReadThreadWaitCount++));
   4.172      while (xen_store_interface->rsp_prod != xen_store_interface->rsp_cons)
   4.173      {
   4.174 @@ -567,6 +598,11 @@ XenBus_WatchThreadProc(PVOID StartContex
   4.175    for(;;)
   4.176    {
   4.177      KeWaitForSingleObject(&XenBus_WatchThreadEvent, Executive, KernelMode, FALSE, NULL);
   4.178 +    if (XenBus_ShuttingDown)
   4.179 +    {
   4.180 +      KdPrint((__DRIVER_NAME "     Shutdown detected in WatchThreadProc\n"));
   4.181 +      PsTerminateSystemThread(0);
   4.182 +    }
   4.183      while (XenBus_WatchRingReadIndex != XenBus_WatchRingWriteIndex)
   4.184      {
   4.185        XenBus_WatchRingReadIndex = (XenBus_WatchRingReadIndex + 1) & 127;
   4.186 @@ -601,7 +637,7 @@ XenBus_AddWatch(xenbus_transaction_t xbt
   4.187    char Token[20];
   4.188    struct write_req req[2];
   4.189  
   4.190 -  KdPrint((__DRIVER_NAME " --> XenBus_AddWatch\n"));
   4.191 +//  KdPrint((__DRIVER_NAME " --> XenBus_AddWatch\n"));
   4.192  
   4.193    // check that Path < 128 chars
   4.194  
   4.195 @@ -636,7 +672,7 @@ XenBus_AddWatch(xenbus_transaction_t xbt
   4.196    XenBus_WatchEntries[i].Count = 0;
   4.197    XenBus_WatchEntries[i].Active = 1;
   4.198  
   4.199 -  KdPrint((__DRIVER_NAME " <-- XenBus_AddWatch\n"));
   4.200 +//  KdPrint((__DRIVER_NAME " <-- XenBus_AddWatch\n"));
   4.201  
   4.202    return NULL;
   4.203  }
     5.1 --- a/xenpci/xenpci.c	Sun Dec 02 23:13:20 2007 +1100
     5.2 +++ b/xenpci/xenpci.c	Wed Dec 05 19:56:11 2007 +1100
     5.3 @@ -585,8 +585,28 @@ XenPCI_D0ExitPreInterruptsDisabled(WDFDE
     5.4    UNREFERENCED_PARAMETER(Device);
     5.5    UNREFERENCED_PARAMETER(TargetState);
     5.6  
     5.7 +  KdPrint((__DRIVER_NAME " --> D0ExitPreInterruptsDisabled\n"));
     5.8 +
     5.9 +  switch (KeGetCurrentIrql())
    5.10 +  {
    5.11 +  case PASSIVE_LEVEL:
    5.12 +    KdPrint((__DRIVER_NAME "     PASSIVE_LEVEL\n"));
    5.13 +    break;
    5.14 +  case APC_LEVEL:
    5.15 +    KdPrint((__DRIVER_NAME "     APC_LEVEL\n"));
    5.16 +    break;
    5.17 +  case DISPATCH_LEVEL:
    5.18 +    KdPrint((__DRIVER_NAME "     DISPATCH_LEVEL\n"));
    5.19 +    break;
    5.20 +  default:
    5.21 +    KdPrint((__DRIVER_NAME "     %d\n", KeGetCurrentIrql()));
    5.22 +    break;
    5.23 +  }
    5.24 +
    5.25    XenBus_Stop();
    5.26  
    5.27 +  KdPrint((__DRIVER_NAME " <-- D0ExitPreInterruptsDisabled\n"));
    5.28 +
    5.29    return status;
    5.30  }
    5.31  
    5.32 @@ -598,9 +618,27 @@ XenPCI_D0Exit(WDFDEVICE Device, WDF_POWE
    5.33    UNREFERENCED_PARAMETER(Device);
    5.34    UNREFERENCED_PARAMETER(TargetState);
    5.35  
    5.36 -  KdPrint((__DRIVER_NAME " --> EvtDeviceD0Exit\n"));
    5.37 +  KdPrint((__DRIVER_NAME " --> DeviceD0Exit\n"));
    5.38  
    5.39 -  KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Exit\n"));
    5.40 +  switch (KeGetCurrentIrql())
    5.41 +  {
    5.42 +  case PASSIVE_LEVEL:
    5.43 +    KdPrint((__DRIVER_NAME "     PASSIVE_LEVEL\n"));
    5.44 +    break;
    5.45 +  case APC_LEVEL:
    5.46 +    KdPrint((__DRIVER_NAME "     APC_LEVEL\n"));
    5.47 +    break;
    5.48 +  case DISPATCH_LEVEL:
    5.49 +    KdPrint((__DRIVER_NAME "     DISPATCH_LEVEL\n"));
    5.50 +    break;
    5.51 +  default:
    5.52 +    KdPrint((__DRIVER_NAME "     %d\n", KeGetCurrentIrql()));
    5.53 +    break;
    5.54 +  }
    5.55 +
    5.56 +  XenBus_Close();
    5.57 +
    5.58 +  KdPrint((__DRIVER_NAME " <-- DeviceD0Exit\n"));
    5.59  
    5.60    return status;
    5.61  }
     6.1 --- a/xenpci/xenpci.h	Sun Dec 02 23:13:20 2007 +1100
     6.2 +++ b/xenpci/xenpci.h	Wed Dec 05 19:56:11 2007 +1100
     6.3 @@ -156,6 +156,8 @@ XenBus_List(xenbus_transaction_t xbt, co
     6.4  NTSTATUS
     6.5  XenBus_Init();
     6.6  NTSTATUS
     6.7 +XenBus_Close();
     6.8 +NTSTATUS
     6.9  XenBus_Start();
    6.10  NTSTATUS
    6.11  XenBus_Stop();
     7.1 --- a/xenvbd/xenvbd.c	Sun Dec 02 23:13:20 2007 +1100
     7.2 +++ b/xenvbd/xenvbd.c	Wed Dec 05 19:56:11 2007 +1100
     7.3 @@ -49,14 +49,6 @@ static NTSTATUS
     7.4  XenVbd_Child_PreprocessWdmIrpDEVICE_CONTROL(WDFDEVICE Device, PIRP Irp);
     7.5  static NTSTATUS
     7.6  XenVbd_Child_PreprocessWdmIrpSomethingSomething(WDFDEVICE Device, PIRP Irp);
     7.7 -static VOID 
     7.8 -XenVbd_Child_IoDefault(WDFQUEUE Queue, WDFREQUEST Request);
     7.9 -static VOID 
    7.10 -XenVbd_Child_IoReadWrite(WDFQUEUE Queue, WDFREQUEST Request, size_t Length);
    7.11 -static VOID 
    7.12 -XenVbd_Child_IoDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode);
    7.13 -static VOID 
    7.14 -XenVbd_Child_IoInternalDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode);
    7.15  
    7.16  static VOID
    7.17  XenVbd_HotPlugHandler(char *Path, PVOID Data);
    7.18 @@ -404,7 +396,7 @@ XenVbd_D0Exit(
    7.19  static NTSTATUS
    7.20  XenVbd_DeviceUsageNotification(WDFDEVICE Device, WDF_SPECIAL_FILE_TYPE NotificationType, BOOLEAN IsInNotificationPath)
    7.21  {
    7.22 -  KdPrint((__DRIVER_NAME " --> DeviceUsageNotification\n"));
    7.23 +//  KdPrint((__DRIVER_NAME " --> DeviceUsageNotification\n"));
    7.24  
    7.25    switch (NotificationType)
    7.26    {
    7.27 @@ -421,7 +413,7 @@ XenVbd_DeviceUsageNotification(WDFDEVICE
    7.28      KdPrint((__DRIVER_NAME "     NotificationType = %d, Using = %d\n", NotificationType, IsInNotificationPath));
    7.29      break;
    7.30    }
    7.31 -  KdPrint((__DRIVER_NAME " <-- DeviceUsageNotification\n"));
    7.32 +//  KdPrint((__DRIVER_NAME " <-- DeviceUsageNotification\n"));
    7.33  
    7.34    return TRUE;
    7.35  }
    7.36 @@ -780,7 +772,7 @@ XenVbd_BackEndStateHandler(char *Path, P
    7.37  
    7.38      KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    7.39      InterlockedIncrement(&EnumeratedDevices);
    7.40 -    KdPrint((__DRIVER_NAME "     Added a disk, notifying\n"));
    7.41 +    KdPrint((__DRIVER_NAME "     Added a device, notifying\n"));
    7.42      
    7.43      KeSetEvent(&WaitDevicesEvent, 1, FALSE);
    7.44  
    7.45 @@ -949,17 +941,15 @@ XenVbd_ChildListCreateDevice(WDFCHILDLIS
    7.46    
    7.47    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&PdoAttributes, PXENVBD_CHILD_DEVICE_DATA);
    7.48  
    7.49 -  //WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSCSI, IRP_MJ_SCSI, ScsiMinors, 1);
    7.50    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSCSI, IRP_MJ_SCSI, NULL, 0);
    7.51    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpDEVICE_CONTROL, IRP_MJ_DEVICE_CONTROL, NULL, 0);
    7.52 -
    7.53 +/*
    7.54    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_CLEANUP, NULL, 0);
    7.55    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_CLOSE, NULL, 0);
    7.56    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_CREATE, NULL, 0);
    7.57    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_DIRECTORY_CONTROL, NULL, 0);
    7.58    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_FILE_SYSTEM_CONTROL, NULL, 0);
    7.59    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_FLUSH_BUFFERS, NULL, 0);
    7.60 -///  WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_INTERNAL_DEVICE_CONTROL, NULL, 0);
    7.61    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_LOCK_CONTROL, NULL, 0);
    7.62    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_POWER, NULL, 0);
    7.63    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_QUERY_EA, NULL, 0);
    7.64 @@ -973,7 +963,7 @@ XenVbd_ChildListCreateDevice(WDFCHILDLIS
    7.65    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_SHUTDOWN, NULL, 0);
    7.66    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_SYSTEM_CONTROL, NULL, 0);
    7.67    WdfDeviceInitAssignWdmIrpPreprocessCallback(ChildInit, XenVbd_Child_PreprocessWdmIrpSomethingSomething, IRP_MJ_WRITE, NULL, 0);
    7.68 -
    7.69 +*/
    7.70    WdfDeviceInitSetIoType(ChildInit, WdfDeviceIoDirect);
    7.71  
    7.72    //WdfDeviceInitSetPowerNotPageable(ChildInit);
    7.73 @@ -1010,21 +1000,6 @@ XenVbd_ChildListCreateDevice(WDFCHILDLIS
    7.74    ChildDeviceData->IrpRemovedFromRing = 0;
    7.75    ChildDeviceData->IrpCompleted = 0;
    7.76  
    7.77 -  WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&IoQueueConfig, WdfIoQueueDispatchSequential);
    7.78 -  IoQueueConfig.AllowZeroLengthRequests = TRUE;
    7.79 -  //IoQueueConfig.EvtIoDefault = XenVbd_Child_IoDefault;
    7.80 -  //IoQueueConfig.EvtIoRead = XenVbd_Child_IoReadWrite;
    7.81 -  //IoQueueConfig.EvtIoWrite = XenVbd_Child_IoReadWrite;
    7.82 -  IoQueueConfig.EvtIoDeviceControl = XenVbd_Child_IoDeviceControl;
    7.83 -  //IoQueueConfig.EvtIoInternalDeviceControl = XenVbd_Child_IoInternalDeviceControl; // is IRP_MJ_SCSI
    7.84 -
    7.85 -  status = WdfIoQueueCreate(ChildDevice, &IoQueueConfig, WDF_NO_OBJECT_ATTRIBUTES, &ChildDeviceData->IoDefaultQueue);
    7.86 -  if(!NT_SUCCESS(status))
    7.87 -  {
    7.88 -    KdPrint((__DRIVER_NAME "WdfIoQueueCreate failed with status 0x%08x\n", status));
    7.89 -    return status;
    7.90 -  }
    7.91 -
    7.92    ChildDeviceData->Device = ChildDevice;
    7.93    
    7.94    KeInitializeSpinLock(&ChildDeviceData->Lock);
    7.95 @@ -1069,7 +1044,7 @@ XenVbd_PutIrpOnRing(WDFDEVICE Device, PI
    7.96    ChildDeviceData = *GetChildDeviceData(Device);
    7.97  
    7.98  //  if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
    7.99 -    KdPrint((__DRIVER_NAME " --> PutIrpOnRing\n"));
   7.100 +//    KdPrint((__DRIVER_NAME " --> PutIrpOnRing\n"));
   7.101  
   7.102    if (RING_FULL(&ChildDeviceData->Ring))
   7.103    {
   7.104 @@ -1146,7 +1121,7 @@ XenVbd_PutIrpOnRing(WDFDEVICE Device, PI
   7.105    ChildDeviceData->IrpAddedToRing++;
   7.106  
   7.107  //  if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.108 -    KdPrint((__DRIVER_NAME " <-- PutIrpOnRing\n"));
   7.109 +//    KdPrint((__DRIVER_NAME " <-- PutIrpOnRing\n"));
   7.110  }
   7.111  
   7.112  static ULONG
   7.113 @@ -1191,9 +1166,19 @@ XenVbd_Child_PreprocessWdmIrpDEVICE_CONT
   7.114    NTSTATUS Status;
   7.115    PIO_STACK_LOCATION IrpStack;
   7.116    PSCSI_ADDRESS ScsiAddress;
   7.117 +  PXENVBD_CHILD_DEVICE_DATA ChildDeviceData;  
   7.118 +  PSTORAGE_PROPERTY_QUERY Spq;
   7.119 +  PSTORAGE_ADAPTER_DESCRIPTOR Sad;
   7.120 +  PSTORAGE_DEVICE_DESCRIPTOR Sdd;
   7.121 +  PSTORAGE_DEVICE_ID_DESCRIPTOR Sdid;
   7.122 +  PSTORAGE_IDENTIFIER Si;
   7.123 +//  ULONG Information;
   7.124 +  int StructEndOffset;
   7.125  
   7.126    KdPrint((__DRIVER_NAME " --> PreprocessWdmIrpDEVICE_CONTROL\n"));
   7.127  
   7.128 +  ChildDeviceData = *GetChildDeviceData(Device);
   7.129 +
   7.130    IrpStack = IoGetCurrentIrpStackLocation(Irp);
   7.131  
   7.132    switch (IrpStack->Parameters.DeviceIoControl.IoControlCode)
   7.133 @@ -1217,11 +1202,189 @@ XenVbd_Child_PreprocessWdmIrpDEVICE_CONT
   7.134      {
   7.135        KdPrint((__DRIVER_NAME "     (Buffer size too small @ %d\n", IrpStack->Parameters.DeviceIoControl.OutputBufferLength));    
   7.136      }
   7.137 -    break;  
   7.138 +    break;
   7.139 +  case IOCTL_STORAGE_QUERY_PROPERTY:
   7.140 +    KdPrint((__DRIVER_NAME "     IOCTL_STORAGE_QUERY_PROPERTY\n"));    
   7.141 +    Spq = (PSTORAGE_PROPERTY_QUERY)Irp->AssociatedIrp.SystemBuffer;
   7.142 +    if (Spq->PropertyId == StorageAdapterProperty && Spq->QueryType == PropertyStandardQuery)
   7.143 +    {
   7.144 +      KdPrint((__DRIVER_NAME "     PropertyId = StorageAdapterProperty, QueryType = PropertyStandardQuery\n"));
   7.145 +      Irp->IoStatus.Information = 0;
   7.146 +      if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength >= 8)
   7.147 +      {
   7.148 +        Irp->IoStatus.Information = 8;
   7.149 +        Sad = (PSTORAGE_ADAPTER_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
   7.150 +        Sad->Version = 1;
   7.151 +        Sad->Size = sizeof(STORAGE_ADAPTER_DESCRIPTOR);
   7.152 +        if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength >= Sad->Size)
   7.153 +        {
   7.154 +          Irp->IoStatus.Information = Sad->Size;
   7.155 +          Sad->MaximumTransferLength = 45056;
   7.156 +          Sad->MaximumPhysicalPages = 11;
   7.157 +          Sad->AlignmentMask = 0;
   7.158 +          Sad->AdapterUsesPio = FALSE;
   7.159 +          Sad->AdapterScansDown = FALSE;
   7.160 +          Sad->CommandQueueing = FALSE;
   7.161 +          Sad->AcceleratedTransfer = FALSE;
   7.162 +          Sad->BusType = BusTypeScsi;
   7.163 +          Sad->BusMajorVersion = 0;
   7.164 +          Sad->BusMinorVersion = 0;
   7.165 +        }
   7.166 +      }
   7.167 +      Status = STATUS_SUCCESS;
   7.168 +      Irp->IoStatus.Status = Status;
   7.169 +      IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.170 +    }
   7.171 +    else if (Spq->PropertyId == StorageDeviceProperty && Spq->QueryType == PropertyStandardQuery)
   7.172 +    {
   7.173 +      KdPrint((__DRIVER_NAME "     PropertyId = StorageDeviceProperty, QueryType = PropertyStandardQuery\n"));
   7.174 +      Irp->IoStatus.Information = 0;
   7.175 +      if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength >= 8)
   7.176 +      {
   7.177 +        Irp->IoStatus.Information = 8;
   7.178 +        Sdd = (PSTORAGE_DEVICE_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
   7.179 +        Sdd->Version = 1;
   7.180 +        Sdd->Size = &Sdd->RawDeviceProperties[36] - (PUCHAR)Sdd + 1;
   7.181 +        // 0       0        1         2       3
   7.182 +        // 0       7        5         4       1
   7.183 +        //"VENDOR\0PRODUCT\0Revision\0Serial\0"
   7.184 +        if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength >= Sdd->Size)
   7.185 +        {
   7.186 +          Irp->IoStatus.Information = Sdd->Size;
   7.187 +          switch (ChildDeviceData->DeviceType)
   7.188 +          { 
   7.189 +          case XENVBD_DEVICETYPE_DISK:
   7.190 +            Sdd->DeviceType = DIRECT_ACCESS_DEVICE;
   7.191 +            Sdd->DeviceTypeModifier = 0x00;
   7.192 +            Sdd->RemovableMedia = FALSE;
   7.193 +            break;
   7.194 +          case XENVBD_DEVICETYPE_CDROM:
   7.195 +            Sdd->DeviceType = READ_ONLY_DIRECT_ACCESS_DEVICE;
   7.196 +            Sdd->DeviceTypeModifier = 0x00;
   7.197 +            Sdd->RemovableMedia = TRUE;
   7.198 +            break;
   7.199 +          default:
   7.200 +            // wtf
   7.201 +            break;
   7.202 +          }
   7.203 +          Sdd->CommandQueueing = FALSE;
   7.204 +          StructEndOffset = Sdd->RawDeviceProperties - (PUCHAR)Sdd;
   7.205 +          Sdd->VendorIdOffset = StructEndOffset + 0;
   7.206 +          Sdd->ProductIdOffset = StructEndOffset + 7;
   7.207 +          Sdd->ProductRevisionOffset = StructEndOffset + 15;
   7.208 +          Sdd->SerialNumberOffset = StructEndOffset + 24;
   7.209 +          Sdd->BusType = BusTypeScsi;
   7.210 +          Sdd->RawPropertiesLength = 36;
   7.211 +          memcpy(Sdd->RawDeviceProperties, "VENDOR\0PRODUCT\0Revision\0Serial99999\0", 36);
   7.212 +        }
   7.213 +      }
   7.214 +      Status = STATUS_SUCCESS;
   7.215 +      Irp->IoStatus.Status = Status;
   7.216 +      IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.217 +    }
   7.218 +    else if (Spq->PropertyId == StorageDeviceIdProperty && Spq->QueryType == PropertyStandardQuery)
   7.219 +    {
   7.220 +      KdPrint((__DRIVER_NAME "     PropertyId = StorageDeviceIdProperty, QueryType = PropertyStandardQuery\n"));
   7.221 +      Irp->IoStatus.Information = 0;
   7.222 +      if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength >= 8)
   7.223 +      {
   7.224 +        Irp->IoStatus.Information = 8;
   7.225 +        Sdid = (PSTORAGE_DEVICE_ID_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
   7.226 +        Sdid->Version = 1;
   7.227 +        Si = (PSTORAGE_IDENTIFIER)Sdid->Identifiers;
   7.228 +        Sdid->Size = &Si->Identifier[8] - (PUCHAR)Sdid + 1;
   7.229 +        if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength >= Sdid->Size)
   7.230 +        {
   7.231 +          Irp->IoStatus.Information = Sdid->Size;
   7.232 +          Sdid->NumberOfIdentifiers = 1;
   7.233 +          Si->CodeSet = StorageIdCodeSetAscii;
   7.234 +          Si->Type = StorageIdTypeScsiNameString;
   7.235 +          //Si->CodeSet = StorageIdCodeSetBinary;
   7.236 +          //Si->Type = StorageIdTypeEUI64;
   7.237 +          Si->IdentifierSize = 9;
   7.238 +          Si->NextOffset = 0;
   7.239 +          Si->Association = StorageIdAssocPort;
   7.240 +          Si->Identifier[0] = 'S';
   7.241 +          Si->Identifier[1] = 'e';
   7.242 +          Si->Identifier[2] = 'r';
   7.243 +          Si->Identifier[3] = 'i';
   7.244 +          Si->Identifier[4] = 'a';
   7.245 +          Si->Identifier[5] = 'l';
   7.246 +          Si->Identifier[6] = '9';
   7.247 +          Si->Identifier[7] = '9';
   7.248 +          Si->Identifier[6] = '9';
   7.249 +          Si->Identifier[7] = '9';
   7.250 +          Si->Identifier[8] = '9';
   7.251 +          //Si->Identifier[8] = 0;
   7.252 +        }
   7.253 +      }
   7.254 +      Status = STATUS_SUCCESS;
   7.255 +      Irp->IoStatus.Status = Status;
   7.256 +      IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.257 +    }
   7.258 +    else
   7.259 +    {
   7.260 +      switch (Spq->PropertyId)
   7.261 +      {
   7.262 +      case StorageDeviceProperty:
   7.263 +        KdPrint((__DRIVER_NAME "     StorageDeviceProperty\n"));
   7.264 +        break;        
   7.265 +      case StorageAccessAlignmentProperty:
   7.266 +        KdPrint((__DRIVER_NAME "     StorageAccessAlignmentProperty\n"));
   7.267 +        break;
   7.268 +      case StorageAdapterProperty:
   7.269 +        KdPrint((__DRIVER_NAME "     StorageAdapterProperty\n"));
   7.270 +        break;
   7.271 +      case StorageDeviceIdProperty:
   7.272 +        KdPrint((__DRIVER_NAME "     StorageDeviceIdProperty\n"));
   7.273 +        break;
   7.274 +      case StorageDeviceUniqueIdProperty:
   7.275 +        KdPrint((__DRIVER_NAME "     StorageDeviceUniqueIdProperty\n"));
   7.276 +        break;
   7.277 +      case StorageDeviceWriteCacheProperty:
   7.278 +        KdPrint((__DRIVER_NAME "     StorageDeviceWriteCacheProperty\n"));
   7.279 +        break;
   7.280 +      default:
   7.281 +        KdPrint((__DRIVER_NAME "     Unknown Property %08x\n", Spq->PropertyId));
   7.282 +        break;
   7.283 +      }
   7.284 +      switch (Spq->QueryType)
   7.285 +      {
   7.286 +      case PropertyStandardQuery:
   7.287 +        KdPrint((__DRIVER_NAME "     PropertyStandardQuery\n"));
   7.288 +        break;        
   7.289 +      case PropertyExistsQuery:
   7.290 +        KdPrint((__DRIVER_NAME "     PropertyExistsQuery\n"));
   7.291 +        break;        
   7.292 +      default:
   7.293 +        KdPrint((__DRIVER_NAME "     Unknown Query %08x\n", Spq->QueryType));
   7.294 +        break;
   7.295 +      }
   7.296 +      Status = STATUS_NOT_IMPLEMENTED;
   7.297 +      Irp->IoStatus.Status = Status;
   7.298 +      IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.299 +    }
   7.300 +    break;
   7.301 +  // http://www.osronline.com/article.cfm?article=229
   7.302 +  // 0x00560030 device = 0x56, Function = 0x00c = 
   7.303 +  case IOCTL_DISK_GET_DRIVE_GEOMETRY:
   7.304 +    KdPrint((__DRIVER_NAME "     IOCTL_DISK_GET_DRIVE_GEOMETRY\n"));
   7.305 +    memcpy(Irp->AssociatedIrp.SystemBuffer, &ChildDeviceData->Geometry, sizeof(DISK_GEOMETRY));
   7.306 +    Status = STATUS_SUCCESS;
   7.307 +    Irp->IoStatus.Status = Status;
   7.308 +    IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.309 +    break;
   7.310 +  case FT_BALANCED_READ_MODE: // just pretend we know what this is...
   7.311 +    KdPrint((__DRIVER_NAME "     FT_BALANCED_READ_MODE\n"));
   7.312 +    Status = STATUS_SUCCESS;
   7.313 +    Irp->IoStatus.Status = Status;
   7.314 +    IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.315 +    break;
   7.316    default:
   7.317      KdPrint((__DRIVER_NAME "     Control Code = %08x\n", IrpStack->Parameters.DeviceIoControl.IoControlCode));
   7.318 -    IoSkipCurrentIrpStackLocation(Irp);
   7.319 -    Status = WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
   7.320 +    Status = STATUS_NOT_IMPLEMENTED;
   7.321 +    Irp->IoStatus.Status = Status;
   7.322 +    IoCompleteRequest(Irp, IO_NO_INCREMENT);      
   7.323    }
   7.324  
   7.325    KdPrint((__DRIVER_NAME " <-- PreprocessWdmIrpDEVICE_CONTROL\n"));
   7.326 @@ -1267,7 +1430,7 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.327    ChildDeviceData = *GetChildDeviceData(Device);
   7.328  
   7.329  //  if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.330 -    KdPrint((__DRIVER_NAME " --> WdmIrpPreprocessSCSI\n"));
   7.331 +//    KdPrint((__DRIVER_NAME " --> WdmIrpPreprocessSCSI\n"));
   7.332  
   7.333    //KdPrint((__DRIVER_NAME "     SCSI Minor = %02X\n", irpSp->MinorFunction));
   7.334  
   7.335 @@ -1278,12 +1441,12 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.336    case SRB_FUNCTION_EXECUTE_SCSI:
   7.337      cdb = (PCDB)Srb->Cdb;
   7.338  //    if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.339 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_EXECUTE_SCSI\n"));
   7.340 +//      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_EXECUTE_SCSI\n"));
   7.341      switch(cdb->CDB6GENERIC.OperationCode) //Srb->Cdb[0])
   7.342      {
   7.343      case SCSIOP_TEST_UNIT_READY:
   7.344  //      if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.345 -        KdPrint((__DRIVER_NAME "     Command = TEST_UNIT_READY\n"));
   7.346 +//        KdPrint((__DRIVER_NAME "     Command = TEST_UNIT_READY\n"));
   7.347        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   7.348        Srb->ScsiStatus = 0;
   7.349        status = STATUS_SUCCESS;
   7.350 @@ -1309,7 +1472,7 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.351        }
   7.352        else
   7.353        {
   7.354 -        //KdPrint((__DRIVER_NAME "     Command = INQUIRY (LUN = %d, EVPD = %d, Page Code = %02X)\n", Srb->Cdb[1] >> 5, Srb->Cdb[1] & 1, Srb->Cdb[2]));
   7.355 +        KdPrint((__DRIVER_NAME "     Command = INQUIRY (LUN = %d, EVPD = %d, Page Code = %02X)\n", Srb->Cdb[1] >> 5, Srb->Cdb[1] & 1, Srb->Cdb[2]));
   7.356          Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   7.357        }
   7.358        Srb->ScsiStatus = 0;
   7.359 @@ -1320,7 +1483,7 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.360        break;
   7.361      case SCSIOP_READ_CAPACITY:
   7.362  //      if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.363 -        KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
   7.364 +//        KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
   7.365  //      DataBuffer = Srb->DataBuffer;
   7.366        DataBuffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, HighPagePriority);
   7.367        DataBuffer[0] = (unsigned char)(ChildDeviceData->TotalSectors >> 24) & 0xff;
   7.368 @@ -1371,8 +1534,8 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.369        break;
   7.370      case SCSIOP_READ:
   7.371      case SCSIOP_WRITE:
   7.372 -      if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.373 -        KdPrint((__DRIVER_NAME "     Command = READ/WRITE\n"));
   7.374 +//      if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.375 +//        KdPrint((__DRIVER_NAME "     Command = READ/WRITE\n"));
   7.376  
   7.377        IoMarkIrpPending(Irp);
   7.378  
   7.379 @@ -1474,8 +1637,8 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.380      break;
   7.381    case SRB_FUNCTION_CLAIM_DEVICE:
   7.382  //    if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.383 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_CLAIM_DEVICE\n"));
   7.384 -//    ObReferenceObject(WdfDeviceWdmGetDeviceObject(Device));
   7.385 +//      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_CLAIM_DEVICE\n"));
   7.386 +    ObReferenceObject(WdfDeviceWdmGetDeviceObject(Device));
   7.387      Srb->DataBuffer = WdfDeviceWdmGetDeviceObject(Device);
   7.388  //    Srb->DataBuffer = WdfDeviceWdmGetAttachedDevice(Device);
   7.389      Srb->SrbStatus = SRB_STATUS_SUCCESS;
   7.390 @@ -1486,7 +1649,7 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.391      break;
   7.392    case SRB_FUNCTION_IO_CONTROL:
   7.393  //    if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.394 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
   7.395 +//      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
   7.396      //status = WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
   7.397      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   7.398      status = STATUS_NOT_IMPLEMENTED;
   7.399 @@ -1496,7 +1659,7 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.400      break;
   7.401    case SRB_FUNCTION_FLUSH:
   7.402  //    if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.403 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   7.404 +//      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   7.405      Srb->SrbStatus = SRB_STATUS_SUCCESS;
   7.406      status = STATUS_SUCCESS;
   7.407      Irp->IoStatus.Status = status;
   7.408 @@ -1510,258 +1673,8 @@ XenVbd_Child_PreprocessWdmIrpSCSI(WDFDEV
   7.409    }
   7.410  
   7.411  //  if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.412 -    KdPrint((__DRIVER_NAME " <-- WdmIrpPreprocessSCSI (AddedToList = %d, RemovedFromList = %d, AddedToRing = %d, AddedToRingAtLastNotify = %d, AddedToRingAtLastInterrupt = %d, RemovedFromRing = %d)\n", ChildDeviceData->IrpAddedToList, ChildDeviceData->IrpRemovedFromList, ChildDeviceData->IrpAddedToRing, ChildDeviceData->IrpAddedToRingAtLastNotify, ChildDeviceData->IrpAddedToRingAtLastInterrupt, ChildDeviceData->IrpCompleted));
   7.413 +//    KdPrint((__DRIVER_NAME " <-- WdmIrpPreprocessSCSI (AddedToList = %d, RemovedFromList = %d, AddedToRing = %d, AddedToRingAtLastNotify = %d, AddedToRingAtLastInterrupt = %d, RemovedFromRing = %d)\n", ChildDeviceData->IrpAddedToList, ChildDeviceData->IrpRemovedFromList, ChildDeviceData->IrpAddedToRing, ChildDeviceData->IrpAddedToRingAtLastNotify, ChildDeviceData->IrpAddedToRingAtLastInterrupt, ChildDeviceData->IrpCompleted));
   7.414    //KdPrint((__DRIVER_NAME " <-- WdmIrpPreprocessSCSI\n"));
   7.415  
   7.416    return status;
   7.417  }
   7.418 -
   7.419 -static VOID 
   7.420 -XenVbd_Child_IoDefault(WDFQUEUE  Queue, WDFREQUEST  Request)
   7.421 -{
   7.422 -  UNREFERENCED_PARAMETER(Queue);
   7.423 -
   7.424 -  KdPrint((__DRIVER_NAME " --> EvtDeviceIoDefault\n"));
   7.425 -
   7.426 -  WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
   7.427 -
   7.428 -  KdPrint((__DRIVER_NAME " <-- EvtDeviceIoDefault\n"));
   7.429 -}
   7.430 -
   7.431 -static VOID 
   7.432 -XenVbd_Child_IoReadWrite(WDFQUEUE Queue, WDFREQUEST Request, size_t Length)
   7.433 -{
   7.434 -  UNREFERENCED_PARAMETER(Queue);
   7.435 -
   7.436 -  KdPrint((__DRIVER_NAME " --> IoReadWrite\n"));
   7.437 -
   7.438 -  WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
   7.439 -
   7.440 -  KdPrint((__DRIVER_NAME " <-- IoReadWrite\n"));
   7.441 -}
   7.442 -
   7.443 -static VOID 
   7.444 -XenVbd_Child_IoDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode)
   7.445 -{
   7.446 -  WDFDEVICE Device;
   7.447 -  PXENVBD_CHILD_DEVICE_DATA ChildDeviceData;  
   7.448 -  PIRP Irp;
   7.449 -  PSTORAGE_PROPERTY_QUERY Spq;
   7.450 -  PSTORAGE_ADAPTER_DESCRIPTOR Sad;
   7.451 -  PSTORAGE_DEVICE_DESCRIPTOR Sdd;
   7.452 -  PSTORAGE_DEVICE_ID_DESCRIPTOR Sdid;
   7.453 -  PSTORAGE_IDENTIFIER Si;
   7.454 -  PSCSI_ADDRESS Sa;
   7.455 -  ULONG Information;
   7.456 -  //NTSTATUS Status;
   7.457 -  int StructEndOffset;
   7.458 -
   7.459 -  UNREFERENCED_PARAMETER(Queue);
   7.460 -  //UNREFERENCED_PARAMETER(Request);
   7.461 -  UNREFERENCED_PARAMETER(OutputBufferLength);
   7.462 -  UNREFERENCED_PARAMETER(InputBufferLength);
   7.463 -
   7.464 -  Device = WdfIoQueueGetDevice(Queue);
   7.465 -
   7.466 -  ChildDeviceData = *GetChildDeviceData(Device);
   7.467 -
   7.468 -//  if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.469 -    KdPrint((__DRIVER_NAME " --> IoDeviceControl\n"));
   7.470 -  //KdPrint((__DRIVER_NAME "     InputBufferLength = %d\n", InputBufferLength));
   7.471 -  //KdPrint((__DRIVER_NAME "     OutputBufferLength = %d\n", OutputBufferLength));
   7.472 -
   7.473 -  Irp = WdfRequestWdmGetIrp(Request);
   7.474 -
   7.475 -  switch (IoControlCode)
   7.476 -  {
   7.477 -  case IOCTL_STORAGE_QUERY_PROPERTY:
   7.478 -    KdPrint((__DRIVER_NAME "     IOCTL_STORAGE_QUERY_PROPERTY\n"));    
   7.479 -    Spq = (PSTORAGE_PROPERTY_QUERY)Irp->AssociatedIrp.SystemBuffer;
   7.480 -    if (Spq->PropertyId == StorageAdapterProperty && Spq->QueryType == PropertyStandardQuery)
   7.481 -    {
   7.482 -      KdPrint((__DRIVER_NAME "     PropertyId = StorageAdapterProperty, QueryType = PropertyStandardQuery\n"));
   7.483 -      Information = 0;
   7.484 -      if (OutputBufferLength >= 8)
   7.485 -      {
   7.486 -        Information = 8;
   7.487 -        Sad = (PSTORAGE_ADAPTER_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
   7.488 -        Sad->Version = 1;
   7.489 -        Sad->Size = sizeof(STORAGE_ADAPTER_DESCRIPTOR);
   7.490 -        if (OutputBufferLength >= Sad->Size)
   7.491 -        {
   7.492 -          Information = Sad->Size;
   7.493 -          Sad->MaximumTransferLength = 45056;
   7.494 -          Sad->MaximumPhysicalPages = 11;
   7.495 -          Sad->AlignmentMask = 0;
   7.496 -          Sad->AdapterUsesPio = FALSE;
   7.497 -          Sad->AdapterScansDown = FALSE;
   7.498 -          Sad->CommandQueueing = FALSE;
   7.499 -          Sad->AcceleratedTransfer = FALSE;
   7.500 -          Sad->BusType = BusTypeScsi;
   7.501 -          Sad->BusMajorVersion = 0;
   7.502 -          Sad->BusMinorVersion = 0;
   7.503 -        }
   7.504 -      }
   7.505 -      WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Information);
   7.506 -    }
   7.507 -    else if (Spq->PropertyId == StorageDeviceProperty && Spq->QueryType == PropertyStandardQuery)
   7.508 -    {
   7.509 -      KdPrint((__DRIVER_NAME "     PropertyId = StorageDeviceProperty, QueryType = PropertyStandardQuery\n"));
   7.510 -      Information = 0;
   7.511 -      if (OutputBufferLength >= 8)
   7.512 -      {
   7.513 -        Information = 8;
   7.514 -        Sdd = (PSTORAGE_DEVICE_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
   7.515 -        Sdd->Version = 1;
   7.516 -        Sdd->Size = &Sdd->RawDeviceProperties[36] - (PUCHAR)Sdd + 1;
   7.517 -        // 0       0        1         2       3
   7.518 -        // 0       7        5         4       1
   7.519 -        //"VENDOR\0PRODUCT\0Revision\0Serial\0"
   7.520 -        if (OutputBufferLength >= Sdd->Size)
   7.521 -        {
   7.522 -          Information = Sdd->Size;
   7.523 -          switch (ChildDeviceData->DeviceType)
   7.524 -          { 
   7.525 -          case XENVBD_DEVICETYPE_DISK:
   7.526 -            Sdd->DeviceType = DIRECT_ACCESS_DEVICE;
   7.527 -            Sdd->DeviceTypeModifier = 0x00;
   7.528 -            Sdd->RemovableMedia = FALSE;
   7.529 -            break;
   7.530 -          case XENVBD_DEVICETYPE_CDROM:
   7.531 -            Sdd->DeviceType = READ_ONLY_DIRECT_ACCESS_DEVICE;
   7.532 -            Sdd->DeviceTypeModifier = 0x00;
   7.533 -            Sdd->RemovableMedia = TRUE;
   7.534 -            break;
   7.535 -          default:
   7.536 -            // wtf
   7.537 -            break;
   7.538 -          }
   7.539 -          Sdd->CommandQueueing = FALSE;
   7.540 -          StructEndOffset = Sdd->RawDeviceProperties - (PUCHAR)Sdd;
   7.541 -          Sdd->VendorIdOffset = StructEndOffset + 0;
   7.542 -          Sdd->ProductIdOffset = StructEndOffset + 7;
   7.543 -          Sdd->ProductRevisionOffset = StructEndOffset + 15;
   7.544 -          Sdd->SerialNumberOffset = StructEndOffset + 24;
   7.545 -          Sdd->BusType = BusTypeScsi;
   7.546 -          Sdd->RawPropertiesLength = 36;
   7.547 -          memcpy(Sdd->RawDeviceProperties, "VENDOR\0PRODUCT\0Revision\0Serial99999\0", 36);
   7.548 -        }
   7.549 -      }
   7.550 -      WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Information);
   7.551 -    }
   7.552 -    else if (Spq->PropertyId == StorageDeviceIdProperty && Spq->QueryType == PropertyStandardQuery)
   7.553 -    {
   7.554 -      KdPrint((__DRIVER_NAME "     PropertyId = StorageDeviceIdProperty, QueryType = PropertyStandardQuery\n"));
   7.555 -      Information = 0;
   7.556 -      if (OutputBufferLength >= 8)
   7.557 -      {
   7.558 -        Information = 8;
   7.559 -        Sdid = (PSTORAGE_DEVICE_ID_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
   7.560 -        Sdid->Version = 1;
   7.561 -        Si = (PSTORAGE_IDENTIFIER)Sdid->Identifiers;
   7.562 -        Sdid->Size = &Si->Identifier[8] - (PUCHAR)Sdid + 1;
   7.563 -        if (OutputBufferLength >= Sdid->Size)
   7.564 -        {
   7.565 -          Information = Sdid->Size;
   7.566 -          Sdid->NumberOfIdentifiers = 1;
   7.567 -          Si->CodeSet = StorageIdCodeSetAscii;
   7.568 -          Si->Type = StorageIdTypeScsiNameString;
   7.569 -          //Si->CodeSet = StorageIdCodeSetBinary;
   7.570 -          //Si->Type = StorageIdTypeEUI64;
   7.571 -          Si->IdentifierSize = 9;
   7.572 -          Si->NextOffset = 0;
   7.573 -          Si->Association = StorageIdAssocPort;
   7.574 -          Si->Identifier[0] = 'S';
   7.575 -          Si->Identifier[1] = 'e';
   7.576 -          Si->Identifier[2] = 'r';
   7.577 -          Si->Identifier[3] = 'i';
   7.578 -          Si->Identifier[4] = 'a';
   7.579 -          Si->Identifier[5] = 'l';
   7.580 -          Si->Identifier[6] = '9';
   7.581 -          Si->Identifier[7] = '9';
   7.582 -          Si->Identifier[6] = '9';
   7.583 -          Si->Identifier[7] = '9';
   7.584 -          Si->Identifier[8] = '9';
   7.585 -          //Si->Identifier[8] = 0;
   7.586 -        }
   7.587 -      }
   7.588 -      WdfRequestCompleteWithInformation(Request, STATUS_SUCCESS, Information);
   7.589 -    }
   7.590 -    else
   7.591 -    {
   7.592 -      switch (Spq->PropertyId)
   7.593 -      {
   7.594 -      case StorageDeviceProperty:
   7.595 -        KdPrint((__DRIVER_NAME "     StorageDeviceProperty\n"));
   7.596 -        break;        
   7.597 -      case StorageAccessAlignmentProperty:
   7.598 -        KdPrint((__DRIVER_NAME "     StorageAccessAlignmentProperty\n"));
   7.599 -        break;
   7.600 -      case StorageAdapterProperty:
   7.601 -        KdPrint((__DRIVER_NAME "     StorageAdapterProperty\n"));
   7.602 -        break;
   7.603 -      case StorageDeviceIdProperty:
   7.604 -        KdPrint((__DRIVER_NAME "     StorageDeviceIdProperty\n"));
   7.605 -        break;
   7.606 -      case StorageDeviceUniqueIdProperty:
   7.607 -        KdPrint((__DRIVER_NAME "     StorageDeviceUniqueIdProperty\n"));
   7.608 -        break;
   7.609 -      case StorageDeviceWriteCacheProperty:
   7.610 -        KdPrint((__DRIVER_NAME "     StorageDeviceWriteCacheProperty\n"));
   7.611 -        break;
   7.612 -      default:
   7.613 -        KdPrint((__DRIVER_NAME "     Unknown Property %08x\n", Spq->PropertyId));
   7.614 -        break;
   7.615 -      }
   7.616 -      switch (Spq->QueryType)
   7.617 -      {
   7.618 -      case PropertyStandardQuery:
   7.619 -        KdPrint((__DRIVER_NAME "     PropertyStandardQuery\n"));
   7.620 -        break;        
   7.621 -      case PropertyExistsQuery:
   7.622 -        KdPrint((__DRIVER_NAME "     PropertyExistsQuery\n"));
   7.623 -        break;        
   7.624 -      default:
   7.625 -        KdPrint((__DRIVER_NAME "     Unknown Query %08x\n", Spq->QueryType));
   7.626 -        break;
   7.627 -      }
   7.628 -      WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
   7.629 -    }
   7.630 -    break;
   7.631 -  // http://www.osronline.com/article.cfm?article=229
   7.632 -  // 0x00560030 device = 0x56, Function = 0x00c = 
   7.633 -  case IOCTL_DISK_GET_DRIVE_GEOMETRY:
   7.634 -    KdPrint((__DRIVER_NAME "     IOCTL_DISK_GET_DRIVE_GEOMETRY\n"));
   7.635 -    memcpy(Irp->AssociatedIrp.SystemBuffer, &ChildDeviceData->Geometry, sizeof(DISK_GEOMETRY));
   7.636 -    WdfRequestComplete(Request, STATUS_SUCCESS);
   7.637 -    break;
   7.638 -  case IOCTL_SCSI_GET_ADDRESS:
   7.639 -    KdPrint((__DRIVER_NAME "     IOCTL_SCSI_GET_ADDRESS\n"));
   7.640 -    Sa = (PSCSI_ADDRESS)Irp->AssociatedIrp.SystemBuffer;
   7.641 -    Sa->Length = sizeof(SCSI_ADDRESS);
   7.642 -    Sa->PortNumber = 0;
   7.643 -    Sa->PathId = 0;
   7.644 -    Sa->TargetId = 0;
   7.645 -    Sa->Lun = 0;
   7.646 -    WdfRequestComplete(Request, STATUS_SUCCESS);
   7.647 -    break;
   7.648 -  case FT_BALANCED_READ_MODE: // just pretend we know what this is...
   7.649 -    KdPrint((__DRIVER_NAME "     FT_BALANCED_READ_MODE\n"));
   7.650 -    WdfRequestComplete(Request, STATUS_SUCCESS);
   7.651 -    break;
   7.652 -  default:
   7.653 -    KdPrint((__DRIVER_NAME "     Not Implemented IoControlCode=%08X\n", IoControlCode));
   7.654 -    WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
   7.655 -    break;
   7.656 -  }
   7.657 -
   7.658 -//  if (ChildDeviceData->DeviceType == XENVBD_DEVICETYPE_CDROM)
   7.659 -    KdPrint((__DRIVER_NAME " <-- IoDeviceControl\n"));
   7.660 -}
   7.661 -
   7.662 -static VOID 
   7.663 -XenVbd_Child_IoInternalDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode)
   7.664 -{
   7.665 -  KdPrint((__DRIVER_NAME " --> IoInternalDeviceControl\n"));
   7.666 -  KdPrint((__DRIVER_NAME " <-- IoInternalDeviceControl\n"));
   7.667 -}