10

On Windows, file comparisons are case insensitive operations. However, a truly case insensitive system would be sensitive to locale settings, and would have to deal with three cases, rather than two (at least, according to Unicode). For various reasons, I'd like to replicate the way Windows does this outside of Windows, if possible.

Does Windows use this kind of locale support, or does it follow a more predictable pattern (e.g. somewhat like C#'s OrdinalIgnoreCase settings)?

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
  • Applying locales to filename comparisons would be a disaster, as two differently named files in one locale could look like they are same file in a different locale.Clearly, filename mapping must be immutable, relative to the FS ... and it is: every NTFS filesystem contains a table -- $UpCase, MFT entry #10 -- that maps characters to upper case. This file is created when the FS is formatted and never changes. – Jim Balter Jun 10 '20 at 09:39

1 Answers1

2

As far as I know NTFS supports two modes:

  1. POSIX namespace:
    Any UTF-16 code unit (case sensitive) except U+0000 (NUL) and / (slash).

  2. Win32 namespace:
    Any UTF-16 code unit (case insensitive) except U+0000 (NUL) / (slash) \ (backslash) and some other characters like :*" etc.

In Win32 mode any program using the Win32-API converts any character of a filename to uppercase (if possible) and uses that name internally.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Mithrandir
  • 24,869
  • 6
  • 50
  • 66
  • Can you reference that? I can't see anywhere that everything gets converted to uppercase -- in particular given that that'd be completely wrong in many locales.... – Billy ONeal Jan 17 '12 at 19:08
  • 1
    i had to dig deep in my bookmarks ... http://blogs.msdn.com/b/michkap/archive/2005/01/16/353873.aspx – Mithrandir Jan 17 '12 at 19:25
  • Well, that's the case mapping table. That doesn't mean that everything gets turned into uppercase first :P – Billy ONeal Jan 17 '12 at 19:32
  • 1
    Found this one too: http://blogs.msdn.com/b/michkap/archive/2005/10/17/481600.aspx – Billy ONeal Jan 17 '12 at 20:15
  • 2
    -1 for this answer. I have had NT filesystem drivers in a kernel debugger. It is trivially observable that filenames are *not* converted to upper case when given to the kernel. – asveikau Jan 04 '16 at 23:47
  • @asveikau Who said anything about NT drivers?! And good for you, keep on trivially observing! – Mithrandir Jan 05 '16 at 08:33
  • @asveikau: see https://support.microsoft.com/en-us/kb/100625 (section "MORE INFOMATION") about the way win32 applications handle filenames. I never said *anything* about the filesystems drivers!!!!! – Mithrandir Jan 05 '16 at 08:45
  • 2
    You implied that the Win32 layer does this. That would imply that NT sees uppercase. It's just a wrong statement. – asveikau Jan 06 '16 at 18:00
  • 3
    The articles linked by @BillyONeal don't exist anymeore, but they're archived here: http://archives.miloush.net/michkap/archive/2005/01/16/353873.html and http://archives.miloush.net/michkap/archive/2005/10/17/481600.html – Tereza Tomcova Jun 16 '16 at 10:45
  • @BillyONeal "in particular given that that'd be completely wrong in many locales" -- obviously the mapping has to be exactly the same regardless of the locale, since it determines which file on a physical disk is selected by a pathname, and the pathname must always select the same file. Just imagine having pathnames that in one locale create two different files and in another locale overwrite the same file. That's clearly an extremely bad design, so it's it not how it works. Tough luck for people whose languages don't match the mapping stored on their NTFS volumes. – Jim Balter Jun 10 '20 at 09:58
  • Sorry, but this answer is quite wrong. Case is preserved on the FS -- programs and the Win32 API do not do any case folding of filenames. What's the Win32 call to do this? Answer: there is none. (There's a call for doing comparisons for sorting, but that's a different matter entirely.) Rather, it is NTFS itself that does the folding when it looks up names on the volume, using the $UpCase file (MFT entry #10) to do the folding. – Jim Balter Jun 10 '20 at 10:10