fs: allow setting max file name explicitly

Zephyr allows an application to register additional file systems,
which may have maximum filename lengths different from the in-tree
FatFs and littlefs options.  Provide a Kconfig variable that allows
the default inference to be overridden.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2020-08-14 10:41:01 -05:00 committed by Carles Cufí
commit ad782596ea
2 changed files with 17 additions and 0 deletions

View file

@ -13,6 +13,10 @@
extern "C" { extern "C" {
#endif #endif
#if (CONFIG_FILE_SYSTEM_MAX_FILE_NAME - 0) > 0
#define MAX_FILE_NAME CONFIG_FILE_SYSTEM_MAX_FILE_NAME
#else /* CONFIG_FILE_SYSTEM_MAX_FILE_NAME */
/* Select from enabled file systems */
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS) #if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
#define MAX_FILE_NAME 256 #define MAX_FILE_NAME 256
#elif defined(CONFIG_FAT_FILESYSTEM_ELM) #elif defined(CONFIG_FAT_FILESYSTEM_ELM)
@ -25,6 +29,7 @@ extern "C" {
/* Use standard 8.3 when no filesystem is explicitly selected */ /* Use standard 8.3 when no filesystem is explicitly selected */
#define MAX_FILE_NAME 12 #define MAX_FILE_NAME 12
#endif /* filesystem selection */ #endif /* filesystem selection */
#endif /* CONFIG_FILE_SYSTEM_MAX_FILE_NAME */
/* Type for fs_open flags */ /* Type for fs_open flags */
typedef uint8_t fs_mode_t; typedef uint8_t fs_mode_t;

View file

@ -36,6 +36,18 @@ config FILE_SYSTEM_MAX_TYPES
LittleFS, but it is possible to define additional ones and LittleFS, but it is possible to define additional ones and
register them. A slot is required for each type. register them. A slot is required for each type.
config FILE_SYSTEM_MAX_FILE_NAME
int "Optional override for maximum file name length"
default -1
help
Specify the maximum file name allowed across all enabled file
system types. Zero or a negative value selects the maximum
file name length for enabled in-tree file systems. This
default may be inappropriate when registering an out-of-tree
file system. Selecting a value less than the actual length
supported by a file system may result in memory access
violations.
menu "FatFs Settings" menu "FatFs Settings"
visible if FAT_FILESYSTEM_ELM visible if FAT_FILESYSTEM_ELM