Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for filesystem with no dtype #27512

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libraries/AP_Filesystem/AP_Filesystem_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions libraries/GCS_MAVLink/GCS_FTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Loading