From b5165b6d7f0bccd2478640c90b6a39f34140e0d7 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 15 Aug 2022 08:14:57 +1000 Subject: [PATCH] AP_FileSystem: add AP_FILESYSTEM_*_ENABLED --- libraries/AP_Filesystem/AP_Filesystem.cpp | 20 +++++++++++++----- .../AP_Filesystem/AP_Filesystem_Mission.cpp | 9 +++++--- .../AP_Filesystem/AP_Filesystem_Mission.h | 6 ++++++ .../AP_Filesystem/AP_Filesystem_Param.cpp | 7 +++++++ libraries/AP_Filesystem/AP_Filesystem_Param.h | 6 ++++++ .../AP_Filesystem/AP_Filesystem_ROMFS.cpp | 9 +++++--- libraries/AP_Filesystem/AP_Filesystem_ROMFS.h | 6 ++++++ libraries/AP_Filesystem/AP_Filesystem_Sys.cpp | 5 +++++ libraries/AP_Filesystem/AP_Filesystem_Sys.h | 6 ++++++ .../AP_Filesystem/AP_Filesystem_config.h | 21 +++++++++++++++++++ 10 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 libraries/AP_Filesystem/AP_Filesystem_config.h diff --git a/libraries/AP_Filesystem/AP_Filesystem.cpp b/libraries/AP_Filesystem/AP_Filesystem.cpp index 2227242de5..4910d09d93 100644 --- a/libraries/AP_Filesystem/AP_Filesystem.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem.cpp @@ -15,6 +15,9 @@ #include "AP_Filesystem.h" +#include "AP_Filesystem_config.h" +#include + static AP_Filesystem fs; #if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS @@ -37,19 +40,22 @@ static AP_Filesystem_ESP32 fs_local; static AP_Filesystem_Posix fs_local; #endif -#ifdef HAL_HAVE_AP_ROMFS_EMBEDDED_H +#if AP_FILESYSTEM_ROMFS_ENABLED #include "AP_Filesystem_ROMFS.h" static AP_Filesystem_ROMFS fs_romfs; #endif +#if AP_FILESYSTEM_PARAM_ENABLED #include "AP_Filesystem_Param.h" static AP_Filesystem_Param fs_param; +#endif +#if AP_FILESYSTEM_SYS_ENABLED #include "AP_Filesystem_Sys.h" static AP_Filesystem_Sys fs_sys; +#endif -#include -#if AP_MISSION_ENABLED +#if AP_FILESYSTEM_MISSION_ENABLED #include "AP_Filesystem_Mission.h" static AP_Filesystem_Mission fs_mission; #endif @@ -59,13 +65,17 @@ static AP_Filesystem_Mission fs_mission; */ const AP_Filesystem::Backend AP_Filesystem::backends[] = { { nullptr, fs_local }, -#ifdef HAL_HAVE_AP_ROMFS_EMBEDDED_H +#if AP_FILESYSTEM_ROMFS_ENABLED { "@ROMFS/", fs_romfs }, #endif +#if AP_FILESYSTEM_PARAM_ENABLED { "@PARAM/", fs_param }, +#endif +#if AP_FILESYSTEM_SYS_ENABLED { "@SYS/", fs_sys }, { "@SYS", fs_sys }, -#if AP_MISSION_ENABLED +#endif +#if AP_FILESYSTEM_MISSION_ENABLED { "@MISSION/", fs_mission }, #endif }; diff --git a/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp b/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp index 6bbc33aa2c..ceaed90404 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp @@ -15,6 +15,11 @@ /* ArduPilot filesystem interface for mission/fence/rally */ + +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_MISSION_ENABLED + #include "AP_Filesystem.h" #include "AP_Filesystem_Mission.h" #include @@ -23,8 +28,6 @@ #include #include -#if AP_MISSION_ENABLED - extern const AP_HAL::HAL& hal; extern int errno; @@ -406,4 +409,4 @@ bool AP_Filesystem_Mission::finish_upload(const rfile &r) return true; } -#endif +#endif // AP_FILESYSTEM_MISSION_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_Mission.h b/libraries/AP_Filesystem/AP_Filesystem_Mission.h index a4f0f869fd..5a6e123527 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Mission.h +++ b/libraries/AP_Filesystem/AP_Filesystem_Mission.h @@ -15,6 +15,10 @@ #pragma once +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_MISSION_ENABLED + #include "AP_Filesystem_backend.h" #include #include @@ -72,3 +76,5 @@ private: // see if a block of memory is all zero bool all_zero(const uint8_t *b, uint8_t size) const; }; + +#endif // AP_FILESYSTEM_MISSION_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_Param.cpp b/libraries/AP_Filesystem/AP_Filesystem_Param.cpp index afa838d0b5..e8ec6a4854 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Param.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_Param.cpp @@ -15,6 +15,11 @@ /* ArduPilot filesystem interface for parameters */ + +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_PARAM_ENABLED + #include "AP_Filesystem.h" #include "AP_Filesystem_Param.h" #include @@ -646,3 +651,5 @@ bool AP_Filesystem_Param::finish_upload(const rfile &r) } return true; } + +#endif // AP_FILESYSTEM_PARAM_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_Param.h b/libraries/AP_Filesystem/AP_Filesystem_Param.h index 8b0af02b37..96f5b7d050 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Param.h +++ b/libraries/AP_Filesystem/AP_Filesystem_Param.h @@ -15,6 +15,10 @@ #pragma once +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_PARAM_ENABLED + #include "AP_Filesystem_backend.h" #include @@ -82,3 +86,5 @@ private: bool finish_upload(const rfile &r); bool param_upload_parse(const rfile &r, bool &need_retry); }; + +#endif // AP_FILESYSTEM_PARAM_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_ROMFS.cpp b/libraries/AP_Filesystem/AP_Filesystem_ROMFS.cpp index d4e3dadb3f..db4ddb42da 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_ROMFS.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_ROMFS.cpp @@ -15,14 +15,17 @@ /* ArduPilot filesystem interface for ROMFS */ + +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_ROMFS_ENABLED + #include "AP_Filesystem.h" #include "AP_Filesystem_ROMFS.h" #include #include #include -#if defined(HAL_HAVE_AP_ROMFS_EMBEDDED_H) - int AP_Filesystem_ROMFS::open(const char *fname, int flags, bool allow_absolute_paths) { if ((flags & O_ACCMODE) != O_RDONLY) { @@ -236,4 +239,4 @@ void AP_Filesystem_ROMFS::unload_file(FileData *fd) AP_ROMFS::free(fd->data); } -#endif // HAL_HAVE_AP_ROMFS_EMBEDDED_H +#endif // AP_FILESYSTEM_ROMFS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_ROMFS.h b/libraries/AP_Filesystem/AP_Filesystem_ROMFS.h index 897195915e..a5176aeaf4 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_ROMFS.h +++ b/libraries/AP_Filesystem/AP_Filesystem_ROMFS.h @@ -15,6 +15,10 @@ #pragma once +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_ROMFS_ENABLED + #include "AP_Filesystem_backend.h" class AP_Filesystem_ROMFS : public AP_Filesystem_Backend @@ -68,3 +72,5 @@ private: struct dirent de; } dir[max_open_dir]; }; + +#endif // AP_FILESYSTEM_ROMFS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_Sys.cpp b/libraries/AP_Filesystem/AP_Filesystem_Sys.cpp index dacd553f35..2898539173 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Sys.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_Sys.cpp @@ -19,6 +19,9 @@ */ #include "AP_Filesystem.h" #include "AP_Filesystem_Sys.h" + +#if AP_FILESYSTEM_SYS_ENABLED + #include #include #include @@ -281,3 +284,5 @@ int AP_Filesystem_Sys::stat(const char *pathname, struct stat *stbuf) } return 0; } + +#endif // AP_FILESYSTEM_SYS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_Sys.h b/libraries/AP_Filesystem/AP_Filesystem_Sys.h index e097b74d4a..e9d186e70f 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Sys.h +++ b/libraries/AP_Filesystem/AP_Filesystem_Sys.h @@ -17,6 +17,10 @@ #include "AP_Filesystem_backend.h" +#include "AP_Filesystem_config.h" + +#if AP_FILESYSTEM_SYS_ENABLED + class ExpandingString; class AP_Filesystem_Sys : public AP_Filesystem_Backend @@ -48,3 +52,5 @@ private: ExpandingString *str; } file[max_open_file]; }; + +#endif // AP_FILESYSTEM_SYS_ENABLED diff --git a/libraries/AP_Filesystem/AP_Filesystem_config.h b/libraries/AP_Filesystem/AP_Filesystem_config.h new file mode 100644 index 0000000000..52e26ef480 --- /dev/null +++ b/libraries/AP_Filesystem/AP_Filesystem_config.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +#include + +#ifndef AP_FILESYSTEM_PARAM_ENABLED +#define AP_FILESYSTEM_PARAM_ENABLED 1 +#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 +#endif + +#ifndef AP_FILESYSTEM_ROMFS_ENABLED +#define AP_FILESYSTEM_ROMFS_ENABLED defined(HAL_HAVE_AP_ROMFS_EMBEDDED_H) +#endif