summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/file.c2
-rw-r--r--firmware/drivers/fat.c30
2 files changed, 19 insertions, 13 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 7f0e0cd9bd..219858cff2 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -386,6 +386,8 @@ int lseek(int fd, int offset, int whence)
386 } 386 }
387 openfiles[fd].cacheoffset = sectoroffset; 387 openfiles[fd].cacheoffset = sectoroffset;
388 } 388 }
389 else
390 openfiles[fd].cacheoffset = -1;
389 } 391 }
390 else 392 else
391 if ( openfiles[fd].cacheoffset != -1 ) 393 if ( openfiles[fd].cacheoffset != -1 )
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index f6d6c73e74..26149d4e4a 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1202,25 +1202,29 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
1202 1202
1203int fat_seek(struct fat_file *file, int seeksector ) 1203int fat_seek(struct fat_file *file, int seeksector )
1204{ 1204{
1205 int clusternum, sectornum, sector=0; 1205 int clusternum=0, sectornum=0, sector=0;
1206 int cluster = file->firstcluster; 1206 int cluster = file->firstcluster;
1207 int i; 1207 int i;
1208 1208
1209 seeksector--; 1209 if (seeksector) {
1210 clusternum = seeksector / fat_bpb.bpb_secperclus; 1210 /* we need to find the sector BEFORE the requested, since
1211 sectornum = seeksector % fat_bpb.bpb_secperclus; 1211 the file struct stores the last accessed sector */
1212 1212 seeksector--;
1213 for (i=0; i<clusternum; i++) { 1213 clusternum = seeksector / fat_bpb.bpb_secperclus;
1214 cluster = get_next_cluster(cluster); 1214 sectornum = seeksector % fat_bpb.bpb_secperclus;
1215 if (!cluster) { 1215
1216 sector = -1; 1216 for (i=0; i<clusternum; i++) {
1217 break; 1217 cluster = get_next_cluster(cluster);
1218 if (!cluster) {
1219 sector = -1;
1220 break;
1221 }
1218 } 1222 }
1223
1224 if ( sector > -1 )
1225 sector = cluster2sec(cluster) + sectornum;
1219 } 1226 }
1220 1227
1221 if ( sector > -1 )
1222 sector = cluster2sec(cluster) + sectornum;
1223
1224 LDEBUGF("fat_seek(%x) == %x, %x, %x\n", 1228 LDEBUGF("fat_seek(%x) == %x, %x, %x\n",
1225 seeksector, cluster, sector, sectornum); 1229 seeksector, cluster, sector, sectornum);
1226 1230