Windows and case-sensitive filesystem

Long ago, at the dawn of its birth, Windows used the FAT file system. Then she replaced Microsoft and IBM developed NTFS. In the old days, there were two opposite approaches to the file system. Linux uses a case-sensitive file system, while Microsoft uses case-insensitive.

The bottom line is that in a case-sensitive file system, it is assumed that names written in different registers (for example, FILE.txt and file.txt) are different names. And for Windows between them there is no difference.



Despite Windows case insensitivity to letters, NTFS developers approached the matter responsibly, and carefully preserve the case of directories and files. Perhaps they did not lose hope for rapprochement with the opposing camp.

First victims


Years passed, information technologies did not stand still, and Linux distributions learned how to mount NTFS partitions. Operating systems became closer, and our opponents first encountered on the same field - and the first problems appeared. By attaching an NTFS partition, a Linux user could create in the same directory several different files with names that differ only in case. And as we know, NTFS preserves the case of letters when creating file system objects. If you later connect the same NTFS partition to Windows, the operating system will start to confuse the twin files with each other. From her point of view, they have the same name! The user clicks on one file, and opens a completely different. In short, chaos and disgrace.

In 2016, Microsoft took a step toward Linux and released Windows 10 Anniversary Update with the WSL subsystem. Windows Subsystem for Linux (WSL) provides interfaces that are largely compatible with the interfaces of the Linux kernel. That allows you to run most Linux-based applications, including the original images of some Linux distributions. For example, Ubuntu 14.04! It was a revolution! Linux and Windows work on the same computer at the same time as partners. But unfortunately, the partners still looked at case sensitivity in different ways in terms of working with the file system. It has become even easier to confuse Windows by creating files or directories with names that differ only in case.

Reconciliation attempt


In the new version of Windows 10 Spring Creators Update, Microsoft has added the ability to set the case-sensitivity mode for a single directory. You can do this with the fsutil utility. The reader is probably already familiar with this useful utility.

Now she has two new teams:

fsutil file queryCaseSensitiveInfo


fsutil file setCaseSensitiveInfo



In order to use these commands, you need to have the WSL subsystem activated, and the setCaseSensitiveInfo command requires administrative rights.

After the inclusion of case-sensitivity mode, the files and directories inside will be available only if you specify their exact name! And Windows now clearly sees the difference between FILE.txt and file.txt.

On the other hand, the WSL subsystem must also consider whether the case-sensitivity mode is enabled or disabled for the directory in which it creates a file or a child directory. Directories that form the WSL structure or are created from WSL immediately have case sensitivity enabled. All other directories do not include default case-sensitivity mode.

If you go to the WSL directory with the case-sensitivity mode disabled and try to create two files in it, the names of which will differ only in case, you will get an error.

Thus, WSL and Windows divided the logical disk among themselves. Part of the directory supports the case-sensitivity mode, and the other part - no.

Get down below


Under the hood, the NtQueryInformationFile and NtSetInformationFile functions with the new FileCaseSensitiveInformation parameter are used to get and set the case-sensitivity flag.

Example:

HANDLE h = CreateFile( path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_SUPPORTS_USN_JOURNAL, 0); if( INVALID_HANDLE_VALUE == h ) return; IO_STATUS_BLOCK io; uint32_t csFlags = 0; DWORD error = NtQueryInformationFile( testHandle, &io, &csFlags, sizeof(csFlags), (FILE_INFORMATION_CLASS)0x47); // FileCaseSensitiveInformation CloseHandle(h); 

As a result, the function in the variable csFlags will be 1 if case sensitivity is enabled, and 0 if it is disabled.

Still lower - Raw NTFS


At the NTFS level, the case-sensitivity flag is stored in the StandartInfoData attribute, in the NumVersion field.
If the attribute is set, then NumVersion = 1, otherwise NumVersion = 0

 typedef struct _StandartInfoData_ { FILETIME CreateTime; FILETIME LastModTime; FILETIME LastModMFT; FILETIME LastAccess; DWORD FileAttrib; DWORD MaxVersions; DWORD NumVersion; // <-- DWORD ClassId; DWORD OwnerId; DWORD SecureId; ULONGLONG Quota; ULONGLONG SequenceNumber; } StandartInfoData; 

Conclusion


We see that Microsoft is making significant efforts to combine two different worlds in one system - Windows and Linux. And for the success of their mission, they made concessions in terms of the case sensitivity of their file system. Will it help? Will the contradictions solve? And what other problems will pop up? All this will show only His Majesty Time.

Wanted


By the way. Or not quite the way. Our colleagues here are looking for the head of the autotest development team. True work in Novosibirsk. If someone is interested, then here is the vacancy .

Source: https://habr.com/ru/post/414239/


All Articles