Index: ntoskrnl/io/pnpmgr/pnpmgr.c =================================================================== --- ntoskrnl/io/pnpmgr/pnpmgr.c (revision 74033) +++ ntoskrnl/io/pnpmgr/pnpmgr.c (working copy) @@ -1867,22 +1867,30 @@ &IoStatusBlock, IRP_MN_QUERY_ID, &Stack); - if (!NT_SUCCESS(Status)) + + InformationString = (PWSTR)IoStatusBlock.Information; + + if (NT_SUCCESS(Status)) { - DPRINT1("IopInitiatePnpIrp() failed (Status %x)\n", Status); - return Status; + // FIXME checks: if (InformationString == NULL || LengthOfInformationString == 0) + + /* Copy the device id string */ + wcscpy(InstancePath, InformationString); } - /* Copy the device id string */ - InformationString = (PWSTR)IoStatusBlock.Information; - wcscpy(InstancePath, InformationString); + /* Cleanup device id string */ + if (InformationString) + { + ExFreePoolWithTag(InformationString, 0); + } - /* - * FIXME: Check for valid characters, if there is invalid characters - * then bugcheck. - */ + if (!NT_SUCCESS(Status)) + { + DPRINT1("IopInitiatePnpIrp(BusQueryDeviceID) failed (Status %x)\n", Status); - ExFreePoolWithTag(InformationString, 0); + /* We have to return success otherwise we abort the traverse operation */ + return STATUS_SUCCESS; + } DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after enumeration)\n"); @@ -1889,7 +1897,7 @@ Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities); if (!NT_SUCCESS(Status)) { - DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status); + DPRINT1("IopQueryDeviceCapabilities() failed (Status 0x%08lx)\n", Status); return Status; } @@ -1905,18 +1913,6 @@ 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; @@ -1924,42 +1920,122 @@ &IoStatusBlock, IRP_MN_QUERY_ID, &Stack); - if (NT_SUCCESS(Status)) + + InformationString = (PWSTR)IoStatusBlock.Information; + // FIXME checks: if (InformationString == NULL || LengthOfInformationString == 0) - it need? + + if (!NT_SUCCESS(Status)) { - InformationString = (PWSTR)IoStatusBlock.Information; + DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %x)\n", Status); + } - /* Append the instance id string */ - wcscat(InstancePath, L"\\"); - if (ParentIdPrefix.Length > 0) + if (!DeviceCapabilities.UniqueID) + { + /* Device has not a unique ID. We need to prepend parent bus unique identifier */ + DPRINT("Instance ID is not unique\n"); + + if (!(DeviceNode->Flags & DNF_HAS_PROBLEM) || + DeviceNode->Problem != CM_PROB_INVALID_DATA) { + Status = IopGetParentIdPrefix(DeviceNode, &ParentIdPrefix); + + if (!ParentIdPrefix.Length) + { + DPRINT1("IopGetParentIdPrefix() - null length for ParentIdPrefix\n"); + ASSERT(!NT_SUCCESS(Status)); + } + + if (!NT_SUCCESS(Status)) + { + DPRINT1("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status); + + if (InformationString) + { + ExFreePoolWithTag(InformationString, 0); + } + + /* We have to return success otherwise we abort the traverse operation */ + return STATUS_SUCCESS; + } + + /* Create globally unique Id */ + /* Add information from parent bus device to InstancePath */ + wcscat(InstancePath, L"\\"); wcscat(InstancePath, ParentIdPrefix.Buffer); + + /* Append the instance id string */ if (InformationString && *InformationString) { wcscat(InstancePath, L"&"); + wcscat(InstancePath, InformationString); } } - if (InformationString) - { - wcscat(InstancePath, InformationString); - } + } + else if (Status == STATUS_NOT_SUPPORTED) + { + DeviceNode->Flags |= DNF_HAS_PROBLEM; + DeviceNode->Problem = CM_PROB_INVALID_DATA; - /* - * FIXME: Check for valid characters, if there is invalid characters - * then bugcheck - */ + /* See msdn "Device Node Status Flags". In RoS no this flag */ + //DeviceNode->Parent->Flags |= DNF_CHILD_WITH_INVALID_ID; - if (InformationString) + DPRINT1("Not valid InstanceID returned - %wZ\n", &DeviceNode->Parent->ServiceName); + ASSERT((Status != STATUS_NOT_SUPPORTED) || !DeviceCapabilities.UniqueID); + } + else + { + if (!(DeviceNode->Flags & DNF_HAS_PROBLEM) || + DeviceNode->Problem != CM_PROB_INVALID_DATA) { - ExFreePoolWithTag(InformationString, 0); + /* Append the instance id string */ + + if (InformationString) + { + wcscat(InstancePath, L"\\"); + wcscat(InstancePath, InformationString); + } } } - else + + if (InformationString) { - DPRINT("IopInitiatePnpIrp() failed (Status %x)\n", Status); + ExFreePoolWithTag(InformationString, 0); } - RtlFreeUnicodeString(&ParentIdPrefix); + if (!DeviceCapabilities.UniqueID) + { + RtlFreeUnicodeString(&ParentIdPrefix); + } + + if (!NT_SUCCESS(Status)) + { + if (!(DeviceNode->Flags & DNF_HAS_PROBLEM) || + DeviceNode->Problem != CM_PROB_INVALID_DATA) + { + DeviceNode->Flags |= DNF_HAS_PROBLEM; + + if (Status == STATUS_INSUFFICIENT_RESOURCES) + { + DeviceNode->Problem = CM_PROB_OUT_OF_MEMORY; + } + else + { + DeviceNode->Problem = CM_PROB_REGISTRY; + } + } + + DPRINT1("IopActionInterrogateDeviceStack failed - %x\n", Status); + + /* We have to return success otherwise we abort the traverse operation */ + return STATUS_SUCCESS; + } + + /* + * FIXME: Check InstancePath for valid characters, + * if there is invalid characters, then bugcheck + */ + if (!RtlCreateUnicodeString(InstancePathU, InstancePath)) { DPRINT1("RtlCreateUnicodeString failed\n");