Implement std::filesystem::space().

This commit is contained in:
Jared Boone 2016-05-11 10:58:57 -07:00
parent c48a88539a
commit f157c13442
2 changed files with 30 additions and 0 deletions

View File

@ -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 */

View File

@ -25,6 +25,7 @@
#include "ff.h"
#include <cstddef>
#include <cstdint>
#include <string>
#include <array>
#include <memory>
@ -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 (<uint64_t)");
std::uintmax_t capacity;
std::uintmax_t free;
std::uintmax_t available;
};
struct directory_entry : public FILINFO {
file_status status() const {
return fattrib;
@ -126,6 +136,8 @@ inline bool operator!=(const directory_iterator& lhs, const directory_iterator&
bool is_regular_file(const file_status s);
space_info space(const path& p);
} /* namespace filesystem */
} /* namespace std */