[PATCH] Get recursive grep to work on Win9x

Ton van Overbeek tvoverbe@cistron.nl
Sun May 12 08:33:00 GMT 2002


There have been various reports over time that recursive grep is not
working on Win9x. For every directory you get a 'Permission denied'
error.
Also there have been reports that using open(2) to open a directory
readonly on Win9x fails.
Both have the same cause.

open(2) calls _open in the cygwin1.dll (See source file syscalls.cc).
When you open a file (or directory) it creates a file_handler
and calls fhandler_base::open (See source file fhandler.cc).
fhandler_base::open adds the FILE_FLAG_BACKUP_SEMANTICS to
the file_attributes for the Win32 CreateFile call in case you
open a directory.
This way of opening a directory is only supported on WinNT and not
on Win9x. See MSDN.
Hence the reports that grep -R works on NT and not on 9x.

To get grep to work on 9x, the fix is simple: get fhandler_base::open
to set the error EISDIR when you try to open a directory.
This is *not* strictly POSIX. According to POSIX open should only
return EISDIR when you try to open a directory read/write or writeonly.
However it fixes the problem for grep.

The patch is simple. It makes use of the wincap.can_open_directories()
capability, which seems to be foreseen for exactly this type of problems.
However I could not find an other place where this capability is used
in the cygwin.dll.

Patch attached: fhandler.diff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fhandler.diff
Type: application/x-unknown-content-type-diff_auto_file
Size: 515 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20020512/3249a6a7/attachment.bin>


More information about the Cygwin-patches mailing list