Commit Graph
16 Commits
Author SHA1 Message Date
Peter Barker 5fac29cd7f AP_Filesystem: give a ROMFS directory record back when opendir fails
opendir() took one of the four directory records, and kept it when the
directory turned out not to exist. Four such attempts left every later
ROMFS opendir() failing with ENFILE until a reboot; over MAVFTP, four
listings of a missing @ROMFS path were enough. It also returned without
setting errno.

Free the record and set ENOENT.
2026-09-24 18:35:09 +10:00
Peter Barker af04ad7253 AP_Filesystem: keep a ROMFS directory's terminator within d_name
readdir() ends a directory's name by writing a terminator at the
directory separator's index, which is past the end of d_name for a
directory name that long. Only shorten the name to the directory where
that falls within the name as copied.
2026-09-24 18:35:09 +10:00
Peter BarkerandDavid Buzz 55ed85764b AP_Filesystem: always terminate a ROMFS directory entry's name
readdir() copied the name with strncpy(), which leaves it unterminated
when it fills d_name, so anything reading it as a string - GCS_FTP's
listing among them - could run off the end of it.

Truncate to leave room for the terminator, as the FATFS backend does.

Co-authored-by: David Buzz <davidbuzz@gmail.com>
2026-09-24 18:35:09 +10:00
Thomas Watson 63afcae8a7 AP_Filesystem: ROMFS: fix open race conditions
Lua opens scripts to load them into memory, then the logger opens them
after to stream them into the dataflash log. When loading multiple large
Lua scripts from ROMFS, decompression takes a significant amount of
time. This creates the opportunity for the Lua interpreter and logging
threads to both be inside `AP_Filesystem_ROMFS::open()` decompressing a
file.

If this happens, the function can return the same `fd` for two different
calls as the `fd` is chosen before decompression starts, but only marked
as being used after that finishes. The read pointers then stomp on each
other, so Lua loads garbled scripts (usually resulting in a syntax
error) and the logger dumps garbled data.

Fix the issue by locking before searching for a free record (or marking
a record as free). Apply the same fix to directories as well. This
doesn't protect against using the same `fd`/`dirp` from multiple
threads, but that behavior is to be discouraged anyway and is not the
root cause here.
2025-02-01 16:51:49 +11:00
Andrew Tridgell f8ce4183b8 AP_Filesystem: support QURT with posix filesystem
some features disabled
2024-07-12 15:56:48 +10:00
Andrew Tridgell a241b13f45 AP_Filesystem: use NEW_NOTHROW for new(std::nothrow) 2024-06-04 09:20:21 +10:00
Thomas Watson 0ca37387be AP_Filesystem: guarantee load_file() data is null-terminated
Improves safety of use and clarity of users. Termination is not
included in the reported size to avoid changing user behavior or
misrepresenting the file contents.
2024-05-04 10:15:44 +10:00
Andrew Tridgell 8763084a9e AP_Filesystem: avoid decompressing in directory listing
this makes ROMFS much more efficient
2024-03-19 19:49:47 +11:00
Iampete1 93d8de2834 AP_Filesystem: support full direcotry listing in ROMFS 2024-02-22 07:43:16 +11:00
Peter Barker b5165b6d7f AP_FileSystem: add AP_FILESYSTEM_*_ENABLED 2022-09-15 10:53:02 +10:00
Willian Galvani 0e62d561d9 AP_Filesystem: add allow_absolute_paths to open(), implement it for posix backend 2022-03-22 10:19:21 +11:00
Andrew Tridgell 773517a473 AP_Filesystem: added load_file() API
this makes it very easy to load a small file from sdcard or ROMFS
2020-11-18 09:11:36 +11:00
Peter Barker f43e48a6f1 AP_Filesystem: correct comparison of signed/unsigned
Closes #14267
2020-05-04 12:06:30 +10:00
Andrew Tridgell 9b14fa7ed9 AP_Filesystem: enable @PARAM, @ROMFS and @SYS with no microSD 2020-04-29 07:36:55 +10:00
Andrew Tridgell a8f7212d79 AP_Filesystem: fixed open for write in ROMFS 2020-03-28 15:28:03 +11:00
Andrew Tridgell 6583f7c13e AP_Filesystem: added VFS system for multiple backends 2020-03-28 15:28:03 +11:00