https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ccb8c906b076f6316b05b…
commit ccb8c906b076f6316b05beaa981e815b3c127278
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Mon Dec 31 11:20:30 2018 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Mon Dec 31 11:21:17 2018 +0100
[UMPNPMGR] PNP_GetDeviceList/PNP_GetDeviceListSize: Move device relations code into
separate functions.
---
base/services/umpnpmgr/umpnpmgr.c | 178 +++++++++++++++++++++++---------------
1 file changed, 108 insertions(+), 70 deletions(-)
diff --git a/base/services/umpnpmgr/umpnpmgr.c b/base/services/umpnpmgr/umpnpmgr.c
index 2420a47a85..e7d1d42bdf 100644
--- a/base/services/umpnpmgr/umpnpmgr.c
+++ b/base/services/umpnpmgr/umpnpmgr.c
@@ -529,6 +529,57 @@ PNP_EnumerateSubKeys(
}
+static
+CONFIGRET
+GetRelationsInstanceList(
+ _In_ PWSTR pszDevice,
+ _In_ DWORD ulFlags,
+ _Inout_ PWSTR pszBuffer,
+ _Inout_ PDWORD pulLength)
+{
+ PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA PlugPlayData;
+ NTSTATUS Status;
+ CONFIGRET ret = CR_SUCCESS;
+
+ RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
+ pszDevice);
+
+ if (ulFlags & CM_GETIDLIST_FILTER_BUSRELATIONS)
+ {
+ PlugPlayData.Relations = 3;
+ }
+ else if (ulFlags & CM_GETIDLIST_FILTER_POWERRELATIONS)
+ {
+ PlugPlayData.Relations = 2;
+ }
+ else if (ulFlags & CM_GETIDLIST_FILTER_REMOVALRELATIONS)
+ {
+ PlugPlayData.Relations = 1;
+ }
+ else if (ulFlags & CM_GETIDLIST_FILTER_EJECTRELATIONS)
+ {
+ PlugPlayData.Relations = 0;
+ }
+
+ PlugPlayData.BufferSize = *pulLength * sizeof(WCHAR);
+ PlugPlayData.Buffer = pszBuffer;
+
+ Status = NtPlugPlayControl(PlugPlayControlQueryDeviceRelations,
+ (PVOID)&PlugPlayData,
+ sizeof(PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA));
+ if (NT_SUCCESS(Status))
+ {
+ *pulLength = PlugPlayData.BufferSize / sizeof(WCHAR);
+ }
+ else
+ {
+ ret = NtStatusToCrError(Status);
+ }
+
+ return ret;
+}
+
+
static
CONFIGRET
GetDeviceInstanceList(
@@ -729,12 +780,10 @@ PNP_GetDeviceList(
PNP_RPC_STRING_LEN *pulLength,
DWORD ulFlags)
{
- PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA PlugPlayData;
WCHAR szEnumerator[MAX_DEVICE_ID_LEN];
WCHAR szDevice[MAX_DEVICE_ID_LEN];
WCHAR szInstance[MAX_DEVICE_ID_LEN];
CONFIGRET ret = CR_SUCCESS;
- NTSTATUS Status;
DPRINT("PNP_GetDeviceList() called\n");
@@ -754,39 +803,10 @@ PNP_GetDeviceList(
CM_GETIDLIST_FILTER_REMOVALRELATIONS |
CM_GETIDLIST_FILTER_EJECTRELATIONS))
{
- RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
- pszFilter);
- if (ulFlags & CM_GETIDLIST_FILTER_BUSRELATIONS)
- {
- PlugPlayData.Relations = 3;
- }
- else if (ulFlags & CM_GETIDLIST_FILTER_POWERRELATIONS)
- {
- PlugPlayData.Relations = 2;
- }
- else if (ulFlags & CM_GETIDLIST_FILTER_REMOVALRELATIONS)
- {
- PlugPlayData.Relations = 1;
- }
- else if (ulFlags & CM_GETIDLIST_FILTER_EJECTRELATIONS)
- {
- PlugPlayData.Relations = 0;
- }
-
- PlugPlayData.BufferSize = *pulLength * sizeof(WCHAR);
- PlugPlayData.Buffer = Buffer;
-
- Status = NtPlugPlayControl(PlugPlayControlQueryDeviceRelations,
- (PVOID)&PlugPlayData,
- sizeof(PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA));
- if (NT_SUCCESS(Status))
- {
- *pulLength = PlugPlayData.BufferSize / sizeof(WCHAR);
- }
- else
- {
- ret = NtStatusToCrError(Status);
- }
+ ret = GetRelationsInstanceList(pszFilter,
+ ulFlags,
+ Buffer,
+ pulLength);
}
else if (ulFlags & CM_GETIDLIST_FILTER_SERVICE)
{
@@ -822,6 +842,56 @@ PNP_GetDeviceList(
}
+static
+CONFIGRET
+GetRelationsInstanceListSize(
+ _In_ PWSTR pszDevice,
+ _In_ DWORD ulFlags,
+ _Inout_ PDWORD pulLength)
+{
+ PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA PlugPlayData;
+ NTSTATUS Status;
+ CONFIGRET ret = CR_SUCCESS;
+
+ RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
+ pszDevice);
+
+ if (ulFlags & CM_GETIDLIST_FILTER_BUSRELATIONS)
+ {
+ PlugPlayData.Relations = 3;
+ }
+ else if (ulFlags & CM_GETIDLIST_FILTER_POWERRELATIONS)
+ {
+ PlugPlayData.Relations = 2;
+ }
+ else if (ulFlags & CM_GETIDLIST_FILTER_REMOVALRELATIONS)
+ {
+ PlugPlayData.Relations = 1;
+ }
+ else if (ulFlags & CM_GETIDLIST_FILTER_EJECTRELATIONS)
+ {
+ PlugPlayData.Relations = 0;
+ }
+
+ PlugPlayData.BufferSize = 0;
+ PlugPlayData.Buffer = NULL;
+
+ Status = NtPlugPlayControl(PlugPlayControlQueryDeviceRelations,
+ (PVOID)&PlugPlayData,
+ sizeof(PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA));
+ if (NT_SUCCESS(Status))
+ {
+ *pulLength = PlugPlayData.BufferSize / sizeof(WCHAR);
+ }
+ else
+ {
+ ret = NtStatusToCrError(Status);
+ }
+
+ return ret;
+}
+
+
static
CONFIGRET
GetDeviceInstanceListSize(
@@ -978,12 +1048,10 @@ PNP_GetDeviceListSize(
PNP_RPC_BUFFER_SIZE *pulLength,
DWORD ulFlags)
{
- PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA PlugPlayData;
WCHAR szEnumerator[MAX_DEVICE_ID_LEN];
WCHAR szDevice[MAX_DEVICE_ID_LEN];
WCHAR szInstance[MAX_DEVICE_ID_LEN];
CONFIGRET ret = CR_SUCCESS;
- NTSTATUS Status;
DPRINT("PNP_GetDeviceListSize(%p %S %p 0x%lx)\n",
hBinding, pszFilter, pulLength, ulFlags);
@@ -1006,39 +1074,9 @@ PNP_GetDeviceListSize(
CM_GETIDLIST_FILTER_REMOVALRELATIONS |
CM_GETIDLIST_FILTER_EJECTRELATIONS))
{
- RtlInitUnicodeString(&PlugPlayData.DeviceInstance,
- pszFilter);
- if (ulFlags & CM_GETIDLIST_FILTER_BUSRELATIONS)
- {
- PlugPlayData.Relations = 3;
- }
- else if (ulFlags & CM_GETIDLIST_FILTER_POWERRELATIONS)
- {
- PlugPlayData.Relations = 2;
- }
- else if (ulFlags & CM_GETIDLIST_FILTER_REMOVALRELATIONS)
- {
- PlugPlayData.Relations = 1;
- }
- else if (ulFlags & CM_GETIDLIST_FILTER_EJECTRELATIONS)
- {
- PlugPlayData.Relations = 0;
- }
-
- PlugPlayData.BufferSize = 0;
- PlugPlayData.Buffer = NULL;
-
- Status = NtPlugPlayControl(PlugPlayControlQueryDeviceRelations,
- (PVOID)&PlugPlayData,
- sizeof(PLUGPLAY_CONTROL_DEVICE_RELATIONS_DATA));
- if (NT_SUCCESS(Status))
- {
- *pulLength = PlugPlayData.BufferSize / sizeof(WCHAR);
- }
- else
- {
- ret = NtStatusToCrError(Status);
- }
+ ret = GetRelationsInstanceListSize(pszFilter,
+ ulFlags,
+ pulLength);
}
else if (ulFlags & CM_GETIDLIST_FILTER_SERVICE)
{