diff options
| author | Björn Stenberg <bjorn@haxx.se> | 2002-11-04 14:59:46 +0000 |
|---|---|---|
| committer | Björn Stenberg <bjorn@haxx.se> | 2002-11-04 14:59:46 +0000 |
| commit | c9fb0982505291c6efab4abfc805fc907c575933 (patch) | |
| tree | ef4186827fe30bdfe685bdfce3f058c56cf351af | |
| parent | 6a8900b528922b4b26ce2f582233036da14c2614 (diff) | |
| download | rockbox-c9fb0982505291c6efab4abfc805fc907c575933.zip rockbox-c9fb0982505291c6efab4abfc805fc907c575933.tar.gz rockbox-c9fb0982505291c6efab4abfc805fc907c575933.tar.bz2 rockbox-c9fb0982505291c6efab4abfc805fc907c575933.tar.xz | |
Bugfix: lseek() did not invalidate sector cache when seeking to start of file.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2803 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | firmware/common/file.c | 2 | ||||
| -rw-r--r-- | firmware/drivers/fat.c | 30 |
2 files changed, 19 insertions, 13 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index 7f0e0cd..219858c 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -386,6 +386,8 @@ int lseek(int fd, int offset, int whence) } openfiles[fd].cacheoffset = sectoroffset; } + else + openfiles[fd].cacheoffset = -1; } else if ( openfiles[fd].cacheoffset != -1 ) diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index f6d6c73..26149d4 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -1202,25 +1202,29 @@ int fat_readwrite( struct fat_file *file, int sectorcount, int fat_seek(struct fat_file *file, int seeksector ) { - int clusternum, sectornum, sector=0; + int clusternum=0, sectornum=0, sector=0; int cluster = file->firstcluster; int i; - seeksector--; - clusternum = seeksector / fat_bpb.bpb_secperclus; - sectornum = seeksector % fat_bpb.bpb_secperclus; - - for (i=0; i<clusternum; i++) { - cluster = get_next_cluster(cluster); - if (!cluster) { - sector = -1; - break; + if (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; + sectornum = seeksector % fat_bpb.bpb_secperclus; + + for (i=0; i<clusternum; i++) { + cluster = get_next_cluster(cluster); + if (!cluster) { + sector = -1; + break; + } } + + if ( sector > -1 ) + sector = cluster2sec(cluster) + sectornum; } - if ( sector > -1 ) - sector = cluster2sec(cluster) + sectornum; - LDEBUGF("fat_seek(%x) == %x, %x, %x\n", seeksector, cluster, sector, sectornum); |