Sync to trunk head (r42241)
[reactos.git] / reactos / ntoskrnl / ke / config.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ke/config.c
5 * PURPOSE: Configuration Tree Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* FUNCTIONS *****************************************************************/
16
17 /*
18 * @implemented
19 */
20 PCONFIGURATION_COMPONENT_DATA
21 NTAPI
22 KeFindConfigurationEntry(IN PCONFIGURATION_COMPONENT_DATA Child,
23 IN CONFIGURATION_CLASS Class,
24 IN CONFIGURATION_TYPE Type,
25 IN PULONG ComponentKey OPTIONAL)
26 {
27 /* Start Search at Root */
28 return KeFindConfigurationNextEntry(Child,
29 Class,
30 Type,
31 ComponentKey,
32 NULL);
33 }
34
35 /*
36 * @implemented
37 */
38 PCONFIGURATION_COMPONENT_DATA
39 NTAPI
40 KeFindConfigurationNextEntry(IN PCONFIGURATION_COMPONENT_DATA Child,
41 IN CONFIGURATION_CLASS Class,
42 IN CONFIGURATION_TYPE Type,
43 IN PULONG ComponentKey OPTIONAL,
44 IN PCONFIGURATION_COMPONENT_DATA *NextLink)
45 {
46 ULONG Key = 0;
47 ULONG Mask = 0;
48 PCONFIGURATION_COMPONENT_DATA Sibling;
49 PCONFIGURATION_COMPONENT_DATA ReturnEntry;
50
51 /* If we did get a key, then use it instead */
52 if (ComponentKey)
53 {
54 Key = *ComponentKey;
55 Mask = -1;
56 }
57
58 /* Loop the Components until we find a a match */
59 while (Child)
60 {
61 /* Check if we are starting somewhere already */
62 if (*NextLink)
63 {
64 /* If we've found the place where we started, clear and continue */
65 if (Child == *NextLink) *NextLink = NULL;
66 }
67 else
68 {
69 /* Try to get a match */
70 if ((Child->ComponentEntry.Class) == Class &&
71 (Child->ComponentEntry.Type) == Type &&
72 (Child->ComponentEntry.Key & Mask) == Key)
73 {
74 /* Match found */
75 return Child;
76 }
77 }
78
79 /* Now we've also got to lookup the siblings */
80 Sibling = Child->Sibling;
81 while (Sibling)
82 {
83 /* Check if we are starting somewhere already */
84 if (*NextLink)
85 {
86 /* If we've found the place where we started, clear and continue */
87 if (Sibling == *NextLink) *NextLink = NULL;
88 }
89 else
90 {
91 /* Try to get a match */
92 if ((Sibling->ComponentEntry.Class == Class) &&
93 (Sibling->ComponentEntry.Type == Type) &&
94 (Sibling->ComponentEntry.Key & Mask) == Key)
95 {
96 /* Match found */
97 return Sibling;
98 }
99 }
100
101 /* We've got to check if the Sibling has a Child as well */
102 if (Sibling->Child)
103 {
104 /* We're just going to call ourselves again */
105 ReturnEntry = KeFindConfigurationNextEntry(Sibling->Child,
106 Class,
107 Type,
108 ComponentKey,
109 NextLink);
110 if (ReturnEntry) return ReturnEntry;
111 }
112
113 /* Next Sibling */
114 Sibling = Sibling->Sibling;
115 }
116
117 /* Next Child */
118 Child = Child->Child;
119 }
120
121 /* If we got here, nothign was found */
122 return NULL;
123 }