Skip to content

AP_Filesystem: add @MAV_LOG virtual path for FTP log download#32860

Draft
julianoes wants to merge 1 commit intoArduPilot:masterfrom
julianoes:pr-logs-via-ftp
Draft

AP_Filesystem: add @MAV_LOG virtual path for FTP log download#32860
julianoes wants to merge 1 commit intoArduPilot:masterfrom
julianoes:pr-logs-via-ftp

Conversation

@julianoes
Copy link
Copy Markdown
Contributor

Summary

Exposes the log directory as @MAV_LOG as specified in: github.com/mavlink/mavlink-devguide/pull/668.

Implemented by Claude Code, tested manually by hand against mavlink/qgroundcontrol#14290.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually
  • Tested on hardware
  • Logs attached
  • Logs available on request

Description

This adds a virtual drive mapping from @MAV_LOG to /APM/LOGS.

FYI @peterbarker and @hamishwillee: one important caveat:

When using FTP instead of the LOG_* messages. We don't have functionality to transmit the file date/time (yet) using MAVLink FTP, so the logs are shown without date when listed via FTP. One way is to encode the date/time as part of the filename (which is what PX4 does). Alternatively, we could potentially extend MAVLink FTP to support list directory with date/time though. The latter solution would be the nicer, and specced way of doing things.

Exposes the log directory as @MAV_LOG as specified in:
github.com/mavlink/mavlink-devguide/pull/668.
@tpwrules
Copy link
Copy Markdown
Contributor

Many boards with dataflash do not have logs on a filesystem and need the legacy protocol.

I think we are also faster at the 'legacy' protocol.

Do you plan to remove it from QGC? How does the user know how to choose?

Comment on lines +36 to +53
// rewrite "foo/bar" to "<log_dir>/foo/bar" in the caller-supplied buffer.
// An empty fname resolves to the log directory itself.
// Returns false if the rewrite doesn't fit.
static bool rewrite_path(const char *fname, char *buf, size_t buflen)
{
const char *dir = log_directory();
int n;
if (fname[0] == '\0') {
n = snprintf(buf, buflen, "%s", dir);
} else {
n = snprintf(buf, buflen, "%s/%s", dir, fname);
}
if (n < 0 || size_t(n) >= buflen) {
errno = ENAMETOOLONG;
return false;
}
return true;
}
Copy link
Copy Markdown
Contributor

@tpwrules tpwrules Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered putting this in the MAVFTP handler?

There is only one place to do it then rather than having to re-implement a whole filesystem.

But I guess that would require some funny gymnastics with listing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds easier actually. Should I give it a try?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the spec have any words on whether you are required to return such virtual items in the directory listing? AP already does several others, but none of the official spec items. If there is no requirement to return particular virtual directories when listing the root, this could be a very simple PR indeed.

But if this will hose legacy boards then maybe it's not worth it at all, or we will need the virtual filesystem to map block loggers to FTP. Like I said earlier I think it is slower. Maybe postpone on precise implementation until we work that out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the spec says that, it's all new, so we can still influence how this works.

My take would be that we don't have to list @MAV_LOG in root, because we already have /APM/LOGS (or /logs for PX4), so @MAV_LOG is only for GCSs that already know that @MAV_LOG could/should exist.

What do you think @hamishwillee?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you say @julianoes this is still open to discussion. The important thing for me here is that we have a compatible and documented interface.

I agree that we don't have to list @MAV_LOG - it's a directory alias so the actual directory is already listed. What do we think the benefit might be in doing so? I was thinking perhaps "to test if the feature is supported", but you might as well just try read the alias.


As an aside, should we make it explicit in the docs that you can't create a directory @Whatever using MAVFTP. My thinking is that we want to reserve potential aliases. Perhaps overthinking it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants