summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-11-05 14:46:27 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-11-05 14:46:27 +0000
commit0e51fefda68c0651bdc3847d30e9644fff840569 (patch)
tree7ce8117ad3691567a09c9f22cc8f355fa082099d /firmware
parentab0dce026489391e8a4426e0cb6e6779814cdb2c (diff)
downloadrockbox-0e51fefda68c0651bdc3847d30e9644fff840569.tar.gz
rockbox-0e51fefda68c0651bdc3847d30e9644fff840569.zip
Bug fixes: fat_seek(0) would sometimes start at sector 1. find_free_cluster() didn't find all free clusters.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2806 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/fat.c12
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);