Skip to content

xorg lndir does not function properly #2229

Closed

Description

@pikajude
  • Your Windows build number: 10.0.15063

In Bash on my Windows computer:

$ sudo apt-get install xutils-dev
$ mkdir out
$ mkdir -p foo/a/b
$ mkdir -p bar/a/c
$ lndir -silent "$PWD/foo" "$PWD/out"
.: File exists
..: File exists
$ lndir -silent "$PWD/bar" "$PWD/out"
.: File exists
..: File exists
a: /home/pikajude/foo/a
$ ls out/a/
b

Meanwhile, on my VPS running nixos:

$ mkdir out
$ mkdir -p foo/a/b
$ mkdir -p bar/a/c
$ lndir -silent "$PWD/foo" "$PWD/out"
$ lndir -silent "$PWD/bar" "$PWD/out"
$ ls out/a/
b   c

Activity

  1. therealkenc commented on Jun 18, 2017

    @therealkenc

    Would need to look at the source to see where the lndir program logic goes south, but the difficulty seems to be with WSL getdents. That /* d_reclen < sizeof(struct dirent) */ looks problematic.

    WSL:

    [usual program startup stuff...]
    open("/home/ken/foo", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
    [...]
    getdents(3, /* d_reclen < sizeof(struct dirent) *//* 1 entries */, 32768) = 64
    readlink(".", 0x7ffff762d6a0, 4096)     = -1 EINVAL (Invalid argument)
    readlink("/home/ken/foo/.", 0x7ffff762e6b0, 4096) = -1 EINVAL (Invalid argument)
    symlink("/home/ken/foo/.", ".")         = -1 EEXIST (File exists)
    [...]
    write(2, ".: File exists\n", 15)        = 15
    

    Real Linux:

    [...]
    open("/home/ken/foo", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
    [...]
    getdents(3, /* 3 entries */, 32768)     = 72
    lstat("/home/ken/foo/a", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    stat("a", 0x7ffe0223ee50)               = -1 ENOENT (No such file or directory)
    mkdir("a", 0777)                        = 0
    stat("a", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    readlink("a", 0x7ffe0223fef0, 4096)     = -1 EINVAL (Invalid argument)
    chdir("a")                              = 0
    [... continues fine doing it's thing]
    
  2. sunilmut commented on Jun 22, 2017

    @sunilmut
    Member

    Adding Sven Groot (@SvenGroot) to see if he can chime in on this.

  3. SvenGroot commented on Jun 22, 2017

    @SvenGroot
    Member

    I've looked into this, and it doesn't look like we'll be able to fix this at this time.

    The getdents issue that therealkenc pointed out is not related to this issue. We're not correctly padding our entries, which confuses strace, but otherwise doesn't impact the functionality.

    The real issue is that lndir is checking st_nlinks on the parent, and assumes that if it's 0, there are no subdirectories. All of the subdirectory processing, including checking for '.' and '..' entries, is then skipped. Unfortunately, we return 0 for st_nlinks because we cannot determine the correct value easily (NTFS does not store this information, so it could only be determined by listing the directory, a very expensive operation).

    It could be argued that this is a bug in lndir. On Linux, with file systems that report the correct link count for directories, the value is always at least 2 (for the '.' and '..' entries). We used to return 2 regardless of how many subdirectories there are, but found that most tools take the value 2 to mean "no subdirectories, so no need to recurse". The value zero seems to mean the value is incorrect and can't be trusted, causing those tools to ignore it. This is why we switched to returning zero.

    This is the first case where we've seen a tool that skips processing based on the value zero (a value which it should never encounter on a file system that returns correct link counts for directories, so this seems like incorrect behavior on the part of lndir). We cannot fix this tool without breaking a whole bunch of others, so unfortunately I don't think there's anything we can do for you right now.

  4. microsoft-github-policy-service commented on Feb 1, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

    Thank you!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions