summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/drivers/fat.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 7d87a8ae9c..8f4e3e0632 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1481,7 +1481,7 @@ static int next_write_cluster(struct fat_file* file,
1481 return cluster; 1481 return cluster;
1482} 1482}
1483 1483
1484static bool transfer( unsigned int start, int count, char* buf, bool write ) 1484static int transfer( unsigned int start, int count, char* buf, bool write )
1485{ 1485{
1486 int rc; 1486 int rc;
1487 1487
@@ -1497,9 +1497,9 @@ static bool transfer( unsigned int start, int count, char* buf, bool write )
1497 DEBUGF( "transfer() - Couldn't %s sector %x" 1497 DEBUGF( "transfer() - Couldn't %s sector %x"
1498 " (error code %d)\n", 1498 " (error code %d)\n",
1499 write ? "write":"read", start, rc); 1499 write ? "write":"read", start, rc);
1500 return false; 1500 return rc;
1501 } 1501 }
1502 return true; 1502 return 0;
1503} 1503}
1504 1504
1505 1505
@@ -1512,6 +1512,7 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
1512 bool eof = file->eof; 1512 bool eof = file->eof;
1513 int first=0, last=0; 1513 int first=0, last=0;
1514 int i; 1514 int i;
1515 int rc;
1515 1516
1516 LDEBUGF( "fat_readwrite(file:%x,count:0x%x,buf:%x,%s)\n", 1517 LDEBUGF( "fat_readwrite(file:%x,count:0x%x,buf:%x,%s)\n",
1517 file->firstcluster,sectorcount,buf,write?"write":"read"); 1518 file->firstcluster,sectorcount,buf,write?"write":"read");
@@ -1560,8 +1561,9 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
1560 if ( ((sector != first) && (sector != last+1)) || /* not sequential */ 1561 if ( ((sector != first) && (sector != last+1)) || /* not sequential */
1561 (last-first+1 == 256) ) { /* max 256 sectors per ata request */ 1562 (last-first+1 == 256) ) { /* max 256 sectors per ata request */
1562 int count = last - first + 1; 1563 int count = last - first + 1;
1563 if (!transfer( first + fat_bpb.startsector, count, buf, write )) 1564 rc = transfer( first + fat_bpb.startsector, count, buf, write );
1564 return -1; 1565 if (rc < 0)
1566 return rc * 10 - 1;
1565 1567
1566 ((char*)buf) += count * SECTOR_SIZE; 1568 ((char*)buf) += count * SECTOR_SIZE;
1567 first = sector; 1569 first = sector;
@@ -1571,9 +1573,9 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
1571 (!eof)) 1573 (!eof))
1572 { 1574 {
1573 int count = sector - first + 1; 1575 int count = sector - first + 1;
1574 if (!transfer( first + fat_bpb.startsector, 1576 rc = transfer( first + fat_bpb.startsector, count, buf, write );
1575 count, buf, write )) 1577 if (rc < 0)
1576 return -2; 1578 return rc * 10 - 2;
1577 } 1579 }
1578 1580
1579 last = sector; 1581 last = sector;