From ecb9a595cacb1976486368d4ed7ed5879bde813e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexe=C3=AF=20KADIR?= Date: Thu, 15 Feb 2024 00:40:47 +0100 Subject: [PATCH] Implemented size measures --- src/entry.c | 19 +++++++++++++++++++ src/sandbox.c | 1 + 2 files changed, 20 insertions(+) diff --git a/src/entry.c b/src/entry.c index 3b49cde..0c20bbf 100644 --- a/src/entry.c +++ b/src/entry.c @@ -8,6 +8,7 @@ #include #include #include +#include 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; +} diff --git a/src/sandbox.c b/src/sandbox.c index c82bea0..027de13 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -12,4 +12,5 @@ #include int main(int argc, char* argv[]) { + log_msg(LOG_INFO, "Available space : %lld", get_available_space()); } \ No newline at end of file