From 97dff5ca7097c3dfd3e417c4e258619496578c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvar=20Ibeas?= Date: Mon, 15 Jan 2024 12:56:14 +0100 Subject: [PATCH] Fix computation of total data clusters and free clusters --- src/core/FatSystem.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/FatSystem.cpp b/src/core/FatSystem.cpp index 79cda8c..352136c 100644 --- a/src/core/FatSystem.cpp +++ b/src/core/FatSystem.cpp @@ -160,7 +160,7 @@ void FatSystem::parseHeader() (rootEntries*FAT_ENTRY_SIZE + bytesPerSector-1)/bytesPerSector; unsigned long dataSectors = totalSectors - (reservedSectors + fats*sectorsPerFat + rootDirSectors); - unsigned long totalClusters = dataSectors/sectorsPerCluster; + totalClusters = dataSectors/sectorsPerCluster; bits = (totalClusters > MAX_FAT12) ? 16 : 12; } else { type = FAT32; @@ -170,6 +170,9 @@ void FatSystem::parseHeader() diskLabel = string(buffer+FAT_DISK_LABEL, FAT_DISK_LABEL_SIZE); rootDirectory = FAT_READ_LONG(buffer, FAT_ROOT_DIRECTORY)&0xffffffff; fsType = string(buffer+FAT_DISK_FS, FAT_DISK_FS_SIZE); + unsigned long dataSectors = totalSectors - + (reservedSectors + fats*sectorsPerFat); + totalClusters = dataSectors/sectorsPerCluster; } if (bytesPerSector != 512) { @@ -663,7 +666,7 @@ bool FatSystem::init() bytesPerCluster = bytesPerSector*sectorsPerCluster; totalSize = totalSectors*bytesPerSector; fatSize = sectorsPerFat*bytesPerSector; - totalClusters = (fatSize*8)/bits; + // totalClusters = (fatSize*8)/bits; dataSize = totalClusters*bytesPerCluster; if (type == FAT16) { @@ -860,7 +863,7 @@ void FatSystem::computeStats() freeClusters = 0; for (unsigned int cluster=0; cluster