From 1c54d1867216e52c43e15f7aca5030e7250ffb91 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 15 May 2023 11:44:22 +1000 Subject: [PATCH] AP_Filesystem: replace HAVE_FILESYSTEM_SUPPORT with backend defines --- libraries/AP_Filesystem/AP_Filesystem.cpp | 21 ++++------ libraries/AP_Filesystem/AP_Filesystem.h | 2 +- .../AP_Filesystem/AP_Filesystem_ESP32.cpp | 6 +-- .../AP_Filesystem/AP_Filesystem_FATFS.cpp | 8 ++-- libraries/AP_Filesystem/AP_Filesystem_FATFS.h | 4 ++ .../AP_Filesystem/AP_Filesystem_config.h | 41 +++++++++++++++---- .../AP_Filesystem/AP_Filesystem_posix.cpp | 10 +++-- libraries/AP_Filesystem/AP_Filesystem_posix.h | 5 +++ libraries/AP_Filesystem/posix_compat.cpp | 4 +- 9 files changed, 66 insertions(+), 35 deletions(-) diff --git a/libraries/AP_Filesystem/AP_Filesystem.cpp b/libraries/AP_Filesystem/AP_Filesystem.cpp index 4e4f129d3d..b7a1cf79af 100644 --- a/libraries/AP_Filesystem/AP_Filesystem.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem.cpp @@ -20,24 +20,19 @@ static AP_Filesystem fs; -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS -#if HAVE_FILESYSTEM_SUPPORT +// create exactly one "local" filesystem: +#if AP_FILESYSTEM_FATFS_ENABLED #include "AP_Filesystem_FATFS.h" static AP_Filesystem_FATFS fs_local; +#elif AP_FILESYSTEM_ESP32_ENABLED +#include "AP_Filesystem_ESP32.h" +static AP_Filesystem_ESP32 fs_local; +#elif AP_FILESYSTEM_POSIX_ENABLED +#include "AP_Filesystem_posix.h" +static AP_Filesystem_Posix fs_local; #else static AP_Filesystem_Backend fs_local; int errno; -#endif // HAVE_FILESYSTEM_SUPPORT -#endif // HAL_BOARD_CHIBIOS - -#if CONFIG_HAL_BOARD == HAL_BOARD_ESP32 -#include "AP_Filesystem_ESP32.h" -static AP_Filesystem_ESP32 fs_local; -#endif // HAL_BOARD_ESP32 - -#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX || CONFIG_HAL_BOARD == HAL_BOARD_SITL -#include "AP_Filesystem_posix.h" -static AP_Filesystem_Posix fs_local; #endif #if AP_FILESYSTEM_ROMFS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem.h b/libraries/AP_Filesystem/AP_Filesystem.h index 193111de19..ac785bf30a 100644 --- a/libraries/AP_Filesystem/AP_Filesystem.h +++ b/libraries/AP_Filesystem/AP_Filesystem.h @@ -35,7 +35,7 @@ #endif #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS -#if HAVE_FILESYSTEM_SUPPORT +#if AP_FILESYSTEM_FATFS_ENABLED #include "AP_Filesystem_FATFS.h" #endif diff --git a/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp b/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp index c41ad9179c..9cb031d867 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_ESP32.cpp @@ -17,8 +17,7 @@ #include "AP_Filesystem.h" #include -#if HAVE_FILESYSTEM_SUPPORT -#if CONFIG_HAL_BOARD == HAL_BOARD_ESP32 +#if AP_FILESYSTEM_ESP32_ENABLED #define FSDEBUG 0 @@ -199,5 +198,4 @@ bool AP_Filesystem_ESP32::set_mtime(const char *filename, const uint32_t mtime_s return utime(filename, ×) == 0; } -#endif // CONFIG_HAL_BOARD -#endif +#endif // AP_FILESYSTEM_ESP32_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp b/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp index 9cd93ceac4..58b387b553 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_FATFS.cpp @@ -1,14 +1,16 @@ /* ArduPilot filesystem interface for systems using the FATFS filesystem */ +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_FATFS_ENABLED + #include "AP_Filesystem.h" #include #include #include #include -#if HAVE_FILESYSTEM_SUPPORT && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS - #include #include #include @@ -975,4 +977,4 @@ char *strerror(int errnum) return NULL; } -#endif // CONFIG_HAL_BOARD +#endif // AP_FILESYSTEM_FATFS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_FATFS.h b/libraries/AP_Filesystem/AP_Filesystem_FATFS.h index ef79a7c475..7b6d51be8e 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_FATFS.h +++ b/libraries/AP_Filesystem/AP_Filesystem_FATFS.h @@ -11,6 +11,8 @@ #include #include "AP_Filesystem_backend.h" +#if AP_FILESYSTEM_FATFS_ENABLED + // Seek offset macros #define SEEK_SET 0 #define SEEK_CUR 1 @@ -57,3 +59,5 @@ private: void format_handler(void); FormatStatus format_status; }; + +#endif // #if AP_FILESYSTEM_FATFS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_config.h b/libraries/AP_Filesystem/AP_Filesystem_config.h index f0b0f8bdc9..75f3aa001c 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_config.h +++ b/libraries/AP_Filesystem/AP_Filesystem_config.h @@ -4,24 +4,49 @@ #include -#if HAL_OS_POSIX_IO || HAL_OS_FATFS_IO -#define HAVE_FILESYSTEM_SUPPORT 1 -#else -#define HAVE_FILESYSTEM_SUPPORT 0 +// backends: + +#ifndef AP_FILESYSTEM_ESP32_ENABLED +#define AP_FILESYSTEM_ESP32_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_ESP32) #endif -#ifndef AP_FILESYSTEM_PARAM_ENABLED -#define AP_FILESYSTEM_PARAM_ENABLED 1 +#ifndef AP_FILESYSTEM_FATFS_ENABLED +#define AP_FILESYSTEM_FATFS_ENABLED HAL_OS_FATFS_IO #endif #ifndef AP_FILESYSTEM_MISSION_ENABLED #define AP_FILESYSTEM_MISSION_ENABLED AP_MISSION_ENABLED #endif -#ifndef AP_FILESYSTEM_SYS_ENABLED -#define AP_FILESYSTEM_SYS_ENABLED 1 +#ifndef AP_FILESYSTEM_PARAM_ENABLED +#define AP_FILESYSTEM_PARAM_ENABLED 1 +#endif + +#ifndef AP_FILESYSTEM_POSIX_ENABLED +#define AP_FILESYSTEM_POSIX_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL || CONFIG_HAL_BOARD == HAL_BOARD_LINUX) #endif #ifndef AP_FILESYSTEM_ROMFS_ENABLED #define AP_FILESYSTEM_ROMFS_ENABLED defined(HAL_HAVE_AP_ROMFS_EMBEDDED_H) #endif + +#ifndef AP_FILESYSTEM_SYS_ENABLED +#define AP_FILESYSTEM_SYS_ENABLED 1 +#endif + +// AP_FILESYSTEM_FILE_READING_ENABLED is true if you could expect to +// be able to open and write a non-virtual file. Notably this +// excludes virtual files like SYSFS, and the magic param/mission +// upload targets, and also excludes ROMFS (where you can read but not +// write!) +#ifndef AP_FILESYSTEM_FILE_WRITING_ENABLED +#define AP_FILESYSTEM_FILE_WRITING_ENABLED (AP_FILESYSTEM_ESP32_ENABLED || AP_FILESYSTEM_FATFS_ENABLED || AP_FILESYSTEM_POSIX_ENABLED) +#endif + +// AP_FILESYSTEM_FILE_READING_ENABLED is true if you could expect to +// be able to open and read a non-virtual file. Notably this excludes +// virtual files like SYSFS, and the magic param/mission upload targets. +#ifndef AP_FILESYSTEM_FILE_READING_ENABLED +#define AP_FILESYSTEM_FILE_READING_ENABLED (AP_FILESYSTEM_FILE_WRITING_ENABLED || AP_FILESYSTEM_ROMFS_ENABLED) +#endif + diff --git a/libraries/AP_Filesystem/AP_Filesystem_posix.cpp b/libraries/AP_Filesystem/AP_Filesystem_posix.cpp index 658edbbf02..039e0685df 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_posix.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_posix.cpp @@ -15,12 +15,15 @@ /* ArduPilot filesystem interface for posix systems */ + +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_POSIX_ENABLED + #include "AP_Filesystem.h" #include #include -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL || CONFIG_HAL_BOARD == HAL_BOARD_LINUX - #if defined(__APPLE__) #include #else @@ -182,5 +185,4 @@ bool AP_Filesystem_Posix::set_mtime(const char *filename, const uint32_t mtime_s return utime(filename, ×) == 0; } -#endif // CONFIG_HAL_BOARD - +#endif // AP_FILESYSTEM_POSIX_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_posix.h b/libraries/AP_Filesystem/AP_Filesystem_posix.h index faea21d71d..e44764213a 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_posix.h +++ b/libraries/AP_Filesystem/AP_Filesystem_posix.h @@ -15,6 +15,10 @@ #pragma once +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_POSIX_ENABLED + #include #include #include @@ -53,3 +57,4 @@ public: bool set_mtime(const char *filename, const uint32_t mtime_sec) override; }; +#endif // AP_FILESYSTEM_POSIX_ENABLED diff --git a/libraries/AP_Filesystem/posix_compat.cpp b/libraries/AP_Filesystem/posix_compat.cpp index 655e3c7dde..143e9d5fd5 100644 --- a/libraries/AP_Filesystem/posix_compat.cpp +++ b/libraries/AP_Filesystem/posix_compat.cpp @@ -24,7 +24,7 @@ #include "AP_Filesystem.h" -#if HAVE_FILESYSTEM_SUPPORT +#if AP_FILESYSTEM_FATFS_ENABLED || AP_FILESYSTEM_POSIX_ENABLED || AP_FILESYSTEM_ESP32_ENABLED #include "posix_compat.h" #include @@ -268,4 +268,4 @@ int apfs_remove(const char *pathname) return AP::FS().unlink(pathname); } -#endif // HAVE_FILESYSTEM_SUPPORT +#endif // AP_FILESYSTEM_POSIX_ENABLED