From a6a0c4b2d5a208bc9034292f1b0045d42faf7ead Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Fri, 16 Dec 2005 20:44:41 +0000 Subject: [PATCH] Now the file corruption bug when reading & writing the same file is hopefully fully fixed. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8251 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/firmware/common/file.c b/firmware/common/file.c index c44f7af809..7f36ecf651 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -445,10 +445,29 @@ static int readwrite(int fd, void* buf, long count, bool write) headbytes = count; file->cacheoffset += count; if ( file->cacheoffset >= SECTOR_SIZE ) + { + /* Flush the cache first if it's dirty. */ + if (file->dirty) + { + rc = flush_cache(fd); + if ( rc < 0 ) { + errno = EIO; + return rc * 10 - 9; + } + } file->cacheoffset = -1; + } } else { headbytes = SECTOR_SIZE - file->cacheoffset; + if (file->dirty) + { + rc = flush_cache(fd); + if ( rc < 0 ) { + errno = EIO; + return rc * 10 - 9; + } + } file->cacheoffset = -1; } @@ -543,17 +562,6 @@ static int readwrite(int fd, void* buf, long count, bool write) file->dirty = true; } else { - /* Flush the cache first if it's dirty. */ - if (file->dirty) - { - rc = flush_cache(fd); - if ( rc < 0 ) { - errno = EIO; - return rc * 10 - 8; - } - file->cacheoffset = -1; - } - rc = fat_readwrite(&(file->fatfile), 1, &(file->cache),false); if (rc < 1 ) { DEBUGF("Failed caching sector\n");