Implemented size measures

This commit is contained in:
Alexei KADIR 2024-02-15 00:40:47 +01:00
parent ee79d7c87d
commit ecb9a595ca
2 changed files with 20 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
char* get_entries_path(void) {
return format("%s/%s", MASTER_DIRECTORY, ENTRIES_DIRECTORY);
@ -68,3 +69,21 @@ bool entry_exists(const char* entry) {
return true;
}
uint64_t get_available_space(void) {
char* entries_path = get_entries_path();
if (entries_path == NULL)
return 0;
// Get the available space in the entries directory
struct statvfs statbuf;
int result = statvfs(entries_path, &statbuf);
// Free the entries path
free(entries_path);
if (result != 0)
return -1;
return statbuf.f_bsize * statbuf.f_bavail;
}

View File

@ -12,4 +12,5 @@
#include <libgen.h>
int main(int argc, char* argv[]) {
log_msg(LOG_INFO, "Available space : %lld", get_available_space());
}