{"id":3155,"date":"2018-06-14T14:51:05","date_gmt":"2018-06-14T22:51:05","guid":{"rendered":"http:\/\/blogs.msdn.microsoft.com\/commandline\/?p=3155"},"modified":"2019-02-18T13:26:39","modified_gmt":"2019-02-18T21:26:39","slug":"improved-per-directory-case-sensitivity-support-in-wsl","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/commandline\/improved-per-directory-case-sensitivity-support-in-wsl\/","title":{"rendered":"Improved per-directory case sensitivity support in WSL"},"content":{"rendered":"<p>With the Windows Subsystem for Linux, we\u2019ve always allowed you to treat your files as case sensitive, just like Linux does. In the past, if you had files whose name differed only by case, these files could not be accessed by Windows, because Windows applications treat the file system as case insensitive.<\/p>\n<p>A while ago, we introduced <a href=\"https:\/\/devblogs.microsoft.com\/commandline\/per-directory-case-sensitivity-and-wsl\/\">per-directory case sensitivity<\/a>. This allows specific directories to be treated as case sensitive by both WSL and Windows applications. Because Linux developers usually expect the file system to be case sensitive, we opted to make new directories created by WSL on your Windows volumes case sensitive by default.<\/p>\n<p>Unfortunately, this had an unintended side effect. Some Windows applications, using the assumption that the file system is case insensitive, don\u2019t use the correct case to refer to files. For example, it\u2019s not uncommon for applications to transform filenames to use all upper or lower case. In directories marked as case sensitive, this means that these applications can no longer access the files.<\/p>\n<p>While in the long term the preferred solution is to fix these applications to correctly handle case sensitive directories, we realize that this isn\u2019t always an option, and you, our customers, shouldn\u2019t have to wait for that.<\/p>\n<p>Additionally, if Windows applications created new directories in a directory tree where you are using case sensitive files, these directories would not be case sensitive. This made it difficult to work with Windows tools in case sensitive directories.<\/p>\n<p>For these reasons, we have made two changes to how case sensitive directories work: an extended attribute to control case sensitivity in WSL, and inheritance of the case sensitivity flag for new directories.<\/p>\n<h2>Using Linux extended attributes to get and set per-directory case sensitivity<\/h2>\n<p>As of Windows insider build 17692, it\u2019s now possible to inspect and modify the case sensitivity flag for a directory from inside WSL. Case sensitivity is exposed using an extended attribute named <code>system.wsl_case_sensitive<\/code>. The value of this attribute will be <code>0<\/code> for case insensitive directories, and <code>1<\/code> for case sensitive directories.<\/p>\n<p>To manipulate extended attributes from the terminal, you can use the <code>setfattr<\/code> and <code>getfattr<\/code> applications. On Ubuntu, these can be installed using <code>sudo apt install attr<\/code>.<\/p>\n<p>With these applications, you can determine if a directory is case sensitive using:<\/p>\n<pre>getfattr -n system.wsl_case_sensitive &lt;path&gt;<\/pre>\n<p>Mark a directory as case sensitive:<\/p>\n<pre>setfattr -n system.wsl_case_sensitive -v 1 &lt;path&gt;<\/pre>\n<p>Mark a directory as case insensitive:<\/p>\n<pre>setfattr -n system.wsl_case_sensitive -v 0 &lt;path&gt;<\/pre>\n<p>The following shows an example where a case insensitive directory is marked as case sensitive:\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/case-xattr.png\" alt=\"\" width=\"979\" height=\"512\" class=\"alignnone size-full wp-image-3165\" \/><\/p>\n<p><b>Note:<\/b> changing the case sensitivity attribute requires \u201cWrite attributes\u201d, \u201cCreate files\u201d, \u201cCreate folders\u201d and \u201cDelete subfolders and files\u201d permissions on the directory. In some cases, with folders outside your user profile, you may not have all these permissions by default even if you own the directory. If you receive an access denied error when changing the attribute, make sure you have the correct Windows permissions on the folder.<\/p>\n<p>Changing the case sensitivity attribute requires that none of the folder\u2019s descendants are currently open in WSL. It is not possible to disable per-directory case sensitivity on a directory that contains files whose names only differ by case.<\/p>\n<p>The case sensitivity attribute is not available on file systems that do not support per-directory case sensitivity, such as FAT or SMB file systems. Currently, only local NTFS volumes support per-directory case sensitivity.<\/p>\n<h2>Case sensitivity inheritance<\/h2>\n<p>Previously, it was necessary to explicitly mark every directory you create as case sensitive. Now, we\u2019ve made it so that the per-directory case sensitivity flag is inherited when creating a new directory. This means that new directories created in a case sensitive directory are automatically case sensitive.<\/p>\n<p>The big advantage of this is that it\u2019s now much easier to use certain Windows tools in case sensitive directories. For example, you can use the in-box tar.exe to extract an archive in a case sensitive directory, and be sure the entire directory subtree is case sensitive. Similarly if you clone a repository using Git for Windows, or if you create new directories using an editor such as Visual Studio Code. This makes it much easier to use Windows applications with case sensitive directories, without needing to modify those applications.<\/p>\n<h2>Case sensitivity mount options in DrvFs<\/h2>\n<p>When mounting Windows volumes in WSL with DrvFs, you can specify the default case sensitivity behavior using the <code>case=off<\/code> or <code>case=dir<\/code> mount option. With <code>case=off<\/code>, new directories are not case sensitive by default. With <code>case=dir<\/code>, they are case sensitive by default. In either case, directories already marked as case sensitive will be treated as case sensitive.<\/p>\n<p>These options are not new, but combined with the <code>system.wsl_case_sensitive<\/code> extended attribute and case sensitivity inheritance, they give you greater control over where per-directory case sensitivity is used.<\/p>\n<p>Now, if you mount DrvFs using <code>case=off<\/code>, it is easy to mark directories case sensitive when you want them to be, and since inheritance also applies to WSL even with <code>case=off<\/code>, you can be sure the entire subtree will be case sensitive.<\/p>\n<p>The following example shows how a new directory created in a case sensitive directory is also case sensitive, even when using <code>case=off<\/code>:\n<img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2018\/06\/case-inheritance.png\" alt=\"\" width=\"979\" height=\"512\" class=\"alignnone size-full wp-image-3175\" \/><\/p>\n<p>We recommend that you start mounting your DrvFs volumes using <code>case=off<\/code> and only enable per-directory case sensitivity when you need it. This can be accomplished using the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/wsl\/wsl-config\">\/etc\/wsl.conf file<\/a>. The following is an example wsl.conf file that sets <code>case=off<\/code> as the default for automounted DrvFs volumes:<\/p>\n<pre>[automount]\noptions = case=off<\/pre>\n<p>In a future Windows Insider build, we will change the default behavior for DrvFs to be <code>case=off<\/code> if no options are specified, and you will need to explicitly mount with <code>case=dir<\/code> if you want to use the old behavior.<\/p>\n<h2>Thanks and Feedback<\/h2>\n<p>A big thanks for helping provide feedback on case-sensitivity. Be sure to continue providing feedback on the <a href=\"https:\/\/github.com\/Microsoft\/WSL\">WSL GitHub repo<\/a> and Tweeting us at #WSLinux.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the Windows Subsystem for Linux, we\u2019ve always allowed you to treat your files as case sensitive, just like Linux does. In the past, if you had files whose name differed only by case, these files could not be accessed by Windows, because Windows applications treat the file system as case insensitive. A while ago, [&hellip;]<\/p>\n","protected":false},"author":1030,"featured_media":4568,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-3155","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-windows-10","category-bash-on-ubuntu-on-windows"],"acf":[],"blog_post_summary":"<p>With the Windows Subsystem for Linux, we\u2019ve always allowed you to treat your files as case sensitive, just like Linux does. In the past, if you had files whose name differed only by case, these files could not be accessed by Windows, because Windows applications treat the file system as case insensitive. A while ago, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/3155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/users\/1030"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/comments?post=3155"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/3155\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media\/4568"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media?parent=3155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/categories?post=3155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/tags?post=3155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}