PiIrpQueryRemoveDevice

NTSTATUS __stdcall PiIrpQueryRemoveDevice(DEVICE_OBJECT *TargetDevice, DRIVER_OBJECT **FailingDriver){
  int v4; 
  _DEVICE_OBJECT *v5; 
  int v6; 
  struct _DMA_ADAPTER *v8; 
  DRIVER_OBJECT *CompletionContext; 
  struct _KEVENT Event; 
  int v11; 
  int v12; 
  PADAPTER_OBJECT DmaAdapter[2]; 
  INT64 result[9]; 
  v12 = 0;
  v4 = 0;
  *(_OWORD *)DmaAdapter = 0i64;
  memset(&Event, 0, sizeof(Event));
  memset((INT64)result, 0i64);
  LOWORD(result[0]) = 283;
  if( PnpFindMountableDevice(TargetDevice) )
  {
    v4 = 1;
    PnpLockMountableDevice(TargetDevice);
    v5 = (_DEVICE_OBJECT *)PnpMarkDeviceForRemove((ULONG_PTR)TargetDevice, 1, (ULONG_PTR *)DmaAdapter);
    PnpUnlockMountableDevice(TargetDevice);
  }
  else
  {
    v5 = TargetDevice;
  }
  CompletionContext = 0i64;
  v11 = -1073741823;
  KeInitializeEvent(&Event, SynchronizationEvent, 0);
  v6 = PnpAsynchronousCall(
         v5,
         (PIO_STACK_LOCATION)result,
         (PIO_COMPLETION_ROUTINE)PnpDiagnosticCompletionRoutine,
         &CompletionContext);
  if( v6 == 259 )
  {
    KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
    v6 = v11;
  }
  if( FailingDriver )
    *FailingDriver = CompletionContext;
  if( v4 )
  {
    PnpLockMountableDevice(TargetDevice);
    v8 = DmaAdapter[1];
    if( DmaAdapter[1] )
    {
      IopDecrementDeviceObjectHandleCount((_DEVICE_OBJECT *)DmaAdapter[1]);
      HalPutDmaAdapter(v8);
    }
    PnpUnlockMountableDevice(TargetDevice);
    if( v6 >= 0 )
      return IopInvalidateVolumesForDevice(TargetDevice);
  }
  return v6;
}

Referenced by:

PnpDisableDevice
PnpQueryRemoveLockedDeviceNode