mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 20:33:22 +00:00
[UMPNPMGR] Move device id generation into a separate function and limit device instance number
This commit is contained in:
parent
426687becf
commit
f63e8f8a03
1 changed files with 49 additions and 30 deletions
|
@ -2983,6 +2983,51 @@ CreateDeviceInstance(LPWSTR pszDeviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
CONFIGRET
|
||||||
|
GenerateDeviceID(
|
||||||
|
_Inout_ LPWSTR pszDeviceID,
|
||||||
|
_In_ PNP_RPC_STRING_LEN ulLength)
|
||||||
|
{
|
||||||
|
WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN];
|
||||||
|
HKEY hKey;
|
||||||
|
DWORD dwInstanceNumber;
|
||||||
|
DWORD dwError = ERROR_SUCCESS;
|
||||||
|
CONFIGRET ret = CR_SUCCESS;
|
||||||
|
|
||||||
|
/* Generated ID is: Root\<Device ID>\<Instance number> */
|
||||||
|
dwInstanceNumber = 0;
|
||||||
|
while (dwError == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
if (dwInstanceNumber >= 10000)
|
||||||
|
return CR_FAILURE;
|
||||||
|
|
||||||
|
swprintf(szGeneratedInstance, L"Root\\%ls\\%04lu",
|
||||||
|
pszDeviceID, dwInstanceNumber);
|
||||||
|
|
||||||
|
/* Try to open the enum key of the device instance */
|
||||||
|
dwError = RegOpenKeyEx(hEnumKey, szGeneratedInstance, 0, KEY_QUERY_VALUE, &hKey);
|
||||||
|
if (dwError == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
dwInstanceNumber++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pszDeviceID is an out parameter too for generated IDs */
|
||||||
|
if (wcslen(szGeneratedInstance) > ulLength)
|
||||||
|
{
|
||||||
|
ret = CR_BUFFER_SMALL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wcscpy(pszDeviceID, szGeneratedInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Function 28 */
|
/* Function 28 */
|
||||||
DWORD
|
DWORD
|
||||||
WINAPI
|
WINAPI
|
||||||
|
@ -3010,36 +3055,10 @@ PNP_CreateDevInst(
|
||||||
|
|
||||||
if (ulFlags & CM_CREATE_DEVNODE_GENERATE_ID)
|
if (ulFlags & CM_CREATE_DEVNODE_GENERATE_ID)
|
||||||
{
|
{
|
||||||
WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN];
|
ret = GenerateDeviceID(pszDeviceID,
|
||||||
DWORD dwInstanceNumber;
|
ulLength);
|
||||||
DWORD dwError = ERROR_SUCCESS;
|
if (ret != CR_SUCCESS)
|
||||||
HKEY hKey;
|
return ret;
|
||||||
|
|
||||||
/* Generated ID is: Root\<Device ID>\<Instance number> */
|
|
||||||
dwInstanceNumber = 0;
|
|
||||||
while (dwError == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
swprintf(szGeneratedInstance, L"Root\\%ls\\%04lu",
|
|
||||||
pszDeviceID, dwInstanceNumber);
|
|
||||||
|
|
||||||
/* Try to open the enum key of the device instance */
|
|
||||||
dwError = RegOpenKeyEx(hEnumKey, szGeneratedInstance, 0, KEY_QUERY_VALUE, &hKey);
|
|
||||||
if (dwError == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
dwInstanceNumber++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pszDeviceID is an out parameter too for generated IDs */
|
|
||||||
if (wcslen(szGeneratedInstance) > ulLength)
|
|
||||||
{
|
|
||||||
ret = CR_BUFFER_SMALL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wcscpy(pszDeviceID, szGeneratedInstance);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the device instance */
|
/* Create the device instance */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue