diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2003-03-10 17:10:46 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2003-03-10 17:10:46 +0000 |
commit | 44e51833ed83c165b22026e7943461f419bccc0e (patch) | |
tree | 327ce89685730e7aa3d7d6e2767b3e9bb94f268e /firmware | |
parent | c5aaab4a36e8010e628cf3846d0fcf3039cb27be (diff) | |
download | rockbox-44e51833ed83c165b22026e7943461f419bccc0e.tar.gz rockbox-44e51833ed83c165b22026e7943461f419bccc0e.zip |
Zagor added the flush() function
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3416 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/file.c | 28 | ||||
-rw-r--r-- | firmware/include/file.h | 1 |
2 files changed, 28 insertions, 1 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index 516618b460..17660d3dc7 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -183,6 +183,31 @@ int close(int fd) return -2; } if (file->write) { + rc = flush(fd); + if (rc < 0) + return rc * 10 - 3; + } + + file->busy = false; + return 0; +} + +int flush(int fd) +{ + struct filedesc* file = &openfiles[fd]; + int rc = 0; + + LDEBUGF("flush(%d)\n", fd); + + if (fd < 0 || fd > MAX_OPEN_FILES-1) { + errno = EINVAL; + return -1; + } + if (!file->busy) { + errno = EBADF; + return -2; + } + if (file->write) { /* flush sector cache */ if ( file->dirty ) { rc = flush_cache(fd); @@ -202,7 +227,6 @@ int close(int fd) if (rc < 0) return rc * 10 - 5; } - file->busy = false; return 0; } @@ -318,9 +342,11 @@ static int flush_cache(int fd) DEBUGF("Flushing dirty sector cache %x\n", sector); /* seek back one sector to get file position right */ +#if 0 rc = fat_seek(&(file->fatfile), sector); if ( rc < 0 ) return rc * 10 - 1; +#endif rc = fat_readwrite(&(file->fatfile), 1, file->cache, true ); diff --git a/firmware/include/file.h b/firmware/include/file.h index 6c81cb93d7..75c55bbac9 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h @@ -56,6 +56,7 @@ extern int remove(const char*); #ifndef SIMULATOR extern int open(const char* pathname, int flags); extern int close(int fd); +extern int flush(int fd); extern int read(int fd, void* buf, int count); extern int lseek(int fd, int offset, int whence); extern int creat(const char *pathname, int mode); |