summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/file.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 8c0f9a8951..46af790bf7 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -421,11 +421,12 @@ static int readwrite(int fd, void* buf, int count, bool write)
421 /* read whole sectors right into the supplied buffer */ 421 /* read whole sectors right into the supplied buffer */
422 sectors = count / SECTOR_SIZE; 422 sectors = count / SECTOR_SIZE;
423 if ( sectors ) { 423 if ( sectors ) {
424 int rc = fat_readwrite(&(file->fatfile), sectors, 424 int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write );
425 buf+nread, write );
426 if ( rc < 0 ) { 425 if ( rc < 0 ) {
427 DEBUGF("Failed read/writing %d sectors\n",sectors); 426 DEBUGF("Failed read/writing %d sectors\n",sectors);
428 errno = EIO; 427 errno = EIO;
428 file->fileoffset += nread;
429 file->cacheoffset = -1;
429 return nread ? nread : rc * 10 - 4; 430 return nread ? nread : rc * 10 - 4;
430 } 431 }
431 else { 432 else {
@@ -453,11 +454,12 @@ static int readwrite(int fd, void* buf, int count, bool write)
453 /* sector is only partially filled. copy-back from disk */ 454 /* sector is only partially filled. copy-back from disk */
454 int rc; 455 int rc;
455 LDEBUGF("Copy-back tail cache\n"); 456 LDEBUGF("Copy-back tail cache\n");
456 rc = fat_readwrite(&(file->fatfile), 1, 457 rc = fat_readwrite(&(file->fatfile), 1, file->cache, false );
457 file->cache, false );
458 if ( rc < 0 ) { 458 if ( rc < 0 ) {
459 DEBUGF("Failed writing\n"); 459 DEBUGF("Failed writing\n");
460 errno = EIO; 460 errno = EIO;
461 file->fileoffset += nread;
462 file->cacheoffset = -1;
461 return nread ? nread : rc * 10 - 5; 463 return nread ? nread : rc * 10 - 5;
462 } 464 }
463 /* seek back one sector to put file position right */ 465 /* seek back one sector to put file position right */
@@ -467,6 +469,8 @@ static int readwrite(int fd, void* buf, int count, bool write)
467 if ( rc < 0 ) { 469 if ( rc < 0 ) {
468 DEBUGF("fat_seek() failed\n"); 470 DEBUGF("fat_seek() failed\n");
469 errno = EIO; 471 errno = EIO;
472 file->fileoffset += nread;
473 file->cacheoffset = -1;
470 return nread ? nread : rc * 10 - 6; 474 return nread ? nread : rc * 10 - 6;
471 } 475 }
472 } 476 }
@@ -478,6 +482,8 @@ static int readwrite(int fd, void* buf, int count, bool write)
478 if (rc < 1 ) { 482 if (rc < 1 ) {
479 DEBUGF("Failed caching sector\n"); 483 DEBUGF("Failed caching sector\n");
480 errno = EIO; 484 errno = EIO;
485 file->fileoffset += nread;
486 file->cacheoffset = -1;
481 return nread ? nread : rc * 10 - 7; 487 return nread ? nread : rc * 10 - 7;
482 } 488 }
483 memcpy( buf + nread, file->cache, count ); 489 memcpy( buf + nread, file->cache, count );