From ae3f242e1f962bfe8477d41f2077c4797e2103b0 Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Wed, 1 Jan 2025 00:03:11 +0000 Subject: [PATCH] AP_Filesystem: 9P2000: add set_mtime --- .../AP_Filesystem/AP_Filesystem_9P2000.cpp | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Filesystem/AP_Filesystem_9P2000.cpp b/libraries/AP_Filesystem/AP_Filesystem_9P2000.cpp index d4f4cf280bb42a..a1939df69f2954 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_9P2000.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_9P2000.cpp @@ -630,13 +630,47 @@ int AP_Filesystem_9P2000::rename(const char *oldpath, const char *newpath) fs.free_file_id(fid); - return fs.rename_result(tag) ? 0 : -1; + return fs.stat_update_result(tag) ? 0 : -1; } // set modification time on a file bool AP_Filesystem_9P2000::set_mtime(const char *filename, const uint32_t mtime_sec) { - return false; + if (hal.scheduler->in_main_thread()) { + // Too slow for the main thread + errno = MAIN_THREAD_ERROR; + return false; + } + + // Make sure filesystem is mounted. + AP_Networking::NineP2000& fs = AP::network().get_filesystem(); + if (!fs.mounted()) { + errno = ENODEV; + return false; + } + + // Navigate to the given path + const uint32_t fid = get_file_id(fs, filename, AP_Networking::NineP2000::walkType::Any); + if (fid == 0) { + errno = ENOENT; + return false; + } + + // Request update, pass new time + const uint16_t tag = fs.request_set_mtime(fid, mtime_sec); + if (tag == fs.NOTAG) { + return -1; + } + + // Wait for the reply + if (!wait_for_tag(fs, tag)) { + fs.free_file_id(fid); + return -1; + } + + fs.free_file_id(fid); + + return fs.stat_update_result(tag); } #endif // AP_FILESYSTEM_P92000_ENABLED