diff options
-rw-r--r-- | firmware/drivers/fat.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 26149d4e4a..fc6b33b4c1 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -331,6 +331,7 @@ int fat_mount(int startsector) | |||
331 | LDEBUGF("Freecount: %x\n",fat_bpb.fsinfo.freecount); | 331 | LDEBUGF("Freecount: %x\n",fat_bpb.fsinfo.freecount); |
332 | LDEBUGF("Nextfree: %x\n",fat_bpb.fsinfo.nextfree); | 332 | LDEBUGF("Nextfree: %x\n",fat_bpb.fsinfo.nextfree); |
333 | LDEBUGF("Cluster count: %x\n",fat_bpb.dataclusters); | 333 | LDEBUGF("Cluster count: %x\n",fat_bpb.dataclusters); |
334 | LDEBUGF("Sectors per cluster: %d\n",fat_bpb.bpb_secperclus); | ||
334 | LDEBUGF("FAT sectors: %x\n",fat_bpb.fatsize); | 335 | LDEBUGF("FAT sectors: %x\n",fat_bpb.fatsize); |
335 | 336 | ||
336 | return 0; | 337 | return 0; |
@@ -442,11 +443,12 @@ static int find_free_cluster(int startcluster) | |||
442 | unsigned int* fat = cache_fat_sector(nr); | 443 | unsigned int* fat = cache_fat_sector(nr); |
443 | if ( !fat ) | 444 | if ( !fat ) |
444 | break; | 445 | break; |
445 | for (j = offset; j < CLUSTERS_PER_FAT_SECTOR; j++) { | 446 | for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { |
446 | if (!(SWAB32(fat[j]) & 0x0fffffff)) { | 447 | int k = (j + offset) % CLUSTERS_PER_FAT_SECTOR; |
447 | int c = nr * CLUSTERS_PER_FAT_SECTOR + j; | 448 | if (!(SWAB32(fat[k]) & 0x0fffffff)) { |
449 | int c = nr * CLUSTERS_PER_FAT_SECTOR + k; | ||
448 | if ( c > fat_bpb.dataclusters+1 ) /* nr 0 is unused */ | 450 | if ( c > fat_bpb.dataclusters+1 ) /* nr 0 is unused */ |
449 | break; | 451 | continue; |
450 | LDEBUGF("find_free_cluster(%x) == %x\n",startcluster,c); | 452 | LDEBUGF("find_free_cluster(%x) == %x\n",startcluster,c); |
451 | fat_bpb.fsinfo.nextfree = c; | 453 | fat_bpb.fsinfo.nextfree = c; |
452 | return c; | 454 | return c; |
@@ -1224,6 +1226,8 @@ int fat_seek(struct fat_file *file, int seeksector ) | |||
1224 | if ( sector > -1 ) | 1226 | if ( sector > -1 ) |
1225 | sector = cluster2sec(cluster) + sectornum; | 1227 | sector = cluster2sec(cluster) + sectornum; |
1226 | } | 1228 | } |
1229 | else | ||
1230 | sectornum = -1; | ||
1227 | 1231 | ||
1228 | LDEBUGF("fat_seek(%x) == %x, %x, %x\n", | 1232 | LDEBUGF("fat_seek(%x) == %x, %x, %x\n", |
1229 | seeksector, cluster, sector, sectornum); | 1233 | seeksector, cluster, sector, sectornum); |