FAT32 kconfig entry to enforce computation of free clusters at mount

Follow up commit for [1] in response to the request to make the mount
behaviour configurable whether the number of free clusters is read
from the fsinfo section or computed (as the white paper suggests).

Default is the original behaviour of NUTTX, just read fsinfo.

[1] https://github.com/apache/incubator-nuttx/pull/3760
This commit is contained in:
GAEHWILER Reto 2021-07-04 14:20:45 +02:00 committed by Xiang Xiao
parent 50c08bf45b
commit 38eadbb575
2 changed files with 23 additions and 6 deletions

View File

@ -12,6 +12,18 @@ config FS_FAT
if FS_FAT
config FAT_COMPUTE_FSINFO
bool "FAT compute free space in FSINFO at mount time"
default n
---help---
Enables the computation of free clusters at mount time as suggested by the
white paper for FAT. The standard behavior of Nuttx is to trust the stored
value and only recompute it once required. This works if the file system
is never mounted to another OS. SD-cards which are mounted to Windows to
modify the content might report wrong space after reinserting it to Nuttx.
It is recommended to activate this setting if the "SD-Card" is swapped
between systems.
config FAT_LCNAMES
bool "FAT upper/lower names"
default n

View File

@ -626,13 +626,23 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable)
if (fs->fs_type == FSTYPE_FAT32)
{
ret = fat_computefreeclusters(fs);
ret = fat_checkfsinfo(fs);
if (ret != OK)
{
goto errout_with_buffer;
}
}
/* Enforce computation of free clusters if configured */
#ifdef CONFIG_FAT_COMPUTE_FSINFO
ret = fat_computefreeclusters(fs);
if (ret != OK)
{
goto errout_with_buffer;
}
#endif
/* We did it! */
finfo("FAT%d:\n", fs->fs_type == 0 ? 12 : fs->fs_type == 1 ? 16 : 32);
@ -2028,11 +2038,6 @@ int fat_updatefsinfo(struct fat_mountpt_s *fs)
int fat_computefreeclusters(struct fat_mountpt_s *fs)
{
if (fat_checkfsinfo(fs) != OK)
{
return -ENODEV;
}
/* We have to count the number of free clusters */
uint32_t nfreeclusters = 0;