[Patch] Add dirent.d_type support to Cygwin 1.7 ?

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Nov 27 09:31:00 GMT 2008

Hi Christian,

On Nov 27 00:12, Christian Franke wrote:
> Christopher Faylor wrote:
>> ...
>>> +#ifdef _DIRENT_HAVE_D_TYPE
>>> +  /* Set d_type if type can be determined from file attributes.
>>> +     FILE_ATTRIBUTE_SYSTEM ommitted to leave DT_UNKNOWN for old 
>>> symlinks.
>>> +     For new symlinks, d_type will be reset to DT_UNKNOWN below.  */
>>> +  if (attr &&
>>> +      !(attr & ~( FILE_ATTRIBUTE_NORMAL
>>> +                | FILE_ATTRIBUTE_READONLY
>>> +                | FILE_ATTRIBUTE_ARCHIVE
>>> +                | FILE_ATTRIBUTE_HIDDEN
>>> +                | FILE_ATTRIBUTE_COMPRESSED
>>> +                | FILE_ATTRIBUTE_ENCRYPTED
>>> +                | FILE_ATTRIBUTE_SPARSE_FILE
>>> +                | FILE_ATTRIBUTE_DIRECTORY)))

I understand why you omit FILE_ATTRIBUTE_REPARSE_POINT in this attribute
FWIW, any other new attributes which will be created in later Windows
versions?  Shouldn't this condition test positively instead like, say,


I must admit I never saw the FILE_ATTRIBUTE_DEVICE attribute actually
set anywhere...

>> This is just checking all of the Windows types but none of the Cygwin
>> types.  Shouldn't it be checking for devices, fifos, and symlinks?
> D_type should only be set to the actual type if this info is available at 
> low cost. This is the case for files/dirs, but not for e.g. Cygwin 
> symlinks. Therefore, DT_UNKNOWN is returned instead and the app must call 
> stat() if this info is required.
> To speed up typical 'find' and 'ls -R' operations, it is IMO enough to 
> handle the most common filesystem types (for now).

Yeah, without OS support we have no cheap way to recognize other
filetypes.  As the readir man page says, "all applications must properly
handle a return of DT_UNKNOWN."


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

More information about the Cygwin-patches mailing list