mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_Filesystem: support full direcotry listing in ROMFS
This commit is contained in:
parent
e01e697343
commit
93d8de2834
@ -64,6 +64,7 @@ const AP_Filesystem::Backend AP_Filesystem::backends[] = {
|
|||||||
{ nullptr, fs_local },
|
{ nullptr, fs_local },
|
||||||
#if AP_FILESYSTEM_ROMFS_ENABLED
|
#if AP_FILESYSTEM_ROMFS_ENABLED
|
||||||
{ "@ROMFS/", fs_romfs },
|
{ "@ROMFS/", fs_romfs },
|
||||||
|
{ "@ROMFS", fs_romfs },
|
||||||
#endif
|
#endif
|
||||||
#if AP_FILESYSTEM_PARAM_ENABLED
|
#if AP_FILESYSTEM_PARAM_ENABLED
|
||||||
{ "@PARAM/", fs_param },
|
{ "@PARAM/", fs_param },
|
||||||
|
@ -159,6 +159,15 @@ void *AP_Filesystem_ROMFS::opendir(const char *pathname)
|
|||||||
if (!dir[idx].path) {
|
if (!dir[idx].path) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Take a sneak peek and reset
|
||||||
|
const char *name = AP_ROMFS::dir_list(dir[idx].path, dir[idx].ofs);
|
||||||
|
dir[idx].ofs = 0;
|
||||||
|
if (!name) {
|
||||||
|
// Directory does not exist
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return (void*)&dir[idx];
|
return (void*)&dir[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,12 +183,28 @@ struct dirent *AP_Filesystem_ROMFS::readdir(void *dirp)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const uint32_t plen = strlen(dir[idx].path);
|
const uint32_t plen = strlen(dir[idx].path);
|
||||||
if (strncmp(name, dir[idx].path, plen) != 0 || name[plen] != '/') {
|
if (plen > 0) {
|
||||||
return nullptr;
|
// Offset to get just file/directory name
|
||||||
|
name += plen + 1;
|
||||||
}
|
}
|
||||||
name += plen + 1;
|
|
||||||
dir[idx].de.d_type = DT_REG;
|
// Copy full name
|
||||||
strncpy(dir[idx].de.d_name, name, sizeof(dir[idx].de.d_name));
|
strncpy(dir[idx].de.d_name, name, sizeof(dir[idx].de.d_name));
|
||||||
|
|
||||||
|
const char* slash = strchr(name, '/');
|
||||||
|
if (slash == nullptr) {
|
||||||
|
// File
|
||||||
|
dir[idx].de.d_type = DT_REG;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Directory
|
||||||
|
dir[idx].de.d_type = DT_DIR;
|
||||||
|
|
||||||
|
// Add null termination after directory name
|
||||||
|
const size_t index = slash - name;
|
||||||
|
dir[idx].de.d_name[index] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return &dir[idx].de;
|
return &dir[idx].de;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user