From adbf9ef3ac3c89fadcdefce72ed2c3b5d17e9160 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 18 May 2020 00:55:43 +0200 Subject: [PATCH] vfs: select VFS params to accommodate all enabled file systems --- pkg/fatfs/Makefile.include | 4 +- pkg/littlefs/Makefile.include | 2 - pkg/littlefs2/Makefile.include | 2 - sys/include/vfs.h | 76 +++++++++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/pkg/fatfs/Makefile.include b/pkg/fatfs/Makefile.include index 0cbc7995b4..61e4b7bd7e 100644 --- a/pkg/fatfs/Makefile.include +++ b/pkg/fatfs/Makefile.include @@ -3,6 +3,7 @@ INCLUDES += -I$(RIOTPKG)/fatfs/fatfs_diskio/mtd/include DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_diskio/mtd + ifneq (,$(filter fatfs_vfs,$(USEMODULE))) DIRS += $(RIOTBASE)/pkg/fatfs/fatfs_vfs endif @@ -17,6 +18,3 @@ endif ifeq ($(OS),Darwin) CFLAGS += -Wno-empty-body endif - -# Set vfs file and dir buffer sizes -CFLAGS += -DVFS_FILE_BUFFER_SIZE=72 -DVFS_DIR_BUFFER_SIZE=44 diff --git a/pkg/littlefs/Makefile.include b/pkg/littlefs/Makefile.include index 4793d99324..129be58296 100644 --- a/pkg/littlefs/Makefile.include +++ b/pkg/littlefs/Makefile.include @@ -4,7 +4,5 @@ ifneq (,$(filter littlefs_fs,$(USEMODULE))) DIRS += $(RIOTBASE)/pkg/littlefs/fs endif -# Set vfs file and dir buffer sizes -CFLAGS += -DVFS_FILE_BUFFER_SIZE=56 -DVFS_DIR_BUFFER_SIZE=44 # Reduce LFS_NAME_MAX to 31 (as VFS_NAME_MAX default) CFLAGS += -DLFS_NAME_MAX=31 diff --git a/pkg/littlefs2/Makefile.include b/pkg/littlefs2/Makefile.include index 84c63eb4fb..aca2d10be6 100644 --- a/pkg/littlefs2/Makefile.include +++ b/pkg/littlefs2/Makefile.include @@ -2,7 +2,5 @@ INCLUDES += -I$(PKGDIRBASE)/littlefs2 DIRS += $(RIOTBASE)/pkg/littlefs2/fs -# Set vfs file and dir buffer sizes -CFLAGS += -DVFS_FILE_BUFFER_SIZE=84 -DVFS_DIR_BUFFER_SIZE=52 # Reduce LFS_NAME_MAX to 31 (as VFS_NAME_MAX default) CFLAGS += -DLFS_NAME_MAX=31 diff --git a/sys/include/vfs.h b/sys/include/vfs.h index 2b547822e0..8c45e99124 100644 --- a/sys/include/vfs.h +++ b/sys/include/vfs.h @@ -79,6 +79,70 @@ extern "C" { /* #define restrict */ #endif +/** + * @brief MAX functions for internal use + * @{ + */ +#ifndef _MAX +#define _MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif +#ifndef MAX4 +#define MAX4(a, b, c, d) _MAX(_MAX((a), (b)), _MAX((c),(d))) +#endif +/** @} */ + +/** + * @brief VFS parameters for FAT + * @{ + */ +#ifdef MODULE_FATFS_VFS +#define FATFS_VFS_DIR_BUFFER_SIZE (44) +#define FATFS_VFS_FILE_BUFFER_SIZE (72) +#else +#define FATFS_VFS_DIR_BUFFER_SIZE (1) +#define FATFS_VFS_FILE_BUFFER_SIZE (1) +#endif +/** @} */ + +/** + * @brief VFS parameters for littlefs + * @{ + */ +#ifdef MODULE_LITTLEFS +#define LITTLEFS_VFS_DIR_BUFFER_SIZE (44) +#define LITTLEFS_VFS_FILE_BUFFER_SIZE (56) +#else +#define LITTLEFS_VFS_DIR_BUFFER_SIZE (1) +#define LITTLEFS_VFS_FILE_BUFFER_SIZE (1) +#endif +/** @} */ + +/** + * @brief VFS parameters for littlefs2 + * @{ + */ +#ifdef MODULE_LITTLEFS2 +#define LITTLEFS2_VFS_DIR_BUFFER_SIZE (52) +#define LITTLEFS2_VFS_FILE_BUFFER_SIZE (84) +#else +#define LITTLEFS2_VFS_DIR_BUFFER_SIZE (1) +#define LITTLEFS2_VFS_FILE_BUFFER_SIZE (1) +#endif +/** @} */ + +/** + * @brief VFS parameters for spiffs + * @{ + */ +#ifdef MODULE_SPIFFS +#define SPIFFS_VFS_DIR_BUFFER_SIZE (12) +#define SPIFFS_VFS_FILE_BUFFER_SIZE (1) +#else +#define SPIFFS_VFS_DIR_BUFFER_SIZE (1) +#define SPIFFS_VFS_FILE_BUFFER_SIZE (1) +#endif +/** @} */ + #ifndef VFS_MAX_OPEN_FILES /** * @brief Maximum number of simultaneous open files @@ -114,7 +178,11 @@ extern "C" { * @attention Put the check in the public header file (.h), do not put the check in the * implementation (.c) file. */ -#define VFS_DIR_BUFFER_SIZE (12) +#define VFS_DIR_BUFFER_SIZE MAX4(FATFS_VFS_DIR_BUFFER_SIZE, \ + LITTLEFS_VFS_DIR_BUFFER_SIZE, \ + LITTLEFS2_VFS_DIR_BUFFER_SIZE, \ + SPIFFS_VFS_DIR_BUFFER_SIZE \ + ) #endif #ifndef VFS_FILE_BUFFER_SIZE @@ -137,7 +205,11 @@ extern "C" { * @attention Put the check in the public header file (.h), do not put the check in the * implementation (.c) file. */ -#define VFS_FILE_BUFFER_SIZE (1) +#define VFS_FILE_BUFFER_SIZE MAX4(FATFS_VFS_FILE_BUFFER_SIZE, \ + LITTLEFS_VFS_FILE_BUFFER_SIZE, \ + LITTLEFS2_VFS_FILE_BUFFER_SIZE,\ + SPIFFS_VFS_FILE_BUFFER_SIZE \ + ) #endif #ifndef VFS_NAME_MAX