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.

207 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. config.c
  5. Abstract:
  6. This module implements the code to find an ARC configuration tree
  7. entry as constructed by the OS Loader.
  8. Author:
  9. David N. Cutler (davec) 9-Sep-1991
  10. Environment:
  11. User mode only.
  12. Revision History:
  13. --*/
  14. #include "ki.h"
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(INIT,KeFindConfigurationEntry)
  17. #pragma alloc_text(INIT,KeFindConfigurationNextEntry)
  18. #endif
  19. PCONFIGURATION_COMPONENT_DATA
  20. KeFindConfigurationEntry (
  21. IN PCONFIGURATION_COMPONENT_DATA Child,
  22. IN CONFIGURATION_CLASS Class,
  23. IN CONFIGURATION_TYPE Type,
  24. IN PULONG Key OPTIONAL
  25. )
  26. /*++
  27. Routine Description:
  28. This function search the specified configuration tree and returns a
  29. pointer to an entry that matches the specified class, type, and key
  30. parameters.
  31. This routine is the same as KeFindConfurationEntryNext expect
  32. that the search is performed from the first entry
  33. N.B. This routine can only be called during system initialization.
  34. --*/
  35. {
  36. PCONFIGURATION_COMPONENT_DATA Resume;
  37. Resume = NULL;
  38. return KeFindConfigurationNextEntry (Child, Class, Type, Key, &Resume);
  39. }
  40. PCONFIGURATION_COMPONENT_DATA
  41. KeFindConfigurationNextEntry (
  42. IN PCONFIGURATION_COMPONENT_DATA Child,
  43. IN CONFIGURATION_CLASS Class,
  44. IN CONFIGURATION_TYPE Type,
  45. IN PULONG Key OPTIONAL,
  46. IN PCONFIGURATION_COMPONENT_DATA *Resume
  47. )
  48. /*++
  49. Routine Description:
  50. This function search the specified configuration tree and returns a
  51. pointer to an entry that matches the specified class, type, and key
  52. parameters.
  53. N.B. This routine can only be called during system initialization.
  54. Arguments:
  55. Child - Supplies an optional pointer to an NT configuration component.
  56. Class - Supplies the configuration class of the entry to locate.
  57. Type - Supplies the configuration type of the entry to locate.
  58. Key - Supplies a pointer to an optional key value to use in locating
  59. the specified entry.
  60. Resume - Supplies the last returned entry for which the search
  61. should resume from.
  62. Return Value:
  63. If the specified entry is located, then a pointer to the configuration
  64. entry is returned as the function value. Otherwise, NULL is returned.
  65. --*/
  66. {
  67. PCONFIGURATION_COMPONENT_DATA Entry;
  68. ULONG MatchKey;
  69. ULONG MatchMask;
  70. PCONFIGURATION_COMPONENT_DATA Sibling;
  71. //
  72. // Initialize the match key and mask based on whether the optional key
  73. // value is specified.
  74. //
  75. if (ARGUMENT_PRESENT(Key)) {
  76. MatchMask = 0xffffffff;
  77. MatchKey = *Key;
  78. } else {
  79. MatchMask = 0;
  80. MatchKey = 0;
  81. }
  82. //
  83. // Search specified configuration tree for an entry that matches the
  84. // the specified class, type, and key.
  85. //
  86. while (Child != NULL) {
  87. if (*Resume) {
  88. //
  89. // If resume location found, clear resume location and continue
  90. // search with next entry
  91. //
  92. if (Child == *Resume) {
  93. *Resume = NULL;
  94. }
  95. } else {
  96. //
  97. // If the class, type, and key match, then return a pointer to
  98. // the child entry.
  99. //
  100. if ((Child->ComponentEntry.Class == Class) &&
  101. (Child->ComponentEntry.Type == Type) &&
  102. ((Child->ComponentEntry.Key & MatchMask) == MatchKey)) {
  103. return Child;
  104. }
  105. }
  106. //
  107. // If the child has a sibling list, then search the sibling list
  108. // for an entry that matches the specified class, type, and key.
  109. //
  110. Sibling = Child->Sibling;
  111. while (Sibling != NULL) {
  112. if (*Resume) {
  113. //
  114. // If resume location found, clear resume location and continue
  115. // search with next entry
  116. //
  117. if (Sibling == *Resume) {
  118. *Resume = NULL;
  119. }
  120. } else {
  121. //
  122. // If the class, type, and key match, then return a pointer to
  123. // the child entry.
  124. //
  125. if ((Sibling->ComponentEntry.Class == Class) &&
  126. (Sibling->ComponentEntry.Type == Type) &&
  127. ((Sibling->ComponentEntry.Key & MatchMask) == MatchKey)) {
  128. return Sibling;
  129. }
  130. }
  131. //
  132. // If the sibling has a child tree, then search the child tree
  133. // for an entry that matches the specified class, type, and key.
  134. //
  135. if (Sibling->Child != NULL) {
  136. Entry = KeFindConfigurationNextEntry (
  137. Sibling->Child,
  138. Class,
  139. Type,
  140. Key,
  141. Resume
  142. );
  143. if (Entry != NULL) {
  144. return Entry;
  145. }
  146. }
  147. Sibling = Sibling->Sibling;
  148. }
  149. Child = Child->Child;
  150. }
  151. return NULL;
  152. }