mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
MAVFTP defines @MAV_LOG as the flight-stack-independent location for log files, so that a GCS can find them without being told where a particular board keeps them. QGroundControl asks for it before anything else, and falls back to guessing per-firmware paths when it is not there. It is an alias rather than a filesystem of its own: the backend table gains a root, and where a row carries one the resolver rewrites a path under that prefix to sit under that directory before handing it to the filesystem which serves it. @MAV_LOG points at the local filesystem, under whatever directory this board logs to, following a custom log directory the same way AP_Logger_File does. The rewritten path has to hold the root as well as the path, so the buffer is sized for the longest path an FTP listing stats - the longest path a request can carry, a separator and a 255 byte name - underneath the longest log directory a board has, and a static_assert holds boards to that. A path too long to rewrite is refused with ENAMETOOLONG before any filesystem sees it, rather than being truncated into the name of some other file. That buffer is not on the stack, where every path-based call would pay for it. It is allocated the first time an alias is used and kept, and a semaphore is held around each backend call which uses it. rename, the one call with two paths alive at once, allocates a second buffer for its new path and frees it afterwards. Paths which are not aliases take neither the semaphore nor a buffer. An alias can't sit on LittleFS for now, and @MAV_LOG is not built where LittleFS is the local filesystem; forcing it on is a build error. LittleFS holds its lock from opendir() to closedir(), so the semaphore, held across each call, would be released before that lock, which ChibiOS mutexes do not allow, and a thread listing an alias directory would wait for the semaphore while holding the lock another thread holding the semaphore could be waiting for. rename now compares the filesystems which serve its two paths rather than their table rows, since an alias shares its filesystem with other paths, and sets EXDEV when they differ. A prefix now has to be the whole of a path's first component, so that "@MAV_LOG_backup" is not served as "_backup" under the log directory. This is not particular to the alias: "@SYSfoo" used to be served by @SYS as "foo", and is now the local file of that name. Nothing in the tree relied on the old behaviour. @MAV_LOG, and the alias support with it, is only built where the logs go to a filesystem at all.
83 lines
3.2 KiB
C
83 lines
3.2 KiB
C
#pragma once
|
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
|
|
|
// backends:
|
|
|
|
#ifndef AP_FILESYSTEM_ESP32_ENABLED
|
|
#define AP_FILESYSTEM_ESP32_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_ESP32)
|
|
#endif
|
|
|
|
#ifndef AP_FILESYSTEM_FATFS_ENABLED
|
|
#define AP_FILESYSTEM_FATFS_ENABLED HAL_OS_FATFS_IO
|
|
#endif
|
|
|
|
#ifndef AP_FILESYSTEM_LITTLEFS_ENABLED
|
|
#define AP_FILESYSTEM_LITTLEFS_ENABLED HAL_OS_LITTLEFS_IO
|
|
#endif
|
|
|
|
#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 || CONFIG_HAL_BOARD == HAL_BOARD_QURT)
|
|
#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_WRITING_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_LITTLEFS_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 || AP_FILESYSTEM_SYS_ENABLED || AP_FILESYSTEM_PARAM_ENABLED)
|
|
#endif
|
|
|
|
#ifndef AP_FILESYSTEM_SYS_FLASH_ENABLED
|
|
#define AP_FILESYSTEM_SYS_FLASH_ENABLED CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
|
|
#endif
|
|
|
|
#ifndef AP_FILESYSTEM_MISSION_ENABLED
|
|
#include <AP_Mission/AP_Mission_config.h>
|
|
#define AP_FILESYSTEM_MISSION_ENABLED AP_MISSION_ENABLED
|
|
#endif
|
|
|
|
// true when AP_Filesystem.cpp picks LittleFS as the local filesystem. an
|
|
// alias can't sit on it; see AP_Filesystem.cpp
|
|
#define AP_FILESYSTEM_LOCAL_IS_LITTLEFS (AP_FILESYSTEM_LITTLEFS_ENABLED && !AP_FILESYSTEM_FATFS_ENABLED && !AP_FILESYSTEM_ESP32_ENABLED)
|
|
|
|
// @MAV_LOG is an alias for the directory this board writes its logs to,
|
|
// where those logs are written to a filesystem
|
|
#ifndef AP_FILESYSTEM_MAVLOG_ENABLED
|
|
#define AP_FILESYSTEM_MAVLOG_ENABLED (AP_FILESYSTEM_FILE_WRITING_ENABLED && !AP_FILESYSTEM_LOCAL_IS_LITTLEFS && defined(HAL_BOARD_LOG_DIRECTORY) && HAL_LOGGING_FILESYSTEM_ENABLED)
|
|
#endif // AP_FILESYSTEM_MAVLOG_ENABLED
|
|
|
|
// only @MAV_LOG uses the alias support
|
|
#ifndef AP_FILESYSTEM_ALIAS_ENABLED
|
|
#define AP_FILESYSTEM_ALIAS_ENABLED AP_FILESYSTEM_MAVLOG_ENABLED
|
|
#endif // AP_FILESYSTEM_ALIAS_ENABLED
|
|
|
|
// longest alias path: root + '/' + 238 byte FTP request + '/' + 255 byte name
|
|
#ifndef AP_FILESYSTEM_ALIAS_PATH_MAX
|
|
#define AP_FILESYSTEM_ALIAS_PATH_MAX 544
|
|
#endif // AP_FILESYSTEM_ALIAS_PATH_MAX
|
|
|
|
// last, for HAL_LOGGING_FILESYSTEM_ENABLED: AP_Logger_config.h includes this
|
|
// header, so nothing above may test that value, only name it
|
|
#include <AP_Logger/AP_Logger_config.h>
|