mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
feat(posix): separate the filesystem root from the storage directory (#28582)
On NuttX these are two things: / is the filesystem root, and /fs/microsd is the SD card mounted under it. MAVLink FTP serves the root and confines writes to the SD card, so the read-only ROMFS at /etc is visible but cannot be written. On POSIX they were the same directory. PX4_ROOTFSDIR and PX4_STORAGEDIR both resolved to CONFIG_BOARD_ROOT_PATH, which on SITL is ".", so the working directory was simultaneously the FTP root and the only writable area. The consequences were that the ROMFS symlink sat inside the FTP root, and that _validatePathIsWritable() had nothing meaningful to check against and so was compiled out on POSIX entirely, leaving no write restriction at all. Give POSIX the same split. CONFIG_BOARD_ROOT_PATH keeps its meaning as the storage directory, and a new CONFIG_BOARD_FS_ROOT_PATH names the root FTP serves, defaulting to the storage path so every existing board is unchanged. SITL sets the root to "." and storage to "./fs", which mirrors NuttX: logs, parameters, dataman and eeprom move under ./fs, and etc/ stays in the root as read-only data. With storage distinct from the root, the write restriction now applies on every platform rather than NuttX only, and no longer compares against a hardcoded prefix length that was wrong for any board not using /fs/microsd. Assisted-by: Claude:claude-opus-5[1m] Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
1 parent
adb45a88b6
commit
cc976e150a
17 files changed
+42
-24
No files matched your search
@@ -141,4 +141,4 @@ jobs:
|
||||
path: |
|
||||
logs/**/**/**/*.log
|
||||
logs/**/**/**/*.ulg
|
||||
build/px4_sitl_default/tmp_ros_tests/rootfs/log/**/*.ulg
|
||||
build/px4_sitl_default/tmp_ros_tests/rootfs/fs/log/**/*.ulg
|
||||
@@ -107,7 +107,7 @@ jobs:
|
||||
path: |
|
||||
logs/**/**/**/*.log
|
||||
logs/**/**/**/*.ulg
|
||||
build/px4_sitl_default/tmp_mavsdk_tests/rootfs/log/**/*.ulg
|
||||
build/px4_sitl_default/tmp_mavsdk_tests/rootfs/fs/log/**/*.ulg
|
||||
|
||||
- name: Look at Core files
|
||||
if: failure() && ${{ hashFiles('px4.core') != '' }}
|
||||
|
||||
@@ -221,9 +221,18 @@ endmenu
|
||||
menu "File paths"
|
||||
|
||||
config BOARD_ROOT_PATH
|
||||
string "PX4 Root file path"
|
||||
string "PX4 storage path (writable: logs, parameters, dataman)"
|
||||
default "/fs/microsd"
|
||||
|
||||
config BOARD_FS_ROOT_PATH
|
||||
string "PX4 filesystem root that MAVLink FTP serves"
|
||||
default BOARD_ROOT_PATH
|
||||
help
|
||||
The directory MAVLink FTP treats as its root. Defaults to the storage path,
|
||||
which keeps FTP confined to it. Set it to a parent of the storage path to
|
||||
expose read-only data alongside, as NuttX does by serving / with the SD card
|
||||
mounted under it.
|
||||
|
||||
config BOARD_PARAM_FILE
|
||||
string "Parameter file"
|
||||
default "/fs/mtd_params"
|
||||
|
||||
@@ -64,8 +64,8 @@ then
|
||||
fi
|
||||
|
||||
# Load parameters
|
||||
set PARAM_FILE parameters.bson
|
||||
set PARAM_BACKUP_FILE parameters_backup.bson
|
||||
set PARAM_FILE fs/parameters.bson
|
||||
set PARAM_BACKUP_FILE fs/parameters_backup.bson
|
||||
|
||||
param select $PARAM_FILE
|
||||
if [ -f $PARAM_FILE ]; then
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# Persist flight logs on the host (ulog files):
|
||||
# mkdir -p ./px4-logs
|
||||
# docker run --rm -it --network host \
|
||||
# -v $(pwd)/px4-logs:/root/.local/share/px4/rootfs/log \
|
||||
# -v $(pwd)/px4-logs:/root/.local/share/px4/rootfs/fs/log \
|
||||
# px4io/px4-sitl-gazebo:v1.17.0
|
||||
|
||||
FROM ubuntu:24.04
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# Persist flight logs on the host (ulog files):
|
||||
# mkdir -p ./px4-logs
|
||||
# docker run --rm -it --network host \
|
||||
# -v $(pwd)/px4-logs:/root/.local/share/px4/rootfs/log \
|
||||
# -v $(pwd)/px4-logs:/root/.local/share/px4/rootfs/fs/log \
|
||||
# px4io/px4-sitl:v1.17.0
|
||||
|
||||
FROM ubuntu:24.04
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
CONFIG_PLATFORM_POSIX=y
|
||||
CONFIG_BOARD_TESTING=y
|
||||
CONFIG_BOARD_ETHERNET=y
|
||||
CONFIG_BOARD_ROOT_PATH="."
|
||||
CONFIG_BOARD_ROOT_PATH="./fs"
|
||||
CONFIG_BOARD_FS_ROOT_PATH="."
|
||||
CONFIG_DRIVERS_CAMERA_TRIGGER=y
|
||||
CONFIG_DRIVERS_GPS=y
|
||||
CONFIG_GPS_SPARTN=y
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
CONFIG_BOARD_ETHERNET=y
|
||||
CONFIG_BOARD_ROOT_PATH="."
|
||||
CONFIG_BOARD_ROOT_PATH="./fs"
|
||||
CONFIG_BOARD_FS_ROOT_PATH="."
|
||||
CONFIG_BOARD_TESTING=y
|
||||
CONFIG_COMMON_SIMULATION=y
|
||||
CONFIG_DRIVERS_CAMERA_TRIGGER=y
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
CONFIG_PLATFORM_POSIX=y
|
||||
CONFIG_BOARD_TESTING=y
|
||||
CONFIG_BOARD_ETHERNET=y
|
||||
CONFIG_BOARD_ROOT_PATH="."
|
||||
CONFIG_BOARD_ROOT_PATH="./fs"
|
||||
CONFIG_BOARD_FS_ROOT_PATH="."
|
||||
CONFIG_DRIVERS_CAMERA_TRIGGER=y
|
||||
CONFIG_DRIVERS_GPS=y
|
||||
CONFIG_DRIVERS_GNSS_SEPTENTRIO=y
|
||||
|
||||
@@ -66,7 +66,7 @@ Reasons for this are given below.
|
||||
|
||||
This will automatically open the log file, apply the parameters and start the replay.
|
||||
Once done, it will report the outcome and exit.
|
||||
The newly generated log file can then be analyzed. It can be found in `rootfs/fs/microsd/log`, in subdirectories organised by date.
|
||||
The newly generated log file can then be analyzed. It can be found in `rootfs/fs/log`, in subdirectories organised by date.
|
||||
Replayed log file names will have the `_replayed` suffix.
|
||||
|
||||
Note that the above command will show the simulator as well, but - depending on what is being replayed - it will not show what's actually going on.
|
||||
|
||||
@@ -52,7 +52,7 @@ This allows, for example, logging of your own uORB topics.
|
||||
|
||||
### SD Card Configuration
|
||||
|
||||
The list of logged topics can also be customized with a file on the SD card: `etc/logging/logger_topics.txt` (for SITL, it's `build/px4_sitl_default/rootfs/fs/microsd/etc/logging/logger_topics.txt`).
|
||||
The list of logged topics can also be customized with a file on the SD card: `etc/logging/logger_topics.txt` (for SITL, it's `build/px4_sitl_default/rootfs/etc/logging/logger_topics.txt`).
|
||||
|
||||
Each topic to be logged is listed on a separate line, with the following format:
|
||||
|
||||
|
||||
@@ -279,7 +279,8 @@ PX4_SIM_MODEL=sihsim_quadx px4 -d
|
||||
### Runtime directories (created on first run, per user)
|
||||
|
||||
```sh
|
||||
$XDG_DATA_HOME/px4/rootfs/<instance>/ # parameters, dataman, eeprom
|
||||
$XDG_DATA_HOME/px4/rootfs/<instance>/ # filesystem root
|
||||
$XDG_DATA_HOME/px4/rootfs/<instance>/fs/ # storage: parameters, dataman, logs, eeprom
|
||||
```
|
||||
|
||||
## Building .deb Files Locally
|
||||
|
||||
@@ -97,11 +97,13 @@ __BEGIN_DECLS
|
||||
extern long PX4_TICKS_PER_SEC;
|
||||
__END_DECLS
|
||||
|
||||
#define PX4_ROOTFSDIR CONFIG_BOARD_ROOT_PATH
|
||||
// Kept separate as on NuttX: the root is what MAVLink FTP serves, the storage directory
|
||||
// is the writable part of it (the SD card equivalent).
|
||||
#define PX4_ROOTFSDIR CONFIG_BOARD_FS_ROOT_PATH
|
||||
|
||||
// Qurt doesn't have an SD card for storage
|
||||
#ifndef __PX4_QURT
|
||||
#define PX4_STORAGEDIR PX4_ROOTFSDIR
|
||||
#define PX4_STORAGEDIR CONFIG_BOARD_ROOT_PATH
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -483,11 +483,13 @@ int create_dirs()
|
||||
{
|
||||
std::string current_path = pwd();
|
||||
|
||||
std::vector<std::string> dirs{"log", "eeprom"};
|
||||
// The storage directory holds everything PX4 writes, and is the only part of the
|
||||
// filesystem root that MAVLink FTP is allowed to write to.
|
||||
std::vector<std::string> dirs{PX4_STORAGEDIR, PX4_STORAGEDIR "/log", PX4_STORAGEDIR "/eeprom"};
|
||||
|
||||
for (const auto &dir : dirs) {
|
||||
PX4_DEBUG("mkdir: %s", dir.c_str());;
|
||||
std::string dir_path = current_path + "/" + dir;
|
||||
std::string dir_path = (dir[0] == '/') ? dir : current_path + "/" + dir;
|
||||
|
||||
if (dir_exists(dir_path)) {
|
||||
continue;
|
||||
|
||||
@@ -163,7 +163,7 @@ private:
|
||||
static constexpr int MAX_MISSION_TOPICS_NUM = 5; /**< Maximum number of mission topics */
|
||||
static constexpr unsigned MAX_NO_LOGFILE = 999; /**< Maximum number of log files */
|
||||
static constexpr const char *LOG_ROOT[(int)LogType::Count] = {
|
||||
CONFIG_BOARD_ROOT_PATH "/log",
|
||||
PX4_STORAGEDIR "/log",
|
||||
CONFIG_BOARD_ROOT_PATH "/mission_log"
|
||||
};
|
||||
|
||||
|
||||
@@ -1192,16 +1192,17 @@ bool MavlinkFTP::_validatePath(const char *path)
|
||||
|
||||
bool MavlinkFTP::_validatePathIsWritable(const char *path)
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
|
||||
// Don't allow writes to system paths as they are in RAM
|
||||
// The root can expose read-only data next to the storage directory, so confine writes
|
||||
// to storage. On NuttX that keeps them off the in-RAM system paths; on POSIX it keeps
|
||||
// them out of the ROMFS.
|
||||
// Ideally we'd canonicalize the path (with 'realpath'), but it might not exist, so realpath() would fail.
|
||||
// The next simpler thing is to check there's no reference to a parent dir.
|
||||
if (strncmp(path, CONFIG_BOARD_ROOT_PATH "/", 12) != 0 || strstr(path, "/../") != nullptr) {
|
||||
static constexpr const char storage_prefix[] = PX4_STORAGEDIR "/";
|
||||
|
||||
if (strncmp(path, storage_prefix, sizeof(storage_prefix) - 1) != 0 || strstr(path, "/../") != nullptr) {
|
||||
PX4_ERR("Disallowing write to %s", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ private:
|
||||
// Paths that start with this prefix are mapped to the flight-stack log root.
|
||||
static constexpr const char _mav_log_prefix[] = "@MAV_LOG";
|
||||
static constexpr const int _mav_log_prefix_len = sizeof(_mav_log_prefix) - 1;
|
||||
static constexpr const char _mav_log_dir[] = CONFIG_BOARD_ROOT_PATH "/log";
|
||||
static constexpr const char _mav_log_dir[] = PX4_STORAGEDIR "/log";
|
||||
static constexpr const int _mav_log_dir_len = sizeof(_mav_log_dir) - 1;
|
||||
|
||||
bool _last_reply_valid = false;
|
||||
|
||||
Reference in new issue
Block a user