summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/fat.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/fat.c')
-rw-r--r--firmware/drivers/fat.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 3a3f63d9f1..a55a8a2864 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -838,22 +838,30 @@ int fat_seek(struct fat_file *file, int seeksector )
int numsec = 0;
int i;
- for (i=0; i<seeksector; i++) {
- numsec++;
- if ( numsec >= fat_bpb.bpb_secperclus ) {
- cluster = get_next_cluster(cluster);
- if (!cluster)
- /* end of file */
- return -1;
-
- sector = cluster2sec(cluster);
- if (sector<0)
- return -2;
- numsec=0;
+ if ( seeksector ) {
+ for (i=0; i<seeksector; i++) {
+ numsec++;
+ if ( numsec >= fat_bpb.bpb_secperclus ) {
+ cluster = get_next_cluster(cluster);
+ if (!cluster)
+ /* end of file */
+ return -1;
+
+ sector = cluster2sec(cluster);
+ if (sector<0)
+ return -2;
+ numsec=0;
+ }
+ else
+ sector++;
}
- else
- sector++;
}
+ else {
+ sector = cluster2sec(cluster);
+ if (sector<0)
+ return -2;
+ }
+
file->nextcluster = cluster;
file->nextsector = sector;
file->sectornum = numsec;