[Tutor] Case Insensitive Globing
eryk sun
eryksun at gmail.com
Sun May 19 08:43:13 EDT 2019
On 5/18/19, Steven D'Aprano <steve at pearwood.info> wrote:
>
> That means that, like Windows file systems FAT and NTFS, file names are
> case-insensitive: files "Foo", "foo" and "FOO" are all considered the
> same. But unlike Windows, the file system preserves the case of the file
> as you created it, so if you created it as "foO" that's how it will be
> recorded on the disk rather than normalizied to "foo".
NTFS and FAT32 are case preserving.
> Fun fact: even NTFS supports a case-sensitive mode! But again, hardly
> anyone uses it.
There's nothing inherent in the design of NTFS that prevents
case-sensitive names in a directory. It's strictly a function of the
OS and filesystem driver. On non-Windows platforms, an NTFS driver can
create names that differ only in case. An example is the Linux ntfs-3g
driver, which allows this unless the "windows_names" option is set.
In a Windows system, the NT object namespace is case sensitive, and
overriding a create or open to be case insensitive requires the flag
OBJ_CASE_INSENSITIVE. The Windows API uses this flag by default in the
file and registry APIs. However, beginning with Windows XP, the kernel
takes it a step further. Regardless of the user-mode subsytem, it
forces this flag for object types that are defined as case
insensitive, such as Object Manager "Directory" and "SymbolicLink"
objects (used in the root object namespace, akin to the root
filesystem in Unix), Configuration Manager "Key" objects (registry),
and I/O manager "Device" and "File" objects.
Prior to Windows XP, it was possible to force a CreateFile or
FindFirstFileEx call to be case sensitive, respectively via the flags
FILE_FLAG_POSIX_SEMANTICS and FIND_FIRST_EX_CASE_SENSITIVE.
Internally, this is implemented by *omitting* the OBJ_CASE_INSENSITIVE
flag that the Windows API usually includes for device and file
operations. This didn't change in XP, but, as mentioned above, it's
impotent now since the kernel itself adds the flag for
case-insensitive object types. The only way to change this is to
restart the system after zeroing the "obcaseinsensitive" value in the
"Session Manager\kernel" registry key. That's not tenable in practice,
so we have to just accept that device and file names are case
insensitive.
That said, in Windows 10, the Windows Subsystem for Linux requires a
way to change the filesystem default to case sensitive for individual
directories. If a directory is case sensitive, then create, open, and
control operations in or on it always ignore OBJ_CASE_INSENSITIVE.
This directory attribute can be queried and set with a new file
information class in the NT API named "FileCaseSensitiveInformation",
or on the command line via `fsutil file queryCaseSensitiveInfo <path>`
and `fsutil file setCaseSensitiveInfo <path> [enable|disable]`.
More information about the Tutor
mailing list