Author: janderwald
Date: Thu Sep 23 11:36:00 2010
New Revision: 48850
URL:
http://svn.reactos.org/svn/reactos?rev=48850&view=rev
Log:
[KS]
- Simplify KsTopologyPropertyHandler by using KspReadMediaCategory helper
- Return correct status code in case of an overflow
Modified:
trunk/reactos/drivers/ksfilter/ks/ksfunc.h
trunk/reactos/drivers/ksfilter/ks/topology.c
Modified: trunk/reactos/drivers/ksfilter/ks/ksfunc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/ksfunc…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/ksfunc.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/ksfunc.h [iso-8859-1] Thu Sep 23 11:36:00 2010
@@ -186,3 +186,9 @@
IN PVOID Descriptors,
IN ULONG DescriptorSize,
OUT PKSPIN_CONNECT* Connect);
+
+NTSTATUS
+KspReadMediaCategory(
+ IN LPGUID Category,
+ PKEY_VALUE_PARTIAL_INFORMATION *OutInformation);
+
Modified: trunk/reactos/drivers/ksfilter/ks/topology.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/topolo…
==============================================================================
--- trunk/reactos/drivers/ksfilter/ks/topology.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/ksfilter/ks/topology.c [iso-8859-1] Thu Sep 23 11:36:00 2010
@@ -147,16 +147,9 @@
IN OUT PVOID Data,
IN const KSTOPOLOGY* Topology)
{
- UNICODE_STRING LocalMachine =
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\MediaCategories\\");
- UNICODE_STRING Name = RTL_CONSTANT_STRING(L"Name");
- UNICODE_STRING GuidString;
- UNICODE_STRING KeyName;
- OBJECT_ATTRIBUTES ObjectAttributes;
KSP_NODE * Node;
PIO_STACK_LOCATION IoStack;
- ULONG Size;
NTSTATUS Status;
- HANDLE hKey;
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
IoStack = IoGetCurrentIrpStackLocation(Irp);
@@ -191,79 +184,26 @@
break;
}
- Status =
RtlStringFromGUID(&Topology->TopologyNodesNames[Node->NodeId],
&GuidString);
+ Status =
KspReadMediaCategory((LPGUID)&Topology->TopologyNodesNames[Node->NodeId],
&KeyInfo);
if (!NT_SUCCESS(Status))
{
Irp->IoStatus.Information = 0;
break;
}
- KeyName.Length = 0;
- KeyName.MaximumLength = LocalMachine.Length + GuidString.Length +
sizeof(WCHAR);
- KeyName.Buffer = AllocateItem(PagedPool, KeyName.MaximumLength);
- if (!KeyName.Buffer)
- {
- Irp->IoStatus.Information = 0;
- Status = STATUS_INSUFFICIENT_RESOURCES;
- RtlFreeUnicodeString(&GuidString);
- break;
- }
-
- RtlAppendUnicodeStringToString(&KeyName, &LocalMachine);
- RtlAppendUnicodeStringToString(&KeyName, &GuidString);
-
- RtlFreeUnicodeString(&GuidString);
-
- InitializeObjectAttributes(&ObjectAttributes, &KeyName,
OBJ_CASE_INSENSITIVE, NULL, NULL);
- Status = ZwOpenKey(&hKey, GENERIC_READ, &ObjectAttributes);
-
- FreeItem(KeyName.Buffer);
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status);
- Irp->IoStatus.Information = 0;
- break;
- }
-
- Status = ZwQueryValueKey(hKey, &Name, KeyValuePartialInformation, NULL,
0, &Size);
- if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
- {
- ZwClose(hKey);
- Irp->IoStatus.Information = 0;
- break;
- }
-
- ASSERT(Size);
- KeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION) AllocateItem(NonPagedPool, Size);
- if (!KeyInfo)
- {
- Status = STATUS_NO_MEMORY;
- break;
- }
-
- Status = ZwQueryValueKey(hKey, &Name, KeyValuePartialInformation,
(PVOID)KeyInfo, Size, &Size);
- if (!NT_SUCCESS(Status))
- {
- FreeItem(KeyInfo);
- ZwClose(hKey);
- Irp->IoStatus.Information = 0;
- break;
- }
-
- ZwClose(hKey);
+ Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
+
if (KeyInfo->DataLength + sizeof(WCHAR) >
IoStack->Parameters.DeviceIoControl.OutputBufferLength)
{
- Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
- Status = STATUS_MORE_ENTRIES;
+ Status = STATUS_BUFFER_OVERFLOW;
FreeItem(KeyInfo);
break;
}
RtlMoveMemory(Irp->UserBuffer, &KeyInfo->Data,
KeyInfo->DataLength);
((LPWSTR)Irp->UserBuffer)[KeyInfo->DataLength / sizeof(WCHAR)] =
L'\0';
- Irp->IoStatus.Information = KeyInfo->DataLength + sizeof(WCHAR);
FreeItem(KeyInfo);
+
break;
default:
Irp->IoStatus.Information = 0;