From 22d077f9f12e8266f2e73ae70eb03cfd38360f84 Mon Sep 17 00:00:00 2001 From: Daniel Victor Date: Tue, 3 Jun 2025 11:47:15 -0300 Subject: [PATCH] [FREELDR] Make the NTFS filename comparison conforming to NTLDR/BOOTMGR (#8021) When an NTFS partition is created with Windows and modified with Linux (see below), the NTLDR/BOOTMGR will compare the file names ignoring the case of the files, while FreeLdr does not and the same hack is on Btrfs file name comparison. This PR is necessary because the case of the file names on registry, etc. may not always be consistent! How to reproduce: - Try to install Windows with NTFS and install FreeLdr on it; - Try to modify Windows partition on Linux like creating/copying some new files; - Try to boot with FreeLdr (it will fail if the hive file path case is different than the actual file path); - Try to boot with NTLDR/BOOTMGR (it will work finally reaching the desktop). --- boot/freeldr/freeldr/lib/fs/ntfs.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/boot/freeldr/freeldr/lib/fs/ntfs.c b/boot/freeldr/freeldr/lib/fs/ntfs.c index c8d4a547d58..1a4b9268ccf 100644 --- a/boot/freeldr/freeldr/lib/fs/ntfs.c +++ b/boot/freeldr/freeldr/lib/fs/ntfs.c @@ -525,18 +525,16 @@ static BOOLEAN NtfsCompareFileName(PCHAR FileName, PNTFS_INDEX_ENTRY IndexEntry) if (strlen(FileName) != EntryFileNameLength) return FALSE; - /* Do case-sensitive compares for Posix file names. */ - if (IndexEntry->FileName.FileNameType == NTFS_FILE_NAME_POSIX) + /* + * Always perform case-insensitive comparison for file names. + * This is necessary, because when modifying e.g. on Linux a Windows NTFS + * partition formatted with Windows itself, the NTLDR/BOOTMGR will boot + * normally ignoring the case of the paths. + */ + for (i = 0; i < EntryFileNameLength; i++) { - for (i = 0; i < EntryFileNameLength; i++) - if (EntryFileName[i] != FileName[i]) - return FALSE; - } - else - { - for (i = 0; i < EntryFileNameLength; i++) - if (tolower(EntryFileName[i]) != tolower(FileName[i])) - return FALSE; + if (tolower(EntryFileName[i]) != tolower(FileName[i])) + return FALSE; } return TRUE;