mirror of
https://github.com/wiiu-env/libfat.git
synced 2024-11-22 01:49:17 +01:00
update FAT32 FSINFO for statvfs if invalid
This commit is contained in:
parent
bc9f4c893a
commit
42fe5af38d
@ -465,16 +465,13 @@ int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
if(memcmp(&buf->f_flag, "SCAN", 4) == 0)
|
||||
{
|
||||
//Special command was given to sync the numberFreeCluster
|
||||
_FAT_partition_createFSinfo(partition);
|
||||
}
|
||||
|
||||
if(partition->filesysType == FS_FAT32)
|
||||
if(partition->filesysType == FS_FAT32) {
|
||||
// Sync FSinfo block
|
||||
_FAT_partition_readFSinfo(partition);
|
||||
freeClusterCount = partition->fat.numberFreeCluster;
|
||||
else
|
||||
} else {
|
||||
freeClusterCount = _FAT_fat_freeClusterCount (partition);
|
||||
}
|
||||
|
||||
// FAT clusters = POSIX blocks
|
||||
buf->f_bsize = partition->bytesPerCluster; // File system block size.
|
||||
|
@ -348,6 +348,13 @@ PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
|
||||
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)
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
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_AA] = 0xAA;
|
||||
|
||||
_FAT_disc_writeSectors (partition->disc, partition->fsInfoSector, 1, sectorBuffer);
|
||||
_FAT_updateFS_INFO(partition,sectorBuffer);
|
||||
|
||||
_FAT_mem_free(sectorBuffer);
|
||||
}
|
||||
@ -398,6 +401,10 @@ void _FAT_partition_readFSinfo(PARTITION * partition)
|
||||
_FAT_partition_createFSinfo(partition);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
_FAT_mem_free(sectorBuffer);
|
||||
|
Loading…
Reference in New Issue
Block a user