Leaked source code of windows server 2003
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.

215 lines
6.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. pnprlist.h
  5. Abstract:
  6. This file declares the routines and data structures used to manipulate
  7. relations list. Relation lists are used by Plug and Play during the
  8. processing of device removal and ejection.
  9. Author:
  10. Robert Nelson (robertn) Apr, 1998.
  11. Revision History:
  12. --*/
  13. //
  14. // An IRPLOCK allows for safe cancellation. The idea is to protect the IRP
  15. // while the canceller is calling IoCancelIrp. This is done by wrapping the
  16. // call in InterlockedExchange(s). The roles are as follows:
  17. //
  18. // Initiator/completion: Cancelable --> IoCallDriver() --> Completed
  19. // Canceller: CancelStarted --> IoCancelIrp() --> CancelCompleted
  20. //
  21. // No cancellation:
  22. // Cancelable-->Completed
  23. //
  24. // Cancellation, IoCancelIrp returns before completion:
  25. // Cancelable --> CancelStarted --> CancelCompleted --> Completed
  26. //
  27. // Canceled after completion:
  28. // Cancelable --> Completed -> CancelStarted
  29. //
  30. // Cancellation, IRP completed during call to IoCancelIrp():
  31. // Cancelable --> CancelStarted -> Completed --> CancelCompleted
  32. //
  33. // The transition from CancelStarted to Completed tells the completer to block
  34. // postprocessing (IRP ownership is transfered to the canceller). Similarly,
  35. // the canceler learns it owns IRP postprocessing (free, completion, etc)
  36. // during a Completed->CancelCompleted transition.
  37. //
  38. typedef enum {
  39. IRPLOCK_CANCELABLE,
  40. IRPLOCK_CANCEL_STARTED,
  41. IRPLOCK_CANCEL_COMPLETE,
  42. IRPLOCK_COMPLETED
  43. } IRPLOCK;
  44. //
  45. // A RELATION_LIST_ENTRY is an element of a relation list.
  46. //
  47. // It contains all the PDEVICE_OBJECTS which exist at the same level in the
  48. // DEVICE_NODE tree.
  49. //
  50. // Individual PDEVICE_OBJECT entries are tagged by setting their lowest bit.
  51. //
  52. // MaxCount indicates the size of the Devices array. Count indicates the number
  53. // of elements which are currently being used. When a relation list is
  54. // compressed Count will equal MaxCount.
  55. //
  56. typedef struct _RELATION_LIST_ENTRY {
  57. ULONG Count; // Number of current entries
  58. ULONG MaxCount; // Size of Entries list
  59. PDEVICE_OBJECT Devices[1]; // Variable length list of device objects
  60. } RELATION_LIST_ENTRY, *PRELATION_LIST_ENTRY;
  61. //
  62. // A RELATION_LIST contains a number of RELATION_LIST_ENTRY structures.
  63. //
  64. // Each entry in Entries describes all the devices of a given level in the
  65. // DEVICE_NODE tree. In order to conserve memory, space is only allocated for
  66. // the entries between the lowest and highest levels inclusive. The member
  67. // FirstLevel indicates which level is at index 0 of Entries. MaxLevel
  68. // indicates the last level represented in Entries. The number of entries is
  69. // determined by the formula MaxLevel - FirstLevel + 1. The Entries array can
  70. // be sparse. Each element of Entries will either be a PRELATION_LIST_ENTRY or
  71. // NULL.
  72. //
  73. // The total number of PDEVICE_OBJECTs in all PRELATION_LIST_ENTRYs is kept in
  74. // Count. Individual PDEVICE_OBJECTS may be tagged. The tag is maintained in
  75. // Bit 0 of the PDEVICE_OBJECT. The total number of PDEVICE_OBJECTs tagged is
  76. // kept in TagCount. This is used to rapidly determine whether or not all
  77. // objects have been tagged.
  78. //
  79. typedef struct _RELATION_LIST {
  80. ULONG Count; // Count of Devices in all Entries
  81. ULONG TagCount; // Count of Tagged Devices
  82. ULONG FirstLevel; // Level Number of Entries[0]
  83. ULONG MaxLevel; // - FirstLevel + 1 = Number of Entries
  84. PRELATION_LIST_ENTRY Entries[1]; // Variable length list of entries
  85. } RELATION_LIST, *PRELATION_LIST;
  86. //
  87. // A PENDING_RELATIONS_LIST_ENTRY is used to track relation lists for operations
  88. // which may pend. This includes removal when open handles exist and device
  89. // ejection.
  90. //
  91. // The Link field is used to link the PENDING_RELATIONS_LIST_ENTRYs together.
  92. //
  93. // The DeviceObject field is the DEVICE_OBJECT to which the operation was
  94. // originally targetted. It will also exist as a member of the relations list.
  95. //
  96. // The RelationsList is a list of BusRelations, RemovalRelations, (and
  97. // EjectionRelations in the case of eject) which are related to DeviceObject and
  98. // its relations.
  99. //
  100. // The EjectIrp is pointer to the Eject IRP which has been sent to the PDO. If
  101. // this is a pending surprise removal then EjectIrp is not used.
  102. //
  103. typedef struct _PENDING_RELATIONS_LIST_ENTRY {
  104. LIST_ENTRY Link;
  105. WORK_QUEUE_ITEM WorkItem;
  106. PPNP_DEVICE_EVENT_ENTRY DeviceEvent;
  107. PDEVICE_OBJECT DeviceObject;
  108. PRELATION_LIST RelationsList;
  109. PIRP EjectIrp;
  110. IRPLOCK Lock;
  111. ULONG Problem;
  112. BOOLEAN ProfileChangingEject;
  113. BOOLEAN DisplaySafeRemovalDialog;
  114. SYSTEM_POWER_STATE LightestSleepState;
  115. PDOCK_INTERFACE DockInterface;
  116. } PENDING_RELATIONS_LIST_ENTRY, *PPENDING_RELATIONS_LIST_ENTRY;
  117. //
  118. // Functions exported to other kernel modules.
  119. //
  120. NTSTATUS
  121. IopAddRelationToList(
  122. IN PRELATION_LIST List,
  123. IN PDEVICE_OBJECT DeviceObject,
  124. IN BOOLEAN DirectDescendant,
  125. IN BOOLEAN Tagged
  126. );
  127. PRELATION_LIST
  128. IopAllocateRelationList(
  129. IN PLUGPLAY_DEVICE_DELETE_TYPE OperationCode
  130. );
  131. NTSTATUS
  132. IopCompressRelationList(
  133. IN OUT PRELATION_LIST *List
  134. );
  135. BOOLEAN
  136. IopEnumerateRelations(
  137. IN PRELATION_LIST List,
  138. IN OUT PULONG Marker,
  139. OUT PDEVICE_OBJECT *PhysicalDevice,
  140. OUT BOOLEAN *DirectDescendant, OPTIONAL
  141. OUT BOOLEAN *Tagged, OPTIONAL
  142. BOOLEAN Reverse
  143. );
  144. VOID
  145. IopFreeRelationList(
  146. IN PRELATION_LIST List
  147. );
  148. ULONG
  149. IopGetRelationsCount(
  150. IN PRELATION_LIST List
  151. );
  152. ULONG
  153. IopGetRelationsTaggedCount(
  154. IN PRELATION_LIST List
  155. );
  156. BOOLEAN
  157. IopIsRelationInList(
  158. IN PRELATION_LIST List,
  159. IN PDEVICE_OBJECT DeviceObject
  160. );
  161. NTSTATUS
  162. IopMergeRelationLists(
  163. IN OUT PRELATION_LIST TargetList,
  164. IN PRELATION_LIST SourceList,
  165. IN BOOLEAN Tagged
  166. );
  167. NTSTATUS
  168. IopRemoveIndirectRelationsFromList(
  169. IN PRELATION_LIST List
  170. );
  171. NTSTATUS
  172. IopRemoveRelationFromList(
  173. IN PRELATION_LIST List,
  174. IN PDEVICE_OBJECT DeviceObject
  175. );
  176. VOID
  177. IopSetAllRelationsTags(
  178. IN PRELATION_LIST List,
  179. IN BOOLEAN Tagged
  180. );
  181. NTSTATUS
  182. IopSetRelationsTag(
  183. IN PRELATION_LIST List,
  184. IN PDEVICE_OBJECT DeviceObject,
  185. IN BOOLEAN Tagged
  186. );