diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/file.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index 01ae17224d..c44f7af809 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -543,6 +543,17 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
543 | file->dirty = true; | 543 | file->dirty = true; |
544 | } | 544 | } |
545 | else { | 545 | else { |
546 | /* Flush the cache first if it's dirty. */ | ||
547 | if (file->dirty) | ||
548 | { | ||
549 | rc = flush_cache(fd); | ||
550 | if ( rc < 0 ) { | ||
551 | errno = EIO; | ||
552 | return rc * 10 - 8; | ||
553 | } | ||
554 | file->cacheoffset = -1; | ||
555 | } | ||
556 | |||
546 | rc = fat_readwrite(&(file->fatfile), 1, &(file->cache),false); | 557 | rc = fat_readwrite(&(file->fatfile), 1, &(file->cache),false); |
547 | if (rc < 1 ) { | 558 | if (rc < 1 ) { |
548 | DEBUGF("Failed caching sector\n"); | 559 | DEBUGF("Failed caching sector\n"); |