summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2005-12-16 20:44:41 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2005-12-16 20:44:41 +0000
commita6a0c4b2d5a208bc9034292f1b0045d42faf7ead (patch)
tree9447614b12120959d89c56f16f862aa5a3691319 /firmware
parentfa51eb4ee8bb2dfebc9bef4ec7168d67c37325a8 (diff)
downloadrockbox-a6a0c4b2d5a208bc9034292f1b0045d42faf7ead.tar.gz
rockbox-a6a0c4b2d5a208bc9034292f1b0045d42faf7ead.zip
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
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/file.c30
1 files 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");