Skip to content

Commit 58fbcfb

Browse files
committed
Merge branch 'feat/ff_fs_nofsinfo_kconfig' into 'master'
feat(fatfs): Add an option to set FF_FS_NOFSINFO value Closes IDFGH-14467 See merge request espressif/esp-idf!36592
2 parents a89fc6d + c918397 commit 58fbcfb

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

components/fatfs/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ menu "FAT Filesystem support"
310310
If enabled, the whole link operation (including file copying) is performed under lock.
311311
This ensures that the link operation is atomic, but may cause performance for large files.
312312
It may create less fragmented file copy.
313+
313314
config FATFS_USE_DYN_BUFFERS
314315
bool "Use dynamic buffers"
315316
depends on CONFIG_WL_SECTOR_SIZE_4096
@@ -321,4 +322,27 @@ menu "FAT Filesystem support"
321322
If disabled, the greatest sector size will be used for all FATFS instances.
322323
(In most cases, this would be the sector size of Wear Levelling library)
323324
This might cause more memory to be used than necessary.
325+
326+
menu "File system free space calculation behavior"
327+
help
328+
Controls if the file system does or does not trust cached data like free cluster count and allocated
329+
cluster number. Setting these to do not trust the data may result of more accurate output from
330+
`f_getfree()` function but increased overhead (forces a full FAT scan, etc.).
331+
332+
config FATFS_DONT_TRUST_FREE_CLUSTER_CNT
333+
int "Don't trust free cluster count"
334+
default 0
335+
range 0 1
336+
help
337+
If 1, the file system will not trust the free cluster count in the FSINFO (in FATFS struct).
338+
This may result in more accurate output from `f_getfree()` function but increased overhead.
339+
340+
config FATFS_DONT_TRUST_LAST_ALLOC
341+
int "Don't trust allocated cluster number"
342+
default 0
343+
range 0 1
344+
help
345+
If 1, the file system will not trust the last allocated cluster number in the FSINFO (in FATFS struct).
346+
This may result in more accurate output from `f_getfree()` function but increased overhead.
347+
endmenu
324348
endmenu

components/fatfs/src/ffconf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
300300

301301

302-
#define FF_FS_NOFSINFO 0
302+
#define FF_FS_NOFSINFO (CONFIG_FATFS_DONT_TRUST_FREE_CLUSTER_CNT << 0 | CONFIG_FATFS_DONT_TRUST_LAST_ALLOC << 1)
303303
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
304304
/ option, and f_getfree() function at the first time after volume mount will force
305305
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.

docs/en/api-reference/storage/fatfs.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ The function :cpp:func:`esp_vfs_fat_unregister_path` deletes the registration wi
2020

2121
Most applications use the following workflow when working with ``esp_vfs_fat_`` functions:
2222

23-
#. Call :cpp:func:`esp_vfs_fat_register` to specify:
23+
#.
24+
Call :cpp:func:`esp_vfs_fat_register` to specify:
25+
2426
- Path prefix where to mount the filesystem (e.g., ``"/sdcard"``, ``"/spiflash"``)
2527
- FatFs drive number
2628
- A variable which receives the pointer to the ``FATFS`` structure
@@ -70,9 +72,18 @@ Configuration options
7072
The following configuration options are available for the FatFs component:
7173

7274
* :ref:`CONFIG_FATFS_USE_FASTSEEK` - If enabled, the POSIX :cpp:func:`lseek` function will be performed faster. The fast seek does not work for files in write mode, so to take advantage of fast seek, you should open (or close and then reopen) the file in read-only mode.
73-
* :ref:`CONFIG_FATFS_IMMEDIATE_FSYNC` - If enabled, the FatFs will automatically call :cpp:func:`f_sync` to flush recent file changes after each call of :cpp:func:`write`, :cpp:func:`pwrite`, :cpp:func:`link`, :cpp:func:`truncate` and :cpp:func:`ftruncate` functions. This feature improves file-consistency and size reporting accuracy for the FatFs, at a price on decreased performance due to frequent disk operations.
75+
* :ref:`CONFIG_FATFS_IMMEDIATE_FSYNC` - If enabled, the FatFs will automatically call :cpp:func:`f_sync` to flush recent file changes after each call of :cpp:func:`write`, :cpp:func:`pwrite`, :cpp:func:`link`, :cpp:func:`truncate` and :cpp:func:`ftruncate` functions. This feature improves file-consistency and size reporting accuracy for the FatFs, at a price of decreased performance due to frequent disk operations.
7476
* :ref:`CONFIG_FATFS_LINK_LOCK` - If enabled, this option guarantees the API thread safety, while disabling this option might be necessary for applications that require fast frequent small file operations (e.g., logging to a file). Note that if this option is disabled, the copying performed by :cpp:func:`link` will be non-atomic. In such case, using :cpp:func:`link` on a large file on the same volume in a different task is not guaranteed to be thread safe.
7577

78+
These options set a behavior of how the FatFs filesystem calculates and reports free space:
79+
80+
* :ref:`CONFIG_FATFS_DONT_TRUST_FREE_CLUSTER_CNT` - If 1, free cluster count will be ignored. Default value is 0.
81+
* :ref:`CONFIG_FATFS_DONT_TRUST_LAST_ALLOC` - If 1, last allocation number will be ignored. Default value is 0.
82+
83+
.. note::
84+
85+
Setting these options to 1 may increase the accuracy of :cpp:func:`f_getfree` output at a price of decreased performance, e.g., due to performing full FAT scan.
86+
7687

7788
.. _fatfs-diskio-layer:
7889

docs/zh_CN/api-reference/storage/fatfs.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ FatFs 与 VFS 配合使用
2020

2121
多数应用程序在使用 ``esp_vfs_fat_`` 函数时,采用如下步骤:
2222

23-
#. 调用 :cpp:func:`esp_vfs_fat_register`,指定:
23+
#.
24+
调用 :cpp:func:`esp_vfs_fat_register`,指定:
25+
2426
- 挂载文件系统的路径前缀(例如,``"/sdcard"`` 或 ``"/spiflash"``)
2527
- FatFs 驱动编号
2628
- 一个用于接收指向 ``FATFS`` 结构指针的变量
@@ -70,9 +72,18 @@ FatFs 与 VFS 配合使用(只读模式下)
7072
FatFs 组件有以下配置选项:
7173

7274
* :ref:`CONFIG_FATFS_USE_FASTSEEK` - 如果启用该选项,POSIX :cpp:func:`lseek` 函数将以更快的速度执行。快速查找不适用于编辑模式下的文件,所以,使用快速查找时,应在只读模式下打开(或者关闭然后重新打开)文件。
73-
* :ref:`CONFIG_FATFS_IMMEDIATE_FSYNC` - 如果启用该选项,FatFs 将在每次调用 :cpp:func:`write`、:cpp:func:`pwrite`、:cpp:func:`link`、:cpp:func:`truncate` 和 :cpp:func:`ftruncate` 函数后,自动调用 :cpp:func:`f_sync` 以同步最近的文件改动。该功能可提高文件系统中文件的一致性和文件大小报告的准确性,但由于需要频繁进行磁盘操作,性能将会受到影响
75+
* :ref:`CONFIG_FATFS_IMMEDIATE_FSYNC` - 如果启用该选项,FatFs 将在每次调用 :cpp:func:`write`、:cpp:func:`pwrite`、:cpp:func:`link`、:cpp:func:`truncate` 和 :cpp:func:`ftruncate` 函数后,自动调用 :cpp:func:`f_sync` 以同步最近的文件改动。该功能提升了 FatFs 的文件一致性和文件大小报告的准确性,但频繁的磁盘操作会降低性能
7476
* :ref:`CONFIG_FATFS_LINK_LOCK` - 如果启用该选项,可保证 API 的线程安全,但如果应用程序需要快速频繁地进行小文件操作(例如将日志记录到文件),则可能有必要禁用该选项。请注意,如果禁用该选项,调用 :cpp:func:`link` 后的复制操作将是非原子的,此时如果在不同任务中对同一卷上的大文件调用 :cpp:func:`link`,则无法确保线程安全。
7577

78+
以下选项用于设置 FatFs 文件系统计算和报告空闲空间的策略:
79+
80+
* :ref:`CONFIG_FATFS_DONT_TRUST_FREE_CLUSTER_CNT` – 如果设置为 1,将忽略空闲簇计数。默认值为 0。
81+
* :ref:`CONFIG_FATFS_DONT_TRUST_LAST_ALLOC` – 如果设置为 1,将忽略上次分配的簇号。默认值为 0。
82+
83+
.. note::
84+
85+
将这两个选项设为 1 可能会提高 :cpp:func:`f_getfree` 输出的准确性,但性能会下降,例如,可能需要执行完整的 FAT 扫描。
86+
7687

7788
.. _fatfs-diskio-layer:
7889

0 commit comments

Comments
 (0)