- Trip trailing whitespace in Io/Pnp
svn path=/trunk/; revision=64906
PLIST_ENTRY ListHead, NextEntry;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR SourceString[54];
PLIST_ENTRY ListHead, NextEntry;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR SourceString[54];
//
// Scan memory descriptors
//
//
// Scan memory descriptors
//
MemoryDescriptor = CONTAINING_RECORD(NextEntry,
MEMORY_ALLOCATION_DESCRIPTOR,
ListEntry);
MemoryDescriptor = CONTAINING_RECORD(NextEntry,
MEMORY_ALLOCATION_DESCRIPTOR,
ListEntry);
//
// Needs to be a ROM/RAM descriptor
//
//
// Needs to be a ROM/RAM descriptor
//
//
NextEntry = NextEntry->Flink;
}
//
NextEntry = NextEntry->Flink;
}
//
// Setup the input buffer
//
//
// Setup the input buffer
//
RamdiskCreate.DiskGuid = RAMDISK_BOOTDISK_GUID;
RamdiskCreate.DriveLetter = L'C';
RamdiskCreate.Options.Fixed = TRUE;
RamdiskCreate.DiskGuid = RAMDISK_BOOTDISK_GUID;
RamdiskCreate.DriveLetter = L'C';
RamdiskCreate.Options.Fixed = TRUE;
//
// Check for commandline parameters
//
//
// Check for commandline parameters
//
// Make everything upper case
//
_strupr(CommandLine);
// Make everything upper case
//
_strupr(CommandLine);
//
// Check for offset parameter
//
//
// Check for offset parameter
//
RamdiskCreate.DiskOffset = atol(OffsetValue + 1);
}
}
RamdiskCreate.DiskOffset = atol(OffsetValue + 1);
}
}
//
// Reduce the disk length
//
RamdiskCreate.DiskLength.QuadPart -= RamdiskCreate.DiskOffset;
//
// Reduce the disk length
//
RamdiskCreate.DiskLength.QuadPart -= RamdiskCreate.DiskOffset;
//
// Check for length parameter
//
//
// Check for length parameter
//
//
// Setup object attributes
//
//
// Setup object attributes
//
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
NULL,
NULL);
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
NULL,
NULL);
//
// Open a handle to the driver
//
//
// Open a handle to the driver
//
//
// Send create command
//
//
// Send create command
//
//
// Convert the GUID
//
//
// Convert the GUID
//
//
// Build the symbolic link name and target
//
//
// Build the symbolic link name and target
//
SymbolicLinkName.Length = 38;
SymbolicLinkName.MaximumLength = 38 + sizeof(UNICODE_NULL);
SymbolicLinkName.Buffer = L"\\ArcName\\ramdisk(0)";
SymbolicLinkName.Length = 38;
SymbolicLinkName.MaximumLength = 38 + sizeof(UNICODE_NULL);
SymbolicLinkName.Buffer = L"\\ArcName\\ramdisk(0)";
//
// Create the symbolic link
//
//
// Create the symbolic link
//
TrackingBlock = ExAllocatePoolWithTag(NonPagedPool, sizeof(IO_REMOVE_LOCK_TRACKING_BLOCK), Lock->Dbg.AllocateTag);
if (!TrackingBlock)
{
TrackingBlock = ExAllocatePoolWithTag(NonPagedPool, sizeof(IO_REMOVE_LOCK_TRACKING_BLOCK), Lock->Dbg.AllocateTag);
if (!TrackingBlock)
{
- /* Keep count of failures for lock release and missing tags */
+ /* Keep count of failures for lock release and missing tags */
InterlockedIncrement(&(Lock->Dbg.LowMemoryCount));
}
else
InterlockedIncrement(&(Lock->Dbg.LowMemoryCount));
}
else
* name lengths than MAXUSHORT, we can't use
* them, because we have to return this in an UNICODE_STRING
* that stores length on USHORT.
* name lengths than MAXUSHORT, we can't use
* them, because we have to return this in an UNICODE_STRING
* that stores length on USHORT.
Length = VolumePath.MultiSzLength + sizeof(VolumePath);
if (Length > MAXUSHORT)
{
Length = VolumePath.MultiSzLength + sizeof(VolumePath);
if (Length > MAXUSHORT)
{
UNICODE_STRING GroupString =
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ServiceGroupOrder");
UNICODE_STRING GroupString =
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ServiceGroupOrder");
/* ReactOS HACK for SETUPLDR */
if (KeLoaderBlock->SetupLdrBlock)
{
/* ReactOS HACK for SETUPLDR */
if (KeLoaderBlock->SetupLdrBlock)
{
PiInitGroupOrderTable = (PVOID)0xBABEB00B;
return STATUS_SUCCESS;
}
PiInitGroupOrderTable = (PVOID)0xBABEB00B;
return STATUS_SUCCESS;
}
/* Open the registry key */
Status = IopOpenRegistryKeyEx(&KeyHandle,
NULL,
/* Open the registry key */
Status = IopOpenRegistryKeyEx(&KeyHandle,
NULL,
/* Get the list */
Status = IopGetRegistryValue(KeyHandle, L"List", &KeyValueInformation);
ZwClose(KeyHandle);
/* Get the list */
Status = IopGetRegistryValue(KeyHandle, L"List", &KeyValueInformation);
ZwClose(KeyHandle);
/* Make sure we got it */
if (NT_SUCCESS(Status))
{
/* Make sure we got it */
if (NT_SUCCESS(Status))
{
Status = PnpRegMultiSzToUnicodeStrings(KeyValueInformation,
&GroupTable,
&Count);
Status = PnpRegMultiSzToUnicodeStrings(KeyValueInformation,
&GroupTable,
&Count);
/* Cache it for later */
PiInitGroupOrderTable = GroupTable;
PiInitGroupOrderTableCount = (USHORT)Count;
/* Cache it for later */
PiInitGroupOrderTable = GroupTable;
PiInitGroupOrderTableCount = (USHORT)Count;
/* Fail */
Status = STATUS_UNSUCCESSFUL;
}
/* Fail */
Status = STATUS_UNSUCCESSFUL;
}
/* Free the information */
ExFreePool(KeyValueInformation);
}
}
/* Free the information */
ExFreePool(KeyValueInformation);
}
}
/* Return status */
return Status;
}
/* Return status */
return Status;
}
PVOID Buffer;
UNICODE_STRING Group;
PAGED_CODE();
PVOID Buffer;
UNICODE_STRING Group;
PAGED_CODE();
/* Make sure we have a cache */
if (!PiInitGroupOrderTable) return -1;
/* Make sure we have a cache */
if (!PiInitGroupOrderTable) return -1;
/* If we don't have a handle, the rest is easy -- return the count */
if (!ServiceHandle) return PiInitGroupOrderTableCount + 1;
/* If we don't have a handle, the rest is easy -- return the count */
if (!ServiceHandle) return PiInitGroupOrderTableCount + 1;
/* Otherwise, get the group value */
Status = IopGetRegistryValue(ServiceHandle, L"Group", &KeyValueInformation);
if (!NT_SUCCESS(Status)) return PiInitGroupOrderTableCount;
/* Otherwise, get the group value */
Status = IopGetRegistryValue(ServiceHandle, L"Group", &KeyValueInformation);
if (!NT_SUCCESS(Status)) return PiInitGroupOrderTableCount;
/* Make sure we have a valid string */
ASSERT(KeyValueInformation->Type == REG_SZ);
ASSERT(KeyValueInformation->DataLength);
/* Make sure we have a valid string */
ASSERT(KeyValueInformation->Type == REG_SZ);
ASSERT(KeyValueInformation->DataLength);
/* Convert to unicode string */
Buffer = (PVOID)((ULONG_PTR)KeyValueInformation + KeyValueInformation->DataOffset);
PnpRegSzToString(Buffer, KeyValueInformation->DataLength, &Group.Length);
Group.MaximumLength = (USHORT)KeyValueInformation->DataLength;
Group.Buffer = Buffer;
/* Convert to unicode string */
Buffer = (PVOID)((ULONG_PTR)KeyValueInformation + KeyValueInformation->DataOffset);
PnpRegSzToString(Buffer, KeyValueInformation->DataLength, &Group.Length);
Group.MaximumLength = (USHORT)KeyValueInformation->DataLength;
Group.Buffer = Buffer;
/* Loop the groups */
for (i = 0; i < PiInitGroupOrderTableCount; i++)
{
/* Try to find a match */
if (RtlEqualUnicodeString(&Group, &PiInitGroupOrderTable[i], TRUE)) break;
}
/* Loop the groups */
for (i = 0; i < PiInitGroupOrderTableCount; i++)
{
/* Try to find a match */
if (RtlEqualUnicodeString(&Group, &PiInitGroupOrderTable[i], TRUE)) break;
}
/* We're done */
ExFreePool(KeyValueInformation);
return i;
/* We're done */
ExFreePool(KeyValueInformation);
return i;
UNICODE_STRING GroupString =
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ServiceGroupOrder");
UNICODE_STRING GroupString =
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ServiceGroupOrder");
/* Open the key */
Status = IopOpenRegistryKeyEx(&KeyHandle, NULL, &GroupString, KEY_READ);
if (!NT_SUCCESS(Status)) goto Quickie;
/* Open the key */
Status = IopOpenRegistryKeyEx(&KeyHandle, NULL, &GroupString, KEY_READ);
if (!NT_SUCCESS(Status)) goto Quickie;
/* Read the group */
Status = IopGetRegistryValue(ServiceHandle, L"Group", &KeyValueInformation);
if (!NT_SUCCESS(Status)) goto Quickie;
/* Read the group */
Status = IopGetRegistryValue(ServiceHandle, L"Group", &KeyValueInformation);
if (!NT_SUCCESS(Status)) goto Quickie;
/* Make sure we have a group */
if ((KeyValueInformation->Type == REG_SZ) &&
(KeyValueInformation->DataLength))
/* Make sure we have a group */
if ((KeyValueInformation->Type == REG_SZ) &&
(KeyValueInformation->DataLength))
Tag = *(PULONG)((ULONG_PTR)KeyValueInformationTag +
KeyValueInformationTag->DataOffset);
}
Tag = *(PULONG)((ULONG_PTR)KeyValueInformationTag +
KeyValueInformationTag->DataOffset);
}
/* We can get rid of this now */
ExFreePool(KeyValueInformationTag);
/* We can get rid of this now */
ExFreePool(KeyValueInformationTag);
Status = IopGetRegistryValue(KeyHandle,
Group.Buffer,
&KeyValueInformationGroupOrderList);
Status = IopGetRegistryValue(KeyHandle,
Group.Buffer,
&KeyValueInformationGroupOrderList);
/* We can get rid of this now */
Quickie:
if (KeyValueInformation) ExFreePool(KeyValueInformation);
if (KeyHandle) NtClose(KeyHandle);
if (!NT_SUCCESS(Status)) return -1;
/* We can get rid of this now */
Quickie:
if (KeyValueInformation) ExFreePool(KeyValueInformation);
if (KeyHandle) NtClose(KeyHandle);
if (!NT_SUCCESS(Status)) return -1;
/* We're on the success path -- validate the tag order*/
if ((KeyValueInformationGroupOrderList->Type == REG_BINARY) &&
(KeyValueInformationGroupOrderList->DataLength))
/* We're on the success path -- validate the tag order*/
if ((KeyValueInformationGroupOrderList->Type == REG_BINARY) &&
(KeyValueInformationGroupOrderList->DataLength))
/* Get the order array */
GroupOrder = (PULONG)((ULONG_PTR)KeyValueInformationGroupOrderList +
KeyValueInformationGroupOrderList->DataOffset);
/* Get the order array */
GroupOrder = (PULONG)((ULONG_PTR)KeyValueInformationGroupOrderList +
KeyValueInformationGroupOrderList->DataOffset);
/* Get the count */
Count = *GroupOrder;
ASSERT(((Count + 1) * sizeof(ULONG)) <=
KeyValueInformationGroupOrderList->DataLength);
/* Get the count */
Count = *GroupOrder;
ASSERT(((Count + 1) * sizeof(ULONG)) <=
KeyValueInformationGroupOrderList->DataLength);
/* Now loop each tag */
GroupOrder++;
for (i = 1; i <= Count; i++)
/* Now loop each tag */
GroupOrder++;
for (i = 1; i <= Count; i++)
/* Last buffer to free */
ExFreePool(KeyValueInformationGroupOrderList);
return i;
/* Last buffer to free */
ExFreePool(KeyValueInformationGroupOrderList);
return i;
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class");
PKEY_VALUE_FULL_INFORMATION KeyValueInformation = NULL;
PWCHAR Buffer;
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class");
PKEY_VALUE_FULL_INFORMATION KeyValueInformation = NULL;
PWCHAR Buffer;
/* Open enumeration root key */
Status = IopOpenRegistryKeyEx(&EnumRootKey,
NULL,
/* Open enumeration root key */
Status = IopOpenRegistryKeyEx(&EnumRootKey,
NULL,
DPRINT1("IopOpenRegistryKeyEx() failed with Status %08X\n", Status);
return Status;
}
DPRINT1("IopOpenRegistryKeyEx() failed with Status %08X\n", Status);
return Status;
}
/* Open instance subkey */
Status = IopOpenRegistryKeyEx(&SubKey,
EnumRootKey,
/* Open instance subkey */
Status = IopOpenRegistryKeyEx(&SubKey,
EnumRootKey,
DPRINT1("IopOpenRegistryKeyEx() failed with Status %08X\n", Status);
return Status;
}
DPRINT1("IopOpenRegistryKeyEx() failed with Status %08X\n", Status);
return Status;
}
/* Get class GUID */
Status = IopGetRegistryValue(SubKey,
REGSTR_VAL_CLASSGUID,
/* Get class GUID */
Status = IopGetRegistryValue(SubKey,
REGSTR_VAL_CLASSGUID,
PnpRegSzToString(Buffer, KeyValueInformation->DataLength, &ClassGuid.Length);
ClassGuid.MaximumLength = (USHORT)KeyValueInformation->DataLength;
ClassGuid.Buffer = Buffer;
PnpRegSzToString(Buffer, KeyValueInformation->DataLength, &ClassGuid.Length);
ClassGuid.MaximumLength = (USHORT)KeyValueInformation->DataLength;
ClassGuid.Buffer = Buffer;
/* Open the key */
Status = IopOpenRegistryKeyEx(&ControlKey,
NULL,
/* Open the key */
Status = IopOpenRegistryKeyEx(&ControlKey,
NULL,
/* Check if we made it till here */
if (ClassKey)
{
/* Check if we made it till here */
if (ClassKey)
{
ZwClose(PropertiesKey);
}
}
ZwClose(PropertiesKey);
}
}
/* Free the registry data */
ExFreePool(KeyValueInformation);
}
/* Free the registry data */
ExFreePool(KeyValueInformation);
}
/* Do ReactOS-style setup */
Status = IopAttachFilterDrivers(DeviceNode, TRUE);
if (!NT_SUCCESS(Status))
/* Do ReactOS-style setup */
Status = IopAttachFilterDrivers(DeviceNode, TRUE);
if (!NT_SUCCESS(Status))
IopRemoveDevice(DeviceNode);
return Status;
}
IopRemoveDevice(DeviceNode);
return Status;
}
Status = IopStartDevice(DeviceNode);
}
Status = IopStartDevice(DeviceNode);
}
/* Return status */
return Status;
}
/* Return status */
return Status;
}
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
UNICODE_STRING PnpManagerDriverName = RTL_CONSTANT_STRING(DRIVER_ROOT_NAME L"PnpManager");
PDEVICE_OBJECT Pdo;
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
UNICODE_STRING PnpManagerDriverName = RTL_CONSTANT_STRING(DRIVER_ROOT_NAME L"PnpManager");
PDEVICE_OBJECT Pdo;
/* Initialize locks and such */
KeInitializeSpinLock(&IopDeviceTreeLock);
/* Initialize locks and such */
KeInitializeSpinLock(&IopDeviceTreeLock);
/* Get the default interface */
PnpDefaultInterfaceType = IopDetermineDefaultInterfaceType();
/* Get the default interface */
PnpDefaultInterfaceType = IopDetermineDefaultInterfaceType();
/* Initialize arbiters */
Status = IopInitializeArbiters();
if (!NT_SUCCESS(Status)) return Status;
/* Initialize arbiters */
Status = IopInitializeArbiters();
if (!NT_SUCCESS(Status)) return Status;
/* Setup the group cache */
Status = PiInitCacheGroupInformation();
if (!NT_SUCCESS(Status)) return Status;
/* Setup the group cache */
Status = PiInitCacheGroupInformation();
if (!NT_SUCCESS(Status)) return Status;
/* Open the current control set */
Status = IopOpenRegistryKeyEx(&KeyHandle,
NULL,
/* Open the current control set */
Status = IopOpenRegistryKeyEx(&KeyHandle,
NULL,
REG_OPTION_NON_VOLATILE,
&Disposition);
if (!NT_SUCCESS(Status)) return Status;
REG_OPTION_NON_VOLATILE,
&Disposition);
if (!NT_SUCCESS(Status)) return Status;
/* Check if it's a new key */
if (Disposition == REG_CREATED_NEW_KEY)
{
/* FIXME: DACLs */
DPRINT1("Need to build DACL\n");
}
/* Check if it's a new key */
if (Disposition == REG_CREATED_NEW_KEY)
{
/* FIXME: DACLs */
DPRINT1("Need to build DACL\n");
}
/* Create the root key */
ParentHandle = EnumHandle;
RtlInitUnicodeString(&KeyName, REGSTR_KEY_ROOTENUM);
/* Create the root key */
ParentHandle = EnumHandle;
RtlInitUnicodeString(&KeyName, REGSTR_KEY_ROOTENUM);
NtClose(ParentHandle);
if (!NT_SUCCESS(Status)) return Status;
NtClose(EnumHandle);
NtClose(ParentHandle);
if (!NT_SUCCESS(Status)) return Status;
NtClose(EnumHandle);
/* Open the root key now */
RtlInitUnicodeString(&KeyName, L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
Status = IopOpenRegistryKeyEx(&EnumHandle,
/* Open the root key now */
RtlInitUnicodeString(&KeyName, L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
Status = IopOpenRegistryKeyEx(&EnumHandle,
DPRINT1("IoCreateDriverObject() failed\n");
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
}
DPRINT1("IoCreateDriverObject() failed\n");
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
}
/* Create the root PDO */
Status = IoCreateDevice(IopRootDriverObject,
sizeof(IOPNP_DEVICE_EXTENSION),
/* Create the root PDO */
Status = IoCreateDevice(IopRootDriverObject,
sizeof(IOPNP_DEVICE_EXTENSION),
DPRINT1("IoCreateDevice() failed\n");
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
}
DPRINT1("IoCreateDevice() failed\n");
KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
}
/* This is a bus enumerated device */
Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
/* This is a bus enumerated device */
Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
/* Create the root device node */
IopRootDeviceNode = PipAllocateDeviceNode(Pdo);
/* Create the root device node */
IopRootDeviceNode = PipAllocateDeviceNode(Pdo);
IopRootDeviceNode->Flags |= DNF_STARTED + DNF_PROCESSED + DNF_ENUMERATED +
DNF_MADEUP + DNF_NO_RESOURCE_REQUIRED +
DNF_ADDED;
IopRootDeviceNode->Flags |= DNF_STARTED + DNF_PROCESSED + DNF_ENUMERATED +
DNF_MADEUP + DNF_NO_RESOURCE_REQUIRED +
DNF_ADDED;
/* Create instance path */
RtlCreateUnicodeString(&IopRootDeviceNode->InstancePath,
REGSTR_VAL_ROOT_DEVNODE);
/* Create instance path */
RtlCreateUnicodeString(&IopRootDeviceNode->InstancePath,
REGSTR_VAL_ROOT_DEVNODE);
/* Call the add device routine */
IopRootDriverObject->DriverExtension->AddDevice(IopRootDriverObject,
IopRootDeviceNode->PhysicalDeviceObject);
/* Call the add device routine */
IopRootDriverObject->DriverExtension->AddDevice(IopRootDriverObject,
IopRootDeviceNode->PhysicalDeviceObject);
/* Initialize PnP-Event notification support */
Status = IopInitPlugPlayEvents();
if (!NT_SUCCESS(Status)) return Status;
/* Initialize PnP-Event notification support */
Status = IopInitPlugPlayEvents();
if (!NT_SUCCESS(Status)) return Status;
/* Report the device to the user-mode pnp manager */
IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
&IopRootDeviceNode->InstancePath);
/* Report the device to the user-mode pnp manager */
IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
&IopRootDeviceNode->InstancePath);
/* Initialize the Bus Type GUID List */
PnpBusTypeGuidList = ExAllocatePool(PagedPool, sizeof(IO_BUS_TYPE_GUID_LIST));
RtlZeroMemory(PnpBusTypeGuidList, sizeof(IO_BUS_TYPE_GUID_LIST));
ExInitializeFastMutex(&PnpBusTypeGuidList->Lock);
/* Initialize the Bus Type GUID List */
PnpBusTypeGuidList = ExAllocatePool(PagedPool, sizeof(IO_BUS_TYPE_GUID_LIST));
RtlZeroMemory(PnpBusTypeGuidList, sizeof(IO_BUS_TYPE_GUID_LIST));
ExInitializeFastMutex(&PnpBusTypeGuidList->Lock);
/* Launch the firmware mapper */
Status = IopUpdateRootKey();
if (!NT_SUCCESS(Status)) return Status;
/* Launch the firmware mapper */
Status = IopUpdateRootKey();
if (!NT_SUCCESS(Status)) return Status;
/* Close the handle to the control set */
NtClose(KeyHandle);
/* Close the handle to the control set */
NtClose(KeyHandle);
/* We made it */
return STATUS_SUCCESS;
}
/* We made it */
return STATUS_SUCCESS;
}
PKEY_VALUE_PARTIAL_INFORMATION PartialInfo;
ULONG HidLength = 0, CidLength = 0, BufferLength;
PWCHAR IdBuffer, OriginalIdBuffer;
PKEY_VALUE_PARTIAL_INFORMATION PartialInfo;
ULONG HidLength = 0, CidLength = 0, BufferLength;
PWCHAR IdBuffer, OriginalIdBuffer;
/* Open the device instance key */
Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, 0, &InstanceKey);
if (Status != STATUS_SUCCESS)
/* Open the device instance key */
Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, 0, &InstanceKey);
if (Status != STATUS_SUCCESS)
ZwClose(InstanceKey);
return;
}
ZwClose(InstanceKey);
return;
}
/* Copy CID next */
CidLength = PartialInfo->DataLength;
RtlCopyMemory(((PUCHAR)IdBuffer) + HidLength, PartialInfo->Data, CidLength);
/* Copy CID next */
CidLength = PartialInfo->DataLength;
RtlCopyMemory(((PUCHAR)IdBuffer) + HidLength, PartialInfo->Data, CidLength);
/* Free our temp buffer */
ExFreePool(PartialInfo);
/* Free our temp buffer */
ExFreePool(PartialInfo);
InitializeObjectAttributes(&ObjectAttributes,
&CriticalDeviceKeyU,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
InitializeObjectAttributes(&ObjectAttributes,
&CriticalDeviceKeyU,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
while (*IdBuffer)
{
USHORT StringLength = (USHORT)wcslen(IdBuffer) + 1, Index;
while (*IdBuffer)
{
USHORT StringLength = (USHORT)wcslen(IdBuffer) + 1, Index;
IopFixupDeviceId(IdBuffer);
IopFixupDeviceId(IdBuffer);
/* Look through all subkeys for a match */
for (Index = 0; TRUE; Index++)
{
ULONG NeededLength;
PKEY_BASIC_INFORMATION BasicInfo;
/* Look through all subkeys for a match */
for (Index = 0; TRUE; Index++)
{
ULONG NeededLength;
PKEY_BASIC_INFORMATION BasicInfo;
Status = ZwEnumerateKey(CriticalDeviceKey,
Index,
KeyBasicInformation,
Status = ZwEnumerateKey(CriticalDeviceKey,
Index,
KeyBasicInformation,
/* Advance to the next ID */
IdBuffer += StringLength;
}
/* Advance to the next ID */
IdBuffer += StringLength;
}
ExFreePool(OriginalIdBuffer);
ZwClose(InstanceKey);
ZwClose(CriticalDeviceKey);
ExFreePool(OriginalIdBuffer);
ZwClose(InstanceKey);
ZwClose(CriticalDeviceKey);
{
PDEVICE_OBJECT Fdo;
NTSTATUS Status;
{
PDEVICE_OBJECT Fdo;
NTSTATUS Status;
if (!DriverObject)
{
/* Special case for bus driven devices */
if (!DriverObject)
{
/* Special case for bus driven devices */
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_EJECT;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_EJECT;
return IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
return IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_SURPRISE_REMOVAL;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_SURPRISE_REMOVAL;
/* Drivers should never fail a IRP_MN_SURPRISE_REMOVAL request */
IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
/* Drivers should never fail a IRP_MN_SURPRISE_REMOVAL request */
IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
IO_STACK_LOCATION Stack;
PVOID Dummy;
NTSTATUS Status;
IO_STACK_LOCATION Stack;
PVOID Dummy;
NTSTATUS Status;
IopQueueTargetDeviceEvent(&GUID_DEVICE_REMOVE_PENDING,
&DeviceNode->InstancePath);
IopQueueTargetDeviceEvent(&GUID_DEVICE_REMOVE_PENDING,
&DeviceNode->InstancePath);
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_QUERY_REMOVE_DEVICE;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_QUERY_REMOVE_DEVICE;
&GUID_TARGET_DEVICE_QUERY_REMOVE,
NULL,
NULL);
&GUID_TARGET_DEVICE_QUERY_REMOVE,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT1("Removal vetoed by %wZ\n", &DeviceNode->InstancePath);
if (!NT_SUCCESS(Status))
{
DPRINT1("Removal vetoed by %wZ\n", &DeviceNode->InstancePath);
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_QUERY_STOP_DEVICE;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_QUERY_STOP_DEVICE;
return IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
return IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
/* Drop all our state for this device in case it isn't really going away */
DeviceNode->Flags &= DNF_ENUMERATED | DNF_PROCESSED;
/* Drop all our state for this device in case it isn't really going away */
DeviceNode->Flags &= DNF_ENUMERATED | DNF_PROCESSED;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_REMOVE_DEVICE;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_REMOVE_DEVICE;
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_CANCEL_REMOVE_DEVICE;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_CANCEL_REMOVE_DEVICE;
/* Drivers should never fail a IRP_MN_CANCEL_REMOVE_DEVICE request */
IopSynchronousCall(DeviceObject, &Stack, &Dummy);
/* Drivers should never fail a IRP_MN_CANCEL_REMOVE_DEVICE request */
IopSynchronousCall(DeviceObject, &Stack, &Dummy);
IopNotifyPlugPlayNotification(DeviceObject,
EventCategoryTargetDeviceChange,
&GUID_TARGET_DEVICE_REMOVE_CANCELLED,
IopNotifyPlugPlayNotification(DeviceObject,
EventCategoryTargetDeviceChange,
&GUID_TARGET_DEVICE_REMOVE_CANCELLED,
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
{
IO_STACK_LOCATION Stack;
PVOID Dummy;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_STOP_DEVICE;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_STOP_DEVICE;
/* Drivers should never fail a IRP_MN_STOP_DEVICE request */
IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
/* Drivers should never fail a IRP_MN_STOP_DEVICE request */
IopSynchronousCall(DeviceObject, &Stack, &Dummy);
}
NTSTATUS Status;
PVOID Dummy;
DEVICE_CAPABILITIES DeviceCapabilities;
NTSTATUS Status;
PVOID Dummy;
DEVICE_CAPABILITIES DeviceCapabilities;
/* Get the device node */
DeviceNode = IopGetDeviceNode(DeviceObject);
/* Get the device node */
DeviceNode = IopGetDeviceNode(DeviceObject);
ASSERT(!(DeviceNode->Flags & DNF_DISABLED));
/* Build the I/O stack location */
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_START_DEVICE;
ASSERT(!(DeviceNode->Flags & DNF_DISABLED));
/* Build the I/O stack location */
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_START_DEVICE;
Stack.Parameters.StartDevice.AllocatedResources =
DeviceNode->ResourceList;
Stack.Parameters.StartDevice.AllocatedResourcesTranslated =
Stack.Parameters.StartDevice.AllocatedResources =
DeviceNode->ResourceList;
Stack.Parameters.StartDevice.AllocatedResourcesTranslated =
DPRINT1("Warning: PnP Start failed (%wZ) [Status: 0x%x]\n", &DeviceNode->InstancePath, Status);
return;
}
DPRINT1("Warning: PnP Start failed (%wZ) [Status: 0x%x]\n", &DeviceNode->InstancePath, Status);
return;
}
DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after start)\n");
Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities);
DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after start)\n");
Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities);
/* Invalidate device state so IRP_MN_QUERY_PNP_DEVICE_STATE is sent */
IoInvalidateDeviceState(DeviceObject);
/* Invalidate device state so IRP_MN_QUERY_PNP_DEVICE_STATE is sent */
IoInvalidateDeviceState(DeviceObject);
/* Otherwise, mark us as started */
DeviceNode->Flags |= DNF_STARTED;
DeviceNode->Flags &= ~DNF_STOPPED;
/* Otherwise, mark us as started */
DeviceNode->Flags |= DNF_STARTED;
DeviceNode->Flags &= ~DNF_STOPPED;
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status;
PAGED_CODE();
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status;
PAGED_CODE();
/* Sanity check */
ASSERT((DeviceNode->Flags & DNF_ADDED));
ASSERT((DeviceNode->Flags & (DNF_RESOURCE_ASSIGNED |
DNF_RESOURCE_REPORTED |
DNF_NO_RESOURCE_REQUIRED)));
/* Sanity check */
ASSERT((DeviceNode->Flags & DNF_ADDED));
ASSERT((DeviceNode->Flags & (DNF_RESOURCE_ASSIGNED |
DNF_RESOURCE_REPORTED |
DNF_NO_RESOURCE_REQUIRED)));
/* Get the device object */
DeviceObject = DeviceNode->PhysicalDeviceObject;
/* Get the device object */
DeviceObject = DeviceNode->PhysicalDeviceObject;
/* Check if we're not started yet */
if (!(DeviceNode->Flags & DNF_STARTED))
{
/* Start us */
IopStartDevice2(DeviceObject);
}
/* Check if we're not started yet */
if (!(DeviceNode->Flags & DNF_STARTED))
{
/* Start us */
IopStartDevice2(DeviceObject);
}
/* Do we need to query IDs? This happens in the case of manual reporting */
#if 0
if (DeviceNode->Flags & DNF_NEED_QUERY_IDS)
/* Do we need to query IDs? This happens in the case of manual reporting */
#if 0
if (DeviceNode->Flags & DNF_NEED_QUERY_IDS)
/* Make sure we're started, and check if we need enumeration */
if ((DeviceNode->Flags & DNF_STARTED) &&
(DeviceNode->Flags & DNF_NEED_ENUMERATION_ONLY))
/* Make sure we're started, and check if we need enumeration */
if ((DeviceNode->Flags & DNF_STARTED) &&
(DeviceNode->Flags & DNF_NEED_ENUMERATION_ONLY))
/* Nothing to do */
Status = STATUS_SUCCESS;
}
/* Nothing to do */
Status = STATUS_SUCCESS;
}
/* Return */
return Status;
}
/* Return */
return Status;
}
NTSTATUS Status;
PDEVICE_OBJECT TopDeviceObject;
PAGED_CODE();
NTSTATUS Status;
PDEVICE_OBJECT TopDeviceObject;
PAGED_CODE();
/* Call the top of the device stack */
TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
/* Call the top of the device stack */
TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
/* Allocate an IRP */
Irp = IoAllocateIrp(TopDeviceObject->StackSize, FALSE);
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
/* Allocate an IRP */
Irp = IoAllocateIrp(TopDeviceObject->StackSize, FALSE);
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
/* Initialize to failure */
Irp->IoStatus.Status = IoStatusBlock.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = IoStatusBlock.Information = 0;
/* Initialize to failure */
Irp->IoStatus.Status = IoStatusBlock.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = IoStatusBlock.Information = 0;
/* Special case for IRP_MN_FILTER_RESOURCE_REQUIREMENTS */
if (IoStackLocation->MinorFunction == IRP_MN_FILTER_RESOURCE_REQUIREMENTS)
{
/* Special case for IRP_MN_FILTER_RESOURCE_REQUIREMENTS */
if (IoStackLocation->MinorFunction == IRP_MN_FILTER_RESOURCE_REQUIREMENTS)
{
Irp->IoStatus.Information =
IoStatusBlock.Information = (ULONG_PTR)IoStackLocation->Parameters.FilterResourceRequirements.IoResourceRequirementList;
}
Irp->IoStatus.Information =
IoStatusBlock.Information = (ULONG_PTR)IoStackLocation->Parameters.FilterResourceRequirements.IoResourceRequirementList;
}
/* Initialize the event */
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
/* Initialize the event */
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
/* Set them up */
Irp->UserIosb = &IoStatusBlock;
Irp->UserEvent = &Event;
/* Set them up */
Irp->UserIosb = &IoStatusBlock;
Irp->UserEvent = &Event;
/* Queue the IRP */
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
IoQueueThreadIrp(Irp);
/* Queue the IRP */
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
IoQueueThreadIrp(Irp);
/* Copy-in the stack */
IrpStack = IoGetNextIrpStackLocation(Irp);
*IrpStack = *IoStackLocation;
/* Copy-in the stack */
IrpStack = IoGetNextIrpStackLocation(Irp);
*IrpStack = *IoStackLocation;
/* Call the driver */
Status = IoCallDriver(TopDeviceObject, Irp);
if (Status == STATUS_PENDING)
/* Call the driver */
Status = IoCallDriver(TopDeviceObject, Irp);
if (Status == STATUS_PENDING)
IN PIO_STACK_LOCATION Stack OPTIONAL)
{
IO_STACK_LOCATION IoStackLocation;
IN PIO_STACK_LOCATION Stack OPTIONAL)
{
IO_STACK_LOCATION IoStackLocation;
/* Fill out the stack information */
RtlZeroMemory(&IoStackLocation, sizeof(IO_STACK_LOCATION));
IoStackLocation.MajorFunction = IRP_MJ_PNP;
/* Fill out the stack information */
RtlZeroMemory(&IoStackLocation, sizeof(IO_STACK_LOCATION));
IoStackLocation.MajorFunction = IRP_MJ_PNP;
&Stack->Parameters,
sizeof(Stack->Parameters));
}
&Stack->Parameters,
sizeof(Stack->Parameters));
}
/* Do the PnP call */
IoStatusBlock->Status = IopSynchronousCall(DeviceObject,
&IoStackLocation,
/* Do the PnP call */
IoStatusBlock->Status = IopSynchronousCall(DeviceObject,
&IoStackLocation,
UNICODE_STRING KeyString;
NTSTATUS Status = STATUS_SUCCESS;
PAGED_CODE();
UNICODE_STRING KeyString;
NTSTATUS Status = STATUS_SUCCESS;
PAGED_CODE();
/* P1 is start, pp is end */
p1 = KeyName->Buffer;
pp = (PVOID)((ULONG_PTR)p1 + KeyName->Length);
/* P1 is start, pp is end */
p1 = KeyName->Buffer;
pp = (PVOID)((ULONG_PTR)p1 + KeyName->Length);
/* Create the target key */
InitializeObjectAttributes(&ObjectAttributes,
KeyName,
/* Create the target key */
InitializeObjectAttributes(&ObjectAttributes,
KeyName,
/* Target key failed, so we'll need to create its parent. Setup array */
HandleArray[0] = NULL;
HandleArray[1] = RootHandle;
/* Target key failed, so we'll need to create its parent. Setup array */
HandleArray[0] = NULL;
HandleArray[1] = RootHandle;
/* Keep recursing for each missing parent */
while (Recursing)
{
/* And if we're deep enough, close the last handle */
if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
/* Keep recursing for each missing parent */
while (Recursing)
{
/* And if we're deep enough, close the last handle */
if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
/* We're setup to ping-pong between the two handle array entries */
RootHandleIndex = i;
i = (i + 1) & 1;
/* We're setup to ping-pong between the two handle array entries */
RootHandleIndex = i;
i = (i + 1) & 1;
/* Clear the one we're attempting to open now */
HandleArray[i] = NULL;
/* Clear the one we're attempting to open now */
HandleArray[i] = NULL;
/* Process the parent key name */
for (p = p1; ((p < pp) && (*p != OBJ_NAME_PATH_SEPARATOR)); p++);
Length = (USHORT)(p - p1) * sizeof(WCHAR);
/* Process the parent key name */
for (p = p1; ((p < pp) && (*p != OBJ_NAME_PATH_SEPARATOR)); p++);
Length = (USHORT)(p - p1) * sizeof(WCHAR);
/* Is there a parent name? */
if (Length)
{
/* Build the unicode string for it */
KeyString.Buffer = p1;
KeyString.Length = KeyString.MaximumLength = Length;
/* Is there a parent name? */
if (Length)
{
/* Build the unicode string for it */
KeyString.Buffer = p1;
KeyString.Length = KeyString.MaximumLength = Length;
/* Now try opening the parent */
InitializeObjectAttributes(&ObjectAttributes,
&KeyString,
/* Now try opening the parent */
InitializeObjectAttributes(&ObjectAttributes,
&KeyString,
Recursing = FALSE;
continue;
}
Recursing = FALSE;
continue;
}
/* Now see if there's more parents to create */
p1 = p + 1;
if ((p == pp) || (p1 == pp))
/* Now see if there's more parents to create */
p1 = p + 1;
if ((p == pp) || (p1 == pp))
/* Outer loop check for handle nesting that requires closing the top handle */
if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
}
/* Outer loop check for handle nesting that requires closing the top handle */
if (NestedCloseLevel > 1) ZwClose(HandleArray[RootHandleIndex]);
}
/* Check if we broke out of the loop due to success */
if (NT_SUCCESS(Status))
{
/* Check if we broke out of the loop due to success */
if (NT_SUCCESS(Status))
{
*Handle = HandleArray[i];
if (Disposition) *Disposition = KeyDisposition;
}
*Handle = HandleArray[i];
if (Disposition) *Disposition = KeyDisposition;
}
/* Return the success state */
return Status;
}
/* Return the success state */
return Status;
}
{
PDEVICE_NODE DeviceNode;
PAGED_CODE();
{
PDEVICE_NODE DeviceNode;
PAGED_CODE();
/* Allocate it */
DeviceNode = ExAllocatePoolWithTag(NonPagedPool, sizeof(DEVICE_NODE), 'donD');
if (!DeviceNode) return DeviceNode;
/* Allocate it */
DeviceNode = ExAllocatePoolWithTag(NonPagedPool, sizeof(DEVICE_NODE), 'donD');
if (!DeviceNode) return DeviceNode;
/* Statistics */
InterlockedIncrement(&IopNumberDeviceNodes);
/* Statistics */
InterlockedIncrement(&IopNumberDeviceNodes);
/* Set it up */
RtlZeroMemory(DeviceNode, sizeof(DEVICE_NODE));
DeviceNode->InterfaceType = InterfaceTypeUndefined;
/* Set it up */
RtlZeroMemory(DeviceNode, sizeof(DEVICE_NODE));
DeviceNode->InterfaceType = InterfaceTypeUndefined;
InitializeListHead(&DeviceNode->TargetDeviceNotify);
InitializeListHead(&DeviceNode->DockInfo.ListEntry);
InitializeListHead(&DeviceNode->PendedSetInterfaceState);
InitializeListHead(&DeviceNode->TargetDeviceNotify);
InitializeListHead(&DeviceNode->DockInfo.ListEntry);
InitializeListHead(&DeviceNode->PendedSetInterfaceState);
/* Check if there is a PDO */
if (PhysicalDeviceObject)
{
/* Check if there is a PDO */
if (PhysicalDeviceObject)
{
((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = DeviceNode;
PhysicalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
}
((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = DeviceNode;
PhysicalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
}
/* Return the node */
return DeviceNode;
}
/* Return the node */
return DeviceNode;
}
/* Acquire the lock */
ExAcquireFastMutex(&PnpBusTypeGuidList->Lock);
/* Acquire the lock */
ExAcquireFastMutex(&PnpBusTypeGuidList->Lock);
/* Validate size */
if (Index < PnpBusTypeGuidList->GuidCount)
{
/* Validate size */
if (Index < PnpBusTypeGuidList->GuidCount)
{
/* Failure path */
Status = STATUS_OBJECT_NAME_NOT_FOUND;
}
/* Failure path */
Status = STATUS_OBJECT_NAME_NOT_FOUND;
}
/* Release lock and return status */
ExReleaseFastMutex(&PnpBusTypeGuidList->Lock);
return Status;
/* Release lock and return status */
ExReleaseFastMutex(&PnpBusTypeGuidList->Lock);
return Status;
PDEVICE_NODE DeviceNode;
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
PAGED_CODE();
PDEVICE_NODE DeviceNode;
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
PAGED_CODE();
/* Open the enum key */
Status = IopOpenRegistryKeyEx(&KeyHandle,
NULL,
&KeyName,
KEY_READ);
if (!NT_SUCCESS(Status)) return Status;
/* Open the enum key */
Status = IopOpenRegistryKeyEx(&KeyHandle,
NULL,
&KeyName,
KEY_READ);
if (!NT_SUCCESS(Status)) return Status;
/* Make sure we have an instance path */
DeviceNode = IopGetDeviceNode(DeviceObject);
if ((DeviceNode) && (DeviceNode->InstancePath.Length))
/* Make sure we have an instance path */
DeviceNode = IopGetDeviceNode(DeviceObject);
if ((DeviceNode) && (DeviceNode->InstancePath.Length))
/* Fail */
Status = STATUS_INVALID_DEVICE_REQUEST;
}
/* Fail */
Status = STATUS_INVALID_DEVICE_REQUEST;
}
/* Close the handle and return status */
ZwClose(KeyHandle);
return Status;
/* Close the handle and return status */
ZwClose(KeyHandle);
return Status;
ULONG FinalSize, PartialSize, EntrySize, i, j;
PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
ULONG FinalSize, PartialSize, EntrySize, i, j;
PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
/* If we don't have one, that's easy */
if (!ResourceList) return 0;
/* If we don't have one, that's easy */
if (!ResourceList) return 0;
/* Start with the minimum size possible */
FinalSize = FIELD_OFFSET(CM_RESOURCE_LIST, List);
/* Start with the minimum size possible */
FinalSize = FIELD_OFFSET(CM_RESOURCE_LIST, List);
/* Loop each full descriptor */
FullDescriptor = ResourceList->List;
for (i = 0; i < ResourceList->Count; i++)
/* Loop each full descriptor */
FullDescriptor = ResourceList->List;
for (i = 0; i < ResourceList->Count; i++)
/* Start with the minimum size possible */
PartialSize = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
/* Start with the minimum size possible */
PartialSize = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
/* Loop each partial descriptor */
PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
for (j = 0; j < FullDescriptor->PartialResourceList.Count; j++)
{
/* Start with the minimum size possible */
EntrySize = sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
/* Loop each partial descriptor */
PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
for (j = 0; j < FullDescriptor->PartialResourceList.Count; j++)
{
/* Start with the minimum size possible */
EntrySize = sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
/* Check if there is extra data */
if (PartialDescriptor->Type == CmResourceTypeDeviceSpecific)
{
/* Add that data */
EntrySize += PartialDescriptor->u.DeviceSpecificData.DataSize;
}
/* Check if there is extra data */
if (PartialDescriptor->Type == CmResourceTypeDeviceSpecific)
{
/* Add that data */
EntrySize += PartialDescriptor->u.DeviceSpecificData.DataSize;
}
/* The size of partial descriptors is bigger */
PartialSize += EntrySize;
/* The size of partial descriptors is bigger */
PartialSize += EntrySize;
/* Go to the next partial descriptor */
PartialDescriptor = (PVOID)((ULONG_PTR)PartialDescriptor + EntrySize);
}
/* Go to the next partial descriptor */
PartialDescriptor = (PVOID)((ULONG_PTR)PartialDescriptor + EntrySize);
}
/* The size of full descriptors is bigger */
FinalSize += PartialSize;
/* The size of full descriptors is bigger */
FinalSize += PartialSize;
/* Go to the next full descriptor */
FullDescriptor = (PVOID)((ULONG_PTR)FullDescriptor + PartialSize);
}
/* Go to the next full descriptor */
FullDescriptor = (PVOID)((ULONG_PTR)FullDescriptor + PartialSize);
}
/* Return the final size */
return FinalSize;
}
/* Return the final size */
return FinalSize;
}
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(GUID), &BusTypeGuid);
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(GUID), &BusTypeGuid);
case DevicePropertyLegacyBusType:
case DevicePropertyLegacyBusType:
/* Validate correct interface type */
if (DeviceNode->ChildInterfaceType == InterfaceTypeUndefined)
return STATUS_OBJECT_NAME_NOT_FOUND;
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(INTERFACE_TYPE), &DeviceNode->ChildInterfaceType);
/* Validate correct interface type */
if (DeviceNode->ChildInterfaceType == InterfaceTypeUndefined)
return STATUS_OBJECT_NAME_NOT_FOUND;
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(INTERFACE_TYPE), &DeviceNode->ChildInterfaceType);
case DevicePropertyBusNumber:
case DevicePropertyBusNumber:
/* Validate correct bus number */
if ((DeviceNode->ChildBusNumber & 0x80000000) == 0x80000000)
return STATUS_OBJECT_NAME_NOT_FOUND;
/* Validate correct bus number */
if ((DeviceNode->ChildBusNumber & 0x80000000) == 0x80000000)
return STATUS_OBJECT_NAME_NOT_FOUND;
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(ULONG), &DeviceNode->ChildBusNumber);
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(ULONG), &DeviceNode->ChildBusNumber);
case DevicePropertyEnumeratorName:
/* Get the instance path */
DeviceInstanceName = DeviceNode->InstancePath.Buffer;
case DevicePropertyEnumeratorName:
/* Get the instance path */
DeviceInstanceName = DeviceNode->InstancePath.Buffer;
/* Sanity checks */
ASSERT((BufferLength & 1) == 0);
ASSERT(DeviceInstanceName != NULL);
/* Sanity checks */
ASSERT((BufferLength & 1) == 0);
ASSERT(DeviceInstanceName != NULL);
/* Get the name from the path */
EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
ASSERT(EnumeratorNameEnd);
/* Get the name from the path */
EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
ASSERT(EnumeratorNameEnd);
/* This is the format of the returned data */
PIP_RETURN_DATA((ULONG)(EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
DeviceInstanceName);
/* This is the format of the returned data */
PIP_RETURN_DATA((ULONG)(EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
DeviceInstanceName);
case DevicePropertyAddress:
/* Query the device caps */
case DevicePropertyAddress:
/* Query the device caps */
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(ULONG), &DeviceCaps.Address);
/* This is the format of the returned data */
PIP_RETURN_DATA(sizeof(ULONG), &DeviceCaps.Address);
case DevicePropertyBootConfigurationTranslated:
case DevicePropertyBootConfigurationTranslated:
/* Validate we have resources */
if (!DeviceNode->BootResources)
// if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
/* Validate we have resources */
if (!DeviceNode->BootResources)
// if (!DeviceNode->BootResourcesTranslated) // FIXFIX: Need this field
*ResultLength = 0;
return STATUS_SUCCESS;
}
*ResultLength = 0;
return STATUS_SUCCESS;
}
/* This is the format of the returned data */
PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode->BootResources), // FIXFIX: Should use BootResourcesTranslated
DeviceNode->BootResources); // FIXFIX: Should use BootResourcesTranslated
case DevicePropertyPhysicalDeviceObjectName:
/* This is the format of the returned data */
PIP_RETURN_DATA(PnpDetermineResourceListSize(DeviceNode->BootResources), // FIXFIX: Should use BootResourcesTranslated
DeviceNode->BootResources); // FIXFIX: Should use BootResourcesTranslated
case DevicePropertyPhysicalDeviceObjectName:
/* Sanity check for Unicode-sized string */
ASSERT((BufferLength & 1) == 0);
/* Sanity check for Unicode-sized string */
ASSERT((BufferLength & 1) == 0);
/* Allocate name buffer */
Length = BufferLength + sizeof(OBJECT_NAME_INFORMATION);
ObjectNameInfo = ExAllocatePool(PagedPool, Length);
if (!ObjectNameInfo) return STATUS_INSUFFICIENT_RESOURCES;
/* Allocate name buffer */
Length = BufferLength + sizeof(OBJECT_NAME_INFORMATION);
ObjectNameInfo = ExAllocatePool(PagedPool, Length);
if (!ObjectNameInfo) return STATUS_INSUFFICIENT_RESOURCES;
/* Query the PDO name */
Status = ObQueryNameString(DeviceObject,
ObjectNameInfo,
/* Query the PDO name */
Status = ObQueryNameString(DeviceObject,
ObjectNameInfo,
/* Let the caller know how big the name is */
*ResultLength -= sizeof(OBJECT_NAME_INFORMATION);
break;
/* Let the caller know how big the name is */
*ResultLength -= sizeof(OBJECT_NAME_INFORMATION);
break;
/* Handle the registry-based properties */
case DevicePropertyUINumber:
PIP_REGISTRY_DATA(REGSTR_VAL_UI_NUMBER, REG_DWORD);
/* Handle the registry-based properties */
case DevicePropertyUINumber:
PIP_REGISTRY_DATA(REGSTR_VAL_UI_NUMBER, REG_DWORD);
default:
return STATUS_INVALID_PARAMETER_2;
}
default:
return STATUS_INVALID_PARAMETER_2;
}
/* Having a registry value name implies registry data */
if (ValueName)
{
/* We know up-front how much data to expect */
*ResultLength = BufferLength;
/* Having a registry value name implies registry data */
if (ValueName)
{
/* We know up-front how much data to expect */
*ResultLength = BufferLength;
/* Go get the data, use the LogConf subkey if necessary */
Status = PiGetDeviceRegistryProperty(DeviceObject,
ValueType,
/* Go get the data, use the LogConf subkey if necessary */
Status = PiGetDeviceRegistryProperty(DeviceObject,
ValueType,
/* Terminate the string */
((PWCHAR)PropertyBuffer)[ReturnLength / sizeof(WCHAR)] = UNICODE_NULL;
}
/* Terminate the string */
((PWCHAR)PropertyBuffer)[ReturnLength / sizeof(WCHAR)] = UNICODE_NULL;
}
/* This is the success path */
Status = STATUS_SUCCESS;
}
/* This is the success path */
Status = STATUS_SUCCESS;
}
Status = STATUS_BUFFER_TOO_SMALL;
}
}
Status = STATUS_BUFFER_TOO_SMALL;
}
}
/* Free any allocation we may have made, and return the status code */
if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
return Status;
/* Free any allocation we may have made, and return the status code */
if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
return Status;
ULONG PnPFlags;
NTSTATUS Status;
IO_STATUS_BLOCK IoStatusBlock;
ULONG PnPFlags;
NTSTATUS Status;
IO_STATUS_BLOCK IoStatusBlock;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_QUERY_PNP_DEVICE_STATE;
RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
Stack.MajorFunction = IRP_MJ_PNP;
Stack.MinorFunction = IRP_MN_QUERY_PNP_DEVICE_STATE;
Status = IopSynchronousCall(PhysicalDeviceObject, &Stack, (PVOID*)&PnPFlags);
if (!NT_SUCCESS(Status))
{
Status = IopSynchronousCall(PhysicalDeviceObject, &Stack, (PVOID*)&PnPFlags);
if (!NT_SUCCESS(Status))
{
/* Send surprise removal */
IopSendSurpriseRemoval(PhysicalDeviceObject);
/* Send surprise removal */
IopSendSurpriseRemoval(PhysicalDeviceObject);
/* Tell the user-mode PnP manager that a device was removed */
IopQueueTargetDeviceEvent(&GUID_DEVICE_SURPRISE_REMOVAL,
&DeviceNode->InstancePath);
/* Tell the user-mode PnP manager that a device was removed */
IopQueueTargetDeviceEvent(&GUID_DEVICE_SURPRISE_REMOVAL,
&DeviceNode->InstancePath);
IopSendRemoveDevice(PhysicalDeviceObject);
}
else if ((PnPFlags & PNP_DEVICE_FAILED) && (PnPFlags & PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED))
IopSendRemoveDevice(PhysicalDeviceObject);
}
else if ((PnPFlags & PNP_DEVICE_FAILED) && (PnPFlags & PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED))
PnPFlags &= ~PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED;
}
}
PnPFlags &= ~PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED;
}
}
/* Resource rebalance */
if (PnPFlags & PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED)
{
DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
/* Resource rebalance */
if (PnPFlags & PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED)
{
DPRINT("Sending IRP_MN_QUERY_RESOURCES to device stack\n");
Status = IopInitiatePnpIrp(PhysicalDeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_RESOURCES,
Status = IopInitiatePnpIrp(PhysicalDeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_RESOURCES,
DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
DeviceNode->BootResources = NULL;
}
DPRINT("IopInitiatePnpIrp() failed (Status %x) or IoStatusBlock.Information=NULL\n", Status);
DeviceNode->BootResources = NULL;
}
DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
DPRINT("Sending IRP_MN_QUERY_RESOURCE_REQUIREMENTS to device stack\n");
Status = IopInitiatePnpIrp(PhysicalDeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_RESOURCE_REQUIREMENTS,
Status = IopInitiatePnpIrp(PhysicalDeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_RESOURCE_REQUIREMENTS,
DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
DeviceNode->ResourceRequirements = NULL;
}
DPRINT("IopInitiatePnpIrp() failed (Status %08lx)\n", Status);
DeviceNode->ResourceRequirements = NULL;
}
/* IRP_MN_FILTER_RESOURCE_REQUIREMENTS is called indirectly by IopStartDevice */
if (IopStartDevice(DeviceNode) != STATUS_SUCCESS)
{
/* IRP_MN_FILTER_RESOURCE_REQUIREMENTS is called indirectly by IopStartDevice */
if (IopStartDevice(DeviceNode) != STATUS_SUCCESS)
{
PDEVICE_NODE ChildDeviceNode, NextDeviceNode, FailedRemoveDevice;
NTSTATUS Status;
KIRQL OldIrql;
PDEVICE_NODE ChildDeviceNode, NextDeviceNode, FailedRemoveDevice;
NTSTATUS Status;
KIRQL OldIrql;
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
while (ChildDeviceNode != NULL)
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
while (ChildDeviceNode != NULL)
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
Status = IopPrepareDeviceForRemoval(ChildDeviceNode->PhysicalDeviceObject, Force);
if (!NT_SUCCESS(Status))
{
FailedRemoveDevice = ChildDeviceNode;
goto cleanup;
}
Status = IopPrepareDeviceForRemoval(ChildDeviceNode->PhysicalDeviceObject, Force);
if (!NT_SUCCESS(Status))
{
FailedRemoveDevice = ChildDeviceNode;
goto cleanup;
}
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = NextDeviceNode;
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = NextDeviceNode;
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
cleanup:
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
cleanup:
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
IopCancelPrepareDeviceForRemoval(ChildDeviceNode->PhysicalDeviceObject);
IopCancelPrepareDeviceForRemoval(ChildDeviceNode->PhysicalDeviceObject);
/* IRP_MN_CANCEL_REMOVE_DEVICE is also sent to the device
* that failed the IRP_MN_QUERY_REMOVE_DEVICE request */
if (ChildDeviceNode == FailedRemoveDevice)
return Status;
/* IRP_MN_CANCEL_REMOVE_DEVICE is also sent to the device
* that failed the IRP_MN_QUERY_REMOVE_DEVICE request */
if (ChildDeviceNode == FailedRemoveDevice)
return Status;
ChildDeviceNode = NextDeviceNode;
ChildDeviceNode = NextDeviceNode;
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
{
PDEVICE_NODE ChildDeviceNode, NextDeviceNode;
KIRQL OldIrql;
{
PDEVICE_NODE ChildDeviceNode, NextDeviceNode;
KIRQL OldIrql;
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
while (ChildDeviceNode != NULL)
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
while (ChildDeviceNode != NULL)
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
IopSendRemoveDevice(ChildDeviceNode->PhysicalDeviceObject);
IopSendRemoveDevice(ChildDeviceNode->PhysicalDeviceObject);
ChildDeviceNode = NextDeviceNode;
ChildDeviceNode = NextDeviceNode;
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
{
PDEVICE_NODE ChildDeviceNode, NextDeviceNode;
KIRQL OldIrql;
{
PDEVICE_NODE ChildDeviceNode, NextDeviceNode;
KIRQL OldIrql;
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
while (ChildDeviceNode != NULL)
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
ChildDeviceNode = ParentDeviceNode->Child;
while (ChildDeviceNode != NULL)
{
NextDeviceNode = ChildDeviceNode->Sibling;
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
IopCancelPrepareDeviceForRemoval(ChildDeviceNode->PhysicalDeviceObject);
IopCancelPrepareDeviceForRemoval(ChildDeviceNode->PhysicalDeviceObject);
ChildDeviceNode = NextDeviceNode;
ChildDeviceNode = NextDeviceNode;
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
KeAcquireSpinLock(&IopDeviceTreeLock, &OldIrql);
}
KeReleaseSpinLock(&IopDeviceTreeLock, OldIrql);
{
/* This function DOES NOT dereference the device objects on SUCCESS
* but it DOES dereference device objects on FAILURE */
{
/* This function DOES NOT dereference the device objects on SUCCESS
* but it DOES dereference device objects on FAILURE */
ULONG i, j;
NTSTATUS Status;
ULONG i, j;
NTSTATUS Status;
for (i = 0; i < DeviceRelations->Count; i++)
{
Status = IopPrepareDeviceForRemoval(DeviceRelations->Objects[i], Force);
for (i = 0; i < DeviceRelations->Count; i++)
{
Status = IopPrepareDeviceForRemoval(DeviceRelations->Objects[i], Force);
cleanup:
/* IRP_MN_CANCEL_REMOVE_DEVICE is also sent to the device
* that failed the IRP_MN_QUERY_REMOVE_DEVICE request */
cleanup:
/* IRP_MN_CANCEL_REMOVE_DEVICE is also sent to the device
* that failed the IRP_MN_QUERY_REMOVE_DEVICE request */
DeviceRelations->Objects[i] = NULL;
}
ExFreePool(DeviceRelations);
DeviceRelations->Objects[i] = NULL;
}
ExFreePool(DeviceRelations);
IopSendRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations)
{
/* This function DOES dereference the device objects in all cases */
IopSendRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations)
{
/* This function DOES dereference the device objects in all cases */
for (i = 0; i < DeviceRelations->Count; i++)
{
IopSendRemoveDevice(DeviceRelations->Objects[i]);
DeviceRelations->Objects[i] = NULL;
}
for (i = 0; i < DeviceRelations->Count; i++)
{
IopSendRemoveDevice(DeviceRelations->Objects[i]);
DeviceRelations->Objects[i] = NULL;
}
ExFreePool(DeviceRelations);
}
ExFreePool(DeviceRelations);
}
IopCancelRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations)
{
/* This function DOES dereference the device objects in all cases */
IopCancelRemoveDeviceRelations(PDEVICE_RELATIONS DeviceRelations)
{
/* This function DOES dereference the device objects in all cases */
for (i = 0; i < DeviceRelations->Count; i++)
{
IopCancelPrepareDeviceForRemoval(DeviceRelations->Objects[i]);
ObDereferenceObject(DeviceRelations->Objects[i]);
DeviceRelations->Objects[i] = NULL;
}
for (i = 0; i < DeviceRelations->Count; i++)
{
IopCancelPrepareDeviceForRemoval(DeviceRelations->Objects[i]);
ObDereferenceObject(DeviceRelations->Objects[i]);
DeviceRelations->Objects[i] = NULL;
}
ExFreePool(DeviceRelations);
}
ExFreePool(DeviceRelations);
}
IO_STATUS_BLOCK IoStatusBlock;
PDEVICE_RELATIONS DeviceRelations;
NTSTATUS Status;
IO_STATUS_BLOCK IoStatusBlock;
PDEVICE_RELATIONS DeviceRelations;
NTSTATUS Status;
IopCancelRemoveDevice(DeviceObject);
IopCancelRemoveDevice(DeviceObject);
Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
Status = IopInitiatePnpIrp(DeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_DEVICE_RELATIONS,
Status = IopInitiatePnpIrp(DeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_DEVICE_RELATIONS,
{
DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
}
{
DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
}
if (DeviceRelations)
IopCancelRemoveDeviceRelations(DeviceRelations);
}
if (DeviceRelations)
IopCancelRemoveDeviceRelations(DeviceRelations);
}
DPRINT1("Removal not allowed for %wZ\n", &DeviceNode->InstancePath);
return STATUS_UNSUCCESSFUL;
}
DPRINT1("Removal not allowed for %wZ\n", &DeviceNode->InstancePath);
return STATUS_UNSUCCESSFUL;
}
if (!Force && IopQueryRemoveDevice(DeviceObject) != STATUS_SUCCESS)
{
DPRINT1("Removal vetoed by failing the query remove request\n");
if (!Force && IopQueryRemoveDevice(DeviceObject) != STATUS_SUCCESS)
{
DPRINT1("Removal vetoed by failing the query remove request\n");
IopCancelRemoveDevice(DeviceObject);
IopCancelRemoveDevice(DeviceObject);
return STATUS_UNSUCCESSFUL;
}
return STATUS_UNSUCCESSFUL;
}
Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
Status = IopInitiatePnpIrp(DeviceObject,
Stack.Parameters.QueryDeviceRelations.Type = RemovalRelations;
Status = IopInitiatePnpIrp(DeviceObject,
if (DeviceRelations)
IopSendRemoveDeviceRelations(DeviceRelations);
IopSendRemoveChildDevices(DeviceNode);
if (DeviceRelations)
IopSendRemoveDeviceRelations(DeviceRelations);
IopSendRemoveChildDevices(DeviceNode);
IO_STACK_LOCATION Stack;
DEVICE_CAPABILITIES Capabilities;
NTSTATUS Status;
IO_STACK_LOCATION Stack;
DEVICE_CAPABILITIES Capabilities;
NTSTATUS Status;
IopQueueTargetDeviceEvent(&GUID_DEVICE_KERNEL_INITIATED_EJECT,
&DeviceNode->InstancePath);
IopQueueTargetDeviceEvent(&GUID_DEVICE_KERNEL_INITIATED_EJECT,
&DeviceNode->InstancePath);
if (IopQueryDeviceCapabilities(DeviceNode, &Capabilities) != STATUS_SUCCESS)
{
goto cleanup;
}
if (IopQueryDeviceCapabilities(DeviceNode, &Capabilities) != STATUS_SUCCESS)
{
goto cleanup;
}
Stack.Parameters.QueryDeviceRelations.Type = EjectionRelations;
Stack.Parameters.QueryDeviceRelations.Type = EjectionRelations;
Status = IopInitiatePnpIrp(PhysicalDeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_DEVICE_RELATIONS,
Status = IopInitiatePnpIrp(PhysicalDeviceObject,
&IoStatusBlock,
IRP_MN_QUERY_DEVICE_RELATIONS,
{
DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
}
{
DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
}
if (DeviceRelations)
{
Status = IopQueryRemoveDeviceRelations(DeviceRelations, FALSE);
if (!NT_SUCCESS(Status))
goto cleanup;
}
if (DeviceRelations)
{
Status = IopQueryRemoveDeviceRelations(DeviceRelations, FALSE);
if (!NT_SUCCESS(Status))
goto cleanup;
}
Status = IopQueryRemoveChildDevices(DeviceNode, FALSE);
if (!NT_SUCCESS(Status))
{
Status = IopQueryRemoveChildDevices(DeviceNode, FALSE);
if (!NT_SUCCESS(Status))
{
IopCancelRemoveDeviceRelations(DeviceRelations);
goto cleanup;
}
IopCancelRemoveDeviceRelations(DeviceRelations);
goto cleanup;
}
if (IopPrepareDeviceForRemoval(PhysicalDeviceObject, FALSE) != STATUS_SUCCESS)
{
if (DeviceRelations)
if (IopPrepareDeviceForRemoval(PhysicalDeviceObject, FALSE) != STATUS_SUCCESS)
{
if (DeviceRelations)
IopCancelRemoveChildDevices(DeviceNode);
goto cleanup;
}
IopCancelRemoveChildDevices(DeviceNode);
goto cleanup;
}
if (DeviceRelations)
IopSendRemoveDeviceRelations(DeviceRelations);
IopSendRemoveChildDevices(DeviceNode);
if (DeviceRelations)
IopSendRemoveDeviceRelations(DeviceRelations);
IopSendRemoveChildDevices(DeviceNode);
{
DeviceNode->Flags |= DNF_DISABLED;
}
{
DeviceNode->Flags |= DNF_DISABLED;
}
IopQueueTargetDeviceEvent(&GUID_DEVICE_EJECT,
&DeviceNode->InstancePath);
IopQueueTargetDeviceEvent(&GUID_DEVICE_EJECT,
&DeviceNode->InstancePath);
cleanup:
IopQueueTargetDeviceEvent(&GUID_DEVICE_EJECT_VETOED,
&DeviceNode->InstancePath);
cleanup:
IopQueueTargetDeviceEvent(&GUID_DEVICE_EJECT_VETOED,
&DeviceNode->InstancePath);
IN DEVICE_RELATION_TYPE Type)
{
PAGED_CODE();
IN DEVICE_RELATION_TYPE Type)
{
PAGED_CODE();
switch (Type)
{
case BusRelations:
switch (Type)
{
case BusRelations:
/* We're enumerated already */
IopDeviceNodeSetFlag(DeviceNode, DNF_ENUMERATED);
/* We're enumerated already */
IopDeviceNodeSetFlag(DeviceNode, DNF_ENUMERATED);
/* We don't call AddDevice for devices reported this way */
IopDeviceNodeSetFlag(DeviceNode, DNF_ADDED);
/* We don't call AddDevice for devices reported this way */
IopDeviceNodeSetFlag(DeviceNode, DNF_ADDED);
ASSERT(IoDesc->Type == CmDesc->Type);
ASSERT(IoDesc->Type == CmResourceTypePort);
ASSERT(IoDesc->Type == CmDesc->Type);
ASSERT(IoDesc->Type == CmResourceTypePort);
/* HACK */
if (IoDesc->u.Port.Alignment == 0) IoDesc->u.Port.Alignment = 1;
/* HACK */
if (IoDesc->u.Port.Alignment == 0) IoDesc->u.Port.Alignment = 1;
PCM_PARTIAL_RESOURCE_LIST PartialList = (*ResourceList) ? &(*ResourceList)->List[0].PartialResourceList : NULL;
PIO_RESOURCE_DESCRIPTOR IoDesc = &ResList->Descriptors[ii];
BOOLEAN Matched = FALSE;
PCM_PARTIAL_RESOURCE_LIST PartialList = (*ResourceList) ? &(*ResourceList)->List[0].PartialResourceList : NULL;
PIO_RESOURCE_DESCRIPTOR IoDesc = &ResList->Descriptors[ii];
BOOLEAN Matched = FALSE;
/* Skip alternates if we don't need one */
if (!AlternateRequired && (IoDesc->Option & IO_RESOURCE_ALTERNATIVE))
{
/* Skip alternates if we don't need one */
if (!AlternateRequired && (IoDesc->Option & IO_RESOURCE_ALTERNATIVE))
{
FoundResource = FALSE;
}
break;
FoundResource = FALSE;
}
break;
case CmResourceTypePort:
/* Find an available port range */
if (!IopFindPortResource(IoDesc, &NewDesc))
case CmResourceTypePort:
/* Find an available port range */
if (!IopFindPortResource(IoDesc, &NewDesc))
FoundResource = FALSE;
}
break;
FoundResource = FALSE;
}
break;
case CmResourceTypeMemory:
/* Find an available memory range */
if (!IopFindMemoryResource(IoDesc, &NewDesc))
case CmResourceTypeMemory:
/* Find an available memory range */
if (!IopFindMemoryResource(IoDesc, &NewDesc))
FoundResource = FALSE;
}
break;
FoundResource = FALSE;
}
break;
case CmResourceTypeBusNumber:
/* Find an available bus address range */
if (!IopFindBusNumberResource(IoDesc, &NewDesc))
case CmResourceTypeBusNumber:
/* Find an available bus address range */
if (!IopFindBusNumberResource(IoDesc, &NewDesc))
FoundResource = FALSE;
}
break;
FoundResource = FALSE;
}
break;
case CmResourceTypeDma:
/* Find an available DMA channel */
if (!IopFindDmaResource(IoDesc, &NewDesc))
case CmResourceTypeDma:
/* Find an available DMA channel */
if (!IopFindDmaResource(IoDesc, &NewDesc))
FoundResource = FALSE;
}
break;
FoundResource = FALSE;
}
break;
default:
DPRINT1("Unsupported resource type: %x\n", IoDesc->Type);
FoundResource = FALSE;
default:
DPRINT1("Unsupported resource type: %x\n", IoDesc->Type);
FoundResource = FALSE;
ULONG OldLength = 0;
ASSERT(DeviceNode->ResourceListTranslated);
ULONG OldLength = 0;
ASSERT(DeviceNode->ResourceListTranslated);
RtlInitUnicodeString(&TranslatedSuffix, L".Translated");
RtlInitUnicodeString(&RawSuffix, L".Raw");
RtlInitUnicodeString(&TranslatedSuffix, L".Translated");
RtlInitUnicodeString(&RawSuffix, L".Raw");
if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL)
{
ASSERT(OldLength);
if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL)
{
ASSERT(OldLength);
NameU.Buffer = ExAllocatePool(PagedPool, OldLength + TranslatedSuffix.Length);
if (!NameU.Buffer)
{
ZwClose(PnpMgrLevel2);
return STATUS_INSUFFICIENT_RESOURCES;
}
NameU.Buffer = ExAllocatePool(PagedPool, OldLength + TranslatedSuffix.Length);
if (!NameU.Buffer)
{
ZwClose(PnpMgrLevel2);
return STATUS_INSUFFICIENT_RESOURCES;
}
NameU.Length = 0;
NameU.MaximumLength = (USHORT)OldLength + TranslatedSuffix.Length;
NameU.Length = 0;
NameU.MaximumLength = (USHORT)OldLength + TranslatedSuffix.Length;
Status = IoGetDeviceProperty(DeviceNode->PhysicalDeviceObject,
DevicePropertyPhysicalDeviceObjectName,
NameU.MaximumLength,
Status = IoGetDeviceProperty(DeviceNode->PhysicalDeviceObject,
DevicePropertyPhysicalDeviceObjectName,
NameU.MaximumLength,
/* This should never happen */
ASSERT(FALSE);
}
/* This should never happen */
ASSERT(FALSE);
}
NameU.Length = (USHORT)OldLength;
RtlAppendUnicodeStringToString(&NameU, &RawSuffix);
NameU.Length = (USHORT)OldLength;
RtlAppendUnicodeStringToString(&NameU, &RawSuffix);
DPRINT1("Failed to translate port resource (Start: 0x%I64x)\n", DescriptorRaw->u.Port.Start.QuadPart);
goto cleanup;
}
DPRINT1("Failed to translate port resource (Start: 0x%I64x)\n", DescriptorRaw->u.Port.Start.QuadPart);
goto cleanup;
}
if (AddressSpace == 0)
{
DPRINT1("Guessed incorrect address space: 1 -> 0\n");
if (AddressSpace == 0)
{
DPRINT1("Guessed incorrect address space: 1 -> 0\n");
- /* FIXME: I think all other CM_RESOURCE_PORT_XXX flags are
+ /* FIXME: I think all other CM_RESOURCE_PORT_XXX flags are
* invalid for this state but I'm not 100% sure */
DescriptorRaw->Flags =
DescriptorTranslated->Flags = CM_RESOURCE_PORT_MEMORY;
* invalid for this state but I'm not 100% sure */
DescriptorRaw->Flags =
DescriptorTranslated->Flags = CM_RESOURCE_PORT_MEMORY;
DescriptorRaw->u.Interrupt.Vector,
(PKIRQL)&DescriptorTranslated->u.Interrupt.Level,
&DescriptorTranslated->u.Interrupt.Affinity);
DescriptorRaw->u.Interrupt.Vector,
(PKIRQL)&DescriptorTranslated->u.Interrupt.Level,
&DescriptorTranslated->u.Interrupt.Affinity);
if (!DescriptorTranslated->u.Interrupt.Vector)
{
Status = STATUS_UNSUCCESSFUL;
if (!DescriptorTranslated->u.Interrupt.Vector)
{
Status = STATUS_UNSUCCESSFUL;
IN ULONG StringCount)
{
ULONG i;
IN ULONG StringCount)
{
ULONG i;
/* Go through the list */
if (UnicodeStringList)
{
/* Go through the list */
if (UnicodeStringList)
{
ExFreePool(UnicodeStringList[i].Buffer);
}
}
ExFreePool(UnicodeStringList[i].Buffer);
}
}
/* Free the whole list */
ExFreePool(UnicodeStringList);
}
/* Free the whole list */
ExFreePool(UnicodeStringList);
}
ULONG i = 0;
SIZE_T n;
ULONG Count = 0;
ULONG i = 0;
SIZE_T n;
ULONG Count = 0;
/* Validate the key information */
if (KeyValueInformation->Type != REG_MULTI_SZ) return STATUS_INVALID_PARAMETER;
/* Validate the key information */
if (KeyValueInformation->Type != REG_MULTI_SZ) return STATUS_INVALID_PARAMETER;
/* Set the pointers */
p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
KeyValueInformation->DataOffset);
pp = (PWCHAR)((ULONG_PTR)p + KeyValueInformation->DataLength);
/* Set the pointers */
p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
KeyValueInformation->DataOffset);
pp = (PWCHAR)((ULONG_PTR)p + KeyValueInformation->DataLength);
/* Loop the data */
while (p != pp)
{
/* Loop the data */
while (p != pp)
{
{
/* Add to our string count */
Count++;
{
/* Add to our string count */
Count++;
/* Check for a double-NULL, which means we're done */
if (((p + 1) == pp) || !(*(p + 1))) break;
}
/* Check for a double-NULL, which means we're done */
if (((p + 1) == pp) || !(*(p + 1))) break;
}
/* Go to the next character */
p++;
}
/* If we looped the whole list over, we missed increment a string, do it */
if (p == pp) Count++;
/* Go to the next character */
p++;
}
/* If we looped the whole list over, we missed increment a string, do it */
if (p == pp) Count++;
/* Allocate the list now that we know how big it is */
*UnicodeStringList = ExAllocatePoolWithTag(PagedPool,
sizeof(UNICODE_STRING) * Count,
'sUpP');
if (!(*UnicodeStringList)) return STATUS_INSUFFICIENT_RESOURCES;
/* Allocate the list now that we know how big it is */
*UnicodeStringList = ExAllocatePoolWithTag(PagedPool,
sizeof(UNICODE_STRING) * Count,
'sUpP');
if (!(*UnicodeStringList)) return STATUS_INSUFFICIENT_RESOURCES;
/* Set pointers for second loop */
ps = p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
KeyValueInformation->DataOffset);
/* Set pointers for second loop */
ps = p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
KeyValueInformation->DataOffset);
/* Loop again, to do the copy this time */
while (p != pp)
{
/* Loop again, to do the copy this time */
while (p != pp)
{
{
/* Check how long this string is */
n = (ULONG_PTR)p - (ULONG_PTR)ps + sizeof(UNICODE_NULL);
{
/* Check how long this string is */
n = (ULONG_PTR)p - (ULONG_PTR)ps + sizeof(UNICODE_NULL);
/* Allocate the buffer */
(*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
n,
/* Allocate the buffer */
(*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
n,
PnpFreeUnicodeStringList(*UnicodeStringList, i);
return STATUS_INSUFFICIENT_RESOURCES;
}
PnpFreeUnicodeStringList(*UnicodeStringList, i);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Copy the string into the buffer */
RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
/* Copy the string into the buffer */
RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
/* Set the lengths */
(*UnicodeStringList)[i].MaximumLength = (USHORT)n;
(*UnicodeStringList)[i].Length = (USHORT)(n - sizeof(UNICODE_NULL));
/* Set the lengths */
(*UnicodeStringList)[i].MaximumLength = (USHORT)n;
(*UnicodeStringList)[i].Length = (USHORT)(n - sizeof(UNICODE_NULL));
/* One more entry done */
i++;
/* One more entry done */
i++;
/* Check for a double-NULL, which means we're done */
if (((p + 1) == pp) || !(*(p + 1))) break;
/* New string */
ps = p + 1;
}
/* Check for a double-NULL, which means we're done */
if (((p + 1) == pp) || !(*(p + 1))) break;
/* New string */
ps = p + 1;
}
/* Check if we've reached the last string */
if (p == pp)
{
/* Calculate the string length */
n = (ULONG_PTR)p - (ULONG_PTR)ps;
/* Check if we've reached the last string */
if (p == pp)
{
/* Calculate the string length */
n = (ULONG_PTR)p - (ULONG_PTR)ps;
/* Allocate the buffer for it */
(*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
n +
/* Allocate the buffer for it */
(*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
n +
PnpFreeUnicodeStringList(*UnicodeStringList, i);
return STATUS_INSUFFICIENT_RESOURCES;
}
PnpFreeUnicodeStringList(*UnicodeStringList, i);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Make sure there's an actual string here */
if (n) RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
/* Null-terminate the string ourselves */
(*UnicodeStringList)[i].Buffer[n / sizeof(WCHAR)] = UNICODE_NULL;
/* Make sure there's an actual string here */
if (n) RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
/* Null-terminate the string ourselves */
(*UnicodeStringList)[i].Buffer[n / sizeof(WCHAR)] = UNICODE_NULL;
/* Set the lengths */
(*UnicodeStringList)[i].Length = (USHORT)n;
(*UnicodeStringList)[i].MaximumLength = (USHORT)(n + sizeof(UNICODE_NULL));
}
/* Set the lengths */
(*UnicodeStringList)[i].Length = (USHORT)n;
(*UnicodeStringList)[i].MaximumLength = (USHORT)(n + sizeof(UNICODE_NULL));
}
/* And we're done */
*UnicodeStringCount = Count;
return STATUS_SUCCESS;
/* And we're done */
*UnicodeStringCount = Count;
return STATUS_SUCCESS;
OUT PUSHORT StringLength OPTIONAL)
{
PWCHAR p, pp;
OUT PUSHORT StringLength OPTIONAL)
{
PWCHAR p, pp;
/* Find the end */
pp = RegSzData + RegSzLength;
for (p = RegSzData; p < pp; p++) if (!*p) break;
/* Find the end */
pp = RegSzData + RegSzLength;
for (p = RegSzData; p < pp; p++) if (!*p) break;
/* Return it */
if (StringLength) *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR);
return TRUE;
/* Return it */
if (StringLength) *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR);
return TRUE;