Author: tkreuzer Date: Sun Feb 9 18:05:00 2014 New Revision: 62079
URL: http://svn.reactos.org/svn/reactos?rev=62079&view=rev Log: [FREELDR] Improve performance of registry enumeration by returning the enumerated subkey in RegEnumKey, instead of searching it by name again.
Modified: trunk/reactos/boot/freeldr/freeldr/include/registry.h trunk/reactos/boot/freeldr/freeldr/reactos/registry.c trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c
Modified: trunk/reactos/boot/freeldr/freeldr/include/registry.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/registry.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/registry.h [iso-8859-1] Sun Feb 9 18:05:00 2014 @@ -78,10 +78,12 @@ PCWSTR Name);
LONG -RegEnumKey(FRLDRHKEY Key, - ULONG Index, - PWCHAR Name, - ULONG* NameSize); +RegEnumKey( + _In_ FRLDRHKEY Key, + _In_ ULONG Index, + _Out_ PWCHAR Name, + _Inout_ ULONG* NameSize, + _Out_opt_ FRLDRHKEY *SubKey);
LONG RegOpenKey(FRLDRHKEY ParentKey,
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/registry.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/reacto... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/reactos/registry.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/reactos/registry.c [iso-8859-1] Sun Feb 9 18:05:00 2014 @@ -259,13 +259,13 @@ return NULL; }
-// FIXME: optionally return the subkey node/handle as optimization LONG RegEnumKey( _In_ FRLDRHKEY Key, _In_ ULONG Index, _Out_ PWCHAR Name, - _Inout_ ULONG* NameSize) + _Inout_ ULONG* NameSize, + _Out_opt_ FRLDRHKEY *SubKey) { PHHIVE Hive = &CmHive->Hive; PCM_KEY_NODE KeyNode, SubKeyNode; @@ -304,6 +304,11 @@ }
*NameSize = CmCopyKeyName(SubKeyNode, Name, *NameSize); + + if (SubKey != NULL) + { + *SubKey = (FRLDRHKEY)SubKeyNode; + }
TRACE("RegEnumKey done -> %u, '%.*s'\n", *NameSize, *NameSize, Name); return STATUS_SUCCESS;
Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/window... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/windows/wlregistry.c [iso-8859-1] Sun Feb 9 18:05:00 2014 @@ -537,7 +537,7 @@ { /* Get the Driver's Name */ ValueSize = sizeof(ServiceName); - rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize); + rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize, &hDriverKey); TRACE("RegEnumKey(): rc %d\n", (int)rc);
/* Make sure it's valid, and check if we're done */ @@ -550,62 +550,58 @@ } //TRACE_CH(REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName);
- /* open driver Key */ - rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey); - if (rc == ERROR_SUCCESS) + /* Read the Start Value */ + ValueSize = sizeof(ULONG); + rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize); + if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1; + //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue); + + /* Read the Tag */ + ValueSize = sizeof(ULONG); + rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize); + if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1; + //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue); + + /* Read the driver's group */ + DriverGroupSize = sizeof(DriverGroup); + rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize); + //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup); + + /* Make sure it should be started */ + if ((StartValue == 0) && + (TagValue == OrderList[TagIndex]) && + (_wcsicmp(DriverGroup, GroupName) == 0)) { + + /* Get the Driver's Location */ + ValueSize = sizeof(TempImagePath); + rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize); + + /* Write the whole path if it suceeded, else prepare to fail */ + if (rc != ERROR_SUCCESS) { + TRACE_CH(REACTOS, "ImagePath: not found\n"); + TempImagePath[0] = 0; + sprintf(ImagePath, "%s\system32\drivers\%S.sys", DirectoryPath, ServiceName); + } else if (TempImagePath[0] != L'\') { + sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath); + } else { + sprintf(ImagePath, "%S", TempImagePath); + TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath); + } + + TRACE("Adding boot driver: '%s'\n", ImagePath); + + Status = WinLdrAddDriverToList(BootDriverListHead, + L"\Registry\Machine\System\CurrentControlSet\Services\", + TempImagePath, + ServiceName); + + if (!Status) + ERR("Failed to add boot driver\n"); + } + else { - /* Read the Start Value */ - ValueSize = sizeof(ULONG); - rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize); - if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1; - //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue); - - /* Read the Tag */ - ValueSize = sizeof(ULONG); - rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize); - if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1; - //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue); - - /* Read the driver's group */ - DriverGroupSize = sizeof(DriverGroup); - rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize); - //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup); - - /* Make sure it should be started */ - if ((StartValue == 0) && - (TagValue == OrderList[TagIndex]) && - (_wcsicmp(DriverGroup, GroupName) == 0)) { - - /* Get the Driver's Location */ - ValueSize = sizeof(TempImagePath); - rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize); - - /* Write the whole path if it suceeded, else prepare to fail */ - if (rc != ERROR_SUCCESS) { - TRACE_CH(REACTOS, "ImagePath: not found\n"); - TempImagePath[0] = 0; - sprintf(ImagePath, "%s\system32\drivers\%S.sys", DirectoryPath, ServiceName); - } else if (TempImagePath[0] != L'\') { - sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath); - } else { - sprintf(ImagePath, "%S", TempImagePath); - TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath); - } - - TRACE("Adding boot driver: '%s'\n", ImagePath); - - Status = WinLdrAddDriverToList(BootDriverListHead, - L"\Registry\Machine\System\CurrentControlSet\Services\", - TempImagePath, - ServiceName); - - if (!Status) - ERR("Failed to add boot driver\n"); - } else - { - //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n", - // ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName); - } + //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n", + // ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName); }
Index++; @@ -617,7 +613,7 @@ { /* Get the Driver's Name */ ValueSize = sizeof(ServiceName); - rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize); + rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize, &hDriverKey);
//TRACE_CH(REACTOS, "RegEnumKey(): rc %d\n", (int)rc); if (rc == ERROR_NO_MORE_ITEMS) @@ -629,61 +625,57 @@ } TRACE("Service %d: '%S'\n", (int)Index, ServiceName);
- /* open driver Key */ - rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey); - if (rc == ERROR_SUCCESS) + /* Read the Start Value */ + ValueSize = sizeof(ULONG); + rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize); + if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1; + //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue); + + /* Read the Tag */ + ValueSize = sizeof(ULONG); + rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize); + if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1; + //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue); + + /* Read the driver's group */ + DriverGroupSize = sizeof(DriverGroup); + rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize); + //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup); + + for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) { + if (TagValue == OrderList[TagIndex]) break; + } + + if ((StartValue == 0) && + (TagIndex > OrderList[0]) && + (_wcsicmp(DriverGroup, GroupName) == 0)) { + + ValueSize = sizeof(TempImagePath); + rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize); + if (rc != ERROR_SUCCESS) { + TRACE_CH(REACTOS, "ImagePath: not found\n"); + TempImagePath[0] = 0; + sprintf(ImagePath, "%ssystem32\drivers\%S.sys", DirectoryPath, ServiceName); + } else if (TempImagePath[0] != L'\') { + sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath); + } else { + sprintf(ImagePath, "%S", TempImagePath); + TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath); + } + TRACE(" Adding boot driver: '%s'\n", ImagePath); + + Status = WinLdrAddDriverToList(BootDriverListHead, + L"\Registry\Machine\System\CurrentControlSet\Services\", + TempImagePath, + ServiceName); + + if (!Status) + ERR(" Failed to add boot driver\n"); + } + else { - /* Read the Start Value */ - ValueSize = sizeof(ULONG); - rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize); - if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1; - //TRACE_CH(REACTOS, " Start: %x \n", (int)StartValue); - - /* Read the Tag */ - ValueSize = sizeof(ULONG); - rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize); - if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1; - //TRACE_CH(REACTOS, " Tag: %x \n", (int)TagValue); - - /* Read the driver's group */ - DriverGroupSize = sizeof(DriverGroup); - rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize); - //TRACE_CH(REACTOS, " Group: '%S' \n", DriverGroup); - - for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) { - if (TagValue == OrderList[TagIndex]) break; - } - - if ((StartValue == 0) && - (TagIndex > OrderList[0]) && - (_wcsicmp(DriverGroup, GroupName) == 0)) { - - ValueSize = sizeof(TempImagePath); - rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize); - if (rc != ERROR_SUCCESS) { - TRACE_CH(REACTOS, "ImagePath: not found\n"); - TempImagePath[0] = 0; - sprintf(ImagePath, "%ssystem32\drivers\%S.sys", DirectoryPath, ServiceName); - } else if (TempImagePath[0] != L'\') { - sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath); - } else { - sprintf(ImagePath, "%S", TempImagePath); - TRACE_CH(REACTOS, "ImagePath: '%s'\n", ImagePath); - } - TRACE(" Adding boot driver: '%s'\n", ImagePath); - - Status = WinLdrAddDriverToList(BootDriverListHead, - L"\Registry\Machine\System\CurrentControlSet\Services\", - TempImagePath, - ServiceName); - - if (!Status) - ERR(" Failed to add boot driver\n"); - } else - { - //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n", - // ServiceName, StartValue, TagValue, DriverGroup, GroupName); - } + //TRACE(" Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n", + // ServiceName, StartValue, TagValue, DriverGroup, GroupName); }
Index++;