in NXP's Kinetis series MCU, I have formatted the 8GB-sized EMMC as a Fatfs file system and also implemented the USB MSC function, which allows accessing the files in Fatfs through USB on a computer. I have used mutex locks to separate the calls to each Fatfs function, as I am using an RTOS.
Sometimes, there is a small probability of file nesting in the file system, although it rarely occurs. For example, if there is a config.ini
file in the config
folder, this file may appear in another folder, and there may also be multiple nested layers of folders. In such cases, when viewing the properties of the USB drive on the computer, the used capacity and total capacity are within the range of the EMMC size, but when viewing the properties of the nested folders by right-clicking, the occupied capacity can be as high as 40GB, which exceeds the 8GB of the EMMC.
Then I discovered that the following two options in Fatfs were not enabled:
#define FF_LBA64 0
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
#define FF_FS_EXFAT 0
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
It seems that before enabling these two options, the individual file size cannot exceed 4GB. But if the combined size of multiple files exceeds 4GB, will there be any impact? I tested by closing the above two options and placing several files in the file system with a total size exceeding 4GB, and the file system did not show any read/write abnormalities or nesting. Sometimes, the USB drive could not read the file list, but restarting the system would be allright. I wonder if this anomaly is related to FF_LBA64
, that is, when the total size of multiple files exceeds 4GB, there is a probability of an anomaly occurring.