Mercurial > ecos-v3_0-branch
changeset 1817:df5dcf4cdc1a
* include/fileio.h:
* src/file.cxx: Added support for cyg_fs_fssync,
cyg_fs_get_attrib, and cyg_fs_set_attrib
* src/file.cxx: Added a check data ptr in LOCK_FS
| author | asl |
|---|---|
| date | Fri, 22 Oct 2004 14:07:49 +0000 |
| parents | 658319b65ae3 |
| children | 5663e2763ba6 |
| files | packages/io/fileio/current/ChangeLog packages/io/fileio/current/include/fileio.h packages/io/fileio/current/src/file.cxx |
| diffstat | 3 files changed, 124 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/io/fileio/current/ChangeLog +++ b/packages/io/fileio/current/ChangeLog @@ -1,3 +1,13 @@ +2004-10-13 David Brennan <eCos@brennanhome.com> + + * include/fileio.h: + * src/file.cxx: Added support for cyg_fs_fssync, + cyg_fs_get_attrib, and cyg_fs_set_attrib + +2004-10-13 David Brennan <eCos@brennanhome.com> + + * src/file.cxx: Added a check data ptr in LOCK_FS + 2004-10-06 David Brennan <eCos@brennanhome.com> * tests/pselect.c: Added check for POSIX signals while building
--- a/packages/io/fileio/current/include/fileio.h +++ b/packages/io/fileio/current/include/fileio.h @@ -154,6 +154,8 @@ struct cyg_fstab_entry #define FS_INFO_CONF 1 /* pathconf() */ #define FS_INFO_ACCESS 2 /* access() */ #define FS_INFO_GETCWD 3 /* getcwd() */ +#define FS_INFO_SYNC 4 /* cyg_fs_fssync() */ +#define FS_INFO_ATTRIB 5 /* cyg_fs_(get|set)_attrib() */ //----------------------------------------------------------------------------- // Types for link() @@ -170,6 +172,8 @@ struct cyg_getcwd_info size_t size; /* size of buffer */ }; +typedef cyg_uint32 cyg_fs_attrib_t; + //----------------------------------------------------------------------------- // Macro to define an initialized fstab entry @@ -330,7 +334,7 @@ struct CYG_FILE_TAG #define CYG_FILE_TYPE_DEVICE 3 /* device */ //----------------------------------------------------------------------------- -// Keys for getinf() and setinfo() +// Keys for getinfo() and setinfo() #define FILE_INFO_CONF 1 /* fpathconf() */ @@ -422,6 +426,21 @@ struct CYG_SELINFO_TAG __externC time_t cyg_timestamp(void); //============================================================================= +// Miscellaneous functions. + +// Provide a function to synchronize an individual file system. (ie write +// file and directory information to disk) +__externC int cyg_fs_fssync(const char *path); + +// Functions to set and get attributes of a file, eg FAT attributes +// like hidden and system. +__externC int cyg_fs_set_attrib( const char *fname, + const cyg_fs_attrib_t new_attrib ); +__externC int cyg_fs_get_attrib( const char *fname, + cyg_fs_attrib_t * const file_attrib ); + + +//============================================================================= // Default functions. // Cast to the appropriate type, these functions can be put into any of // the operation table slots to provide the defined error code.
--- a/packages/io/fileio/current/src/file.cxx +++ b/packages/io/fileio/current/src/file.cxx @@ -71,6 +71,7 @@ #define LOCK_FS( _mte_ ) { \ CYG_ASSERT(_mte_ != NULL, "Bad mount table entry"); \ + CYG_ASSERT(_mte_->fs != NULL, "Bad mount filesystem entry"); \ cyg_fs_lock( _mte_, (_mte_)->fs->syncmode); \ } @@ -524,6 +525,99 @@ static Cyg_Mutex getcwd_lock CYGBLD_ATTR } //========================================================================== +// Sync filesystem without unmounting + +__externC int cyg_fs_fssync( const char *path ) +{ + FILEIO_ENTRY(); + + int ret = 0; + cyg_mtab_entry *mte = cyg_cdir_mtab_entry; + cyg_dir dir = cyg_cdir_dir; + const char *name = path; + + ret = cyg_mtab_lookup( &dir, &name, &mte ); + + if( 0 != ret ) + FILEIO_RETURN(ENOENT); + + LOCK_FS( mte ); + + ret = mte->fs->setinfo( mte, dir, name, FS_INFO_SYNC, NULL, 0 ); + + UNLOCK_FS( mte ); + + if( 0 != ret ) + FILEIO_RETURN(ret); + + FILEIO_RETURN_VALUE(ENOERR); +} + +//========================================================================== +// Set file attributes + +__externC int cyg_fs_set_attrib( const char *fname, + const cyg_fs_attrib_t new_attrib ) +{ + FILEIO_ENTRY(); + + int ret = 0; + cyg_mtab_entry *mte = cyg_cdir_mtab_entry; + cyg_dir dir = cyg_cdir_dir; + const char *name = fname; + + ret = cyg_mtab_lookup( &dir, &name, &mte ); + + if( 0 != ret ) + FILEIO_RETURN(ENOENT); + + LOCK_FS( mte ); + + ret = mte->fs->setinfo( mte, dir, name, + FS_INFO_ATTRIB, + (char *)&new_attrib, sizeof(new_attrib) ); + + UNLOCK_FS( mte ); + + if( 0 != ret ) + FILEIO_RETURN(ret); + + FILEIO_RETURN(ENOERR); +} + +//========================================================================== +// Get file attributes + +__externC int cyg_fs_get_attrib( const char *fname, + cyg_fs_attrib_t * const file_attrib ) +{ + FILEIO_ENTRY(); + + int ret = 0; + cyg_mtab_entry *mte = cyg_cdir_mtab_entry; + cyg_dir dir = cyg_cdir_dir; + const char *name = fname; + + ret = cyg_mtab_lookup( &dir, &name, &mte ); + + if( 0 != ret ) + FILEIO_RETURN(ENOENT); + + LOCK_FS( mte ); + + ret = mte->fs->getinfo( mte, dir, name, + FS_INFO_ATTRIB, + (char *)file_attrib, sizeof(*file_attrib) ); + + UNLOCK_FS( mte ); + + if( 0 != ret ) + FILEIO_RETURN(ret); + + FILEIO_RETURN(ENOERR); +} + +//========================================================================== // Access() function. // This simply piggybacks onto stat().
