Mercurial > ecos
changeset 2472:c5e3739b3c9a
* 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.
| author | asl |
|---|---|
| date | Thu, 01 May 2008 09:31:09 +0000 |
| parents | 6d6c8afc94a4 |
| children | 9f64d4601b5b |
| files | packages/io/fileio/current/ChangeLog packages/io/fileio/current/cdl/fileio.cdl packages/io/fileio/current/doc/fileio.sgml packages/io/fileio/current/include/dirent.h packages/io/fileio/current/src/dir.cxx |
| diffstat | 5 files changed, 52 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/io/fileio/current/ChangeLog +++ b/packages/io/fileio/current/ChangeLog @@ -1,3 +1,13 @@ +2008-04-02 Xinghua Yang <yxinghua@sunnorth.com.cn> + Andrew Lunn <andrew.lunn@ascom.ch> + + * 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 <rosenfeld@grumpf.hope-2000.org> tests/fnmatch.c (main): Fix cut/paste error in final pass/fail
--- 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
--- a/packages/io/fileio/current/doc/fileio.sgml +++ b/packages/io/fileio/current/doc/fileio.sgml @@ -520,8 +520,14 @@ specifier of <literal>SEEK_SET</literal> Most of these considerations are invisible to clients of a filesystem since they will access directories via the POSIX <function>opendir()</function>, <function>readdir()</function> and -<function>closedir()</function> functions. -</para> +<function>closedir()</function> functions. The <structname> struct +dirent</structname> object returned by <function>readdir()</function> +will always contain <structname>d_name</structname> as required by +POSIX. When <literal>CYGPKG_FILEIO_DIRENT_DTYPE</literal> is enabled +it will also contain <structname>d_type</structname>, 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.</para> <para> Support for the <function>getcwd()</function> function is provided by @@ -1193,4 +1199,4 @@ examples of how this has been done. <!-- }}} --> -</part> \ No newline at end of file +</part>
--- 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]; };
--- 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 ); }
