update FAT32 FSINFO for statvfs if invalid

This commit is contained in:
Dave Murphy 2017-07-31 14:45:57 +01:00
parent bc9f4c893a
commit 42fe5af38d
2 changed files with 17 additions and 13 deletions

View File

@ -465,16 +465,13 @@ int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
_FAT_lock(&partition->lock); _FAT_lock(&partition->lock);
if(memcmp(&buf->f_flag, "SCAN", 4) == 0) if(partition->filesysType == FS_FAT32) {
{ // Sync FSinfo block
//Special command was given to sync the numberFreeCluster _FAT_partition_readFSinfo(partition);
_FAT_partition_createFSinfo(partition);
}
if(partition->filesysType == FS_FAT32)
freeClusterCount = partition->fat.numberFreeCluster; freeClusterCount = partition->fat.numberFreeCluster;
else } else {
freeClusterCount = _FAT_fat_freeClusterCount (partition); freeClusterCount = _FAT_fat_freeClusterCount (partition);
}
// FAT clusters = POSIX blocks // FAT clusters = POSIX blocks
buf->f_bsize = partition->bytesPerCluster; // File system block size. buf->f_bsize = partition->bytesPerCluster; // File system block size.

View File

@ -348,6 +348,13 @@ PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
return (PARTITION*)devops->deviceData; return (PARTITION*)devops->deviceData;
} }
static void _FAT_updateFS_INFO(PARTITION * partition, uint8_t *sectorBuffer) {
partition->fat.numberFreeCluster = _FAT_fat_freeClusterCount(partition);
u32_to_u8array(sectorBuffer, FSIB_numberOfFreeCluster, partition->fat.numberFreeCluster);
u32_to_u8array(sectorBuffer, FSIB_numberLastAllocCluster, partition->fat.numberLastAllocCluster);
_FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer);
}
void _FAT_partition_createFSinfo(PARTITION * partition) void _FAT_partition_createFSinfo(PARTITION * partition)
{ {
if(partition->readOnly || partition->filesysType != FS_FAT32) if(partition->readOnly || partition->filesysType != FS_FAT32)
@ -364,14 +371,10 @@ void _FAT_partition_createFSinfo(PARTITION * partition)
sectorBuffer[FSIB_SIG2+i] = FS_INFO_SIG2[i]; sectorBuffer[FSIB_SIG2+i] = FS_INFO_SIG2[i];
} }
partition->fat.numberFreeCluster = _FAT_fat_freeClusterCount(partition);
u32_to_u8array(sectorBuffer, FSIB_numberOfFreeCluster, partition->fat.numberFreeCluster);
u32_to_u8array(sectorBuffer, FSIB_numberLastAllocCluster, partition->fat.numberLastAllocCluster);
sectorBuffer[FSIB_bootSig_55] = 0x55; sectorBuffer[FSIB_bootSig_55] = 0x55;
sectorBuffer[FSIB_bootSig_AA] = 0xAA; sectorBuffer[FSIB_bootSig_AA] = 0xAA;
_FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer); _FAT_updateFS_INFO(partition,sectorBuffer);
_FAT_mem_free(sectorBuffer); _FAT_mem_free(sectorBuffer);
} }
@ -398,6 +401,10 @@ void _FAT_partition_readFSinfo(PARTITION * partition)
_FAT_partition_createFSinfo(partition); _FAT_partition_createFSinfo(partition);
} else { } else {
partition->fat.numberFreeCluster = u8array_to_u32(sectorBuffer, FSIB_numberOfFreeCluster); partition->fat.numberFreeCluster = u8array_to_u32(sectorBuffer, FSIB_numberOfFreeCluster);
if(partition->fat.numberFreeCluster == 0xffffffff) {
_FAT_updateFS_INFO(partition,sectorBuffer);
partition->fat.numberFreeCluster = u8array_to_u32(sectorBuffer, FSIB_numberOfFreeCluster);
}
partition->fat.numberLastAllocCluster = u8array_to_u32(sectorBuffer, FSIB_numberLastAllocCluster); partition->fat.numberLastAllocCluster = u8array_to_u32(sectorBuffer, FSIB_numberLastAllocCluster);
} }
_FAT_mem_free(sectorBuffer); _FAT_mem_free(sectorBuffer);