From 7d826ccb99205a629fed84aa3ece6db807cfbac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexe=C3=AF=20KADIR?= Date: Thu, 15 Feb 2024 00:34:48 +0100 Subject: [PATCH] Added some more unimplemented functions --- src/backing.c | 7 ++++++- src/backing.h | 5 +++++ src/disk.h | 6 ++++++ src/entry.h | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/backing.c b/src/backing.c index 88f9eca..91e884f 100644 --- a/src/backing.c +++ b/src/backing.c @@ -63,4 +63,9 @@ bool backing_exists(const char* backing) { return false; return true; -} \ No newline at end of file +} + +uint64_t get_backing_creation_time(const char* backing) { + // A valid backing name is a number, corresponding to the timestamp of the backing disk creation + return strtoull(backing, NULL, 10); +} diff --git a/src/backing.h b/src/backing.h index 97fcf98..e698774 100644 --- a/src/backing.h +++ b/src/backing.h @@ -26,6 +26,11 @@ bool backing_exists(const char* backing); /// @return The list of backing disks. The caller is responsible for freeing the returned array and strings. This function can return NULL. char** list_backings(void); +/// @brief Get the creation time of the specified backing disk. +/// @param backing The valid backing disk name. +/// @return The creation time of the specified backing disk. If the backing disk does not exist, this function returns 0. +uint64_t get_backing_creation_time(const char* backing); + /// @brief Finds the latest backing disk. /// @return The latest backing disk. The caller is responsible for freeing the returned string. This function can return NULL. char* find_latest_backing(void); diff --git a/src/disk.h b/src/disk.h index 5d0e207..65ef452 100644 --- a/src/disk.h +++ b/src/disk.h @@ -20,6 +20,12 @@ bool create_backed_disk(const char* disk, const char* backing); /// @return true if the disk is packed, otherwise false. bool pack_disk(const char* disk); +/// @brief Moves the backing file of a disk. +/// @param disk The path to the disk, which exists. +/// @param backing The path to the new backing file, which exists. +/// @return true if the backing file is moved, otherwise false. +bool move_backing_file(const char* disk, const char* backing); + /// @brief Gets the backing file of a disk. /// @param disk The path to the disk, which exists. /// @return The backing file of the disk. The caller is responsible for freeing the returned string. This function can return NULL. diff --git a/src/entry.h b/src/entry.h index c5666c4..a0f4f48 100644 --- a/src/entry.h +++ b/src/entry.h @@ -26,6 +26,11 @@ bool entry_exists(const char* entry); /// @return The list of entries. The caller is responsible for freeing the returned array and strings. This function can return NULL. char** list_entries(void); +/// @brief Get the last access time of the specified entry. +/// @param entry The valid entry name, which must exist. +/// @return The last access time of the specified entry. If the entry does not exist, this function returns 0. +uint64_t get_entry_last_access(const char* entry); + /// @brief Finds the oldest entry (based on last access time). /// @return The oldest entry. The caller is responsible for freeing the returned string. This function can return NULL. char* find_oldest_entry(void); @@ -39,3 +44,17 @@ bool create_entry(const char* entry); /// @param entry The valid entry name. /// @return true if the entry was deleted, otherwise false. bool delete_entry(const char* entry); + +/// @brief Updates the last access time of the specified entry. +/// @param entry The valid entry name, which must exist. +/// @return true if the last access time was updated, otherwise false. +bool update_entry_last_access(const char* entry); + +/// @brief Returns the available space in the entries directory. +/// @return The available space in the entries directory. If the entries directory does not exist, this function returns 0. +uint64_t get_available_space(void); + +/// @brief Reserves the specified space in the entries directory, by deleting the oldest entries. +/// @param space The space to reserve, in bytes. +/// @return true if the space was fully reserved, otherwise false. +bool reserve_space(uint64_t space);