2024-02-19 16:01:53 +01:00
# pragma once
# include "utils.h"
2024-02-28 17:50:27 +01:00
# include "config.h"
2024-02-19 16:01:53 +01:00
2024-02-28 17:50:27 +01:00
/// @brief The maximum length of a container identifier.
# define MAX_CONTAINER_IDENTIFIER_LENGTH 64
2024-02-19 16:01:53 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Checks whether the specified container identifier is valid. This call returns a failure if the identifier is invalid.
/// @param container The container identifier to check.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-19 16:01:53 +01:00
result_t check_container_identifier ( const char * container ) ;
2024-02-19 20:03:30 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Returns the path of the container pool.
/// @param _path The pointer to where the path should be stored. The caller is responsible for freeing the path.
/// @param config The program configuration to use.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t get_container_pool_path ( char * * _path , const config_t * config ) ;
2024-02-19 16:01:53 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Returns the path of the specified container.
/// @param _path The pointer to where the path should be stored. The caller is responsible for freeing the path.
/// @param config The program configuration to use.
/// @param container The identifier of the container to get the path of.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t get_container_path ( char * * _path , const config_t * config , const char * container ) ;
2024-02-19 20:03:30 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Checks whether the specified container exists. This call returns a failure if the container does not exist.
/// @param config The program configuration to use.
/// @param container The identifier of the container to check.
/// @return Whether the container exists.
result_t check_container_exists ( const config_t * config , const char * container ) ;
2024-02-19 16:01:53 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Adds a new root container to the container pool, with the specified identifier and size.
/// @param config The program configuration to use.
/// @param container The identifier of the container to add.
2024-02-19 20:03:30 +01:00
/// @param size The size of the container to add, in bytes.
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t add_root_container ( const config_t * config , const char * container , uint64_t size ) ;
2024-02-19 20:03:30 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Adds a new backed container to the container pool, with the specified identifier and backing.
/// @param config The program configuration to use.
/// @param container The identifier of the container to add.
/// @param backing The identifier of the backing to use.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t add_backed_container ( const config_t * config , const char * container , const char * backing ) ;
2024-02-19 16:01:53 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Removes the specified container from the container pool.
/// @param config The program configuration to use.
/// @param container The identifier of the container to remove.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t remove_container ( const config_t * config , const char * container ) ;
2024-02-19 20:03:30 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Resets the specified container to its original state.
/// @param config The program configuration to use.
/// @param container The identifier of the container to reset.
2024-02-19 20:03:30 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t reset_container ( const config_t * config , const char * container ) ;
2024-02-19 20:23:26 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Trims the specified container.
/// @param config The program configuration to use.
/// @param container The identifier of the container to trim.
2024-02-19 20:23:26 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t trim_container ( const config_t * config , const char * container ) ;
2024-02-20 14:54:04 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Lists the containers in the container pool, and returns the result in a null-terminated array of strings.
/// @param _containers The pointer to where the containers array should be stored. The caller is responsible for freeing the containers array as well as the strings in the array.
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t list_containers ( char * * * _containers , const config_t * config ) ;
2024-02-20 14:54:04 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Returns the oldest container in the container pool.
/// @param _container The pointer to where the container should be stored. The caller is responsible for freeing the container.
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t get_oldest_container ( char * * _container , const config_t * config ) ;
2024-02-20 14:54:04 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Calculates the total available space in the container pool.
/// @param _size The pointer to where the size should be stored.
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t get_available_space ( uint64_t * _size , const config_t * config ) ;
2024-02-20 14:54:04 +01:00
2024-02-28 17:50:27 +01:00
/// @brief Reserves the specified space in the container pool, by removing the oldest containers.
/// @param config The program configuration to use.
2024-02-20 14:54:04 +01:00
/// @param size The size to reserve, in bytes.
/// @return The result of the operation.
2024-02-28 17:50:27 +01:00
result_t reserve_space ( const config_t * config , uint64_t size ) ;