From c498d0930a790bdb498b873f43dad34bb5ca4280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 10 Apr 2026 19:13:45 +0200 Subject: [PATCH] [SMSS] "BootDir" value creation: Use a fallback if no drive letter was assigned to the SystemPartition In `SmpTranslateSystemPartitionInformation()`, fall back to using the OS boot drive letter if none was found to be assigned to the SystemPartition. Otherwise, just fail if any other error was encountered. (This behaviour has been introduced in a post-SP1 Windows 7 update.) Additionally, simplify very slightly the code. --- base/system/smss/sminit.c | 43 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/base/system/smss/sminit.c b/base/system/smss/sminit.c index bba8faf7cbe..3594e52d62c 100644 --- a/base/system/smss/sminit.c +++ b/base/system/smss/sminit.c @@ -872,17 +872,11 @@ SmpTranslateSystemPartitionInformation(VOID) TRUE, &Context, NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT1("SMSS: Cannot find drive letter for system partition\n"); - return; - } - /* Keep searching until we find it */ - do + while (NT_SUCCESS(Status)) { /* Is this it? */ - if ((RtlEqualUnicodeString(&DirInfo->TypeName, &SearchString, TRUE)) && + if (RtlEqualUnicodeString(&DirInfo->TypeName, &SearchString, TRUE) && (DirInfo->Name.Length == 2 * sizeof(WCHAR)) && (DirInfo->Name.Buffer[1] == L':')) { @@ -904,13 +898,9 @@ SmpTranslateSystemPartitionInformation(VOID) NtClose(LinkHandle); /* Check if it matches the string we had found earlier */ - if ((NT_SUCCESS(Status)) && - ((RtlEqualUnicodeString(&SystemPartition, - &LinkTarget, - TRUE)) || - ((RtlPrefixUnicodeString(&SystemPartition, - &LinkTarget, - TRUE)) && + if (NT_SUCCESS(Status) && + (RtlEqualUnicodeString(&SystemPartition, &LinkTarget, TRUE) || + (RtlPrefixUnicodeString(&SystemPartition, &LinkTarget, TRUE) && (LinkTarget.Buffer[SystemPartition.Length / sizeof(WCHAR)] == L'\\')))) { /* All done */ @@ -927,11 +917,22 @@ SmpTranslateSystemPartitionInformation(VOID) FALSE, &Context, NULL); - } while (NT_SUCCESS(Status)); + } if (!NT_SUCCESS(Status)) { - DPRINT1("SMSS: Cannot find drive letter for system partition\n"); + DPRINT1("SMSS: Cannot find drive letter for system partition: 0x%x\n", Status); +#if (NTDDI_VERSION > NTDDI_WIN7SP1) || defined(__REACTOS__) + /* If we failed because no drive letter associated to the system + * volume was found (none was assigned to it), fall back to using + * the OS boot drive letter instead. Otherwise, fail altogether. + * NOTE: This has been introduced in a post-SP1 Windows 7 update. */ + if (Status != STATUS_NO_MORE_ENTRIES) + return; + DirInfo->Name.Buffer[0] = SharedUserData->NtSystemRoot[0]; + DirInfo->Name.Buffer[1] = SharedUserData->NtSystemRoot[1]; // == L':'; +#else return; +#endif } /* Open the setup key again, for full access this time */ @@ -945,15 +946,15 @@ SmpTranslateSystemPartitionInformation(VOID) Status = NtOpenKey(&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes); if (!NT_SUCCESS(Status)) { - DPRINT1("SMSS: Cannot open software setup key for writing: 0x%x\n", - Status); + DPRINT1("SMSS: Cannot open software setup key for writing: 0x%x\n", Status); return; } /* Wrap up the end of the link buffer */ - wcsncpy(LinkBuffer, DirInfo->Name.Buffer, 2); + LinkBuffer[0] = DirInfo->Name.Buffer[0]; + LinkBuffer[1] = DirInfo->Name.Buffer[1]; // == L':'; LinkBuffer[2] = L'\\'; - LinkBuffer[3] = L'\0'; + LinkBuffer[3] = UNICODE_NULL; /* Now set this as the "BootDir" */ RtlInitUnicodeString(&UnicodeString, L"BootDir");