mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-11 06:05:21 -05:00
fat_read() now reads multiple sectors per ATA command
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1737 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
63457c5c63
commit
30033df6fa
1 changed files with 18 additions and 9 deletions
|
|
@ -881,20 +881,14 @@ int fat_read( struct fat_file *file, int sectorcount, void* buf )
|
||||||
int cluster = file->nextcluster;
|
int cluster = file->nextcluster;
|
||||||
int sector = file->nextsector;
|
int sector = file->nextsector;
|
||||||
int numsec = file->sectornum;
|
int numsec = file->sectornum;
|
||||||
|
int first = sector, last = sector;
|
||||||
int err, i;
|
int err, i;
|
||||||
|
|
||||||
if ( sector == -1 )
|
if ( sector == -1 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* find sequential sectors and read them all at once */
|
||||||
for (i=0; i<sectorcount; i++ ) {
|
for (i=0; i<sectorcount; i++ ) {
|
||||||
err = ata_read_sectors(sector + fat_bpb.startsector, 1,
|
|
||||||
(char*)buf+(i*SECTOR_SIZE));
|
|
||||||
if(err) {
|
|
||||||
DEBUGF( "fat_read() - Couldn't read sector %d"
|
|
||||||
" (error code %d)\n", sector,err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
numsec++;
|
numsec++;
|
||||||
if ( numsec >= fat_bpb.bpb_secperclus ) {
|
if ( numsec >= fat_bpb.bpb_secperclus ) {
|
||||||
cluster = get_next_cluster(cluster);
|
cluster = get_next_cluster(cluster);
|
||||||
|
|
@ -911,6 +905,21 @@ int fat_read( struct fat_file *file, int sectorcount, void* buf )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sector++;
|
sector++;
|
||||||
|
|
||||||
|
if ( (sector != last+1) || /* not sequential any more? */
|
||||||
|
(i == sectorcount-1) || /* last sector requested? */
|
||||||
|
(last-first+1 == 256) ) { /* max 256 sectors per ata request */
|
||||||
|
int count = last-first+1;
|
||||||
|
err = ata_read_sectors(first + fat_bpb.startsector, count, buf);
|
||||||
|
if(err) {
|
||||||
|
DEBUGF( "fat_read() - Couldn't read sector %d"
|
||||||
|
" (error code %d)\n", sector,err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
((char*)buf) += count * SECTOR_SIZE;
|
||||||
|
first = sector;
|
||||||
|
}
|
||||||
|
last = sector;
|
||||||
}
|
}
|
||||||
file->nextcluster = cluster;
|
file->nextcluster = cluster;
|
||||||
file->nextsector = sector;
|
file->nextsector = sector;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue