summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHardeep Sidhu <dyp@pobox.com>2003-06-03 18:04:22 +0000
committerHardeep Sidhu <dyp@pobox.com>2003-06-03 18:04:22 +0000
commitfc9b28d0a943033e7224c92c5a387e422dd469af (patch)
tree0ca692ca85e3017c840d561d439aea170d153637
parenta3216f88d6fa51fde151b595d217fe710a9e6f5f (diff)
downloadrockbox-fc9b28d0a943033e7224c92c5a387e422dd469af.zip
rockbox-fc9b28d0a943033e7224c92c5a387e422dd469af.tar.gz
rockbox-fc9b28d0a943033e7224c92c5a387e422dd469af.tar.bz2
rockbox-fc9b28d0a943033e7224c92c5a387e422dd469af.tar.xz
Small seek optimization -- begin seek at last read cluster if possible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3720 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/fat.c23
-rw-r--r--firmware/export/fat.h1
2 files changed, 20 insertions, 4 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 8f4e3e0..ac6d240 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1218,6 +1218,7 @@ int fat_open(unsigned int startcluster,
file->firstcluster = startcluster;
file->lastcluster = startcluster;
file->lastsector = 0;
+ file->clusternum = 0;
file->sectornum = 0;
file->eof = false;
@@ -1243,6 +1244,7 @@ int fat_create_file(char* name,
file->firstcluster = 0;
file->lastcluster = 0;
file->lastsector = 0;
+ file->clusternum = 0;
file->sectornum = 0;
file->eof = false;
}
@@ -1508,6 +1510,7 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
{
int cluster = file->lastcluster;
int sector = file->lastsector;
+ int clusternum = file->clusternum;
int numsec = file->sectornum;
bool eof = file->eof;
int first=0, last=0;
@@ -1533,17 +1536,21 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
cluster = get_next_cluster(cluster);
sector = cluster2sec(cluster);
}
+
+ clusternum++;
+ numsec=1;
+
if (!cluster) {
eof = true;
if ( write ) {
/* remember last cluster, in case
we want to append to the file */
cluster = oldcluster;
+ clusternum--;
}
}
else
eof = false;
- numsec=1;
}
else {
if (sector)
@@ -1583,6 +1590,7 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
file->lastcluster = cluster;
file->lastsector = sector;
+ file->clusternum = clusternum;
file->sectornum = numsec;
file->eof = eof;
@@ -1595,7 +1603,7 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
int fat_seek(struct fat_file *file, unsigned int seeksector )
{
- int clusternum=0, sectornum=0, sector=0;
+ int clusternum=0, numclusters=0, sectornum=0, sector=0;
int cluster = file->firstcluster;
int i;
@@ -1604,10 +1612,16 @@ int fat_seek(struct fat_file *file, unsigned int seeksector )
/* we need to find the sector BEFORE the requested, since
the file struct stores the last accessed sector */
seeksector--;
- clusternum = seeksector / fat_bpb.bpb_secperclus;
+ numclusters = clusternum = seeksector / fat_bpb.bpb_secperclus;
sectornum = seeksector % fat_bpb.bpb_secperclus;
- for (i=0; i<clusternum; i++) {
+ if (file->clusternum && clusternum >= file->clusternum)
+ {
+ cluster = file->lastcluster;
+ numclusters -= file->clusternum;
+ }
+
+ for (i=0; i<numclusters; i++) {
cluster = get_next_cluster(cluster);
if (!cluster) {
DEBUGF("Seeking beyond the end of the file! "
@@ -1627,6 +1641,7 @@ int fat_seek(struct fat_file *file, unsigned int seeksector )
file->lastcluster = cluster;
file->lastsector = sector;
+ file->clusternum = clusternum;
file->sectornum = sectornum + 1;
return 0;
}
diff --git a/firmware/export/fat.h b/firmware/export/fat.h
index ec71fce..921f04e 100644
--- a/firmware/export/fat.h
+++ b/firmware/export/fat.h
@@ -51,6 +51,7 @@ struct fat_file
int firstcluster; /* first cluster in file */
int lastcluster; /* cluster of last access */
int lastsector; /* sector of last access */
+ int clusternum; /* current clusternum */
int sectornum; /* sector number in this cluster */
unsigned int direntry; /* short dir entry index from start of dir */
unsigned int direntries; /* number of dir entries used by this file */