mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
POSIX rename() silently replaces the destination when it already exists, while FatFs' f_rename() refuses with FR_EXIST. rename() on a FAT mount therefore fails with EEXIST where the same call succeeds on other file systems, and every caller that wants portable behaviour has to remove the destination itself. Add CONFIG_FATFS_VFS_RENAME_REPLACES_DESTINATION (default n, so existing behaviour is unchanged) to emulate the POSIX semantics: when f_rename() reports FR_EXIST, remove the destination and retry, all under the lock already held for the rename so no other VFS caller observes the gap. The POSIX rules on what may replace what are applied before anything is removed, because f_unlink() deletes empty directories as readily as files and would otherwise discard a directory to make way for a file: renaming a file onto a directory fails with EISDIR, a directory onto a file with ENOTDIR, and a directory onto a non-empty directory with ENOTEMPTY. Without the option all of these keep failing with EEXIST. Moving a directory into its own subtree is rejected with EINVAL as well. f_rename() does not check for this and links the directory into its own tree, losing its contents, so this is a correctness fix rather than a matter of which error is reported. Renaming an entry to itself needs no special handling: f_rename() reports FR_EXIST only when the destination resolves to a different directory entry, so a self-rename, including one written with a different spelling of the same name, already succeeds. The emulation cannot be atomic, nor can it honour the POSIX guarantee that a failed rename leaves an instance of the destination in place: FAT cannot replace a directory entry in one step, so an interruption between removing the destination and completing the rename can leave neither name. This is documented in the option's help text.
390 lines
16 KiB
Plaintext
390 lines
16 KiB
Plaintext
menu "FAT Filesystem support"
|
|
|
|
config FATFS_VOLUME_COUNT
|
|
int "Number of volumes"
|
|
default 2
|
|
range 1 10
|
|
help
|
|
Number of volumes (logical drives) to use.
|
|
|
|
choice FATFS_LONG_FILENAMES
|
|
prompt "Long filename support"
|
|
default FATFS_LFN_HEAP
|
|
help
|
|
Support long filenames in FAT. Long filename data increases
|
|
memory usage. FATFS can be configured to store the buffer for
|
|
long filename data in stack or heap.
|
|
|
|
config FATFS_LFN_NONE
|
|
bool "No long filenames"
|
|
config FATFS_LFN_HEAP
|
|
bool "Long filename buffer in heap"
|
|
config FATFS_LFN_STACK
|
|
bool "Long filename buffer on stack"
|
|
endchoice
|
|
choice FATFS_SECTOR_SIZE
|
|
prompt "Sector size"
|
|
default FATFS_SECTOR_4096
|
|
help
|
|
Specify the size of the sector in bytes for FATFS partition generator.
|
|
|
|
config FATFS_SECTOR_512
|
|
bool "512"
|
|
config FATFS_SECTOR_4096
|
|
bool "4096"
|
|
endchoice
|
|
choice FATFS_CHOOSE_CODEPAGE
|
|
prompt "OEM Code Page"
|
|
default FATFS_CODEPAGE_437
|
|
help
|
|
OEM code page used for file name encodings.
|
|
|
|
If "Dynamic" is selected, code page can be chosen at runtime using
|
|
f_setcp function. Note that choosing this option will increase
|
|
application size by ~480kB.
|
|
|
|
config FATFS_CODEPAGE_DYNAMIC
|
|
bool "Dynamic (all code pages supported)"
|
|
config FATFS_CODEPAGE_437
|
|
bool "US (CP437)"
|
|
config FATFS_CODEPAGE_720
|
|
bool "Arabic (CP720)"
|
|
config FATFS_CODEPAGE_737
|
|
bool "Greek (CP737)"
|
|
config FATFS_CODEPAGE_771
|
|
bool "KBL (CP771)"
|
|
config FATFS_CODEPAGE_775
|
|
bool "Baltic (CP775)"
|
|
config FATFS_CODEPAGE_850
|
|
bool "Latin 1 (CP850)"
|
|
config FATFS_CODEPAGE_852
|
|
bool "Latin 2 (CP852)"
|
|
config FATFS_CODEPAGE_855
|
|
bool "Cyrillic (CP855)"
|
|
config FATFS_CODEPAGE_857
|
|
bool "Turkish (CP857)"
|
|
config FATFS_CODEPAGE_860
|
|
bool "Portuguese (CP860)"
|
|
config FATFS_CODEPAGE_861
|
|
bool "Icelandic (CP861)"
|
|
config FATFS_CODEPAGE_862
|
|
bool "Hebrew (CP862)"
|
|
config FATFS_CODEPAGE_863
|
|
bool "Canadian French (CP863)"
|
|
config FATFS_CODEPAGE_864
|
|
bool "Arabic (CP864)"
|
|
config FATFS_CODEPAGE_865
|
|
bool "Nordic (CP865)"
|
|
config FATFS_CODEPAGE_866
|
|
bool "Russian (CP866)"
|
|
config FATFS_CODEPAGE_869
|
|
bool "Greek 2 (CP869)"
|
|
config FATFS_CODEPAGE_932
|
|
bool "Japanese (DBCS) (CP932)"
|
|
config FATFS_CODEPAGE_936
|
|
bool "Simplified Chinese (DBCS) (CP936)"
|
|
config FATFS_CODEPAGE_949
|
|
bool "Korean (DBCS) (CP949)"
|
|
config FATFS_CODEPAGE_950
|
|
bool "Traditional Chinese (DBCS) (CP950)"
|
|
|
|
endchoice
|
|
config FATFS_CODEPAGE
|
|
int
|
|
default 0 if FATFS_CODEPAGE_DYNAMIC
|
|
default 437 if FATFS_CODEPAGE_437
|
|
default 720 if FATFS_CODEPAGE_720
|
|
default 737 if FATFS_CODEPAGE_737
|
|
default 771 if FATFS_CODEPAGE_771
|
|
default 775 if FATFS_CODEPAGE_775
|
|
default 850 if FATFS_CODEPAGE_850
|
|
default 852 if FATFS_CODEPAGE_852
|
|
default 855 if FATFS_CODEPAGE_855
|
|
default 857 if FATFS_CODEPAGE_857
|
|
default 860 if FATFS_CODEPAGE_860
|
|
default 861 if FATFS_CODEPAGE_861
|
|
default 862 if FATFS_CODEPAGE_862
|
|
default 863 if FATFS_CODEPAGE_863
|
|
default 864 if FATFS_CODEPAGE_864
|
|
default 865 if FATFS_CODEPAGE_865
|
|
default 866 if FATFS_CODEPAGE_866
|
|
default 869 if FATFS_CODEPAGE_869
|
|
default 932 if FATFS_CODEPAGE_932
|
|
default 936 if FATFS_CODEPAGE_936
|
|
default 949 if FATFS_CODEPAGE_949
|
|
default 950 if FATFS_CODEPAGE_950
|
|
default 437
|
|
|
|
config FATFS_MAX_LFN
|
|
int "Max long filename length"
|
|
depends on !FATFS_LFN_NONE
|
|
default 255
|
|
range 12 255
|
|
help
|
|
Maximum long filename length. Can be reduced to save RAM.
|
|
|
|
choice FATFS_API_ENCODING
|
|
prompt "API character encoding"
|
|
depends on !FATFS_LFN_NONE
|
|
default FATFS_API_ENCODING_ANSI_OEM
|
|
help
|
|
Choose encoding for character and string arguments/returns when using
|
|
FATFS APIs. The encoding of arguments will usually depend on text
|
|
editor settings.
|
|
|
|
config FATFS_API_ENCODING_ANSI_OEM
|
|
bool "API uses ANSI/OEM encoding"
|
|
config FATFS_API_ENCODING_UTF_8
|
|
bool "API uses UTF-8 encoding"
|
|
endchoice
|
|
|
|
config FATFS_FS_LOCK
|
|
int "Number of simultaneously open files protected by lock function"
|
|
default 0
|
|
range 0 65535
|
|
help
|
|
This option sets the FATFS configuration value _FS_LOCK.
|
|
The option _FS_LOCK switches file lock function to control duplicated file open
|
|
and illegal operation to open objects.
|
|
|
|
* 0: Disable file lock function. To avoid volume corruption, application
|
|
should avoid illegal open, remove and rename to the open objects.
|
|
|
|
* >0: Enable file lock function. The value defines how many files/sub-directories
|
|
can be opened simultaneously under file lock control.
|
|
|
|
Note that the file lock control is independent of re-entrancy.
|
|
|
|
config FATFS_TIMEOUT_MS
|
|
int "Timeout for acquiring a file lock, ms"
|
|
default 10000
|
|
help
|
|
This option sets FATFS configuration value _FS_TIMEOUT, scaled to milliseconds.
|
|
Sets the number of milliseconds FATFS will wait to acquire a mutex when
|
|
operating on an open file. For example, if one task is performing a lengthy
|
|
operation, another task will wait for the first task to release the lock,
|
|
and time out after amount of time set by this option.
|
|
|
|
|
|
config FATFS_PER_FILE_CACHE
|
|
bool "Use separate cache for each file"
|
|
default y
|
|
help
|
|
This option affects FATFS configuration value _FS_TINY.
|
|
|
|
If this option is set, _FS_TINY is 0, and each open file has its own cache,
|
|
size of the cache is equal to the _MAX_SS variable (512 or 4096 bytes).
|
|
This option uses more RAM if more than 1 file is open, but needs less reads
|
|
and writes to the storage for some operations.
|
|
|
|
If this option is not set, _FS_TINY is 1, and single cache is used for
|
|
all open files, size is also equal to _MAX_SS variable. This reduces the
|
|
amount of heap used when multiple files are open, but increases the number
|
|
of read and write operations which FATFS needs to make.
|
|
|
|
|
|
config FATFS_ALLOC_PREFER_EXTRAM
|
|
bool "Prefer external RAM when allocating FATFS buffers"
|
|
default y
|
|
depends on SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC
|
|
help
|
|
When the option is enabled, internal buffers used by FATFS will be allocated
|
|
from external RAM. If the allocation from external RAM fails, the buffer will
|
|
be allocated from the internal RAM.
|
|
Disable this option if optimizing for performance. Enable this option if
|
|
optimizing for internal memory size.
|
|
|
|
config FATFS_ALLOC_PREFER_ALIGNED_WORK_BUFFERS
|
|
bool "Prefer aligned, DMA capable RAM when allocating FATFS buffers"
|
|
default y if SOC_SDMMC_HOST_SUPPORTED
|
|
default n
|
|
help
|
|
Tries to allocate FATFS heap buffers in a way they can be used directly by the SDMMC driver without
|
|
extra copies when DMA is enabled (for example when using PSRAM on ESP32-P4).
|
|
Disable this if you need the absolute minimum heap overhead and do not use SDMMC.
|
|
This option can be combined with CONFIG_FATFS_ALLOC_PREFER_EXTRAM,
|
|
in which case, the following order is tried: DMA capable RAM, external RAM, internal RAM.
|
|
|
|
config FATFS_USE_FASTSEEK
|
|
bool "Enable fast seek algorithm when using lseek function through VFS FAT"
|
|
default n
|
|
help
|
|
The fast seek feature enables fast backward/long seek operations without
|
|
FAT access by using an in-memory CLMT (cluster link map table).
|
|
Please note, fast-seek is only allowed for read-mode files, if a
|
|
file is opened in write-mode, the seek mechanism will automatically fallback
|
|
to the default implementation.
|
|
|
|
choice FATFS_USE_STRFUNC_CHOICE
|
|
prompt "Enable string functions, f_gets(), f_putc(), f_puts() and f_printf()"
|
|
default FATFS_USE_STRFUNC_NONE
|
|
help
|
|
These are specialized alternatives to stdio functions for working
|
|
directly with FATFS without VFS. Legacy code may need functions,
|
|
but for new development, it is advised to use stdio under VFS.
|
|
|
|
0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
|
|
1: Enable without LF-CRLF conversion.
|
|
2: Enable with LF-CRLF conversion.
|
|
|
|
config FATFS_USE_STRFUNC_NONE
|
|
bool "0:Disable"
|
|
|
|
config FATFS_USE_STRFUNC_WITHOUT_CRLF_CONV
|
|
bool "1:Enable without LF-CRLF conversion"
|
|
|
|
config FATFS_USE_STRFUNC_WITH_CRLF_CONV
|
|
bool "2:Enable with LF-CRLF conversion"
|
|
endchoice
|
|
|
|
config FATFS_PRINT_LLI
|
|
depends on !FATFS_USE_STRFUNC_NONE
|
|
bool "Make fatfs f_printf() support long long argument"
|
|
default n
|
|
|
|
config FATFS_PRINT_FLOAT
|
|
depends on !FATFS_USE_STRFUNC_NONE
|
|
bool "Make fatfs f_printf() support floating point argument"
|
|
default n
|
|
|
|
choice FATFS_STRF_ENCODE_CHOICE
|
|
prompt "FatFS string functions: convert character encoding"
|
|
depends on !FATFS_LFN_NONE && !FATFS_USE_STRFUNC_NONE
|
|
default FATFS_STRF_ENCODE_UTF8
|
|
help
|
|
When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
|
|
encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
|
|
to be read/written via those functions.
|
|
0: ANSI/OEM in current CP
|
|
1: Unicode in UTF-16LE
|
|
2: Unicode in UTF-16BE
|
|
3: Unicode in UTF-8
|
|
|
|
config FATFS_STRF_ENCODE_ANSI
|
|
bool "0:ANSI/OEM in current CP"
|
|
|
|
config FATFS_STRF_ENCODE_UTF16LE
|
|
bool "1:Unicode in UTF-16LE"
|
|
|
|
config FATFS_STRF_ENCODE_UTF16BE
|
|
bool "2:Unicode in UTF-16BE"
|
|
|
|
config FATFS_STRF_ENCODE_UTF8
|
|
bool "3:Unicode in UTF-8"
|
|
endchoice
|
|
|
|
config FATFS_FAST_SEEK_BUFFER_SIZE
|
|
int "Fast seek CLMT buffer size"
|
|
default 64
|
|
depends on FATFS_USE_FASTSEEK
|
|
help
|
|
If fast seek algorithm is enabled, this defines the size of
|
|
CLMT buffer used by this algorithm in 32-bit word units.
|
|
This value should be chosen based on prior knowledge of
|
|
maximum elements of each file entry would store.
|
|
|
|
config FATFS_VFS_FSTAT_BLKSIZE
|
|
int "Default block size"
|
|
default 0
|
|
help
|
|
If set to 0, the 'newlib' library's default size (BLKSIZ) is used (128 B).
|
|
If set to a non-zero value, the value is used as the block size.
|
|
Default file buffer size is set to this value
|
|
and the buffer is allocated when first attempt of reading/writing to a file is made.
|
|
Increasing this value improves fread() speed, however the heap usage is increased as well.
|
|
|
|
NOTE: The block size value is shared by all the filesystem functions
|
|
accessing target media for given file descriptor!
|
|
See 'Improving I/O performance' section of 'Maximizing Execution Speed' documentation page
|
|
for more details.
|
|
|
|
config FATFS_IMMEDIATE_FSYNC
|
|
bool "Enable automatic f_sync"
|
|
default n
|
|
help
|
|
Enables automatic calling of f_sync() to flush recent file changes after each call of vfs_fat_write(),
|
|
vfs_fat_pwrite(), vfs_fat_link(), vfs_fat_truncate() and vfs_fat_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
|
|
|
|
config FATFS_USE_LABEL
|
|
bool "Use FATFS volume label"
|
|
default n
|
|
help
|
|
Allows FATFS volume label to be specified using f_setlabel
|
|
|
|
config FATFS_LINK_LOCK
|
|
bool "Perform the whole link operation under lock"
|
|
default y
|
|
help
|
|
If enabled, the whole link operation (including file copying) is performed under lock.
|
|
This ensures that the link operation is atomic, but may cause performance for large files.
|
|
It may create less fragmented file copy.
|
|
|
|
config FATFS_VFS_RENAME_REPLACES_DESTINATION
|
|
bool "Make rename() replace an existing destination (POSIX behavior)"
|
|
default n
|
|
help
|
|
POSIX rename() silently replaces the destination if it already exists,
|
|
while FatFs' f_rename() refuses with FR_EXIST, so by default rename() on a
|
|
FAT mount fails with EEXIST where it would succeed on other file systems.
|
|
|
|
Enable this option to emulate the POSIX behavior: when the destination
|
|
exists, it is removed and the rename is retried, with the whole sequence
|
|
performed under the same lock as the rename itself. The POSIX rules on what
|
|
may replace what are applied first, so that a directory is never silently
|
|
removed to make way for a file:
|
|
|
|
- a directory can only replace an empty directory (ENOTEMPTY otherwise),
|
|
- renaming a directory onto a file fails with ENOTDIR,
|
|
- renaming a file onto a directory fails with EISDIR.
|
|
|
|
Without this option all of these fail with EEXIST instead.
|
|
|
|
Moving a directory into its own subtree is also rejected with EINVAL, as
|
|
POSIX requires. f_rename() does not check for this and would link the
|
|
directory into its own tree, losing its contents; without this option that
|
|
call still succeeds and corrupts the volume.
|
|
|
|
Note that the emulation is not atomic, and that it cannot honour the POSIX
|
|
guarantee that a failed rename leaves an instance of the destination in
|
|
place. FAT offers no way to replace a directory entry in a single step, so
|
|
an interruption (such as a power loss) between removing the destination and
|
|
completing the rename can leave neither name present. Code that must not
|
|
lose the destination should copy to a temporary name and rename over it.
|
|
|
|
config FATFS_USE_DYN_BUFFERS
|
|
bool "Use dynamic buffers"
|
|
default y
|
|
help
|
|
If enabled, the buffers used by FATFS will be allocated separately from the rest of the structure.
|
|
This option is useful when using multiple FATFS instances with different
|
|
sector sizes, as the buffers will be allocated according to the sector size.
|
|
If disabled, the greatest sector size will be used for all FATFS instances.
|
|
(In most cases, this would be the sector size of Wear Levelling library)
|
|
This might cause more memory to be used than necessary.
|
|
|
|
menu "File system free space calculation behavior"
|
|
help
|
|
Controls if the file system does or does not trust cached data like free cluster count and allocated
|
|
cluster number. Setting these to do not trust the data may result of more accurate output from
|
|
`f_getfree()` function but increased overhead (forces a full FAT scan, etc.).
|
|
|
|
config FATFS_DONT_TRUST_FREE_CLUSTER_CNT
|
|
int "Don't trust free cluster count"
|
|
default 0
|
|
range 0 1
|
|
help
|
|
If 1, the file system will not trust the free cluster count in the FSINFO (in FATFS struct).
|
|
This may result in more accurate output from `f_getfree()` function but increased overhead.
|
|
|
|
config FATFS_DONT_TRUST_LAST_ALLOC
|
|
int "Don't trust allocated cluster number"
|
|
default 0
|
|
range 0 1
|
|
help
|
|
If 1, the file system will not trust the last allocated cluster number in the FSINFO (in FATFS struct).
|
|
This may result in more accurate output from `f_getfree()` function but increased overhead.
|
|
endmenu
|
|
endmenu
|