Skip to content

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

Description

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

Activity

  1. SibiSiddharthan commented on Jul 25, 2021

    @SibiSiddharthan
    ContributorAuthor

    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?

  2. SibiSiddharthan commented on Jul 25, 2021

    @SibiSiddharthan
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis issue is incorrect or by design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions