Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<filesystem>: read_symlink does not work with junctions #2077

Closed
SibiSiddharthan opened this issue Jul 25, 2021 · 2 comments
Closed

<filesystem>: read_symlink does not work with junctions #2077

SibiSiddharthan opened this issue Jul 25, 2021 · 2 comments
Labels
invalid This issue is incorrect or by design

Comments

@SibiSiddharthan
Copy link
Contributor

Command-line test case

C:\Temp> mkdir a
C:\Temp> mklink /J b a

C:\Temp>type repro.cpp
#include <filesystem>
#include <iostream>

using namespace std;
namespace fs = std::filesystem;

int main()
{
	error_code ec;
	auto p = fs::read_symlink("b",ec);
	printf("%ls %d %s\n",p.c_str(), ec.value(), ec.message().c_str());
}

C:\Temp>cl /EHsc /std:c++17 .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.23.28019.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.23.28019.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

C:\Temp>.\repro.exe

Expected behavior
a 0 The operation completed successfully.

Observed behavior
 4393 The tag present in the reparse point buffer is invalid.

STL version

9a9820d

@SibiSiddharthan
Copy link
Contributor Author

SibiSiddharthan commented Jul 25, 2021

I tried debugging this and here are my findings.

When we do DeviceIoControl with FSCTL_GET_REPARSE_POINT, if the HANDLE refers to a symlinked file the ReparseTag reads
2684354572 which is IO_REPARSE_TAG_SYMLINK (0xA000000C). But if the HANDLE points to junction the ReparseTag reads
2684354563 which is IO_REPARSE_TAG_SYMLINK - 9. I am not sure why this happens.

Another weird thing

If the HANDLE refers to a symlinked file, the SymbolicLinkReparseBuffer.Flags reads 1 which is SYMLINK_FLAG_RELATIVE 0x1 and B->SymbolicLinkReparseBuffer.PathBuffer reads the relative path wrt the current working directory. This is as expected. But
when the HANDLE refers to a junction , the SymbolicLinkReparseBuffer.Flags reads 4128860 ? and B->SymbolicLinkReparseBuffer.PathBuffer reads the absolute path excluding the volume. Is this expected behavior or am I missing something?

@SibiSiddharthan
Copy link
Contributor Author

I got confused between IO_REPARSE_TAG_MOUNT_POINT and IO_REPARSE_TAG_SYMLINK. Things work as expected. Sorry about this. Closing this issue.

@StephanTLavavej StephanTLavavej added the invalid This issue is incorrect or by design label Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This issue is incorrect or by design
Projects
None yet
Development

No branches or pull requests

2 participants