summaryrefslogtreecommitdiff
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 )
838 int numsec = 0; 838 int numsec = 0;
839 int i; 839 int i;
840 840
841 for (i=0; i<seeksector; i++) { 841 if ( seeksector ) {
842 numsec++; 842 for (i=0; i<seeksector; i++) {
843 if ( numsec >= fat_bpb.bpb_secperclus ) { 843 numsec++;
844 cluster = get_next_cluster(cluster); 844 if ( numsec >= fat_bpb.bpb_secperclus ) {
845 if (!cluster) 845 cluster = get_next_cluster(cluster);
846 /* end of file */ 846 if (!cluster)
847 return -1; 847 /* end of file */
848 848 return -1;
849 sector = cluster2sec(cluster); 849
850 if (sector<0) 850 sector = cluster2sec(cluster);
851 return -2; 851 if (sector<0)
852 numsec=0; 852 return -2;
853 numsec=0;
854 }
855 else
856 sector++;
853 } 857 }
854 else
855 sector++;
856 } 858 }
859 else {
860 sector = cluster2sec(cluster);
861 if (sector<0)
862 return -2;
863 }
864
857 file->nextcluster = cluster; 865 file->nextcluster = cluster;
858 file->nextsector = sector; 866 file->nextsector = sector;
859 file->sectornum = numsec; 867 file->sectornum = numsec;