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

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

commit 642750fd0b509c4344b206cefc256dfbad653f58
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 8 15:58:02 2026 +0100

    fsutils/mkfatfs: Write the right FAT32 FSINFO free cluster count.
    
    For FAT32, fv_nclusters is the number of data clusters less the root
    directory cluster: mkfatfs_clustersearch() takes the sectors of that
    cluster out of the available sectors.  mkfatfs_initfsinfo() wrote
    fv_nclusters - 1 as FSI_Free_Count, so the count was one too low.  On a
    new 34 MiB volume with 512-byte clusters the count was 68888, but a file
    got 68889 clusters.
    
    FSI_Free_Count is the number of free clusters.  On a new volume only the
    root directory cluster is in use.  Write fv_nclusters.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fsutils/mkfatfs/writefat.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fsutils/mkfatfs/writefat.c b/fsutils/mkfatfs/writefat.c
index 01837d05c..70edcd6b8 100644
--- a/fsutils/mkfatfs/writefat.c
+++ b/fsutils/mkfatfs/writefat.c
@@ -337,9 +337,11 @@ static inline void mkfatfs_initfsinfo(FAR struct 
fat_format_s *fmt,
 
   FSI_PUTSTRUCTSIG(var->fv_sect, 0x61417272);
 
-  /* 4@488: Last free cluster count on volume */
+  /* 4@488: Last free cluster count on volume.  fv_nclusters does not
+   * include the root directory cluster.
+   */
 
-  FSI_PUTFREECOUNT(var->fv_sect, var->fv_nclusters - 1);
+  FSI_PUTFREECOUNT(var->fv_sect, var->fv_nclusters);
 
   /* 4@492: Cluster number of 1st free cluster */
 

Reply via email to