# HG changeset patch # User asl # Date 1209634269 0 # Node ID c5e3739b3c9afd9be35c642ef87dbd224eddd3b3 # Parent 6d6c8afc94a4a7929deeba0d0e5d576c7dac2e66 * cdl/fileio.cdl: Use CYGPKG_FILEIO_DIRENT_DTYPE to enable/disable d_type field of struct dirent. * include/dirent.h: Add a d_type field to struct dirent, in order to distinguish file type directly without calling stat. * doc/fileio.sgml: Documentation about this new member and the fact it is not portable. diff --git a/packages/io/fileio/current/ChangeLog b/packages/io/fileio/current/ChangeLog --- a/packages/io/fileio/current/ChangeLog +++ b/packages/io/fileio/current/ChangeLog @@ -1,3 +1,13 @@ +2008-04-02 Xinghua Yang + Andrew Lunn + + * cdl/fileio.cdl: Use CYGPKG_FILEIO_DIRENT_DTYPE to enable/disable + d_type field of struct dirent. + * include/dirent.h: Add a d_type field to struct dirent, in order to + distinguish file type directly without calling stat. + * doc/fileio.sgml: Documentation about this new member and the fact + it is not portable. + 2007-08-17 Hans Rosenfeld tests/fnmatch.c (main): Fix cut/paste error in final pass/fail diff --git a/packages/io/fileio/current/cdl/fileio.cdl b/packages/io/fileio/current/cdl/fileio.cdl --- a/packages/io/fileio/current/cdl/fileio.cdl +++ b/packages/io/fileio/current/cdl/fileio.cdl @@ -247,6 +247,20 @@ cdl_package CYGPKG_IO_FILEIO { compile fnmatch.c } + cdl_option CYGPKG_FILEIO_DIRENT_DTYPE { + display "Struct dirent contains a d_type field" + flavor bool + default_value 0 + description " + If this option is enabled then struct dirent contains a + d_type field. With this field, file type may be + distinguished directly without calling stat. Note: This + member is not part of the POSIX standard, however is + commonely implemented in Linux, FreeBSD, but not SunOS. + Also, not all filesystems support it. So this feature is + not portable and should be used with caution." + } + # ---------------------------------------------------------------- # Tests diff --git a/packages/io/fileio/current/doc/fileio.sgml b/packages/io/fileio/current/doc/fileio.sgml --- a/packages/io/fileio/current/doc/fileio.sgml +++ b/packages/io/fileio/current/doc/fileio.sgml @@ -520,8 +520,14 @@ specifier of SEEK_SET Most of these considerations are invisible to clients of a filesystem since they will access directories via the POSIX opendir(), readdir() and -closedir() functions. - +closedir() functions. The struct +dirent object returned by readdir() +will always contain d_name as required by +POSIX. When CYGPKG_FILEIO_DIRENT_DTYPE is enabled +it will also contain d_type, which is not +part of POSIX, but often implemented by OSes. Currently only the +FATFS, RAMFS, ROMFS and JFFS2 filesystem sets this value. For other +filesystems a value of 0 will be returned in the member. Support for the getcwd() function is provided by @@ -1193,4 +1199,4 @@ examples of how this has been done. - \ No newline at end of file + diff --git a/packages/io/fileio/current/include/dirent.h b/packages/io/fileio/current/include/dirent.h --- a/packages/io/fileio/current/include/dirent.h +++ b/packages/io/fileio/current/include/dirent.h @@ -34,9 +34,6 @@ // // This exception does not invalidate any other reasons why a work based on // this file might be covered by the GNU General Public License. -// -// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. -// at http://sources.redhat.com/ecos/ecos-license/ // ------------------------------------------- //####ECOSGPLCOPYRIGHTEND#### //======================================================================== @@ -72,6 +69,13 @@ extern "C" { struct dirent { +#ifdef CYGPKG_FILEIO_DIRENT_DTYPE + + mode_t d_type; // Only supported with FATFS, RAMFS, ROMFS, + // and JFFS2. + // d_type is not part of POSIX so + // should be used with caution. +#endif char d_name[NAME_MAX+1]; }; diff --git a/packages/io/fileio/current/src/dir.cxx b/packages/io/fileio/current/src/dir.cxx --- a/packages/io/fileio/current/src/dir.cxx +++ b/packages/io/fileio/current/src/dir.cxx @@ -32,9 +32,6 @@ // // This exception does not invalidate any other reasons why a work based on // this file might be covered by the GNU General Public License. -// -// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. -// at http://sources.redhat.com/ecos/ecos-license/ // ------------------------------------------- //####ECOSGPLCOPYRIGHTEND#### //========================================================================== @@ -186,6 +183,12 @@ extern int readdir_r( DIR *dirp, struct FILEIO_RETURN_VALUE( EBADF ); } +#ifdef CYGPKG_FILEIO_DIRENT_DTYPE + // d_type is only supposed by a few filesystems, so make sure other + // filesystems return a sane value; + entry->d_type = 0; +#endif + res = read( fd, (void *)entry, sizeof(struct dirent)); if( res < 0 ) @@ -195,7 +198,13 @@ extern int readdir_r( DIR *dirp, struct if( res > 0 ) *result = entry; + +#ifdef CYGPKG_FILEIO_DIRENT_DTYPE + // Only the lower bits contain the type of file, so and those out. + entry->d_type &= S_IFMT; +#endif + FILEIO_RETURN( ENOERR ); }