Why does ls // hang in Cygwin

1

When I run the command ls // is Cygwin, the shell hangs for about 12 seconds, then gives the error ls: reading directory '//': Permission denied. I remember reading somewhere that /some//path is interpreted the same as /some/path in POSIX paths, and accordingly, when I run the command in an Ubuntu virtual machine, there is no delay, and ls outputs the contents of /.

I can't find anything about // in the Cygwin special filenames documentation, so why does this happen, and how can I reduce the delay?

Edit:

It turns out \\* paths are network paths on Windows. When I disconnect my computer from all networks, ls \\ returns an empty listing immediately. When I connect to a some networks, I get a listing of hosts on the network, but on other networks, I encounter the problem described above. Considering this, is the some way to configure Windows so that the delay is reduced, even in the case of a permission error?

Vaelus

Posted 2016-03-23T16:13:04.437

Reputation: 123

I can't reproduce this here. ls // returns instantly and no files are listed. – DavidPostill – 2016-03-23T16:17:35.830

Answers

1

It’s not a Cygwin issue, it’s a Unix issue.  In the early days of computer networking, before Sun (Solaris) introduced the /net/hostname syntax for accessing remote filesystems1, and NFS allowed remote filesystems to be mounted at arbitrary mount points (e.g., /mnt or /home/username), some versions of Unix implemented a //hostname/pathname syntax for the same purpose.  See On what systems is //foo/bar different from /foo/bar?  Over the years, that syntax has fallen out of favor, yielding (mostly?) to NFS.

However, to allow these legacy systems to be POSIX-compliant, the standard explicitly allows // to mean something different from / (at the beginning of a path):

If a pathname begins with two successive <slash> characters, the first component following the leading <slash> characters may be interpreted in an implementation-defined manner, although more than two leading <slash> characters shall be treated as a single <slash> character.
        (from near the end of the “Pathname Resolution” section)

— although it doesn’t specify what it should mean (if anything).

Cygwin interprets // much the same as the old /net, as documented here.  It references Windows’ “Network” (pseudo-)folder — the one that contains “This Computer” and other discoverable machines.

See also Unix: difference between path starting with / and //.
____________
1 … and, optionally, /net could be listed to produce a list of the names of accessible hosts with exported filesystems — i.e., fileservers.

G-Man Says 'Reinstate Monica'

Posted 2016-03-23T16:13:04.437

Reputation: 6 509

0

https://cygwin.com/cygwin-ug-net/using.html#unc-paths

There's also a virtual directory // which allows to enumerate the fileservers known to the local machine with ls.

matzeri

Posted 2016-03-23T16:13:04.437

Reputation: 1 662

0

On my computer, ls // also runs slowly, printing a couple of cannot access '//some-computer-name': No such file or directory, and in the end printing a few computer names. These are Windows PCs on the local network, and apparently ls tries to connect to them (don't know what for).

On the other hand, dir \\ runs quickly and prints the same computer names (no error messages).

I don't think there's a way to configure Windows to prevent that, looks to me like a Cygwin issue (or feature). Best thing would be to write to Cygwin's mailing list about that, asking to fix it.

Anyway, can I ask why do you run ls // at all?

Gene Pavlovsky

Posted 2016-03-23T16:13:04.437

Reputation: 356

I don't run ls // directly, but my editor, Kakoune, presumably runs it whenever I type // in order to suggest filenames for completion. You can imagine how hanging for over 10 seconds every time I type // might be problematic. – Vaelus – 2016-04-20T15:39:25.287

You mean any time you write // to start a comment in your code, your editor tries to offer filename completion? Otherwise, where/why do you have to write // for filename completion? – Gene Pavlovsky – 2016-04-20T19:04:21.393

Exactly, whenever I have to write a C++ style comment, my editor tries to offer filename completion. Obviously I can turn of filename completion in my editor, but in every other case, filename completion is pretty handy, so I'd like to avoid that. – Vaelus – 2016-04-20T19:08:34.880

I don't get it, why do you need filename completion in C++ code? Have you tried asking the editor's author to change the // behavior by default or as an option? – Gene Pavlovsky – 2016-04-20T19:23:06.603

Filename completion is useful, for instance, in #include directives. I have not tried asking the editor's author, but really, this seems like a Cygwin problem, so I'll probably ask on Cygwin's mailing list, like you suggested, for either a fix or a workaround. – Vaelus – 2016-04-20T19:27:32.463

A smart editor knows when it's meaningful to offer filename completion, and when it's not (based on context). I'd definitely log a feature request. Cygwin's behavior might be by design (as it seems that Cygwin tries to connect to each computer on the network, although it escapes me what for), please post here any response you receive from them. – Gene Pavlovsky – 2016-04-21T12:34:38.943