From ad782596ea05813b972e159621dcea64ee61b6eb Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Fri, 14 Aug 2020 10:41:01 -0500 Subject: [PATCH] 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 --- include/fs/fs_interface.h | 5 +++++ subsys/fs/Kconfig | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/fs/fs_interface.h b/include/fs/fs_interface.h index 2f20b58179d..0089b145d35 100644 --- a/include/fs/fs_interface.h +++ b/include/fs/fs_interface.h @@ -13,6 +13,10 @@ extern "C" { #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) #define MAX_FILE_NAME 256 #elif defined(CONFIG_FAT_FILESYSTEM_ELM) @@ -25,6 +29,7 @@ extern "C" { /* Use standard 8.3 when no filesystem is explicitly selected */ #define MAX_FILE_NAME 12 #endif /* filesystem selection */ +#endif /* CONFIG_FILE_SYSTEM_MAX_FILE_NAME */ /* Type for fs_open flags */ typedef uint8_t fs_mode_t; diff --git a/subsys/fs/Kconfig b/subsys/fs/Kconfig index dfc93291973..9c0d9d445e2 100644 --- a/subsys/fs/Kconfig +++ b/subsys/fs/Kconfig @@ -36,6 +36,18 @@ config FILE_SYSTEM_MAX_TYPES LittleFS, but it is possible to define additional ones and 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" visible if FAT_FILESYSTEM_ELM