diff --git a/firmware/application/file.cpp b/firmware/application/file.cpp index 18e75005..7c73a729 100644 --- a/firmware/application/file.cpp +++ b/firmware/application/file.cpp @@ -164,5 +164,23 @@ bool is_regular_file(const file_status s) { return !(s & AM_DIR); } +space_info space(const path& p) { + DWORD free_clusters { 0 }; + FATFS* fs; + if( f_getfree(p.c_str(), &free_clusters, &fs) == FR_OK ) { +#if _MAX_SS != _MIN_SS + static_assert(false, "FatFs not configured for fixed sector size"); +#else + return { + (fs->n_fatent - 2) * fs->csize * _MIN_SS, + free_clusters * fs->csize * _MIN_SS, + free_clusters * fs->csize * _MIN_SS, + }; +#endif + } else { + return { 0, 0, 0 }; + } +} + } /* namespace filesystem */ } /* namespace std */ diff --git a/firmware/application/file.hpp b/firmware/application/file.hpp index 6be0f9dd..fde40db2 100644 --- a/firmware/application/file.hpp +++ b/firmware/application/file.hpp @@ -25,6 +25,7 @@ #include "ff.h" #include +#include #include #include #include @@ -75,8 +76,17 @@ std::string next_filename_stem_matching_pattern(const std::string& filename_stem namespace std { namespace filesystem { +using path = std::string; using file_status = BYTE; +struct space_info { + static_assert(sizeof(std::uintmax_t) >= 8, "std::uintmax_t too small (