Skip to content

Commit

Permalink
AP_Filesystem: 9P2000: add set_mtime
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed Jan 1, 2025
1 parent 6f31c83 commit ae3f242
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions libraries/AP_Filesystem/AP_Filesystem_9P2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ae3f242

Please sign in to comment.