mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-06 19:00:27 +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.