summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/file.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index dd953f44c5..3755560998 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -409,7 +409,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
409 if (count && file->dirty) { 409 if (count && file->dirty) {
410 rc = flush_cache(fd); 410 rc = flush_cache(fd);
411 if (rc < 0) 411 if (rc < 0)
412 return rc * 10 - 3; 412 return nread ? nread : rc * 10 - 3;
413 } 413 }
414 414
415 /* read whole sectors right into the supplied buffer */ 415 /* read whole sectors right into the supplied buffer */
@@ -420,7 +420,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
420 if ( rc < 0 ) { 420 if ( rc < 0 ) {
421 DEBUGF("Failed read/writing %d sectors\n",sectors); 421 DEBUGF("Failed read/writing %d sectors\n",sectors);
422 errno = EIO; 422 errno = EIO;
423 return rc * 10 - 4; 423 return nread ? nread : rc * 10 - 4;
424 } 424 }
425 else { 425 else {
426 if ( rc > 0 ) { 426 if ( rc > 0 ) {
@@ -452,7 +452,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
452 if ( rc < 0 ) { 452 if ( rc < 0 ) {
453 DEBUGF("Failed writing\n"); 453 DEBUGF("Failed writing\n");
454 errno = EIO; 454 errno = EIO;
455 return rc * 10 - 5; 455 return nread ? nread : rc * 10 - 5;
456 } 456 }
457 /* seek back one sector to put file position right */ 457 /* seek back one sector to put file position right */
458 rc = fat_seek(&(file->fatfile), 458 rc = fat_seek(&(file->fatfile),
@@ -461,7 +461,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
461 if ( rc < 0 ) { 461 if ( rc < 0 ) {
462 DEBUGF("fat_seek() failed\n"); 462 DEBUGF("fat_seek() failed\n");
463 errno = EIO; 463 errno = EIO;
464 return rc * 10 - 6; 464 return nread ? nread : rc * 10 - 6;
465 } 465 }
466 } 466 }
467 memcpy( file->cache, buf + nread, count ); 467 memcpy( file->cache, buf + nread, count );
@@ -472,7 +472,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
472 if (rc < 1 ) { 472 if (rc < 1 ) {
473 DEBUGF("Failed caching sector\n"); 473 DEBUGF("Failed caching sector\n");
474 errno = EIO; 474 errno = EIO;
475 return rc * 10 - 7; 475 return nread ? nread : rc * 10 - 7;
476 } 476 }
477 memcpy( buf + nread, file->cache, count ); 477 memcpy( buf + nread, file->cache, count );
478 } 478 }