From 10fe08e2242df638965c21d64053724ccfdd1051 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 6 Jul 2024 09:42:28 +1000 Subject: [PATCH 1/2] GCS_MAVLINK: cope with dirent not having dtype --- libraries/GCS_MAVLink/GCS_FTP.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libraries/GCS_MAVLink/GCS_FTP.cpp b/libraries/GCS_MAVLink/GCS_FTP.cpp index e3e6509579810..488d67e691319 100644 --- a/libraries/GCS_MAVLink/GCS_FTP.cpp +++ b/libraries/GCS_MAVLink/GCS_FTP.cpp @@ -588,16 +588,23 @@ void GCS_MAVLINK::ftp_worker(void) { // calculates how much string length is needed to fit this in a list response int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const struct dirent * entry) { +#if AP_FILESYSTEM_HAVE_DIRENT_DTYPE const bool is_file = entry->d_type == DT_REG || entry->d_type == DT_LNK; +#else + // assume true initially, then handle below + const bool is_file = true; +#endif if (space < 3) { return -1; } dest[0] = 0; +#if AP_FILESYSTEM_HAVE_DIRENT_DTYPE if (!is_file && entry->d_type != DT_DIR) { return -1; // this just forces it so we can't send this back, it's easier then sending skips to a GCS } +#endif if (is_file) { #ifdef MAX_NAME_LEN @@ -612,6 +619,12 @@ int GCS_MAVLINK::gen_dir_entry(char *dest, size_t space, const char *path, const if (AP::FS().stat(full_path, &st)) { return -1; } + +#if !AP_FILESYSTEM_HAVE_DIRENT_DTYPE + if (S_ISDIR(st.st_mode)) { + return hal.util->snprintf(dest, space, "D%s%c", entry->d_name, (char)0); + } +#endif return hal.util->snprintf(dest, space, "F%s\t%u%c", entry->d_name, (unsigned)st.st_size, (char)0); } else { return hal.util->snprintf(dest, space, "D%s%c", entry->d_name, (char)0); From 94b29145eaa3e74e4601b21ef428289a95629c1c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 Jul 2024 11:58:42 +1000 Subject: [PATCH 2/2] AP_Filesystem: allow for filesystem with no dtype --- libraries/AP_Filesystem/AP_Filesystem_config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/AP_Filesystem/AP_Filesystem_config.h b/libraries/AP_Filesystem/AP_Filesystem_config.h index a184051610cc4..e96b33d105920 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_config.h +++ b/libraries/AP_Filesystem/AP_Filesystem_config.h @@ -53,3 +53,7 @@ #ifndef AP_FILESYSTEM_SYS_FLASH_ENABLED #define AP_FILESYSTEM_SYS_FLASH_ENABLED CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS #endif + +#ifndef AP_FILESYSTEM_HAVE_DIRENT_DTYPE +#define AP_FILESYSTEM_HAVE_DIRENT_DTYPE 1 +#endif