PnpCancelRemoveOnHungDevices

__int64 __fastcall PnpCancelRemoveOnHungDevices(__int64 a1, int a2, char a3, _RELATION_LIST *a4, _QWORD *a5){
  int v8; 
  _RELATION_LIST *RelationList; 
  _DWORD *DeviceNode; 
  int v11; 
  NTSTATUS v12; 
  _DWORD *v13; 
  _QWORD *v14; 
  _DWORD *v15; 
  int v16; 
  int v17; 
  void *v18; 
  int v19; 
  _RELATION_LIST_MARKER Marker; 
  _DEVICE_OBJECT *DeviceObject; 
  void *P[2]; 
  _DEVICE_RELATION_LEVEL RelationLevel; 

  DeviceObject = 0i64;
  RelationLevel = RELATION_LEVEL_REMOVE_EJECT;
  P[0] = 0i64;
  if( (a2 & 0xFFFFFFFB) != 0 )
    __fastfail(5u);
  v8 = PnpCompileDeviceInstancePaths(a2, a4, a3, 1, a5);
  if( v8 >= 0 )
  {
    RelationList = IopAllocateRelationList((PNP_DEVICE_DELETE_TYPE)a2);
    if( RelationList )
    {
      Marker = (_RELATION_LIST_MARKER)2i64;
      while( IopEnumerateRelations(a4, &Marker, &DeviceObject, &RelationLevel, 0i64) )
      {
        if( DeviceObject )
          DeviceNode = DeviceObject->DeviceObjectExtension->DeviceNode;
        else
          DeviceNode = 0i64;
        if( DeviceNode )
        {
          if( (DeviceNode[176] & 2) != 0 )
          {
            IopAddRelationToList((_FILE_OBJECT *)RelationList, (_SHARE_ACCESS *)DeviceObject);
            v8 = v11;
            if( v11 < 0 )
              goto LABEL_35;
          }
        }
      }
      RelationList->Sorted = 1;
      Marker = (_RELATION_LIST_MARKER)1i64;
      while( IopEnumerateRelations(RelationList, &Marker, &DeviceObject, 0i64, 0i64) )
      {
        if( DeviceObject )
          v13 = DeviceObject->DeviceObjectExtension->DeviceNode;
        else
          v13 = 0i64;
        if( v13[75] == 784 )
          PnpDeleteLockedDeviceNode(v13, 1, 0, v12, 0i64, 0i64);
      }
      Marker = (_RELATION_LIST_MARKER)1i64;
      while( IopEnumerateRelations(RelationList, &Marker, &DeviceObject, 0i64, 0i64) )
      {
        if( DeviceObject )
          v15 = DeviceObject->DeviceObjectExtension->DeviceNode;
        else
          v15 = 0i64;
        v16 = v15[75];
        if( v16 != 786 && v16 != 770 && v16 != 769 )
          PnpNotifyTargetDeviceChange(&GUID_TARGET_DEVICE_REMOVE_CANCELLED, DeviceObject, 0i64, v14);
      }
      v17 = PnpCompileDeviceInstancePaths(a2, RelationList, 0, (char)v14, P);
      v18 = P[0];
      v8 = v17;
      if( v17 >= 0 )
      {
        PnpNotifyUserModeDeviceRemoval(
          a1,
          (_WORD *)P[0],
          (__int128 *)&GUID_TARGET_DEVICE_REMOVE_CANCELLED,
          0i64,
          0i64,
          0i64);
        v8 = v19;
      }
      if( v18 )
        ExFreePoolWithTag(v18, 0x4B706E50u);
LABEL_35:
      IopFreeRelationList(RelationList);
    }
    else
    {
      return(unsigned int)-1073741801;
    }
  }
  return(unsigned int)v8;
}

Referenced by:

PiProcessQueryAndCancelRemoval