ReactOS  0.4.12-dev-916-gffc4e30
cmconfig.c File Reference
#include "ntoskrnl.h"
#include "debug.h"
Include dependency graph for cmconfig.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

INIT_FUNCTION NTSTATUS NTAPI CmpInitializeRegistryNode (IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE NodeHandle, OUT PHANDLE NewHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PUSHORT DeviceIndexTable)
 
INIT_FUNCTION NTSTATUS NTAPI CmpSetupConfigurationTree (IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE ParentHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber)
 
INIT_FUNCTION NTSTATUS NTAPI CmpInitializeHardwareConfiguration (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmconfig.c.

Function Documentation

◆ CmpInitializeHardwareConfiguration()

INIT_FUNCTION NTSTATUS NTAPI CmpInitializeHardwareConfiguration ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 328 of file cmconfig.c.

329 {
335 
336  /* Setup the key name */
338  L"\\Registry\\Machine\\Hardware\\DeviceMap");
340  &KeyName,
342  NULL,
343  NULL);
344 
345  /* Create the device map key */
349  0,
350  NULL,
351  0,
352  &Disposition);
353  if (!NT_SUCCESS(Status))
354  return Status;
356 
357  /* Nobody should've created this key yet! */
359 
360  /* Setup the key name */
362  L"\\Registry\\Machine\\Hardware\\Description");
364  &KeyName,
366  NULL,
367  NULL);
368 
369  /* Create the description key */
373  0,
374  NULL,
375  0,
376  &Disposition);
377  if (!NT_SUCCESS(Status))
378  return Status;
379 
380  /* Nobody should've created this key yet! */
382 
383  /* Allocate the configuration data buffer */
386  TAG_CM);
388  {
391  }
392 
393  /* Check if we got anything from NTLDR */
394  if (LoaderBlock->ConfigurationRoot)
395  {
396  /* Setup the configuration tree */
397  Status = CmpSetupConfigurationTree(LoaderBlock->ConfigurationRoot,
398  KeyHandle,
399  -1,
400  -1);
401  }
402  else
403  {
404  /* Nothing else to do */
406  }
407 
408  /* Free the buffer, close our handle and return status */
411  return Status;
412 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4693
ULONG CmpConfigurationAreaSize
Definition: cmdata.c:36
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
#define KEY_READ
Definition: nt_native.h:1023
LONG NTSTATUS
Definition: precomp.h:26
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
INIT_FUNCTION NTSTATUS NTAPI CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE ParentHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber)
Definition: cmconfig.c:205
smooth NULL
Definition: ftsmooth.c:416
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define KEY_WRITE
Definition: nt_native.h:1031
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define TAG_CM
Definition: cmlib.h:203
static const WCHAR L[]
Definition: oid.c:1250
PCM_FULL_RESOURCE_DESCRIPTOR CmpConfigurationData
Definition: cmdata.c:37
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by CmInitSystem1().

◆ CmpInitializeRegistryNode()

INIT_FUNCTION NTSTATUS NTAPI CmpInitializeRegistryNode ( IN PCONFIGURATION_COMPONENT_DATA  CurrentEntry,
IN HANDLE  NodeHandle,
OUT PHANDLE  NewHandle,
IN INTERFACE_TYPE  InterfaceType,
IN ULONG  BusNumber,
IN PUSHORT  DeviceIndexTable 
)

Definition at line 20 of file cmconfig.c.

26 {
30  HANDLE KeyHandle, ParentHandle;
31  ANSI_STRING TempString;
32  CHAR TempBuffer[12];
33  WCHAR Buffer[12];
34  PCONFIGURATION_COMPONENT Component;
36 
37  /* Get the component */
38  Component = &CurrentEntry->ComponentEntry;
39 
40  /* Set system class components to ARC system type */
41  if (Component->Class == SystemClass) Component->Type = ArcSystem;
42 
43  /* Create a key for the component */
45  &CmTypeName[Component->Type],
47  NodeHandle,
48  NULL);
52  0,
53  NULL,
54  0,
55  &Disposition);
56  if (!NT_SUCCESS(Status)) return Status;
57 
58  /* Check if this is anything but a system class component */
59  if (Component->Class != SystemClass)
60  {
61  /* Build the sub-component string */
62  RtlIntegerToChar(DeviceIndexTable[Component->Type]++,
63  10,
64  12,
65  TempBuffer);
66  RtlInitAnsiString(&TempString, TempBuffer);
67 
68  /* Convert it to Unicode */
69  RtlInitEmptyUnicodeString(&KeyName, Buffer, sizeof(Buffer));
71  if (!NT_SUCCESS(Status))
72  {
74  return Status;
75  }
76 
77  /* Create the key */
78  ParentHandle = KeyHandle;
80  &KeyName,
82  ParentHandle,
83  NULL);
87  0,
88  NULL,
89  0,
90  &Disposition);
91  NtClose(ParentHandle);
92 
93  /* Fail if the key couldn't be created, and make sure it's a new key */
94  if (!NT_SUCCESS(Status)) return Status;
96  }
97 
98  /* Setup the component information key */
99  RtlInitUnicodeString(&ValueName, L"Component Information");
101  &ValueName,
102  0,
103  REG_BINARY,
104  &Component->Flags,
106  ConfigurationDataLength) -
108  if (!NT_SUCCESS(Status))
109  {
110  /* Fail */
112  return Status;
113  }
114 
115  /* Check if we have an identifier */
116  if (Component->IdentifierLength)
117  {
118  /* Build the string and convert it to Unicode */
119  RtlInitUnicodeString(&ValueName, L"Identifier");
120  RtlInitAnsiString(&TempString, Component->Identifier);
122  &TempString,
123  TRUE);
124  if (NT_SUCCESS(Status))
125  {
126  /* Save the identifier in the registry */
128  &ValueName,
129  0,
130  REG_SZ,
131  ValueData.Buffer,
132  ValueData.Length + sizeof(UNICODE_NULL));
134  }
135 
136  /* Check for failure during conversion or registry write */
137  if (!NT_SUCCESS(Status))
138  {
139  /* Fail */
141  return Status;
142  }
143  }
144 
145  /* Setup the configuration data string */
146  RtlInitUnicodeString(&ValueName, L"Configuration Data");
147 
148  /* Check if we got configuration data */
149  if (CurrentEntry->ConfigurationData)
150  {
151  /* Calculate the total length and check if it fits into our buffer */
152  Length = Component->ConfigurationDataLength +
153  FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList);
155  {
156  ASSERTMSG("Component too large -- need reallocation!\n", FALSE);
157  }
158  else
159  {
160  /* Copy the data */
162  CurrentEntry->ConfigurationData,
163  Component->ConfigurationDataLength);
164  }
165  }
166  else
167  {
168  /* No configuration data, setup defaults */
172  Length = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
173  FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList);
174  }
175 
176  /* Set the interface type and bus number */
177  CmpConfigurationData->InterfaceType = InterfaceType;
179 
180  /* Save the actual data */
182  &ValueName,
183  0,
186  Length);
187  if (!NT_SUCCESS(Status))
188  {
189  /* Fail */
191  }
192  else
193  {
194  /* Return the new handle */
195  *NewHandle = KeyHandle;
196  }
197 
198  /* Return status */
199  return Status;
200 }
ULONG IdentifierLength
Definition: arc.h:112
IDENTIFIER_FLAG Flags
Definition: arc.h:106
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4693
ULONG CmpConfigurationAreaSize
Definition: cmdata.c:36
ULONG ConfigurationDataLength
Definition: arc.h:111
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4575
NTSYSAPI NTSTATUS NTAPI RtlIntegerToChar(_In_ ULONG Value, _In_ ULONG Base, _In_ ULONG Length, _Out_ PCHAR String)
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define UNICODE_NULL
INIT_SECTION UNICODE_STRING CmTypeName[MaximumType+1]
Definition: cmdata.c:80
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
CONFIGURATION_TYPE Type
Definition: arc.h:105
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define REG_FULL_RESOURCE_DESCRIPTOR
Definition: nt_native.h:1503
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define KEY_WRITE
Definition: nt_native.h:1031
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CONFIGURATION_CLASS Class
Definition: arc.h:104
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
PCM_FULL_RESOURCE_DESCRIPTOR CmpConfigurationData
Definition: cmdata.c:37
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_SZ
Definition: layer.c:22

Referenced by CmpInitializeMachineDependentConfiguration(), and CmpSetupConfigurationTree().

◆ CmpSetupConfigurationTree()

INIT_FUNCTION NTSTATUS NTAPI CmpSetupConfigurationTree ( IN PCONFIGURATION_COMPONENT_DATA  CurrentEntry,
IN HANDLE  ParentHandle,
IN INTERFACE_TYPE  InterfaceType,
IN ULONG  BusNumber 
)

Definition at line 205 of file cmconfig.c.

209 {
210  PCONFIGURATION_COMPONENT Component;
211  USHORT DeviceIndexTable[MaximumType + 1] = {0};
212  ULONG Interface = InterfaceType, Bus = BusNumber, i;
214  HANDLE NewHandle;
215 
216  /* Loop each entry */
217  while (CurrentEntry)
218  {
219  /* Check if this is an adapter */
220  Component = &CurrentEntry->ComponentEntry;
221  if ((Component->Class == AdapterClass) &&
222  (CurrentEntry->Parent->ComponentEntry.Class == SystemClass))
223  {
224  /* Check what kind of adapter it is */
225  switch (Component->Type)
226  {
227  /* EISA */
228  case EisaAdapter:
229  {
230  /* Fixup information */
231  Interface = Eisa;
232  Bus = CmpTypeCount[EisaAdapter]++;
233  break;
234  }
235 
236  /* Turbo-channel */
237  case TcAdapter:
238  {
239  /* Fixup information */
241  Bus = CmpTypeCount[TurboChannel]++;
242  break;
243  }
244 
245  /* ISA, PCI, etc busses */
246  case MultiFunctionAdapter:
247  {
248  /* Check if we have an identifier */
249  if (Component->Identifier)
250  {
251  /* Loop each multi-function adapter type */
252  for (i = 0; CmpMultifunctionTypes[i].Identifier; i++)
253  {
254  /* Check for a name match */
255  if (!_stricmp(CmpMultifunctionTypes[i].Identifier,
256  Component->Identifier))
257  {
258  /* Match found */
259  break;
260  }
261  }
262 
263  /* Fix up information */
265  Bus = CmpMultifunctionTypes[i].Count++;
266  }
267  break;
268  }
269 
270  /* SCSI Bus */
271  case ScsiAdapter:
272  {
273  /* Fix up */
275  Bus = CmpTypeCount[ScsiAdapter]++;
276  break;
277  }
278 
279  /* Unknown */
280  default:
281  {
282  Interface = -1;
283  Bus = CmpUnknownBusCount++;
284  break;
285  }
286  }
287  }
288 
289  /* Dump information on the component */
290 
291  /* Setup the hardware node */
292  Status = CmpInitializeRegistryNode(CurrentEntry,
293  ParentHandle,
294  &NewHandle,
295  Interface,
296  Bus,
297  DeviceIndexTable);
298  if (!NT_SUCCESS(Status)) return Status;
299 
300  /* Check for children */
301  if (CurrentEntry->Child)
302  {
303  /* Recurse child */
304  Status = CmpSetupConfigurationTree(CurrentEntry->Child,
305  NewHandle,
306  Interface,
307  Bus);
308  if (!NT_SUCCESS(Status))
309  {
310  /* Fail */
311  NtClose(NewHandle);
312  return Status;
313  }
314  }
315 
316  /* Get to the next entry */
317  NtClose(NewHandle);
318  CurrentEntry = CurrentEntry->Sibling;
319  }
320 
321  /* We're done */
322  return STATUS_SUCCESS;
323 }
PCHAR Identifier
Definition: cm.h:498
USHORT Count
Definition: cm.h:500
LONG NTSTATUS
Definition: precomp.h:26
INIT_SECTION CMP_MF_TYPE CmpMultifunctionTypes[]
Definition: cmdata.c:126
#define _stricmp
Definition: cat.c:22
INIT_FUNCTION NTSTATUS NTAPI CmpSetupConfigurationTree(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE ParentHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber)
Definition: cmconfig.c:205
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
USHORT CmpUnknownBusCount
Definition: cmdata.c:63
ULONG CmpTypeCount[MaximumType+1]
Definition: cmdata.c:64
CONFIGURATION_TYPE Type
Definition: arc.h:105
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
INIT_FUNCTION NTSTATUS NTAPI CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE NodeHandle, OUT PHANDLE NewHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PUSHORT DeviceIndexTable)
Definition: cmconfig.c:20
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CONFIGURATION_CLASS Class
Definition: arc.h:104
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
USHORT InterfaceType
Definition: cm.h:499
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by CmpInitializeHardwareConfiguration().