summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/drivers/fat.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 099417baca..079bf1ea10 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -550,10 +550,6 @@ static unsigned int find_free_cluster(unsigned int startcluster)
550 unsigned int offset; 550 unsigned int offset;
551 unsigned int i; 551 unsigned int i;
552 552
553 /* Cluster 0 and 1 are reserved */
554 if(startcluster < 2)
555 startcluster = 2;
556
557 sector = startcluster / CLUSTERS_PER_FAT_SECTOR; 553 sector = startcluster / CLUSTERS_PER_FAT_SECTOR;
558 offset = startcluster % CLUSTERS_PER_FAT_SECTOR; 554 offset = startcluster % CLUSTERS_PER_FAT_SECTOR;
559 555
@@ -567,7 +563,9 @@ static unsigned int find_free_cluster(unsigned int startcluster)
567 int k = (j + offset) % CLUSTERS_PER_FAT_SECTOR; 563 int k = (j + offset) % CLUSTERS_PER_FAT_SECTOR;
568 if (!(SWAB32(fat[k]) & 0x0fffffff)) { 564 if (!(SWAB32(fat[k]) & 0x0fffffff)) {
569 unsigned int c = nr * CLUSTERS_PER_FAT_SECTOR + k; 565 unsigned int c = nr * CLUSTERS_PER_FAT_SECTOR + k;
570 if ( c > fat_bpb.dataclusters+1 ) /* nr 0 is unused */ 566 /* Ignore the reserved clusters 0 & 1, and also
567 cluster numbers out of bounds */
568 if ( c < 2 || c > fat_bpb.dataclusters+1 )
571 continue; 569 continue;
572 LDEBUGF("find_free_cluster(%x) == %x\n",startcluster,c); 570 LDEBUGF("find_free_cluster(%x) == %x\n",startcluster,c);
573 fat_bpb.fsinfo.nextfree = c; 571 fat_bpb.fsinfo.nextfree = c;