This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 38eadbb  FAT32 kconfig entry to enforce computation of free clusters 
at mount
38eadbb is described below

commit 38eadbb57598f952c9c580dece28695cac3fc566
Author: GAEHWILER Reto <reto.gaehwi...@hexagon.com>
AuthorDate: Sun Jul 4 14:20:45 2021 +0200

    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
---
 fs/fat/Kconfig        | 12 ++++++++++++
 fs/fat/fs_fat32util.c | 17 +++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig
index 710d634..c572c3c 100644
--- a/fs/fat/Kconfig
+++ b/fs/fat/Kconfig
@@ -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
diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c
index 7045068..d24d8fe 100644
--- a/fs/fat/fs_fat32util.c
+++ b/fs/fat/fs_fat32util.c
@@ -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;

Reply via email to