<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147131>147131</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] Calling `std::filesystem::canonical` on ramdisks throws an exception on Windows
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wepavos293
</td>
</tr>
</table>
<pre>
Calling `std::filesystem::canonical` on paths located on ramdisk throws `std::__1::__fs::filesystem::filesystem_error`. It's caused by internal call to `GetFinalPathNameByHandleW`.
The problematic call:
[posix_compat.h#L344](https://github.com/llvm/llvm-project/blob/main/libcxx/src/filesystem/posix_compat.h#L344)
A similar issue was resolved in the past by adding special handling for these cases:
[Path.inc#L384](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/Windows/Path.inc#L384)
**Reproduction Steps:**
1. Create a ramdisk using software like ImDisk.
2. Compile and run the following code on the ramdisk:
```
#include <filesystem>
#include <iostream>
int main(){
std::cout << std::filesystem::canonical(std::filesystem::current_path()) << std::endl;
return 0;
}
```
Sorry for posting from a burner account, GitHub now enforces 2FA for accounts interacting with high-impact projects.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVN-L4zYQ_muUl-GMIiVx8uCHJFvfHZRSuoV7XMbSJFZXlowkbzb_fZHi7G3vrtCWgiDxaH59o-8bjNGcHVHD1ge2fljglHofmguN-OKj2MlF5_W1OaK1xp2BbXhMmsk9k_uTsRSvMdFw-1bovDMKLdtw8A5GTH0E6xUm0tkQcNAmPkPqg7_Ev-R6elre_5zij9N__X6iEHxgG17B58REHUHhFElDdwXjEgWHFhRaC8nnKh8ptcah_RVT_wsOdLh-QqctfckpGN8zvv-9JxiD7ywNmIwq0bks37P1YfTRvD4pP4yYqp4J-bNcrdj6gYltn9JY-hUtE-3ZpH7qKuUHJlprX-4_H8bg_yCVmGg76zsm2gGNy5emU6-vTLQxKCbad5BF--OqYndreA_RDMZiABPjRHDBCIGity-kwThIGRDGlGeCWue3iyMpgxb6DD4bTj5kv0igMFJ8w5vnVBmnSs3t_4R09jHZ9jiNow_Z6Ytx2l8iE-23Re9AmcjnNxqD15NKxjt4TDS3Uk5xW1ZwDISJAN94NsUC25_SBQOBNc8En4cHE5_zq4sKjn4YjSVApyFMt6GdvLX-kgOV15Rpm61zynlEGz6f3J40TtlJEzB5fM_Zn767NT6mQHi_43vjEtzms81460Mx795UofyUciCTR_gHshPbv3eaQiCXnrIm52pi911qctoyeYBbG4HSFBxwJktf9cO30Pn-0YdwLTwafUyFU8EPgNBNwVEAVMpPLjFxhI8mfZo6cP4C5E4-KIog2n0Jnt3iTb2oSqaLST305tx_MMOIKsFMrVgtdCP1Tu5wQc2yXi9rvuRbueibk-q0XpFWnRArjrutwI1adXy33HQcV3phGsHFmtd8zWu55bLS9VZLUUvZbbqd5JytOA1obJX5WvlwXhR5NctVvZTLhcWObCy7UogsXiYO5Yi8O0NTJNBN58hW3JqY4tc8ySRbtuy7sPUD_JfFOpMx3hcpOqBXRWMRh3cwi2oxBdv8a9kWvFmQM-SXRvwZAAD__zNh94g">