1.7.1(0.218/5/3): ls -R bug (Windows XP)

Corinna Vinschen corinna-cygwin@cygwin.com
Fri Feb 19 11:47:00 GMT 2010

On Feb 19 11:44, Jeff Wilcox wrote:
> In Cygwin 1.7.x if I ls -R the root of a drive which contains only
> directories (i.e. no files at the root level), whatever directory comes
> first is omitted from the listing and the following error is thrown:
> ls: ./<DIR NAME>: not listing already-listed directory

Thanks for the report.  I can reproduce it, even with files in the root
directory.  I'm wondering that this has never been found before.

I see what's going on but not why.

Eric?  Ping?  I need your help.

This only occurs on NTFS drives.  AFAICS, what happens is this:

- ls calls opendir.  This opens the directory with very limited
  permissions, SYNCHRONIZE | FILE_LIST_DIRECTORY.  Note especially

- Apparently ls fetches the directory descriptor from the DIR structure
  calling dirfd().  Then it calls fstat(dirfd()).

- Cygwin enters the fhandler_base::fstat_by_handle function and
  the call to NtQueryInformationFile fails with STAUS_ACCESS_DENIED.

- Cygwin tries the alternative call fhandler_base::fstat_by_name
  which succeeds.

- For some unknown reason ls claims
  "ls: ./<DIR NAME>: not listing already-listed directory".

What I did for testing was to change fhandler_disk_file::opendir to open
the directory with FILE_READ_ATTRIBUTES | READ_CONTROL rights.

The change here is that fstat_by_handle now works.  And the end result
is that ls does *not* complain.

However, that's quite puzzeling.  The stat entries are identical.
There's something going on I don't see, and that makes me wary.  I don't
want to change fhandler_disk_file::opendir - even though it's the right
thing to do - unless we are sure about the cause for the above problem.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

More information about the Cygwin mailing list