Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
8.5 KiB

  1. /*CM_Connect_Machine
  2. CM_Get_Device_ID_List_Size_Ex
  3. CM_Get_Child_Ex
  4. CM_Get_Sibling_Ex
  5. CM_Get_Parent_Ex
  6. CM_Get_DevNode_Registry_Property_Ex
  7. CM_Get_Class_Name_Ex
  8. CM_Get_DevNode_Status_Ex
  9. CM_Get_Device_ID_Ex
  10. CM_Request_Device_Eject_Ex
  11. CM_Locate_DevNode_Ex*/
  12. InitDevTreeDlgProc
  13. DEVINST* DeviceInstance
  14. HMACHINE DeviceTree->hMachine
  15. DEVINST DeviceTree->DevInst
  16. GUID DeviceTreeNode->ClassGuid
  17. TCHAR DeviceID[MAX_DEVICE_ID_LEN]
  18. PTSTR DeviceInterface
  19. //
  20. // Get the root devnode.
  21. //
  22. ConfigRet = CM_Locate_DevNode_Ex(&DeviceTree->DevInst,
  23. NULL,
  24. CM_LOCATE_DEVNODE_NORMAL,
  25. DeviceTree->hMachine (NULL)
  26. );
  27. if (ConfigRet != CR_SUCCESS) {
  28. ConfigRet = CM_Get_Child_Ex(&DeviceInstance, (Out param)
  29. DeviceTree->DevInst, (prev call)
  30. 0,
  31. DeviceTree->hMachine (NULL)
  32. );
  33. if (ConfigRet == CR_SUCCESS) {
  34. // for info
  35. ConfigRet = CM_Get_DevNode_Registry_Property_Ex(DeviceInstance, (from above)
  36. CM_DRP_CLASSGUID,
  37. NULL,
  38. &Buffer,
  39. &Len,
  40. 0,
  41. DeviceTree->hMachine (NULL)
  42. );
  43. if (ConfigRet == CR_SUCCESS) {
  44. Out: // GUID_DEVCLASS_COMPUTER
  45. {0x4d36e966L, 0xe325, 0x11ce,
  46. {0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}},
  47. if (ConfigRet == CR_SUCCESS) {
  48. ConfigRet = CM_Get_Class_Name_Ex(&DeviceTreeNode->ClassGuid,
  49. Buffer,
  50. &Len,
  51. 0,
  52. DeviceTree->hMachine
  53. );
  54. Out: Computer
  55. if (ConfigRet == CR_SUCCESS) {
  56. // trying to find drive letter
  57. x DevNodeToDriveLetter(x
  58. x
  59. x if (CM_Get_Device_ID_Ex(DevInst,
  60. x DeviceID,
  61. x sizeof(DeviceID)/sizeof(TCHAR),
  62. x 0,
  63. x NULL
  64. x ) == CR_SUCCESS) {
  65. x Out: 0x0006ee8c "ROOT\ACPI_HAL\0000"
  66. x
  67. x
  68. x if (CM_Get_Device_Interface_List_Size(&ulSize,
  69. x (LPGUID)&VolumeClassGuid,
  70. x DeviceID,
  71. x 0) == CR_SUCCESS) &&
  72. x
  73. x Out: FAILS
  74. x (ulSize > 1) &&
  75. x ((DeviceInterface = LocalAlloc(LPTR, ulSize*sizeof(TCHAR))) != NULL) &&
  76. x (CM_Get_Device_Interface_List((LPGUID)&VolumeClassGuid,
  77. x DeviceID,
  78. x DeviceInterface,
  79. x ulSize,
  80. x 0
  81. x ) == CR_SUCCESS) &&
  82. ConfigRet = CM_Get_DevNode_Registry_Property_Ex(DeviceInstance,
  83. CM_DRP_FRIENDLYNAME,
  84. NULL,
  85. Buffer,
  86. &Len,
  87. 0,
  88. DeviceTree->hMachine
  89. );
  90. then, CM_DRP_DEVICEDESC... out: "Advanced Configuration and Power Interface (ACPI) PC"
  91. ....
  92. BuildLocationInformation: Boring....
  93. // Get InstanceId
  94. ConfigRet = CM_Get_Device_ID_ExW(DeviceInstance,
  95. Buffer,
  96. Len/sizeof(TCHAR),
  97. 0,
  98. DeviceTree->hMachine
  99. );
  100. Out "ROOT\ACPI_HAL\0000"
  101. { // should skip
  102. BuildDeviceRelationsList
  103. ConfigRet = CM_Get_Device_ID_List_Size_Ex(&Len,
  104. DeviceId, ("ROOT\ACPI_HAL\0000")
  105. FilterFlag, (CM_GETIDLIST_FILTER_EJECTRELATIONS)
  106. hMachine (NULL)
  107. );
  108. BuildDeviceRelationsList
  109. ConfigRet = CM_Get_Device_ID_List_Size_Ex(&Len,
  110. DeviceId, ("ROOT\ACPI_HAL\0000")
  111. FilterFlag, (CM_GETIDLIST_FILTER_REMOVALRELATIONS)
  112. hMachine
  113. );
  114. // Both FAILED, if would have succeeded, would have trierd to enum drive letters
  115. }
  116. // If this devinst has children, then recurse to fill in its child sibling list.
  117. ConfigRet = CM_Get_Child_Ex(&ChildDeviceInstance, (out param)
  118. DeviceInstance, (same as above)
  119. 0,
  120. DeviceTree->hMachine (NULL)
  121. );
  122. //recurse to redo the same as above for child, then ...
  123. // Next sibling ...
  124. ConfigRet = CM_Get_Sibling_Ex(&DeviceInstance, (Ouch!)
  125. DeviceInstance,
  126. 0,
  127. DeviceTree->hMachine
  128. );
  129. ///////////////////////////////////////////////////////////////////////////////
  130. //
  131. // Device Instance status flags, returned by call to CM_Get_DevInst_Status
  132. //
  133. #define DN_ROOT_ENUMERATED (0x00000001) // Was enumerated by ROOT
  134. #define DN_DRIVER_LOADED (0x00000002) // Has Register_Device_Driver
  135. #define DN_ENUM_LOADED (0x00000004) // Has Register_Enumerator
  136. #define DN_STARTED (0x00000008) // Is currently configured
  137. #define DN_MANUAL (0x00000010) // Manually installed
  138. #define DN_NEED_TO_ENUM (0x00000020) // May need reenumeration
  139. #define DN_NOT_FIRST_TIME (0x00000040) // Has received a config
  140. #define DN_HARDWARE_ENUM (0x00000080) // Enum generates hardware ID
  141. #define DN_LIAR (0x00000100) // Lied about can reconfig once
  142. #define DN_HAS_MARK (0x00000200) // Not CM_Create_DevInst lately
  143. #define DN_HAS_PROBLEM (0x00000400) // Need device installer
  144. #define DN_FILTERED (0x00000800) // Is filtered
  145. #define DN_MOVED (0x00001000) // Has been moved
  146. #define DN_DISABLEABLE (0x00002000) // Can be rebalanced
  147. #define DN_REMOVABLE (0x00004000) // Can be removed
  148. #define DN_PRIVATE_PROBLEM (0x00008000) // Has a private problem
  149. #define DN_MF_PARENT (0x00010000) // Multi function parent
  150. #define DN_MF_CHILD (0x00020000) // Multi function child
  151. #define DN_WILL_BE_REMOVED (0x00040000) // DevInst is being removed
  152. // Flags for CM_Get_Device_ID_List, CM_Get_Device_ID_List_Size
  153. //
  154. #define CM_GETIDLIST_FILTER_NONE (0x00000000)
  155. #define CM_GETIDLIST_FILTER_ENUMERATOR (0x00000001)
  156. #define CM_GETIDLIST_FILTER_SERVICE (0x00000002)
  157. #define CM_GETIDLIST_FILTER_EJECTRELATIONS (0x00000004)
  158. #define CM_GETIDLIST_FILTER_REMOVALRELATIONS (0x00000008)
  159. #define CM_GETIDLIST_FILTER_POWERRELATIONS (0x00000010)
  160. #define CM_GETIDLIST_FILTER_BUSRELATIONS (0x00000020)
  161. #define CM_GETIDLIST_DONOTGENERATE (0x10000040)
  162. #define CM_GETIDLIST_FILTER_BITS (0x1000007F)
  163. //
  164. // Flags for CM_Get_Device_Interface_List, CM_Get_Device_Interface_List_Size
  165. //
  166. #define CM_GET_DEVICE_INTERFACE_LIST_PRESENT (0x00000000) // only currently 'live' device interfaces
  167. #define CM_GET_DEVICE_INTERFACE_LIST_ALL_DEVICES (0x00000001) // all registered device interfaces, live or not
  168. #define CM_GET_DEVICE_INTERFACE_LIST_BITS (0x00000001)