- Partly implement KsCreateBusEnumObject

svn path=/trunk/; revision=42823
This commit is contained in:
Johannes Anderwald 2009-08-21 12:58:20 +00:00
parent d93536f7a1
commit a6407bcf60
2 changed files with 128 additions and 3 deletions

View file

@ -1709,7 +1709,7 @@ KsCompletePendingRequest(
}
/*
@unimplemented
@implemented
*/
KSDDKAPI
NTSTATUS
@ -1722,8 +1722,118 @@ KsCreateBusEnumObject(
IN REFGUID InterfaceGuid OPTIONAL,
IN PWCHAR ServiceRelativePath OPTIONAL)
{
UNIMPLEMENTED
return STATUS_UNSUCCESSFUL;
ULONG Length;
NTSTATUS Status = STATUS_SUCCESS;
UNICODE_STRING ServiceKeyPath = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\");
PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension;
PDEVICE_EXTENSION DeviceExtension;
/* calculate sizeof bus enum device extension */
Length = wcslen(BusIdentifier) * sizeof(WCHAR);
Length += sizeof(BUS_ENUM_DEVICE_EXTENSION);
BusDeviceExtension = ExAllocatePool(NonPagedPool, Length);
if (!BusDeviceExtension)
{
/* not enough memory */
return STATUS_INSUFFICIENT_RESOURCES;
}
/* zero device extension */
RtlZeroMemory(BusDeviceExtension, sizeof(BUS_ENUM_DEVICE_EXTENSION));
/* initialize bus device extension */
wcscpy(BusDeviceExtension->BusIdentifier, BusIdentifier);
/* allocate service path string */
Length = ServiceKeyPath.MaximumLength;
Length += BusDeviceObject->DriverObject->DriverExtension->ServiceKeyName.MaximumLength;
if (ServiceRelativePath)
{
/* relative path for devices */
Length += wcslen(ServiceRelativePath) + 2 * sizeof(WCHAR);
}
BusDeviceExtension->ServicePath.Length = 0;
BusDeviceExtension->ServicePath.MaximumLength = Length;
BusDeviceExtension->ServicePath.Buffer = ExAllocatePool(NonPagedPool, Length);
if (!BusDeviceExtension->ServicePath.Buffer)
{
/* not enough memory */
ExFreePool(BusDeviceExtension);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlAppendUnicodeStringToString(&BusDeviceExtension->ServicePath, &ServiceKeyPath);
RtlAppendUnicodeStringToString(&BusDeviceExtension->ServicePath, &BusDeviceObject->DriverObject->DriverExtension->ServiceKeyName);
if (ServiceRelativePath)
{
RtlAppendUnicodeToString(&BusDeviceExtension->ServicePath, L"\\");
RtlAppendUnicodeToString(&BusDeviceExtension->ServicePath, ServiceRelativePath);
}
if (InterfaceGuid)
{
/* register an device interface */
Status = IoRegisterDeviceInterface(PhysicalDeviceObject, InterfaceGuid, NULL, &BusDeviceExtension->SymbolicLinkName);
/* check for success */
if (!NT_SUCCESS(Status))
{
ExFreePool(BusDeviceExtension->ServicePath.Buffer);
ExFreePool(BusDeviceExtension);
return Status;
}
/* now enable device interface */
Status = IoSetDeviceInterfaceState(&BusDeviceExtension->SymbolicLinkName, TRUE);
if (!NT_SUCCESS(Status))
{
ExFreePool(BusDeviceExtension->ServicePath.Buffer);
ExFreePool(BusDeviceExtension);
return Status;
}
/* set state enabled */
BusDeviceExtension->Enabled = TRUE;
}
/* store device objects */
BusDeviceExtension->BusDeviceObject = BusDeviceObject;
BusDeviceExtension->PnpDeviceObject = PnpDeviceObject;
BusDeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
if (!PnpDeviceObject)
{
BusDeviceExtension->PnpDeviceObject = IoAttachDeviceToDeviceStack(BusDeviceObject, PhysicalDeviceObject);
if (!BusDeviceExtension->PnpDeviceObject)
{
/* failed to attach device */
if (BusDeviceExtension->Enabled)
{
IoSetDeviceInterfaceState(&BusDeviceExtension->SymbolicLinkName, FALSE);
RtlFreeUnicodeString(&BusDeviceExtension->SymbolicLinkName);
}
/* free device extension */
ExFreePool(BusDeviceExtension->ServicePath.Buffer);
ExFreePool(BusDeviceExtension);
return STATUS_DEVICE_REMOVED;
}
}
/* attach device extension */
DeviceExtension = (PDEVICE_EXTENSION)BusDeviceObject->DeviceExtension;
DeviceExtension->DeviceHeader = (PKSIDEVICE_HEADER)BusDeviceExtension;
/* FIXME scan bus and invalidate device relations */
return Status;
}
NTSTATUS

View file

@ -145,4 +145,19 @@ typedef struct
typedef BOOLEAN (NTAPI *PKSEVENT_SYNCHRONIZED_ROUTINE)(PKSEVENT_CTX Context);
typedef struct
{
BOOLEAN Enabled;
PDEVICE_OBJECT PnpDeviceObject;
PDEVICE_OBJECT PhysicalDeviceObject;
PDEVICE_OBJECT BusDeviceObject;
UNICODE_STRING ServicePath;
UNICODE_STRING SymbolicLinkName;
WCHAR BusIdentifier[1];
}BUS_ENUM_DEVICE_EXTENSION, *PBUS_ENUM_DEVICE_EXTENSION;
#endif