ReactOS 0.4.15-dev-5666-gc548b97
iorsrce.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for iorsrce.c:

Go to the source code of this file.

Classes

struct  IO_QUERY
 

Typedefs

typedef struct IO_QUERY IO_QUERY
 
typedef struct IO_QUERYPIO_QUERY
 

Functions

NTSTATUS NTAPI IopQueryDeviceDescription (PIO_QUERY Query, UNICODE_STRING RootKey, HANDLE RootKeyHandle, ULONG Bus, PKEY_VALUE_FULL_INFORMATION *BusInformation)
 
NTSTATUS NTAPI IopQueryBusDescription (PIO_QUERY Query, UNICODE_STRING RootKey, HANDLE RootKeyHandle, PULONG Bus, BOOLEAN KeyIsRoot)
 
NTSTATUS NTAPI IopFetchConfigurationInformation (OUT PWSTR *SymbolicLinkList, IN GUID Guid, IN ULONG ExpectedInterfaces, IN PULONG Interfaces)
 
VOID NTAPI IopStoreSystemPartitionInformation (IN PUNICODE_STRING NtSystemPartitionDeviceName, IN PUNICODE_STRING OsLoaderPathName)
 
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation (VOID)
 
NTSTATUS NTAPI IoReportResourceUsage (PUNICODE_STRING DriverClassName, PDRIVER_OBJECT DriverObject, PCM_RESOURCE_LIST DriverList, ULONG DriverListSize, PDEVICE_OBJECT DeviceObject, PCM_RESOURCE_LIST DeviceList, ULONG DeviceListSize, BOOLEAN OverrideConflict, PBOOLEAN ConflictDetected)
 
NTSTATUS NTAPI IopLegacyResourceAllocation (IN ARBITER_REQUEST_SOURCE AllocationType, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
 
NTSTATUS NTAPI IoAssignResources (IN PUNICODE_STRING RegistryPath, IN PUNICODE_STRING DriverClassName, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
 
NTSTATUS NTAPI IoQueryDeviceDescription (PINTERFACE_TYPE BusType OPTIONAL, PULONG BusNumber OPTIONAL, PCONFIGURATION_TYPE ControllerType OPTIONAL, PULONG ControllerNumber OPTIONAL, PCONFIGURATION_TYPE PeripheralType OPTIONAL, PULONG PeripheralNumber OPTIONAL, PIO_QUERY_DEVICE_ROUTINE CalloutRoutine, PVOID Context)
 
NTSTATUS NTAPI IoReportHalResourceUsage (PUNICODE_STRING HalDescription, PCM_RESOURCE_LIST RawList, PCM_RESOURCE_LIST TranslatedList, ULONG ListSize)
 

Variables

static CONFIGURATION_INFORMATION _SystemConfigurationInformation = { 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, 0, 0 }
 
PWSTR ArcTypes [42]
 

Typedef Documentation

◆ IO_QUERY

◆ PIO_QUERY

Function Documentation

◆ IoAssignResources()

NTSTATUS NTAPI IoAssignResources ( IN PUNICODE_STRING  RegistryPath,
IN PUNICODE_STRING  DriverClassName,
IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  DeviceObject,
IN PIO_RESOURCE_REQUIREMENTS_LIST  RequestedResources,
IN OUT PCM_RESOURCE_LIST AllocatedResources 
)

Definition at line 953 of file iorsrce.c.

959{
961
962 /* Do we have a DO? */
963 if (DeviceObject)
964 {
965 /* Get its device node */
968 {
969 /* New drivers should not call this API */
970 KeBugCheckEx(PNP_DETECTED_FATAL_ERROR,
971 0,
972 0,
975 }
976 }
977
978 /* Did the driver supply resources? */
979 if (RequestedResources)
980 {
981 /* Make sure there's actually something useful in them */
982 if (!(RequestedResources->AlternativeLists) || !(RequestedResources->List[0].Count))
983 {
984 /* Empty resources are no resources */
985 RequestedResources = NULL;
986 }
987 }
988
989 /* Initialize output if given */
991
992 /* Call internal helper function */
996 RequestedResources,
998}
@ DeviceNode
Definition: Node.h:9
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IopLegacyResourceAllocation(IN ARBITER_REQUEST_SOURCE AllocationType, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
Definition: iorsrce.c:913
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4643
#define DNF_LEGACY_RESOURCE_DEVICENODE
Definition: iotypes.h:187
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
@ ArbiterRequestLegacyAssigned
Definition: iotypes.h:4616

Referenced by PciAssignSlotResources(), and VideoPortGetAccessRanges().

◆ IoGetConfigurationInformation()

◆ IopFetchConfigurationInformation()

NTSTATUS NTAPI IopFetchConfigurationInformation ( OUT PWSTR SymbolicLinkList,
IN GUID  Guid,
IN ULONG  ExpectedInterfaces,
IN PULONG  Interfaces 
)

Definition at line 656 of file iorsrce.c.

660{
662 ULONG IntInterfaces = 0;
663 PWSTR IntSymbolicLinkList;
664
665 /* Get the associated enabled interfaces with the given GUID */
667 if (!NT_SUCCESS(Status))
668 {
669 /* Zero output and leave */
670 if (SymbolicLinkList != 0)
671 {
672 *SymbolicLinkList = 0;
673 }
674
675 return STATUS_UNSUCCESSFUL;
676 }
677
678 IntSymbolicLinkList = *SymbolicLinkList;
679
680 /* Count the number of enabled interfaces by counting the number of symbolic links */
681 while (*IntSymbolicLinkList != UNICODE_NULL)
682 {
683 IntInterfaces++;
684 IntSymbolicLinkList += wcslen(IntSymbolicLinkList) + (sizeof(UNICODE_NULL) / sizeof(WCHAR));
685 }
686
687 /* Matching result will define the result */
689 /* Finally, give back to the caller the number of found interfaces */
690 *Interfaces = IntInterfaces;
691
692 return Status;
693}
LONG NTSTATUS
Definition: precomp.h:26
static const CLASS_AND_INTERFACES ExpectedInterfaces[]
Definition: browseui.c:13
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
unsigned int ULONG
Definition: retypes.h:1
#define UNICODE_NULL
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
#define STATUS_SUCCESS
Definition: shellext.h:65
uint16_t * PWSTR
Definition: typedefs.h:56
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by IopCreateArcNamesCd(), and IopCreateArcNamesDisk().

◆ IopLegacyResourceAllocation()

NTSTATUS NTAPI IopLegacyResourceAllocation ( IN ARBITER_REQUEST_SOURCE  AllocationType,
IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT DeviceObject  OPTIONAL,
IN PIO_RESOURCE_REQUIREMENTS_LIST  ResourceRequirements,
IN OUT PCM_RESOURCE_LIST AllocatedResources 
)

Definition at line 913 of file iorsrce.c.

918{
920
921 DPRINT1("IopLegacyResourceAllocation is halfplemented!\n");
922
924 {
925 /* We can get there by calling IoAssignResources() with RequestedResources = NULL.
926 * TODO: not sure what we should do, but we shouldn't crash.
927 * */
930 }
931
934 if (!NT_SUCCESS(Status))
935 {
937 {
938 DPRINT1("Denying an attempt to claim resources currently in use by another device!\n");
939 }
940
941 return Status;
942 }
943
944 /* TODO: Claim resources in registry */
945 return STATUS_SUCCESS;
946}
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: debug.h:115
NTSTATUS NTAPI IopFixupResourceListWithRequirements(IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList, OUT PCM_RESOURCE_LIST *ResourceList)
Definition: pnpres.c:219
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
Definition: iofuncs.h:1551

Referenced by IoAssignResources().

◆ IopQueryBusDescription()

NTSTATUS NTAPI IopQueryBusDescription ( PIO_QUERY  Query,
UNICODE_STRING  RootKey,
HANDLE  RootKeyHandle,
PULONG  Bus,
BOOLEAN  KeyIsRoot 
)

Definition at line 454 of file iorsrce.c.

460{
462 ULONG BusLoop;
463 UNICODE_STRING SubRootRegName;
464 UNICODE_STRING BusString;
465 UNICODE_STRING SubBusString;
466 ULONG LenBasicInformation = 0;
467 ULONG LenFullInformation;
468 ULONG LenKeyFullInformation;
469 ULONG LenKey;
470 HANDLE SubRootKeyHandle;
471 PKEY_FULL_INFORMATION FullInformation;
472 PKEY_BASIC_INFORMATION BasicInformation = NULL;
475
476 /* How much buffer space */
477 Status = ZwQueryKey(RootKeyHandle, KeyFullInformation, NULL, 0, &LenFullInformation);
478
480 return Status;
481
482 /* Allocate it */
483 FullInformation = ExAllocatePoolWithTag(PagedPool, LenFullInformation, TAG_IO_RESOURCE);
484
485 if (!FullInformation)
486 return STATUS_NO_MEMORY;
487
488 /* Get the Information */
489 Status = ZwQueryKey(RootKeyHandle, KeyFullInformation, FullInformation, LenFullInformation, &LenFullInformation);
490
491 /* Everything was fine */
492 if (NT_SUCCESS(Status))
493 {
494 /* Buffer needed for all the keys under this one */
495 LenBasicInformation = FullInformation->MaxNameLen + sizeof(KEY_BASIC_INFORMATION);
496
497 /* Allocate it */
498 BasicInformation = ExAllocatePoolWithTag(PagedPool, LenBasicInformation, TAG_IO_RESOURCE);
499 }
500
501 /* Deallocate the old Buffer */
502 ExFreePoolWithTag(FullInformation, TAG_IO_RESOURCE);
503
504 /* Try to find a Bus */
505 for (BusLoop = 0; NT_SUCCESS(Status); BusLoop++)
506 {
507 /* Bus parameter was passed and number was matched */
508 if ((Query->BusNumber) && (*(Query->BusNumber)) == *Bus) break;
509
510 /* Enumerate the Key */
511 Status = ZwEnumerateKey(
512 RootKeyHandle,
513 BusLoop,
515 BasicInformation,
516 LenBasicInformation,
517 &LenKey);
518
519 /* Everything enumerated */
520 if (!NT_SUCCESS(Status)) break;
521
522 /* What Bus are we going to go down? (only check if this is a Root Key) */
523 if (KeyIsRoot)
524 {
525 if (wcsncmp(BasicInformation->Name, L"MultifunctionAdapter", BasicInformation->NameLength / 2) &&
526 wcsncmp(BasicInformation->Name, L"EisaAdapter", BasicInformation->NameLength / 2) &&
527 wcsncmp(BasicInformation->Name, L"TcAdapter", BasicInformation->NameLength / 2))
528 {
529 /* Nothing found, check next */
530 continue;
531 }
532 }
533
534 /* Enumerate the Bus. */
535 BusString.Buffer = BasicInformation->Name;
536 BusString.Length = (USHORT)BasicInformation->NameLength;
537 BusString.MaximumLength = (USHORT)BasicInformation->NameLength;
538
539 /* Open a handle to the Root Registry Key */
542 &BusString,
544 RootKeyHandle,
545 NULL);
546
547 Status = ZwOpenKey(&SubRootKeyHandle, KEY_READ, &ObjectAttributes);
548
549 /* Go on if we can't */
550 if (!NT_SUCCESS(Status)) continue;
551
552 /* Key opened. Create the path */
553 SubRootRegName = RootKey;
554 RtlAppendUnicodeToString(&SubRootRegName, L"\\");
555 RtlAppendUnicodeStringToString(&SubRootRegName, &BusString);
556
557 if (!KeyIsRoot)
558 {
559 /* Parsing a SubBus-key */
560 int SubBusLoop;
561 PWSTR Strings[3] = {
562 L"Identifier",
563 L"Configuration Data",
564 L"Component Information"};
565
566 for (SubBusLoop = 0; SubBusLoop < 3; SubBusLoop++)
567 {
568 /* Identifier String First */
569 RtlInitUnicodeString(&SubBusString, Strings[SubBusLoop]);
570
571 /* How much buffer space */
572 ZwQueryValueKey(SubRootKeyHandle, &SubBusString, KeyValueFullInformation, NULL, 0, &LenKeyFullInformation);
573
574 /* Allocate it */
575 BusInformation[SubBusLoop] = ExAllocatePoolWithTag(PagedPool, LenKeyFullInformation, TAG_IO_RESOURCE);
576
577 /* Get the Information */
578 Status = ZwQueryValueKey(SubRootKeyHandle, &SubBusString, KeyValueFullInformation, BusInformation[SubBusLoop], LenKeyFullInformation, &LenKeyFullInformation);
579 }
580
581 if (NT_SUCCESS(Status))
582 {
583 /* Do we have something */
584 if (BusInformation[1] != NULL &&
585 BusInformation[1]->DataLength != 0 &&
586 /* Does it match what we want? */
588 {
589 /* Found a bus */
590 (*Bus)++;
591
592 /* Is it the bus we wanted */
593 if (Query->BusNumber == NULL || *(Query->BusNumber) == *Bus)
594 {
595 /* If we don't want Controller Information, we're done... call the callback */
596 if (Query->ControllerType == NULL)
597 {
598 Status = Query->CalloutRoutine(
599 Query->Context,
600 &SubRootRegName,
601 *(Query->BusType),
602 *Bus,
604 0,
605 0,
606 NULL,
607 0,
608 0,
609 NULL);
610 } else {
611 /* We want Controller Info...get it */
612 Status = IopQueryDeviceDescription(Query, SubRootRegName, RootKeyHandle, *Bus, (PKEY_VALUE_FULL_INFORMATION*)BusInformation);
613 }
614 }
615 }
616 }
617
618 /* Free the allocated memory */
619 for (SubBusLoop = 0; SubBusLoop < 3; SubBusLoop++)
620 {
621 if (BusInformation[SubBusLoop])
622 {
624 BusInformation[SubBusLoop] = NULL;
625 }
626 }
627
628 /* Exit the Loop if we found the bus */
629 if (Query->BusNumber != NULL && *(Query->BusNumber) == *Bus)
630 {
631 ZwClose(SubRootKeyHandle);
632 SubRootKeyHandle = NULL;
633 continue;
634 }
635 }
636
637 /* Enumerate the buses below us recursively if we haven't found the bus yet */
638 Status = IopQueryBusDescription(Query, SubRootRegName, SubRootKeyHandle, Bus, !KeyIsRoot);
639
640 /* Everything enumerated */
642
643 ZwClose(SubRootKeyHandle);
644 SubRootKeyHandle = NULL;
645 }
646
647 /* Free the last remaining Allocated Memory */
648 if (BasicInformation)
649 ExFreePoolWithTag(BasicInformation, TAG_IO_RESOURCE);
650
651 return Status;
652}
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
Definition: query.c:292
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
static const WCHAR Strings[]
Definition: reg.c:35
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define PagedPool
Definition: env_spec_w32.h:308
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS NTAPI IopQueryBusDescription(PIO_QUERY Query, UNICODE_STRING RootKey, HANDLE RootKeyHandle, PULONG Bus, BOOLEAN KeyIsRoot)
Definition: iorsrce.c:454
NTSTATUS NTAPI IopQueryDeviceDescription(PIO_QUERY Query, UNICODE_STRING RootKey, HANDLE RootKeyHandle, ULONG Bus, PKEY_VALUE_FULL_INFORMATION *BusInformation)
Definition: iorsrce.c:100
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyBasicInformation
Definition: nt_native.h:1131
@ KeyFullInformation
Definition: nt_native.h:1133
@ KeyValueFullInformation
Definition: nt_native.h:1181
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define KEY_READ
Definition: nt_native.h:1023
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
static PMEMKEY RootKey
Definition: registry.c:55
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_IO_RESOURCE
Definition: tag.h:93
_In_ WDFDEVICE _In_ PPNP_BUS_INFORMATION BusInformation
Definition: wdfdevice.h:3915
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463

Referenced by IopQueryBusDescription(), and IoQueryDeviceDescription().

◆ IopQueryDeviceDescription()

NTSTATUS NTAPI IopQueryDeviceDescription ( PIO_QUERY  Query,
UNICODE_STRING  RootKey,
HANDLE  RootKeyHandle,
ULONG  Bus,
PKEY_VALUE_FULL_INFORMATION BusInformation 
)

Definition at line 100 of file iorsrce.c.

106{
108
109 /* Controller Stuff */
110 UNICODE_STRING ControllerString;
111 UNICODE_STRING ControllerRootRegName = RootKey;
112 UNICODE_STRING ControllerRegName;
113 HANDLE ControllerKeyHandle;
114 PKEY_FULL_INFORMATION ControllerFullInformation = NULL;
115 PKEY_VALUE_FULL_INFORMATION ControllerInformation[3] = {NULL, NULL, NULL};
116 ULONG ControllerNumber;
117 ULONG ControllerLoop;
118 ULONG MaximumControllerNumber;
119
120 /* Peripheral Stuff */
121 UNICODE_STRING PeripheralString;
122 HANDLE PeripheralKeyHandle;
123 PKEY_FULL_INFORMATION PeripheralFullInformation;
124 PKEY_VALUE_FULL_INFORMATION PeripheralInformation[3] = {NULL, NULL, NULL};
125 ULONG PeripheralNumber;
126 ULONG PeripheralLoop;
127 ULONG MaximumPeripheralNumber;
128
129 /* Global Registry Stuff */
131 ULONG LenFullInformation;
132 ULONG LenKeyFullInformation;
133 UNICODE_STRING TempString;
134 WCHAR TempBuffer[14];
135 PWSTR Strings[3] = {
136 L"Identifier",
137 L"Configuration Data",
138 L"Component Information"
139 };
140
141 /* Temporary String */
142 TempString.MaximumLength = sizeof(TempBuffer);
143 TempString.Length = 0;
144 TempString.Buffer = TempBuffer;
145
146 /* Add Controller Name to String */
147 RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
148 RtlAppendUnicodeToString(&ControllerRootRegName, ArcTypes[*Query->ControllerType]);
149
150 /* Set the Controller Number if specified */
151 if (Query->ControllerNumber && *(Query->ControllerNumber))
152 {
153 ControllerNumber = *Query->ControllerNumber;
154 MaximumControllerNumber = ControllerNumber + 1;
155 } else {
156 /* Find out how many Controller Numbers there are */
159 &ControllerRootRegName,
161 NULL,
162 NULL);
163
164 Status = ZwOpenKey(&ControllerKeyHandle, KEY_READ, &ObjectAttributes);
165 if (NT_SUCCESS(Status))
166 {
167 /* How much buffer space */
168 ZwQueryKey(ControllerKeyHandle, KeyFullInformation, NULL, 0, &LenFullInformation);
169
170 /* Allocate it */
171 ControllerFullInformation = ExAllocatePoolWithTag(PagedPool, LenFullInformation, TAG_IO_RESOURCE);
172
173 /* Get the Information */
174 Status = ZwQueryKey(ControllerKeyHandle, KeyFullInformation, ControllerFullInformation, LenFullInformation, &LenFullInformation);
175 ZwClose(ControllerKeyHandle);
176 ControllerKeyHandle = NULL;
177 }
178
179 /* No controller was found, go back to function. */
180 if (!NT_SUCCESS(Status))
181 {
182 if (ControllerFullInformation != NULL)
183 ExFreePoolWithTag(ControllerFullInformation, TAG_IO_RESOURCE);
184 return Status;
185 }
186
187 /* Find out Controller Numbers */
188 ControllerNumber = 0;
189 MaximumControllerNumber = ControllerFullInformation->SubKeys;
190
191 /* Free Memory */
192 ExFreePoolWithTag(ControllerFullInformation, TAG_IO_RESOURCE);
193 ControllerFullInformation = NULL;
194 }
195
196 /* Save String */
197 ControllerRegName = ControllerRootRegName;
198
199 /* Loop through controllers */
200 for (; ControllerNumber < MaximumControllerNumber; ControllerNumber++)
201 {
202 /* Load String */
203 ControllerRootRegName = ControllerRegName;
204
205 /* Controller Number to Registry String */
206 Status = RtlIntegerToUnicodeString(ControllerNumber, 10, &TempString);
207
208 /* Create String */
209 Status |= RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
210 Status |= RtlAppendUnicodeStringToString(&ControllerRootRegName, &TempString);
211
212 /* Something messed up */
213 if (!NT_SUCCESS(Status)) break;
214
215 /* Open the Registry Key */
218 &ControllerRootRegName,
220 NULL,
221 NULL);
222
223 Status = ZwOpenKey(&ControllerKeyHandle, KEY_READ, &ObjectAttributes);
224
225 /* Read the Configuration Data... */
226 if (NT_SUCCESS(Status))
227 {
228 for (ControllerLoop = 0; ControllerLoop < 3; ControllerLoop++)
229 {
230 /* Identifier String First */
231 RtlInitUnicodeString(&ControllerString, Strings[ControllerLoop]);
232
233 /* How much buffer space */
234 Status = ZwQueryValueKey(ControllerKeyHandle, &ControllerString, KeyValueFullInformation, NULL, 0, &LenKeyFullInformation);
235
237 continue;
238
239 /* Allocate it */
240 ControllerInformation[ControllerLoop] = ExAllocatePoolWithTag(PagedPool, LenKeyFullInformation, TAG_IO_RESOURCE);
241
242 /* Get the Information */
243 Status = ZwQueryValueKey(ControllerKeyHandle, &ControllerString, KeyValueFullInformation, ControllerInformation[ControllerLoop], LenKeyFullInformation, &LenKeyFullInformation);
244 }
245
246 /* Clean Up */
247 ZwClose(ControllerKeyHandle);
248 ControllerKeyHandle = NULL;
249 }
250
251 /* Something messed up */
252 if (!NT_SUCCESS(Status))
253 goto EndLoop;
254
255 /* We now have Bus *AND* Controller Information.. is it enough? */
256 if (!Query->PeripheralType || !(*Query->PeripheralType))
257 {
258 Status = Query->CalloutRoutine(
259 Query->Context,
260 &ControllerRootRegName,
261 *Query->BusType,
262 Bus,
264 *Query->ControllerType,
265 ControllerNumber,
266 ControllerInformation,
267 0,
268 0,
269 NULL);
270 goto EndLoop;
271 }
272
273 /* Not enough...caller also wants peripheral name */
274 Status = RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
275 Status |= RtlAppendUnicodeToString(&ControllerRootRegName, ArcTypes[*Query->PeripheralType]);
276
277 /* Something messed up */
278 if (!NT_SUCCESS(Status)) goto EndLoop;
279
280 /* Set the Peripheral Number if specified */
281 if (Query->PeripheralNumber && *Query->PeripheralNumber)
282 {
283 PeripheralNumber = *Query->PeripheralNumber;
284 MaximumPeripheralNumber = PeripheralNumber + 1;
285 } else {
286 /* Find out how many Peripheral Numbers there are */
289 &ControllerRootRegName,
291 NULL,
292 NULL);
293
294 Status = ZwOpenKey(&PeripheralKeyHandle, KEY_READ, &ObjectAttributes);
295
296 if (NT_SUCCESS(Status))
297 {
298 /* How much buffer space */
299 ZwQueryKey(PeripheralKeyHandle, KeyFullInformation, NULL, 0, &LenFullInformation);
300
301 /* Allocate it */
302 PeripheralFullInformation = ExAllocatePoolWithTag(PagedPool, LenFullInformation, TAG_IO_RESOURCE);
303
304 /* Get the Information */
305 Status = ZwQueryKey(PeripheralKeyHandle, KeyFullInformation, PeripheralFullInformation, LenFullInformation, &LenFullInformation);
306 ZwClose(PeripheralKeyHandle);
307 PeripheralKeyHandle = NULL;
308 }
309
310 /* No controller was found, go back to function but clean up first */
311 if (!NT_SUCCESS(Status))
312 {
314 goto EndLoop;
315 }
316
317 /* Find out Peripheral Number */
318 PeripheralNumber = 0;
319 MaximumPeripheralNumber = PeripheralFullInformation->SubKeys;
320
321 /* Free Memory */
322 ExFreePoolWithTag(PeripheralFullInformation, TAG_IO_RESOURCE);
323 PeripheralFullInformation = NULL;
324 }
325
326 /* Save Name */
327 ControllerRegName = ControllerRootRegName;
328
329 /* Loop through Peripherals */
330 for (; PeripheralNumber < MaximumPeripheralNumber; PeripheralNumber++)
331 {
332 /* Restore Name */
333 ControllerRootRegName = ControllerRegName;
334
335 /* Peripheral Number to Registry String */
336 Status = RtlIntegerToUnicodeString(PeripheralNumber, 10, &TempString);
337
338 /* Create String */
339 Status |= RtlAppendUnicodeToString(&ControllerRootRegName, L"\\");
340 Status |= RtlAppendUnicodeStringToString(&ControllerRootRegName, &TempString);
341
342 /* Something messed up */
343 if (!NT_SUCCESS(Status)) break;
344
345 /* Open the Registry Key */
348 &ControllerRootRegName,
350 NULL,
351 NULL);
352
353 Status = ZwOpenKey(&PeripheralKeyHandle, KEY_READ, &ObjectAttributes);
354
355 if (NT_SUCCESS(Status))
356 {
357 for (PeripheralLoop = 0; PeripheralLoop < 3; PeripheralLoop++)
358 {
359 /* Identifier String First */
360 RtlInitUnicodeString(&PeripheralString, Strings[PeripheralLoop]);
361
362 /* How much buffer space */
363 Status = ZwQueryValueKey(PeripheralKeyHandle, &PeripheralString, KeyValueFullInformation, NULL, 0, &LenKeyFullInformation);
364
366 {
367 PeripheralInformation[PeripheralLoop] = NULL;
368 continue;
369 }
370
371 /* Allocate it */
372 PeripheralInformation[PeripheralLoop] = ExAllocatePoolWithTag(PagedPool, LenKeyFullInformation, TAG_IO_RESOURCE);
373
374 /* Get the Information */
375 Status = ZwQueryValueKey(PeripheralKeyHandle, &PeripheralString, KeyValueFullInformation, PeripheralInformation[PeripheralLoop], LenKeyFullInformation, &LenKeyFullInformation);
376 }
377
378 /* Clean Up */
379 ZwClose(PeripheralKeyHandle);
380 PeripheralKeyHandle = NULL;
381
382 /* We now have everything the caller could possibly want */
383 if (NT_SUCCESS(Status))
384 {
385 Status = Query->CalloutRoutine(
386 Query->Context,
387 &ControllerRootRegName,
388 *Query->BusType,
389 Bus,
391 *Query->ControllerType,
392 ControllerNumber,
393 ControllerInformation,
394 *Query->PeripheralType,
395 PeripheralNumber,
396 PeripheralInformation);
397 }
398
399 /* Free the allocated memory */
400 for (PeripheralLoop = 0; PeripheralLoop < 3; PeripheralLoop++)
401 {
402 if (PeripheralInformation[PeripheralLoop])
403 {
404 ExFreePoolWithTag(PeripheralInformation[PeripheralLoop], TAG_IO_RESOURCE);
405 PeripheralInformation[PeripheralLoop] = NULL;
406 }
407 }
408
409 /* Something Messed up */
410 if (!NT_SUCCESS(Status)) break;
411 }
412 }
413
414EndLoop:
415 /* Free the allocated memory */
416 for (ControllerLoop = 0; ControllerLoop < 3; ControllerLoop++)
417 {
418 if (ControllerInformation[ControllerLoop])
419 {
420 ExFreePoolWithTag(ControllerInformation[ControllerLoop], TAG_IO_RESOURCE);
421 ControllerInformation[ControllerLoop] = NULL;
422 }
423 }
424
425 /* Something Messed up */
426 if (!NT_SUCCESS(Status)) break;
427 }
428
429 return Status;
430}
PWSTR ArcTypes[42]
Definition: iorsrce.c:34
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)

Referenced by IopQueryBusDescription().

◆ IopStoreSystemPartitionInformation()

VOID NTAPI IopStoreSystemPartitionInformation ( IN PUNICODE_STRING  NtSystemPartitionDeviceName,
IN PUNICODE_STRING  OsLoaderPathName 
)

Definition at line 697 of file iorsrce.c.

699{
703 HANDLE LinkHandle, RegistryHandle, KeyHandle;
704 WCHAR LinkTargetBuffer[256];
705 UNICODE_STRING CmRegistryMachineSystemName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM");
706
707 ASSERT(NtSystemPartitionDeviceName->MaximumLength >= NtSystemPartitionDeviceName->Length + sizeof(WCHAR));
708 ASSERT(NtSystemPartitionDeviceName->Buffer[NtSystemPartitionDeviceName->Length / sizeof(WCHAR)] == UNICODE_NULL);
709 ASSERT(OsLoaderPathName->MaximumLength >= OsLoaderPathName->Length + sizeof(WCHAR));
710 ASSERT(OsLoaderPathName->Buffer[OsLoaderPathName->Length / sizeof(WCHAR)] == UNICODE_NULL);
711
712 /* First define needed stuff to open NtSystemPartitionDeviceName symbolic link */
714 NtSystemPartitionDeviceName,
716 NULL,
717 NULL);
718
719 /* Open NtSystemPartitionDeviceName symbolic link */
720 Status = ZwOpenSymbolicLinkObject(&LinkHandle,
723 if (!NT_SUCCESS(Status))
724 {
725 DPRINT("Failed to open symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName, Status);
726 return;
727 }
728
729 /* Prepare the string that will receive where symbolic link points to */
730 LinkTarget.Length = 0;
731 /* We will zero the end of the string after having received it */
732 LinkTarget.MaximumLength = sizeof(LinkTargetBuffer) - sizeof(UNICODE_NULL);
733 LinkTarget.Buffer = LinkTargetBuffer;
734
735 /* Query target */
736 Status = ZwQuerySymbolicLinkObject(LinkHandle,
737 &LinkTarget,
738 NULL);
739
740 /* We are done with symbolic link */
741 ObCloseHandle(LinkHandle, KernelMode);
742
743 if (!NT_SUCCESS(Status))
744 {
745 DPRINT("Failed querying symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName, Status);
746 return;
747 }
748
749 /* As promised, we zero the end */
751
752 /* Open registry to save data (HKLM\SYSTEM) */
753 Status = IopOpenRegistryKeyEx(&RegistryHandle,
754 NULL,
755 &CmRegistryMachineSystemName,
757 if (!NT_SUCCESS(Status))
758 {
759 DPRINT("Failed to open HKLM\\SYSTEM, Status=%lx\n", Status);
760 return;
761 }
762
763 /* Open or create the Setup subkey where we'll store in */
765
767 RegistryHandle,
768 &KeyName,
771 NULL);
772
773 /* We're done with HKLM\SYSTEM */
774 ObCloseHandle(RegistryHandle, KernelMode);
775
776 if (!NT_SUCCESS(Status))
777 {
778 DPRINT("Failed opening/creating Setup key, Status=%lx\n", Status);
779 return;
780 }
781
782 /* Prepare first data writing... */
783 RtlInitUnicodeString(&KeyName, L"SystemPartition");
784
785 /* Write SystemPartition value which is the target of the symbolic link */
786 Status = ZwSetValueKey(KeyHandle,
787 &KeyName,
788 0,
789 REG_SZ,
791 LinkTarget.Length + sizeof(WCHAR));
792 if (!NT_SUCCESS(Status))
793 {
794 DPRINT("Failed writing SystemPartition value, Status=%lx\n", Status);
795 }
796
797 /* Prepare for second data writing... */
798 RtlInitUnicodeString(&KeyName, L"OsLoaderPath");
799
800 /* Remove trailing slash if any (one slash only excepted) */
801 if (OsLoaderPathName->Length > sizeof(WCHAR) &&
802 OsLoaderPathName->Buffer[(OsLoaderPathName->Length / sizeof(WCHAR)) - 1] == OBJ_NAME_PATH_SEPARATOR)
803 {
804 OsLoaderPathName->Length -= sizeof(WCHAR);
805 OsLoaderPathName->Buffer[OsLoaderPathName->Length / sizeof(WCHAR)] = UNICODE_NULL;
806 }
807
808 /* Then, write down data */
809 Status = ZwSetValueKey(KeyHandle,
810 &KeyName,
811 0,
812 REG_SZ,
813 OsLoaderPathName->Buffer,
814 OsLoaderPathName->Length + sizeof(UNICODE_NULL));
815 if (!NT_SUCCESS(Status))
816 {
817 DPRINT("Failed writing OsLoaderPath value, Status=%lx\n", Status);
818 }
819
820 /* We're finally done! */
822}
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define REG_SZ
Definition: layer.c:22
#define ASSERT(a)
Definition: mode.c:44
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define SYMBOLIC_LINK_QUERY
Definition: nt_native.h:1265
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:1455
NTSTATUS NTAPI IopCreateRegistryKeyEx(OUT PHANDLE Handle, IN HANDLE BaseHandle OPTIONAL, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
#define DPRINT
Definition: sndvol32.h:71
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Inout_ PUNICODE_STRING LinkTarget
Definition: zwfuncs.h:292

Referenced by IopCreateArcNames(), and IopCreateArcNamesDisk().

◆ IoQueryDeviceDescription()

NTSTATUS NTAPI IoQueryDeviceDescription ( PINTERFACE_TYPE BusType  OPTIONAL,
PULONG BusNumber  OPTIONAL,
PCONFIGURATION_TYPE ControllerType  OPTIONAL,
PULONG ControllerNumber  OPTIONAL,
PCONFIGURATION_TYPE PeripheralType  OPTIONAL,
PULONG PeripheralNumber  OPTIONAL,
PIO_QUERY_DEVICE_ROUTINE  CalloutRoutine,
PVOID  Context 
)

Definition at line 1020 of file iorsrce.c.

1028{
1030 ULONG BusLoopNumber = -1; /* Root Bus */
1032 UNICODE_STRING RootRegKey;
1033 HANDLE RootRegHandle;
1035
1036 /* Set up the String */
1037 RootRegKey.Length = 0;
1038 RootRegKey.MaximumLength = 2048;
1040 RtlAppendUnicodeToString(&RootRegKey, L"\\REGISTRY\\MACHINE\\HARDWARE\\DESCRIPTION\\SYSTEM");
1041
1042 /* Open a handle to the Root Registry Key */
1045 &RootRegKey,
1047 NULL,
1048 NULL);
1049
1050 Status = ZwOpenKey(&RootRegHandle, KEY_READ, &ObjectAttributes);
1051
1052 if (NT_SUCCESS(Status))
1053 {
1054 /* Use a helper function to loop though this key and get the info */
1055 Query.BusType = BusType;
1056 Query.BusNumber = BusNumber;
1057 Query.ControllerType = ControllerType;
1058 Query.ControllerNumber = ControllerNumber;
1059 Query.PeripheralType = PeripheralType;
1060 Query.PeripheralNumber = PeripheralNumber;
1061 Query.CalloutRoutine = CalloutRoutine;
1062 Query.Context = Context;
1063 Status = IopQueryBusDescription(&Query, RootRegKey, RootRegHandle, &BusLoopNumber, TRUE);
1064
1065 /* Close registry */
1066 ZwClose(RootRegHandle);
1067 }
1068
1069 /* Free Memory */
1071
1072 return Status;
1073}
#define TRUE
Definition: types.h:120
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:159

Referenced by AddControllers(), FdcFdoQueryBusRelations(), and SpiCreatePortConfig().

◆ IoReportHalResourceUsage()

NTSTATUS NTAPI IoReportHalResourceUsage ( PUNICODE_STRING  HalDescription,
PCM_RESOURCE_LIST  RawList,
PCM_RESOURCE_LIST  TranslatedList,
ULONG  ListSize 
)

Definition at line 1079 of file iorsrce.c.

1098{
1103 HANDLE ResourcemapKey;
1104 HANDLE HalKey;
1106
1107 /* Open/Create 'RESOURCEMAP' key. */
1109 L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP");
1111 &Name,
1113 0,
1114 NULL);
1115 Status = ZwCreateKey(&ResourcemapKey,
1118 0,
1119 NULL,
1121 &Disposition);
1122 if (!NT_SUCCESS(Status))
1123 return(Status);
1124
1125 /* Open/Create 'Hardware Abstraction Layer' key */
1127 L"Hardware Abstraction Layer");
1129 &Name,
1131 ResourcemapKey,
1132 NULL);
1133 Status = ZwCreateKey(&HalKey,
1136 0,
1137 NULL,
1139 &Disposition);
1140 ZwClose(ResourcemapKey);
1141 if (!NT_SUCCESS(Status))
1142 return(Status);
1143
1144 /* Create 'HalDescription' key */
1146 HalDescription,
1148 HalKey,
1149 NULL);
1150 Status = ZwCreateKey(&DescriptionKey,
1153 0,
1154 NULL,
1156 &Disposition);
1157 ZwClose(HalKey);
1158 if (!NT_SUCCESS(Status))
1159 return(Status);
1160
1161 /* Add '.Raw' value. */
1163 L".Raw");
1164 Status = ZwSetValueKey(DescriptionKey,
1165 &Name,
1166 0,
1168 RawList,
1169 ListSize);
1170 if (!NT_SUCCESS(Status))
1171 {
1173 return(Status);
1174 }
1175
1176 /* Add '.Translated' value. */
1178 L".Translated");
1179 Status = ZwSetValueKey(DescriptionKey,
1180 &Name,
1181 0,
1183 TranslatedList,
1184 ListSize);
1186
1187 return(Status);
1188}
struct NameRec_ * Name
Definition: cdprocs.h:460
static const WCHAR DescriptionKey[]
Definition: install.c:37
#define OBJ_OPENIF
Definition: winternl.h:229
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060

Referenced by HalpReportResourceUsage().

◆ IoReportResourceUsage()

NTSTATUS NTAPI IoReportResourceUsage ( PUNICODE_STRING  DriverClassName,
PDRIVER_OBJECT  DriverObject,
PCM_RESOURCE_LIST  DriverList,
ULONG  DriverListSize,
PDEVICE_OBJECT  DeviceObject,
PCM_RESOURCE_LIST  DeviceList,
ULONG  DeviceListSize,
BOOLEAN  OverrideConflict,
PBOOLEAN  ConflictDetected 
)

Definition at line 839 of file iorsrce.c.

870{
873
874 DPRINT1("IoReportResourceUsage is halfplemented!\n");
875
876 if (!DriverList && !DeviceList)
878
879 if (DeviceList)
881 else
882 ResourceList = DriverList;
883
886 {
887 *ConflictDetected = TRUE;
888
889 if (!OverrideConflict)
890 {
891 DPRINT1("Denying an attempt to claim resources currently in use by another device!\n");
893 }
894 else
895 {
896 DPRINT1("Proceeding with conflicting resources\n");
897 }
898 }
899 else if (!NT_SUCCESS(Status))
900 {
901 return Status;
902 }
903
904 /* TODO: Claim resources in registry */
905
906 *ConflictDetected = FALSE;
907
908 return STATUS_SUCCESS;
909}
#define FALSE
Definition: types.h:117
PDEVICE_LIST DeviceList
Definition: utils.c:27
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1255
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309

Variable Documentation

◆ _SystemConfigurationInformation

CONFIGURATION_INFORMATION _SystemConfigurationInformation = { 0, 0, 0, 0, 0, 0, 0, FALSE, FALSE, 0, 0 }
static

Definition at line 20 of file iorsrce.c.

Referenced by IoGetConfigurationInformation().

◆ ArcTypes

PWSTR ArcTypes[42]

Definition at line 34 of file iorsrce.c.

Referenced by IopQueryDeviceDescription().