mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:03:00 +00:00
[NTOS:PNP]
- Move generation of the device instance path into its own function svn path=/trunk/; revision=74024
This commit is contained in:
parent
ebc3d8bfbc
commit
240072132d
1 changed files with 127 additions and 108 deletions
|
@ -1847,6 +1847,128 @@ IopQueryCompatibleIds(PDEVICE_NODE DeviceNode,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
IopCreateDeviceInstancePath(
|
||||||
|
_In_ PDEVICE_NODE DeviceNode,
|
||||||
|
_Out_ PUNICODE_STRING InstancePathU)
|
||||||
|
{
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
PWSTR InformationString;
|
||||||
|
WCHAR InstancePath[MAX_PATH];
|
||||||
|
IO_STACK_LOCATION Stack;
|
||||||
|
NTSTATUS Status;
|
||||||
|
UNICODE_STRING ParentIdPrefix = { 0, 0, NULL };
|
||||||
|
DEVICE_CAPABILITIES DeviceCapabilities;
|
||||||
|
|
||||||
|
DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
|
||||||
|
|
||||||
|
Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
|
||||||
|
Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
|
||||||
|
&IoStatusBlock,
|
||||||
|
IRP_MN_QUERY_ID,
|
||||||
|
&Stack);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("IopInitiatePnpIrp() failed (Status %x)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy the device id string */
|
||||||
|
InformationString = (PWSTR)IoStatusBlock.Information;
|
||||||
|
wcscpy(InstancePath, InformationString);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME: Check for valid characters, if there is invalid characters
|
||||||
|
* then bugcheck.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ExFreePoolWithTag(InformationString, 0);
|
||||||
|
|
||||||
|
DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after enumeration)\n");
|
||||||
|
|
||||||
|
Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This bit is only check after enumeration */
|
||||||
|
if (DeviceCapabilities.HardwareDisabled)
|
||||||
|
{
|
||||||
|
/* FIXME: Cleanup device */
|
||||||
|
DeviceNode->Flags |= DNF_DISABLED;
|
||||||
|
return STATUS_PLUGPLAY_NO_DEVICE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DeviceNode->Flags &= ~DNF_DISABLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DeviceCapabilities.UniqueID)
|
||||||
|
{
|
||||||
|
/* Device has not a unique ID. We need to prepend parent bus unique identifier */
|
||||||
|
DPRINT("Instance ID is not unique\n");
|
||||||
|
Status = IopGetParentIdPrefix(DeviceNode, &ParentIdPrefix);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("Sending IRP_MN_QUERY_ID.BusQueryInstanceID to device stack\n");
|
||||||
|
|
||||||
|
Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
|
||||||
|
Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
|
||||||
|
&IoStatusBlock,
|
||||||
|
IRP_MN_QUERY_ID,
|
||||||
|
&Stack);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
InformationString = (PWSTR)IoStatusBlock.Information;
|
||||||
|
|
||||||
|
/* Append the instance id string */
|
||||||
|
wcscat(InstancePath, L"\\");
|
||||||
|
if (ParentIdPrefix.Length > 0)
|
||||||
|
{
|
||||||
|
/* Add information from parent bus device to InstancePath */
|
||||||
|
wcscat(InstancePath, ParentIdPrefix.Buffer);
|
||||||
|
if (InformationString && *InformationString)
|
||||||
|
{
|
||||||
|
wcscat(InstancePath, L"&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (InformationString)
|
||||||
|
{
|
||||||
|
wcscat(InstancePath, InformationString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME: Check for valid characters, if there is invalid characters
|
||||||
|
* then bugcheck
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (InformationString)
|
||||||
|
{
|
||||||
|
ExFreePoolWithTag(InformationString, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
|
||||||
|
}
|
||||||
|
RtlFreeUnicodeString(&ParentIdPrefix);
|
||||||
|
|
||||||
|
if (!RtlCreateUnicodeString(InstancePathU, InstancePath))
|
||||||
|
{
|
||||||
|
DPRINT1("RtlCreateUnicodeString failed\n");
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IopActionInterrogateDeviceStack
|
* IopActionInterrogateDeviceStack
|
||||||
|
@ -1871,16 +1993,13 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
PWSTR InformationString;
|
PWSTR InformationString;
|
||||||
PDEVICE_NODE ParentDeviceNode;
|
PDEVICE_NODE ParentDeviceNode;
|
||||||
WCHAR InstancePath[MAX_PATH];
|
|
||||||
IO_STACK_LOCATION Stack;
|
IO_STACK_LOCATION Stack;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG RequiredLength;
|
ULONG RequiredLength;
|
||||||
LCID LocaleId;
|
LCID LocaleId;
|
||||||
HANDLE InstanceKey = NULL;
|
HANDLE InstanceKey = NULL;
|
||||||
UNICODE_STRING ValueName;
|
UNICODE_STRING ValueName;
|
||||||
UNICODE_STRING ParentIdPrefix = { 0, 0, NULL };
|
|
||||||
UNICODE_STRING InstancePathU;
|
UNICODE_STRING InstancePathU;
|
||||||
DEVICE_CAPABILITIES DeviceCapabilities;
|
|
||||||
PDEVICE_OBJECT OldDeviceObject;
|
PDEVICE_OBJECT OldDeviceObject;
|
||||||
|
|
||||||
DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
|
DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
|
||||||
|
@ -1928,118 +2047,18 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
|
||||||
* return STATUS_SUCCESS.
|
* return STATUS_SUCCESS.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
|
Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
|
||||||
|
|
||||||
Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
|
|
||||||
Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
|
|
||||||
&IoStatusBlock,
|
|
||||||
IRP_MN_QUERY_ID,
|
|
||||||
&Stack);
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("IopInitiatePnpIrp() failed (Status %x)\n", Status);
|
if (Status != STATUS_PLUGPLAY_NO_DEVICE)
|
||||||
|
{
|
||||||
|
DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
|
||||||
|
}
|
||||||
|
|
||||||
/* We have to return success otherwise we abort the traverse operation */
|
/* We have to return success otherwise we abort the traverse operation */
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the device id string */
|
|
||||||
InformationString = (PWSTR)IoStatusBlock.Information;
|
|
||||||
wcscpy(InstancePath, InformationString);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: Check for valid characters, if there is invalid characters
|
|
||||||
* then bugcheck.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ExFreePoolWithTag(InformationString, 0);
|
|
||||||
|
|
||||||
DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after enumeration)\n");
|
|
||||||
|
|
||||||
Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
|
|
||||||
|
|
||||||
/* We have to return success otherwise we abort the traverse operation */
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This bit is only check after enumeration */
|
|
||||||
if (DeviceCapabilities.HardwareDisabled)
|
|
||||||
{
|
|
||||||
/* FIXME: Cleanup device */
|
|
||||||
DeviceNode->Flags |= DNF_DISABLED;
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeviceNode->Flags &= ~DNF_DISABLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DeviceCapabilities.UniqueID)
|
|
||||||
{
|
|
||||||
/* Device has not a unique ID. We need to prepend parent bus unique identifier */
|
|
||||||
DPRINT("Instance ID is not unique\n");
|
|
||||||
Status = IopGetParentIdPrefix(DeviceNode, &ParentIdPrefix);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status);
|
|
||||||
|
|
||||||
/* We have to return success otherwise we abort the traverse operation */
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("Sending IRP_MN_QUERY_ID.BusQueryInstanceID to device stack\n");
|
|
||||||
|
|
||||||
Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
|
|
||||||
Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
|
|
||||||
&IoStatusBlock,
|
|
||||||
IRP_MN_QUERY_ID,
|
|
||||||
&Stack);
|
|
||||||
if (NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
InformationString = (PWSTR)IoStatusBlock.Information;
|
|
||||||
|
|
||||||
/* Append the instance id string */
|
|
||||||
wcscat(InstancePath, L"\\");
|
|
||||||
if (ParentIdPrefix.Length > 0)
|
|
||||||
{
|
|
||||||
/* Add information from parent bus device to InstancePath */
|
|
||||||
wcscat(InstancePath, ParentIdPrefix.Buffer);
|
|
||||||
if (InformationString && *InformationString)
|
|
||||||
{
|
|
||||||
wcscat(InstancePath, L"&");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (InformationString)
|
|
||||||
{
|
|
||||||
wcscat(InstancePath, InformationString);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: Check for valid characters, if there is invalid characters
|
|
||||||
* then bugcheck
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (InformationString)
|
|
||||||
{
|
|
||||||
ExFreePoolWithTag(InformationString, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status);
|
|
||||||
}
|
|
||||||
RtlFreeUnicodeString(&ParentIdPrefix);
|
|
||||||
|
|
||||||
if (!RtlCreateUnicodeString(&InstancePathU, InstancePath))
|
|
||||||
{
|
|
||||||
DPRINT("No resources\n");
|
|
||||||
/* FIXME: Cleanup and disable device */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Verify that this is not a duplicate */
|
/* Verify that this is not a duplicate */
|
||||||
OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
|
OldDeviceObject = IopGetDeviceObjectFromDeviceInstance(&InstancePathU);
|
||||||
if (OldDeviceObject != NULL)
|
if (OldDeviceObject != NULL)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue