From 44e51833ed83c165b22026e7943461f419bccc0e Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Mon, 10 Mar 2003 17:10:46 +0000 Subject: Zagor added the flush() function git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3416 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 28 +++++++++++++++++++++++++++- firmware/include/file.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'firmware') 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 @@ -174,6 +174,31 @@ int close(int fd) LDEBUGF("close(%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) { + 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; @@ -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); -- cgit v1.2.3